From a37287f13c708ce5a7386b4144d7db5441358883 Mon Sep 17 00:00:00 2001 From: Valentin Mihai Date: Tue, 20 Feb 2024 14:54:23 +0200 Subject: [PATCH 1/2] RED-7874 - Integrate "user has no roles" message in sign-in page --- src/lib/tenants/tenant-select/tenant-select.component.html | 4 ++-- src/lib/tenants/tenant-select/tenant-select.component.ts | 3 +++ src/lib/users/guards/roles.guard.ts | 6 +++--- src/lib/users/services/iqser-user.service.ts | 5 +++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/lib/tenants/tenant-select/tenant-select.component.html b/src/lib/tenants/tenant-select/tenant-select.component.html index 2916df5..6a7c697 100644 --- a/src/lib/tenants/tenant-select/tenant-select.component.html +++ b/src/lib/tenants/tenant-select/tenant-select.component.html @@ -8,8 +8,8 @@ - -
+ +
diff --git a/src/lib/tenants/tenant-select/tenant-select.component.ts b/src/lib/tenants/tenant-select/tenant-select.component.ts index 4dddadf..8030209 100644 --- a/src/lib/tenants/tenant-select/tenant-select.component.ts +++ b/src/lib/tenants/tenant-select/tenant-select.component.ts @@ -9,6 +9,7 @@ import { getKeycloakOptions } from '../keycloak-initializer'; import { IStoredTenantId, TenantsService } from '../services'; import { KeycloakStatusService } from '../services/keycloak-status.service'; import { UI_ROOT } from '../../utils'; +import { selectTenantTranslations } from '../../../../../../apps/red-ui/src/app/translations/select-tenant-translations'; @Component({ templateUrl: './tenant-select.component.html', @@ -17,6 +18,7 @@ import { UI_ROOT } from '../../utils'; }) export class TenantSelectComponent { @Input() isLoggedOut = false; + @Input() noRoleLogOut = false; protected readonly logger = inject(NGXLogger); protected readonly tenantsService = inject(TenantsService); protected storedTenants: IStoredTenantId[] = []; @@ -29,6 +31,7 @@ export class TenantSelectComponent { // eslint-disable-next-line @typescript-eslint/unbound-method tenantId: ['', Validators.required], }); + protected readonly translations = selectTenantTranslations; readonly #uiRoot = inject(UI_ROOT); constructor() { diff --git a/src/lib/users/guards/roles.guard.ts b/src/lib/users/guards/roles.guard.ts index 68ca869..fcfda12 100644 --- a/src/lib/users/guards/roles.guard.ts +++ b/src/lib/users/guards/roles.guard.ts @@ -17,11 +17,11 @@ export function doesNotHaveAnyRole(): AsyncGuard { export function hasAnyRole(): AsyncGuard { return async () => { - const router = inject(Router); - const user = await inject(IqserUserService).loadCurrentUser(); + const userService = inject(IqserUserService); + const user = await userService.loadCurrentUser(); if (!user?.hasAnyRole) { - await router.navigate(['auth-error']); + await userService.logout(true); return false; } return true; diff --git a/src/lib/users/services/iqser-user.service.ts b/src/lib/users/services/iqser-user.service.ts index 2e598fc..730ffce 100644 --- a/src/lib/users/services/iqser-user.service.ts +++ b/src/lib/users/services/iqser-user.service.ts @@ -58,11 +58,12 @@ export abstract class IqserUserService< await firstValueFrom(this.loadAll()); } - async logout() { + async logout(noRoleLogOut = false) { try { await this._keycloakService.loadUserProfile(true); await this._cacheApiService.wipeCaches(); - const redirectUri = window.location.origin + this.#uiRoot + '/?isLoggedOut=true'; + const logoutParam = noRoleLogOut ? 'noRoleLogOut' : 'isLoggedOut'; + const redirectUri = window.location.origin + this.#uiRoot + `/?${logoutParam}=true`; await this._keycloakService.logout(redirectUri); } catch (e) { console.log('Logout failed: ', e); From 5d31262fb3d09f02fb1bb7b30c587f689963e85a Mon Sep 17 00:00:00 2001 From: Valentin Mihai Date: Tue, 20 Feb 2024 15:17:22 +0200 Subject: [PATCH 2/2] RED-7874 - moved 'select-tenant-translations' to common-ui --- src/lib/tenants/tenant-select/tenant-select.component.ts | 2 +- src/lib/translations/select-tenant-translations.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 src/lib/translations/select-tenant-translations.ts diff --git a/src/lib/tenants/tenant-select/tenant-select.component.ts b/src/lib/tenants/tenant-select/tenant-select.component.ts index 8030209..6344a6e 100644 --- a/src/lib/tenants/tenant-select/tenant-select.component.ts +++ b/src/lib/tenants/tenant-select/tenant-select.component.ts @@ -9,7 +9,7 @@ import { getKeycloakOptions } from '../keycloak-initializer'; import { IStoredTenantId, TenantsService } from '../services'; import { KeycloakStatusService } from '../services/keycloak-status.service'; import { UI_ROOT } from '../../utils'; -import { selectTenantTranslations } from '../../../../../../apps/red-ui/src/app/translations/select-tenant-translations'; +import { selectTenantTranslations } from '../../translations/select-tenant-translations'; @Component({ templateUrl: './tenant-select.component.html', diff --git a/src/lib/translations/select-tenant-translations.ts b/src/lib/translations/select-tenant-translations.ts new file mode 100644 index 0000000..506b305 --- /dev/null +++ b/src/lib/translations/select-tenant-translations.ts @@ -0,0 +1,6 @@ +import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; + +export const selectTenantTranslations: { [key in string]: string } = { + IS_LOGGED_OUT: _('tenant-resolve.header.youre-logged-out'), + NO_ROLE_LOG_OUT: _('tenant-resolve.header.no-role-log-out'), +} as const;