diff --git a/libs/angular-integration-interface/src/lib/model/config-key.model.ts b/libs/angular-integration-interface/src/lib/model/config-key.model.ts index ee6ffec5..0146be2c 100644 --- a/libs/angular-integration-interface/src/lib/model/config-key.model.ts +++ b/libs/angular-integration-interface/src/lib/model/config-key.model.ts @@ -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' } diff --git a/libs/angular-integration-interface/src/lib/services/user.service.ts b/libs/angular-integration-interface/src/lib/services/user.service.ts index 1df2810b..b72e95f4 100644 --- a/libs/angular-integration-interface/src/lib/services/user.service.ts +++ b/libs/angular-integration-interface/src/lib/services/user.service.ts @@ -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' @@ -10,6 +10,7 @@ export class UserService implements OnDestroy { lang$ = new BehaviorSubject(this.determineLanguage() ?? DEFAULT_LANG) private permissionsTopic$ = new PermissionsTopic() + private oldStylePermissionsInitialized: Promise constructor() { this.profile$ @@ -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 { @@ -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) => { @@ -80,13 +87,17 @@ export class UserService implements OnDestroy { }) }) }) + return permissions } } - return permissions + return null } get isInitialized(): Promise { - // 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(() => {}) } } diff --git a/libs/portal-integration-angular/src/lib/core/initializer/standalone.initializer.ts b/libs/portal-integration-angular/src/lib/core/initializer/standalone.initializer.ts index 70b22383..5f88bb91 100644 --- a/libs/portal-integration-angular/src/lib/core/initializer/standalone.initializer.ts +++ b/libs/portal-integration-angular/src/lib/core/initializer/standalone.initializer.ts @@ -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' @@ -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: '.',