Skip to content

Commit

Permalink
NOBUG: Re-implement common constants (#557)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
dhlevi authored Aug 18, 2020
1 parent 0c97216 commit a50563b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
10 changes: 5 additions & 5 deletions angular/projects/admin-nrpti/src/app/services/factory.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { RecordService } from './record.service';
import { catchError } from 'rxjs/operators';
import { TaskService, ITaskParams } from './task.service';
import { DocumentService } from './document.service';
import { ApplicationRoles } from '../../../../../../api/src/utils/constants/misc';
import { Constants } from '../utils/constants/misc';
/**
* Facade service for all admin-nrpti services.
*
Expand Down Expand Up @@ -160,23 +160,23 @@ export class FactoryService {
// to handle any case issues with role or the scopes, convert them
// all to lower case first
const userRoles = jwt.realm_access.roles.map((userRole: string) => userRole.toLowerCase());
return userRoles.includes(ApplicationRoles.ADMIN) || userRoles.includes(role.toLowerCase());
return userRoles.includes(Constants.ApplicationRoles.ADMIN) || userRoles.includes(role.toLowerCase());
}
}

return false;
}

userInLngRole() {
return this.userInRole(ApplicationRoles.ADMIN_LNG);
return this.userInRole(Constants.ApplicationRoles.ADMIN_LNG);
}

userInBcmiRole() {
return this.userInRole(ApplicationRoles.ADMIN_BCMI);
return this.userInRole(Constants.ApplicationRoles.ADMIN_BCMI);
}

userInNrcedRole() {
return this.userInRole(ApplicationRoles.ADMIN_NRCED);
return this.userInRole(Constants.ApplicationRoles.ADMIN_NRCED);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { JwtUtil } from '../utils/jwt-utils';
import { Observable } from 'rxjs';
import { ApplicationRoles } from '../../../../../../api/src/utils/constants/misc';
import { Constants } from '../utils/constants/misc';

declare let Keycloak: any;

Expand Down Expand Up @@ -115,8 +115,8 @@ export class KeycloakService {
}

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

Expand Down
8 changes: 8 additions & 0 deletions angular/projects/admin-nrpti/src/app/utils/constants/misc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export class Constants {
public static readonly ApplicationRoles: any = {
ADMIN: 'sysadmin',
ADMIN_NRCED: 'admin:nrced',
ADMIN_LNG: 'admin:lng',
ADMIN_BCMI: 'admin:bcmi',
};
}

0 comments on commit a50563b

Please sign in to comment.