Skip to content

Commit a50563b

Browse files
authored
NOBUG: Re-implement common constants (#557)
* NOBUG: Declare wildcard for role types import * NOBUG: declare type for ApplicationRoles * NOBUG: If at first you don't succeed, try try again Nuclear option, just to get the builds working. Putting the constants back in place on the common lib and removing the failing reference to the API package.
1 parent 0c97216 commit a50563b

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

angular/projects/admin-nrpti/src/app/services/factory.service.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { RecordService } from './record.service';
88
import { catchError } from 'rxjs/operators';
99
import { TaskService, ITaskParams } from './task.service';
1010
import { DocumentService } from './document.service';
11-
import { ApplicationRoles } from '../../../../../../api/src/utils/constants/misc';
11+
import { Constants } from '../utils/constants/misc';
1212
/**
1313
* Facade service for all admin-nrpti services.
1414
*
@@ -160,23 +160,23 @@ export class FactoryService {
160160
// to handle any case issues with role or the scopes, convert them
161161
// all to lower case first
162162
const userRoles = jwt.realm_access.roles.map((userRole: string) => userRole.toLowerCase());
163-
return userRoles.includes(ApplicationRoles.ADMIN) || userRoles.includes(role.toLowerCase());
163+
return userRoles.includes(Constants.ApplicationRoles.ADMIN) || userRoles.includes(role.toLowerCase());
164164
}
165165
}
166166

167167
return false;
168168
}
169169

170170
userInLngRole() {
171-
return this.userInRole(ApplicationRoles.ADMIN_LNG);
171+
return this.userInRole(Constants.ApplicationRoles.ADMIN_LNG);
172172
}
173173

174174
userInBcmiRole() {
175-
return this.userInRole(ApplicationRoles.ADMIN_BCMI);
175+
return this.userInRole(Constants.ApplicationRoles.ADMIN_BCMI);
176176
}
177177

178178
userInNrcedRole() {
179-
return this.userInRole(ApplicationRoles.ADMIN_NRCED);
179+
return this.userInRole(Constants.ApplicationRoles.ADMIN_NRCED);
180180
}
181181

182182
/**

angular/projects/admin-nrpti/src/app/services/keycloak.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Injectable } from '@angular/core';
22
import { JwtUtil } from '../utils/jwt-utils';
33
import { Observable } from 'rxjs';
4-
import { ApplicationRoles } from '../../../../../../api/src/utils/constants/misc';
4+
import { Constants } from '../utils/constants/misc';
55

66
declare let Keycloak: any;
77

@@ -115,8 +115,8 @@ export class KeycloakService {
115115
}
116116

117117
// Make sure they have at least one instance of including a role in the ROLE array
118-
return Object.keys(ApplicationRoles).some(role => {
119-
return jwt.realm_access.roles.includes(ApplicationRoles[role]);
118+
return Object.keys(Constants.ApplicationRoles).some(role => {
119+
return jwt.realm_access.roles.includes(Constants.ApplicationRoles[role]);
120120
});
121121
}
122122

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export class Constants {
2+
public static readonly ApplicationRoles: any = {
3+
ADMIN: 'sysadmin',
4+
ADMIN_NRCED: 'admin:nrced',
5+
ADMIN_LNG: 'admin:lng',
6+
ADMIN_BCMI: 'admin:bcmi',
7+
};
8+
}

0 commit comments

Comments
 (0)