Skip to content

Commit b214b84

Browse files
25912 - Bugfix - Assigned role was not returning correct roles (bcgov#3271)
1 parent 55e6987 commit b214b84

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

auth-web/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

auth-web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "auth-web",
3-
"version": "2.8.11",
3+
"version": "2.8.12",
44
"appName": "Auth Web",
55
"sbcName": "SBC Common Components",
66
"private": true,

auth-web/src/stores/org.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -315,31 +315,35 @@ export const useOrgStore = defineStore('org', () => {
315315
return response
316316
}
317317

318-
const rolesMapping = {
319-
[Role.ContactCentreStaff]: {
318+
const rolesMapping = [
319+
{
320+
role: Role.ContactCentreStaff,
320321
permissions: CommonUtils.getContactCentreStaffPermissions(),
321322
membershipType: MembershipType.Admin
322323
},
323-
[Role.StaffManageAccounts]: {
324+
{
325+
role: Role.StaffManageAccounts,
324326
permissions: CommonUtils.getAdminPermissions(),
325327
membershipType: MembershipType.Admin
326328
},
327-
[Role.StaffViewAccounts]: {
329+
{
330+
role: Role.StaffViewAccounts,
328331
permissions: CommonUtils.getViewOnlyPermissions(),
329332
membershipType: MembershipType.User
330333
}
331-
}
334+
]
332335

333336
async function syncMembership (orgId: number): Promise<Member> {
334337
const { roles } = KeyCloakService.getUserInfo()
335338

336-
// If user has any of the roles in the mapping, assign the permissions and membership type
337-
const assignedRole = roles.find(role => Object.prototype.hasOwnProperty.call(rolesMapping, role))
339+
// In the sequential order of the rolesMapping array, check if user has any of the roles in the mapping
340+
// and assign the permissions and membership type
341+
const assignedRole = rolesMapping.find((role) => roles.includes(role.role))
338342

339343
if (assignedRole) {
340-
state.permissions = rolesMapping[assignedRole].permissions
344+
state.permissions = assignedRole.permissions
341345
state.currentMembership = {
342-
membershipTypeCode: rolesMapping[assignedRole].membershipType,
346+
membershipTypeCode: assignedRole.membershipType,
343347
id: null,
344348
membershipStatus: MembershipStatus.Active,
345349
user: null

0 commit comments

Comments
 (0)