Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<td class="col-3 text-center">
<ui-switch
size="small"
(change)="switchGroup('time-tracker-admin', user); updateRole(ROLES.admin, user, $event);"
(change)="!isDevelopment?switchGroup('time-tracker-admin', user):null; updateRole(ROLES.admin, user, $event);"
[checked]="user.groups.includes('time-tracker-admin')"></ui-switch>
admin
<span *ngIf="!isDevelopment">
Expand Down
24 changes: 24 additions & 0 deletions src/app/modules/users/services/users.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,47 @@ describe('UsersService', () => {
it('grant role to a User', () => {
const userId = 'userId';
const roleId = 'admin';
service.isProduction = true;

service.grantRole(userId, roleId).subscribe();

const grantRoleRequest = httpMock.expectOne(`${service.baseUrl}/${userId}/roles/${roleId}/grant`);
expect(grantRoleRequest.request.method).toBe('POST');
});

it('grant role to a User locally', () => {
const userId = 'userId';
const roleId = 'admin';
service.isProduction = false;

service.grantRole(userId, roleId).subscribe();

const grantRoleRequest = httpMock.expectOne(`${service.baseUrl}/${userId}/${roleId}/grant`);
expect(grantRoleRequest.request.method).toBe('POST');
});

it('revoke role to a User', () => {
const userId = 'userId';
const roleId = 'admin';
service.isProduction = true;

service.revokeRole(userId, roleId).subscribe();

const grantRoleRequest = httpMock.expectOne(`${service.baseUrl}/${userId}/roles/${roleId}/revoke`);
expect(grantRoleRequest.request.method).toBe('POST');
});

it('revoke role to a User locally', () => {
const userId = 'userId';
const roleId = 'admin';
service.isProduction = false;

service.revokeRole(userId, roleId).subscribe();

const grantRoleRequest = httpMock.expectOne(`${service.baseUrl}/${userId}/${roleId}/revoke`);
expect(grantRoleRequest.request.method).toBe('POST');
});

it('add user to group', () => {
const userId = 'userId';
const group = 'admin';
Expand Down
7 changes: 5 additions & 2 deletions src/app/modules/users/services/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { environment } from './../../../../environments/environment';
providedIn: 'root',
})
export class UsersService {
isProduction = environment.production;
constructor(private http: HttpClient) {}

baseUrl = `${environment.timeTrackerApiUrl}/users`;
Expand All @@ -16,12 +17,14 @@ export class UsersService {
}

grantRole(userId: string, roleId: string): Observable<any> {
const url = `${this.baseUrl}/${userId}/roles/${roleId}/grant`;
const url = this.isProduction ? `${this.baseUrl}/${userId}/roles/${roleId}/grant`
: `${this.baseUrl}/${userId}/${roleId}/grant`;
return this.http.post(url, null);
}

revokeRole(userId: string, roleId: string): Observable<any> {
const url = `${this.baseUrl}/${userId}/roles/${roleId}/revoke`;
const url = this.isProduction ? `${this.baseUrl}/${userId}/roles/${roleId}/revoke`
: `${this.baseUrl}/${userId}/${roleId}/revoke`;
return this.http.post(url, null);
}

Expand Down