Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: TT-188 add & remove groups to user service
  • Loading branch information
thegreatyamori committed Mar 24, 2021
commit d9fd3d68f4a554e38b8fc20c6dfb56be41be95a8
6 changes: 6 additions & 0 deletions src/app/modules/users/models/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ export interface User {
name: string;
email: string;
roles?: string[];
groups?: string[];
id: string;
tenant_id?: string;
deleted?: string;
}

export interface UserState extends User {
isLoading: boolean;
error: string;
}
20 changes: 20 additions & 0 deletions src/app/modules/users/services/users.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,24 @@ describe('UsersService', () => {
const grantRoleRequest = httpMock.expectOne(`${service.baseUrl}/${userId}/roles/${roleId}/revoke`);
expect(grantRoleRequest.request.method).toBe('POST');
});

it('add group to a User', () => {
const userId = 'userId';
const group = 'admin';
const addGroupURL = `${service.baseUrl}/${userId}/groups/add`;

service.addGroupToUser(userId, group).subscribe();

expect(httpMock.expectOne(addGroupURL).request.method).toBe('POST');
});

it('remove group to a User', () => {
const userId = 'userId';
const group = 'admin';
const removeGroupURL = `${service.baseUrl}/${userId}/groups/remove`;

service.removeGroupToUser(userId, group).subscribe();

expect(httpMock.expectOne(removeGroupURL).request.method).toBe('POST');
});
});
13 changes: 13 additions & 0 deletions src/app/modules/users/services/users.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { User } from '../models/users';
import { environment } from './../../../../environments/environment';
@Injectable({
providedIn: 'root',
Expand All @@ -23,4 +24,16 @@ export class UsersService {
const url = `${this.baseUrl}/${userId}/roles/${roleId}/revoke`;
return this.http.post(url, null);
}

addGroupToUser(userId: string, group: string): Observable<User> {
return this.http.post<User>(`${this.baseUrl}/${userId}/groups/add`, {
group_name: group,
});
}

removeGroupToUser(userId: string, group: string): Observable<User> {
return this.http.post<User>(`${this.baseUrl}/${userId}/groups/remove`, {
group_name: group,
});
}
}