From 23bb666d823ab43cf3d2d294377a00d053b48b8f Mon Sep 17 00:00:00 2001 From: "kim.tran" Date: Wed, 24 Apr 2024 08:21:06 +0200 Subject: [PATCH 1/4] feat: add enum to dropdown utils --- libs/angular-accelerator/src/index.ts | 1 + .../lib/utils/enum-to-dropdown-options.utils.ts | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 libs/angular-accelerator/src/lib/utils/enum-to-dropdown-options.utils.ts diff --git a/libs/angular-accelerator/src/index.ts b/libs/angular-accelerator/src/index.ts index 1652ef40..2482ba21 100644 --- a/libs/angular-accelerator/src/index.ts +++ b/libs/angular-accelerator/src/index.ts @@ -57,3 +57,4 @@ export * from './lib/utils/objectutils' export * from './lib/utils/primeicon.utils' export * from './lib/utils/translate.combined.loader' export * from './lib/utils/create-remote-component-translate-loader.utils' +export * from './lib/utils/enum-to-dropdown-options.utils' diff --git a/libs/angular-accelerator/src/lib/utils/enum-to-dropdown-options.utils.ts b/libs/angular-accelerator/src/lib/utils/enum-to-dropdown-options.utils.ts new file mode 100644 index 00000000..c3484176 --- /dev/null +++ b/libs/angular-accelerator/src/lib/utils/enum-to-dropdown-options.utils.ts @@ -0,0 +1,17 @@ +import { TranslateService } from '@ngx-translate/core' +import { Observable, map } from 'rxjs' + +export function enumToDropdownOptions( + translateService: TranslateService, + enumType: T, + translationKeyPrefix: string +): Observable<{ label: string; value: T }[]> { + return translateService.get(Object.values(enumType).map((v) => translationKeyPrefix + v)).pipe( + map((translations) => + Object.values(enumType).map((v) => ({ + label: translations[translationKeyPrefix + v], + value: v, + })) + ) + ) +} From 31b0ec80c89a756d3a8a906c85f271889b4bf36c Mon Sep 17 00:00:00 2001 From: "kim.tran" Date: Wed, 24 Apr 2024 13:10:48 +0200 Subject: [PATCH 2/4] fix: temporary permission fix for standalone mode --- .../src/lib/model/config-key.model.ts | 1 + .../lib/core/initializer/standalone.initializer.ts | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) 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 0146be2c..ee6ffec5 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,4 +24,5 @@ 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/portal-integration-angular/src/lib/core/initializer/standalone.initializer.ts b/libs/portal-integration-angular/src/lib/core/initializer/standalone.initializer.ts index 5fe774fd..70b22383 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 } from '@onecx/integration-interface' +import { MfeInfo, PermissionsTopic } from '@onecx/integration-interface' import { PortalApiService } from '../../services/portal-api.service' import { UserProfileAPIService } from '../../services/userprofile-api.service' @@ -31,7 +31,7 @@ export function standaloneInitializer( ): () => Promise { // eslint-disable-next-line no-restricted-syntax console.time('initializer') - console.log(`⭐ Standalone initializer for: `, +appName) + console.log(`⭐ Standalone initializer for: `, appName) let errCause: string return async () => { @@ -66,9 +66,14 @@ export function standaloneInitializer( console.log(`📃 portal OK? `, portal) await appStateService.currentPortal$.publish({ ...portal, - workspaceName: portal.portalName + 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: '.', From 1241c97512e313b35a3463adedc5f9402643d2e5 Mon Sep 17 00:00:00 2001 From: "kim.tran" Date: Thu, 25 Apr 2024 15:29:38 +0200 Subject: [PATCH 3/4] fix: permission loading in standalone and old shell --- .../src/lib/services/user.service.ts | 23 ++++++++++++++----- .../initializer/standalone.initializer.ts | 7 +----- 2 files changed, 18 insertions(+), 12 deletions(-) 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: '.', From 40f16d555b763984a7e5cb6382699b043f9c9a68 Mon Sep 17 00:00:00 2001 From: "kim.tran" Date: Thu, 25 Apr 2024 15:31:22 +0200 Subject: [PATCH 4/4] fix: remove standalone permission config key --- .../src/lib/model/config-key.model.ts | 1 - 1 file changed, 1 deletion(-) 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' }