Skip to content

Commit 21c3b5b

Browse files
authored
fix: TT-483 consume new endpoint from be v2 (#786)
1 parent eadd183 commit 21c3b5b

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

src/app/modules/users/components/users-list/users-list.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<td class="col-3 text-center">
2121
<ui-switch
2222
size="small"
23-
(change)="switchGroup('time-tracker-admin', user); updateRole(ROLES.admin, user, $event);"
23+
(change)="!isDevelopment?switchGroup('time-tracker-admin', user):null; updateRole(ROLES.admin, user, $event);"
2424
[checked]="user.groups.includes('time-tracker-admin')"></ui-switch>
2525
admin
2626
<span *ngIf="!isDevelopment">

src/app/modules/users/services/users.service.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,47 @@ describe('UsersService', () => {
3535
it('grant role to a User', () => {
3636
const userId = 'userId';
3737
const roleId = 'admin';
38+
service.isProduction = true;
3839

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

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

46+
it('grant role to a User locally', () => {
47+
const userId = 'userId';
48+
const roleId = 'admin';
49+
service.isProduction = false;
50+
51+
service.grantRole(userId, roleId).subscribe();
52+
53+
const grantRoleRequest = httpMock.expectOne(`${service.baseUrl}/${userId}/${roleId}/grant`);
54+
expect(grantRoleRequest.request.method).toBe('POST');
55+
});
56+
4557
it('revoke role to a User', () => {
4658
const userId = 'userId';
4759
const roleId = 'admin';
60+
service.isProduction = true;
4861

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

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

68+
it('revoke role to a User locally', () => {
69+
const userId = 'userId';
70+
const roleId = 'admin';
71+
service.isProduction = false;
72+
73+
service.revokeRole(userId, roleId).subscribe();
74+
75+
const grantRoleRequest = httpMock.expectOne(`${service.baseUrl}/${userId}/${roleId}/revoke`);
76+
expect(grantRoleRequest.request.method).toBe('POST');
77+
});
78+
5579
it('add user to group', () => {
5680
const userId = 'userId';
5781
const group = 'admin';

src/app/modules/users/services/users.service.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { environment } from './../../../../environments/environment';
77
providedIn: 'root',
88
})
99
export class UsersService {
10+
isProduction = environment.production;
1011
constructor(private http: HttpClient) {}
1112

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

1819
grantRole(userId: string, roleId: string): Observable<any> {
19-
const url = `${this.baseUrl}/${userId}/roles/${roleId}/grant`;
20+
const url = this.isProduction ? `${this.baseUrl}/${userId}/roles/${roleId}/grant`
21+
: `${this.baseUrl}/${userId}/${roleId}/grant`;
2022
return this.http.post(url, null);
2123
}
2224

2325
revokeRole(userId: string, roleId: string): Observable<any> {
24-
const url = `${this.baseUrl}/${userId}/roles/${roleId}/revoke`;
26+
const url = this.isProduction ? `${this.baseUrl}/${userId}/roles/${roleId}/revoke`
27+
: `${this.baseUrl}/${userId}/${roleId}/revoke`;
2528
return this.http.post(url, null);
2629
}
2730

0 commit comments

Comments
 (0)