Skip to content

Commit

Permalink
fix: permissions loading in standalone and old shell (#233)
Browse files Browse the repository at this point in the history
* feat: add enum to dropdown utils

* fix: temporary permission fix for standalone mode

* fix: permission loading in standalone and old shell

* fix: remove standalone permission config key

---------

Co-authored-by: kim.tran <[email protected]>
  • Loading branch information
KimFFVII and kim.tran authored Apr 25, 2024
1 parent 132d441 commit 8b3b21a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ export enum CONFIG_KEY {
IS_SHELL = 'IS_SHELL',
AUTH_SERVICE = 'AUTH_SERVICE',
AUTH_SERVICE_CUSTOM_URL = 'AUTH_SERVICE_CUSTOM_URL',
STANDALONE_PERMISSIONS = 'STANDALONE_PERMISSIONS'
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable, OnDestroy } from '@angular/core'
import { BehaviorSubject, map } from 'rxjs'
import { BehaviorSubject, map, filter, firstValueFrom, skip } from 'rxjs'
import { PermissionsTopic, UserProfile, UserProfileTopic } from '@onecx/integration-interface'
import { DEFAULT_LANG } from '../api/constants'

Expand All @@ -10,6 +10,7 @@ export class UserService implements OnDestroy {
lang$ = new BehaviorSubject(this.determineLanguage() ?? DEFAULT_LANG)

private permissionsTopic$ = new PermissionsTopic()
private oldStylePermissionsInitialized: Promise<string[]>

constructor() {
this.profile$
Expand All @@ -21,7 +22,13 @@ export class UserService implements OnDestroy {
)
.subscribe(this.lang$)

this.profile$.pipe(map((profile) => this.extractPermissions(profile))).subscribe(this.permissions$)
this.oldStylePermissionsInitialized = firstValueFrom(this.permissions$.pipe(skip(1)))
this.profile$
.pipe(
map((profile) => this.extractPermissions(profile)),
filter((permissions): permissions is string[] => !!permissions)
)
.subscribe(this.permissions$)
}

ngOnDestroy(): void {
Expand Down Expand Up @@ -66,9 +73,9 @@ export class UserService implements OnDestroy {
}

private extractPermissions(userProfile: UserProfile) {
const permissions: string[] = []
if (userProfile) {
if (userProfile.memberships) {
const permissions: string[] = []
userProfile.memberships.forEach((m) => {
m.roleMemberships?.forEach((r) => {
r.permissions?.forEach((p) => {
Expand All @@ -80,13 +87,17 @@ export class UserService implements OnDestroy {
})
})
})
return permissions
}
}
return permissions
return null
}

get isInitialized(): Promise<void> {
// eslint-disable-next-line @typescript-eslint/no-empty-function
return Promise.all([this.permissionsTopic$.isInitialized, this.profile$.isInitialized]).then(() => {})
return Promise.all([
Promise.race([this.permissionsTopic$.isInitialized, this.oldStylePermissionsInitialized]),
this.profile$.isInitialized,
// eslint-disable-next-line @typescript-eslint/no-empty-function
]).then(() => {})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
CONFIG_KEY,
IAuthService,
} from '@onecx/angular-integration-interface'
import { MfeInfo, PermissionsTopic } from '@onecx/integration-interface'
import { MfeInfo } from '@onecx/integration-interface'
import { PortalApiService } from '../../services/portal-api.service'
import { UserProfileAPIService } from '../../services/userprofile-api.service'

Expand Down Expand Up @@ -69,11 +69,6 @@ export function standaloneInitializer(
workspaceName: portal.portalName,
})

// TODO remove when permissions concept for standalone is there
const permissionsTopic$ = new PermissionsTopic()
await permissionsTopic$.publish((config.getProperty(CONFIG_KEY.STANDALONE_PERMISSIONS) ?? '').split(';'))
permissionsTopic$.destroy()

const standaloneMfeInfo: MfeInfo = {
mountPath: '/',
remoteBaseUrl: '.',
Expand Down

0 comments on commit 8b3b21a

Please sign in to comment.