Skip to content

Commit

Permalink
25912 - Bugfix - Assigned role was not returning correct roles (#3271)
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigo-barraza authored Feb 20, 2025
1 parent 55e6987 commit b214b84
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions auth-web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion auth-web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "auth-web",
"version": "2.8.11",
"version": "2.8.12",
"appName": "Auth Web",
"sbcName": "SBC Common Components",
"private": true,
Expand Down
22 changes: 13 additions & 9 deletions auth-web/src/stores/org.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,31 +315,35 @@ export const useOrgStore = defineStore('org', () => {
return response
}

const rolesMapping = {
[Role.ContactCentreStaff]: {
const rolesMapping = [
{
role: Role.ContactCentreStaff,
permissions: CommonUtils.getContactCentreStaffPermissions(),
membershipType: MembershipType.Admin
},
[Role.StaffManageAccounts]: {
{
role: Role.StaffManageAccounts,
permissions: CommonUtils.getAdminPermissions(),
membershipType: MembershipType.Admin
},
[Role.StaffViewAccounts]: {
{
role: Role.StaffViewAccounts,
permissions: CommonUtils.getViewOnlyPermissions(),
membershipType: MembershipType.User
}
}
]

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

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

if (assignedRole) {
state.permissions = rolesMapping[assignedRole].permissions
state.permissions = assignedRole.permissions
state.currentMembership = {
membershipTypeCode: rolesMapping[assignedRole].membershipType,
membershipTypeCode: assignedRole.membershipType,
id: null,
membershipStatus: MembershipStatus.Active,
user: null
Expand Down

0 comments on commit b214b84

Please sign in to comment.