From 561a9c5f7004955f6afefe03ec3bb19bdbb244c7 Mon Sep 17 00:00:00 2001 From: Odysseus Chiu Date: Wed, 18 Dec 2024 09:27:58 -0800 Subject: [PATCH] kc group contact_centre_staff test code --- .../account-info/AccountInfo.vue | 2 +- .../auth/common/StaffAccountsTable.vue | 4 +-- .../StaffAccountManagement.vue | 4 +-- auth-web/src/routes/index.ts | 4 ++- auth-web/src/routes/router.ts | 26 +++++++++++-------- auth-web/src/stores/org.ts | 8 +++++- auth-web/src/util/constants.ts | 1 + auth-web/src/views/auth/AccountSettings.vue | 2 +- 8 files changed, 32 insertions(+), 19 deletions(-) diff --git a/auth-web/src/components/auth/account-settings/account-info/AccountInfo.vue b/auth-web/src/components/auth/account-settings/account-info/AccountInfo.vue index 235ad42032..0843ebf0f2 100644 --- a/auth-web/src/components/auth/account-settings/account-info/AccountInfo.vue +++ b/auth-web/src/components/auth/account-settings/account-info/AccountInfo.vue @@ -361,7 +361,7 @@ export default defineComponent({ isBusinessAccount: computed(() => orgStore.isBusinessAccount), baseAddress: computed(() => currentOrgAddress.value), - isStaff: computed(() => userStore.currentUser.roles.includes(Role.Staff)), + isStaff: computed(() => userStore.currentUser.roles.includes(Role.Staff) || userStore.currentUser.roles.includes(Role.ContactCentreStaff)), isSuspendButtonVisible: computed(() => ( (currentOrganization.value.statusCode === AccountStatus.ACTIVE || currentOrganization.value.statusCode === AccountStatus.SUSPENDED) && diff --git a/auth-web/src/components/auth/common/StaffAccountsTable.vue b/auth-web/src/components/auth/common/StaffAccountsTable.vue index aa6cf89cdc..de3cdc51a7 100644 --- a/auth-web/src/components/auth/common/StaffAccountsTable.vue +++ b/auth-web/src/components/auth/common/StaffAccountsTable.vue @@ -553,8 +553,8 @@ export default defineComponent({ }, { deep: true }) async function viewInBusinessRegistryDashboard (org: Organization) { - await syncBeforeNavigate(org) - root.$router.push(`/account/${org.id}/business`) + // await syncBeforeNavigate(org) + // root.$router.push(`/account/${org.id}/business`) } async function view (org: Organization) { diff --git a/auth-web/src/components/auth/staff/account-management/StaffAccountManagement.vue b/auth-web/src/components/auth/staff/account-management/StaffAccountManagement.vue index 906a49dc41..898b8ff8df 100644 --- a/auth-web/src/components/auth/staff/account-management/StaffAccountManagement.vue +++ b/auth-web/src/components/auth/staff/account-management/StaffAccountManagement.vue @@ -231,11 +231,11 @@ export default class StaffAccountManagement extends Vue { } private get canManageAccounts () { - return this.currentUser?.roles?.includes(Role.StaffManageAccounts) + return this.currentUser?.roles?.includes(Role.StaffManageAccounts) || this.currentUser?.roles?.includes(Role.ContactCentreStaff) } private get canCreateAccounts () { - return this.currentUser?.roles?.includes(Role.StaffCreateAccounts) + return this.currentUser?.roles?.includes(Role.StaffCreateAccounts) || this.currentUser?.roles?.includes(Role.ContactCentreStaff) } private get canViewAccounts () { diff --git a/auth-web/src/routes/index.ts b/auth-web/src/routes/index.ts index ae1deb2448..7214b69a47 100644 --- a/auth-web/src/routes/index.ts +++ b/auth-web/src/routes/index.ts @@ -34,8 +34,10 @@ router.beforeEach(async (to, from, next) => { // If there are allowed or disabled roles specified on the route check if the user has those roles else route to unauthorized // If the user is not authenticated // Redirect the user to login page to login page + console.log('beforeEach') if (to.matched.some(record => record.meta.requiresAuth)) { if (sessionStorage.getItem(SessionStorageKeys.KeyCloakToken)) { + console.log(to.meta.allowedRoles) if (!KeyCloakService.verifyRoles(to.meta.allowedRoles, to.meta.disabledRoles)) { return next({ path: '/unauthorized', @@ -43,7 +45,7 @@ router.beforeEach(async (to, from, next) => { }) } } else { - if (to.meta.allowedRoles?.length === 1 && to.meta.allowedRoles[0] === Role.Staff) { + if (to.meta.allowedRoles?.length === 1 && [Role.Staff, Role.ContactCentreStaff].includes(to.meta.allowedRoles[0])) { return next({ path: `/signin/idir${to.path}`, query: { redirect: to.fullPath } diff --git a/auth-web/src/routes/router.ts b/auth-web/src/routes/router.ts index ff7244ef10..11a0fff4b8 100644 --- a/auth-web/src/routes/router.ts +++ b/auth-web/src/routes/router.ts @@ -129,11 +129,15 @@ function mapPendingDetails (route: any) { } } -function isStaff (): boolean { +function isStaff(): boolean { const kcUserProfile = KeyCloakService.getUserInfo() - return kcUserProfile?.roles?.includes(Role.Staff) || false + console.log('isstaff', kcUserProfile?.roles?.includes(Role.Staff) || + kcUserProfile?.roles?.includes(Role.ContactCentreStaff) || + false) + return kcUserProfile?.roles?.includes(Role.Staff) || + kcUserProfile?.roles?.includes(Role.ContactCentreStaff) || + false } - export function getRoutes (): RouteConfig[] { const accountSettings = () => import('../views/auth/AccountSettings.vue') const accountInfo = () => import('../components/auth/account-settings/account-info/AccountInfo.vue') @@ -453,7 +457,7 @@ export function getRoutes (): RouteConfig[] { path: '/review-account/:orgId', name: 'review-account', component: ReviewAccountView, - meta: { requiresAuth: true, allowedRoles: [Role.StaffManageAccounts] }, + meta: { requiresAuth: true, allowedRoles: [Role.StaffManageAccounts, Role.ContactCentreStaff] }, props: true }, { @@ -630,7 +634,7 @@ export function getRoutes (): RouteConfig[] { path: Pages.STAFF_DASHBOARD, component: StaffDashboardView, props: true, - meta: { requiresAuth: true, allowedRoles: [Role.Staff] }, + meta: { requiresAuth: true, allowedRoles: [Role.Staff, Role.ContactCentreStaff] }, children: [ { path: '', @@ -643,7 +647,7 @@ export function getRoutes (): RouteConfig[] { component: StaffActiveAccountsTable, meta: { requiresAuth: true, - allowedRoles: [Role.Staff], + allowedRoles: [Role.Staff, Role.ContactCentreStaff], breadcrumb: [ { text: StaffDashboardBreadcrumb.text, @@ -659,7 +663,7 @@ export function getRoutes (): RouteConfig[] { component: StaffPendingAccountInvitationsTable, meta: { requiresAuth: true, - allowedRoles: [Role.Staff], + allowedRoles: [Role.Staff, Role.ContactCentreStaff], breadcrumb: [ { text: StaffDashboardBreadcrumb.text, @@ -675,7 +679,7 @@ export function getRoutes (): RouteConfig[] { component: StaffPendingAccountsTable, meta: { requiresAuth: true, - allowedRoles: [Role.Staff], + allowedRoles: [Role.Staff, Role.ContactCentreStaff], breadcrumb: [ { text: StaffDashboardBreadcrumb.text, @@ -691,7 +695,7 @@ export function getRoutes (): RouteConfig[] { component: StaffRejectedAccountsTable, meta: { requiresAuth: true, - allowedRoles: [Role.Staff], + allowedRoles: [Role.Staff, Role.ContactCentreStaff], breadcrumb: [ { text: StaffDashboardBreadcrumb.text, @@ -707,7 +711,7 @@ export function getRoutes (): RouteConfig[] { component: StaffSuspendedAccountsTable, meta: { requiresAuth: true, - allowedRoles: [Role.Staff], + allowedRoles: [Role.Staff, Role.ContactCentreStaff], breadcrumb: [ { text: StaffDashboardBreadcrumb.text, @@ -723,7 +727,7 @@ export function getRoutes (): RouteConfig[] { component: StaffInactiveAccountsTable, meta: { requiresAuth: true, - allowedRoles: [Role.Staff], + allowedRoles: [Role.Staff, Role.ContactCentreStaff], breadcrumb: [ { text: StaffDashboardBreadcrumb.text, diff --git a/auth-web/src/stores/org.ts b/auth-web/src/stores/org.ts index e0f2ec87d7..6168d819ca 100644 --- a/auth-web/src/stores/org.ts +++ b/auth-web/src/stores/org.ts @@ -312,11 +312,12 @@ export const useOrgStore = defineStore('org', () => { } async function syncMembership (orgId: number): Promise { + console.log('syncMembership') let permissions:string[] = [] let response let membership:Member = null const kcUserProfile = KeyCloakService.getUserInfo() - if (!kcUserProfile.roles.includes(Role.Staff)) { + if (!kcUserProfile.roles.includes(Role.Staff) && !kcUserProfile.roles.includes(Role.ContactCentreStaff)) { response = await UserService.getMembership(orgId) membership = response?.data // const org: Organization = state.currentOrganization'] @@ -331,6 +332,9 @@ export const useOrgStore = defineStore('org', () => { // Create permissions to enable actions for staff if (kcUserProfile.roles.includes(Role.StaffManageAccounts)) { permissions = CommonUtils.getAdminPermissions() + } else if (kcUserProfile.roles.includes(Role.ContactCentreStaff)) { + permissions = CommonUtils.getAdminPermissions() + console.log('Contact Centre Staff permissions', permissions) } else if (kcUserProfile.roles.includes(Role.StaffViewAccounts)) { permissions = CommonUtils.getViewOnlyPermissions() } @@ -338,6 +342,8 @@ export const useOrgStore = defineStore('org', () => { let membershipTypeCode = null if (kcUserProfile.roles.includes(Role.StaffManageAccounts)) { membershipTypeCode = MembershipType.Admin + } if (kcUserProfile.roles.includes(Role.ContactCentreStaff)) { + membershipTypeCode = MembershipType.Admin } else if (kcUserProfile.roles.includes(Role.StaffViewAccounts)) { membershipTypeCode = MembershipType.User } diff --git a/auth-web/src/util/constants.ts b/auth-web/src/util/constants.ts index 510dc68784..cc81f4b0aa 100644 --- a/auth-web/src/util/constants.ts +++ b/auth-web/src/util/constants.ts @@ -42,6 +42,7 @@ export enum Role { AdminEdit = 'admin_edit', BnEdit = 'bn_edit', Staff = 'staff', + ContactCentreStaff = 'contact_centre_staff', Public = 'public_user', Edit = 'edit', Basic = 'basic', diff --git a/auth-web/src/views/auth/AccountSettings.vue b/auth-web/src/views/auth/AccountSettings.vue index f7f90282dd..a243d70354 100644 --- a/auth-web/src/views/auth/AccountSettings.vue +++ b/auth-web/src/views/auth/AccountSettings.vue @@ -408,7 +408,7 @@ export default class AccountSettings extends Mixins(AccountMixin) { } private get isStaff ():boolean { - return this.currentUser.roles.includes(Role.Staff) + return this.currentUser.roles.includes(Role.Staff) || this.currentUser.roles.includes(Role.ContactCentreStaff) } private get accountInfoUrl (): string {