Skip to content

Commit

Permalink
kc group contact_centre_staff test code
Browse files Browse the repository at this point in the history
  • Loading branch information
ochiu committed Dec 18, 2024
1 parent 5c9737d commit 561a9c5
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand Down
4 changes: 2 additions & 2 deletions auth-web/src/components/auth/common/StaffAccountsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,8 @@ export default defineComponent({
}, { deep: true })
async function viewInBusinessRegistryDashboard (org: Organization) {

Check failure on line 555 in auth-web/src/components/auth/common/StaffAccountsTable.vue

View workflow job for this annotation

GitHub Actions / account-ui-ci / linting-npm (20.5.1)

'org' is defined but never used

Check failure on line 555 in auth-web/src/components/auth/common/StaffAccountsTable.vue

View workflow job for this annotation

GitHub Actions / account-ui-ci / linting-npm (20.5.1)

'org' is defined but never used
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
4 changes: 3 additions & 1 deletion auth-web/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@ 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',
query: { redirect: to.fullPath }
})
}
} 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 }
Expand Down
26 changes: 15 additions & 11 deletions auth-web/src/routes/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
},
{
Expand Down Expand Up @@ -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: '',
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion auth-web/src/stores/org.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,12 @@ export const useOrgStore = defineStore('org', () => {
}

async function syncMembership (orgId: number): Promise<Member> {
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']
Expand All @@ -331,13 +332,18 @@ 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()
}
// Create an empty membership model for staff. Map view_account as User and manage_accounts as Admin
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
}
Expand Down
1 change: 1 addition & 0 deletions auth-web/src/util/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion auth-web/src/views/auth/AccountSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 561a9c5

Please sign in to comment.