File tree Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,13 @@ export interface User {
22 name : string ;
33 email : string ;
44 roles ?: string [ ] ;
5+ groups ?: string [ ] ;
56 id : string ;
67 tenant_id ?: string ;
78 deleted ?: string ;
89}
10+
11+ export interface UserState extends User {
12+ isLoading : boolean ;
13+ error : string ;
14+ }
Original file line number Diff line number Diff line change @@ -51,4 +51,24 @@ describe('UsersService', () => {
5151 const grantRoleRequest = httpMock . expectOne ( `${ service . baseUrl } /${ userId } /roles/${ roleId } /revoke` ) ;
5252 expect ( grantRoleRequest . request . method ) . toBe ( 'POST' ) ;
5353 } ) ;
54+
55+ it ( 'add group to a User' , ( ) => {
56+ const userId = 'userId' ;
57+ const group = 'admin' ;
58+ const addGroupURL = `${ service . baseUrl } /${ userId } /groups/add` ;
59+
60+ service . addGroupToUser ( userId , group ) . subscribe ( ) ;
61+
62+ expect ( httpMock . expectOne ( addGroupURL ) . request . method ) . toBe ( 'POST' ) ;
63+ } ) ;
64+
65+ it ( 'remove group to a User' , ( ) => {
66+ const userId = 'userId' ;
67+ const group = 'admin' ;
68+ const removeGroupURL = `${ service . baseUrl } /${ userId } /groups/remove` ;
69+
70+ service . removeGroupToUser ( userId , group ) . subscribe ( ) ;
71+
72+ expect ( httpMock . expectOne ( removeGroupURL ) . request . method ) . toBe ( 'POST' ) ;
73+ } ) ;
5474} ) ;
Original file line number Diff line number Diff line change 11import { HttpClient } from '@angular/common/http' ;
22import { Injectable } from '@angular/core' ;
33import { Observable } from 'rxjs' ;
4+ import { User } from '../models/users' ;
45import { environment } from './../../../../environments/environment' ;
56@Injectable ( {
67 providedIn : 'root' ,
@@ -23,4 +24,16 @@ export class UsersService {
2324 const url = `${ this . baseUrl } /${ userId } /roles/${ roleId } /revoke` ;
2425 return this . http . post ( url , null ) ;
2526 }
27+
28+ addGroupToUser ( userId : string , group : string ) : Observable < User > {
29+ return this . http . post < User > ( `${ this . baseUrl } /${ userId } /groups/add` , {
30+ group_name : group ,
31+ } ) ;
32+ }
33+
34+ removeGroupToUser ( userId : string , group : string ) : Observable < User > {
35+ return this . http . post < User > ( `${ this . baseUrl } /${ userId } /groups/remove` , {
36+ group_name : group ,
37+ } ) ;
38+ }
2639}
You can’t perform that action at this time.
0 commit comments