From e373d13e14416160d561c46cf7ce786e31973f5f Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Tue, 8 Aug 2023 11:28:58 +0300 Subject: [PATCH] remove emails from stored tenants --- .../tenants-menu/tenants-menu.component.html | 25 ++++++++------- .../tenants-menu/tenants-menu.component.scss | 15 +++++++++ .../tenants-menu/tenants-menu.component.ts | 32 ++++++++----------- .../edit-dossier-team.component.ts | 20 ++++++------ apps/red-ui/src/app/utils/main.resolver.ts | 25 +++++++-------- apps/red-ui/src/assets/i18n/redact/en.json | 2 +- apps/red-ui/src/assets/i18n/scm/en.json | 2 +- libs/common-ui | 2 +- 8 files changed, 65 insertions(+), 58 deletions(-) diff --git a/apps/red-ui/src/app/components/tenants-menu/tenants-menu.component.html b/apps/red-ui/src/app/components/tenants-menu/tenants-menu.component.html index 96ee8315f..722aca3c5 100644 --- a/apps/red-ui/src/app/components/tenants-menu/tenants-menu.component.html +++ b/apps/red-ui/src/app/components/tenants-menu/tenants-menu.component.html @@ -1,17 +1,18 @@
- -
{{ item.key }}
+ + {{ stored.tenantId }} + + - - {{ stored.email }} - - -
+ diff --git a/apps/red-ui/src/app/components/tenants-menu/tenants-menu.component.scss b/apps/red-ui/src/app/components/tenants-menu/tenants-menu.component.scss index 79680a493..e81863163 100644 --- a/apps/red-ui/src/app/components/tenants-menu/tenants-menu.component.scss +++ b/apps/red-ui/src/app/components/tenants-menu/tenants-menu.component.scss @@ -11,3 +11,18 @@ padding-top: 5px; padding-bottom: 5px; } + +.disabled { + background-color: var(--iqser-grey-6); + color: var(--iqser-grey-3); + cursor: default; +} + +.little-padding { + padding: 0 8px 0 8px; +} + +.reverse-icon { + flex-direction: row-reverse; + justify-content: space-between; +} diff --git a/apps/red-ui/src/app/components/tenants-menu/tenants-menu.component.ts b/apps/red-ui/src/app/components/tenants-menu/tenants-menu.component.ts index 01054e7ea..36bf18837 100644 --- a/apps/red-ui/src/app/components/tenants-menu/tenants-menu.component.ts +++ b/apps/red-ui/src/app/components/tenants-menu/tenants-menu.component.ts @@ -1,10 +1,12 @@ import { Component, inject } from '@angular/core'; import { getConfig } from '@iqser/common-ui'; -import { User } from '@red/domain'; -import { KeycloakService } from 'keycloak-angular'; -import { getCurrentUser } from '@iqser/common-ui/lib/users'; -import { BASE_HREF } from '@iqser/common-ui/lib/utils'; import { getKeycloakOptions, IStoredTenantId, KeycloakStatusService, TenantsService } from '@iqser/common-ui/lib/tenants'; +import { BASE_HREF } from '@iqser/common-ui/lib/utils'; +import { KeycloakService } from 'keycloak-angular'; + +interface ITenant extends IStoredTenantId { + readonly isCurrent: boolean; +} @Component({ selector: 'app-tenants-menu', @@ -15,21 +17,20 @@ export class TenantsMenuComponent { readonly #baseHref = inject(BASE_HREF); readonly #keycloakService = inject(KeycloakService); readonly #keycloakStatusService = inject(KeycloakStatusService); - readonly #currentUser = getCurrentUser(); readonly #config = getConfig(); readonly tenantsService = inject(TenantsService); - readonly storedTenants: { key: string; value: IStoredTenantId[] }[]; + readonly storedTenants: ITenant[]; constructor() { this.storedTenants = this.#getStoredTenants(); } - trackBy(_index: number, item: { key: string; value: IStoredTenantId[] }) { - return item.key; + trackBy(_index: number, item: ITenant) { + return item.tenantId; } // TODO: this should be moved to the keycloak status service - async selectTenant(tenantId?: string, email?: string) { + async selectTenant(tenantId?: string) { if (tenantId && tenantId !== this.tenantsService.activeTenantId) { await this.#keycloakService.init(getKeycloakOptions(this.#baseHref, this.#config, tenantId)); } @@ -38,7 +39,6 @@ export class TenantsMenuComponent { const url = this.#keycloakService.getKeycloakInstance().createLoginUrl({ redirectUri: this.#keycloakStatusService.createLoginUrl(tenantId), idpHint: this.#config.OAUTH_IDP_HINT, - loginHint: email ?? undefined, }); return this.#keycloakService.logout(url); } @@ -46,15 +46,9 @@ export class TenantsMenuComponent { return this.#keycloakService.logout(window.location.origin + this.#baseHref); } - #getStoredTenants() { + #getStoredTenants(): ITenant[] { const storedTenants = this.tenantsService.getStoredTenants(); - - const otherTenant = storedTenants.filter(t => { - const isCurrentTenant = t.tenantId === this.tenantsService.activeTenantId; - const isCurrentUser = t.email === this.#currentUser.email || t.email === this.#currentUser.username; - return !(isCurrentTenant && isCurrentUser); - }); - const grouped = otherTenant.groupBy(t => t.tenantId); - return [...grouped.keys()].sort((a, b) => a.localeCompare(b)).map(key => ({ key, value: grouped.get(key) })); + const sorted = storedTenants.sort((a, b) => a.tenantId.localeCompare(b.tenantId)); + return sorted.map(tenant => ({ ...tenant, isCurrent: tenant.tenantId === this.tenantsService.activeTenantId })); } } diff --git a/apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/edit-dossier-team/edit-dossier-team.component.ts b/apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/edit-dossier-team/edit-dossier-team.component.ts index 4dbbfd7f8..5a5c65771 100644 --- a/apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/edit-dossier-team/edit-dossier-team.component.ts +++ b/apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/edit-dossier-team/edit-dossier-team.component.ts @@ -1,16 +1,16 @@ import { ChangeDetectionStrategy, Component, inject, Input, OnChanges, SimpleChanges } from '@angular/core'; -import { UserService } from '@users/user.service'; import { FormControl, FormGroup, Validators } from '@angular/forms'; -import { Dossier, IDossierRequest } from '@red/domain'; -import { EditDossierSaveResult, EditDossierSectionInterface } from '../edit-dossier-section.interface'; -import { firstValueFrom } from 'rxjs'; -import { PermissionsService } from '@services/permissions.service'; -import { DossiersService } from '@services/dossiers/dossiers.service'; -import { compareLists } from '@utils/functions'; -import { FilesService } from '@services/files/files.service'; -import { map } from 'rxjs/operators'; -import { Debounce } from '@iqser/common-ui/lib/utils'; import { getConfig } from '@iqser/common-ui'; +import { Debounce } from '@iqser/common-ui/lib/utils'; +import { Dossier, IDossierRequest } from '@red/domain'; +import { DossiersService } from '@services/dossiers/dossiers.service'; +import { FilesService } from '@services/files/files.service'; +import { PermissionsService } from '@services/permissions.service'; +import { UserService } from '@users/user.service'; +import { compareLists } from '@utils/functions'; +import { firstValueFrom } from 'rxjs'; +import { map } from 'rxjs/operators'; +import { EditDossierSaveResult, EditDossierSectionInterface } from '../edit-dossier-section.interface'; @Component({ selector: 'redaction-edit-dossier-team', diff --git a/apps/red-ui/src/app/utils/main.resolver.ts b/apps/red-ui/src/app/utils/main.resolver.ts index 2d1bd2db7..aadfd031a 100644 --- a/apps/red-ui/src/app/utils/main.resolver.ts +++ b/apps/red-ui/src/app/utils/main.resolver.ts @@ -1,19 +1,18 @@ import { inject } from '@angular/core'; -import { NGXLogger } from 'ngx-logger'; -import { ConfigService } from '@services/config.service'; -import { UserService } from '@users/user.service'; -import { SystemPreferencesService } from '@services/system-preferences.service'; -import { UserPreferenceService } from '@users/user-preference.service'; +import { ResolveFn } from '@angular/router'; import { IqserPermissionsService, LoadingService } from '@iqser/common-ui'; +import { TenantsService } from '@iqser/common-ui/lib/tenants'; +import { BASE_HREF } from '@iqser/common-ui/lib/utils'; +import { ConfigService } from '@services/config.service'; +import { DossiersChangesService } from '@services/dossiers/dossier-changes.service'; import { FeaturesService } from '@services/features.service'; import { GeneralSettingsService } from '@services/general-settings.service'; -import { tap } from 'rxjs/operators'; -import { firstValueFrom } from 'rxjs'; +import { SystemPreferencesService } from '@services/system-preferences.service'; import { Roles } from '@users/roles'; -import { DossiersChangesService } from '@services/dossiers/dossier-changes.service'; -import { ResolveFn } from '@angular/router'; -import { BASE_HREF } from '@iqser/common-ui/lib/utils'; -import { TenantsService } from '@iqser/common-ui/lib/tenants'; +import { UserPreferenceService } from '@users/user-preference.service'; +import { NGXLogger } from 'ngx-logger'; +import { firstValueFrom } from 'rxjs'; +import { tap } from 'rxjs/operators'; function redirectToLastDossierTemplate(baseHref: string, tenant: string, lastDossierTemplate: string) { const lastUrlSegment = window.location.pathname.split('/').filter(Boolean).pop(); @@ -36,7 +35,6 @@ export const mainResolver: ResolveFn = async () => { const tenantsService = inject(TenantsService); const loadingService = inject(LoadingService); const configService = inject(ConfigService); - const userService = inject(UserService); const baseHref = inject(BASE_HREF); const generalConfig$ = inject(GeneralSettingsService).getGeneralConfigurations(); @@ -51,8 +49,7 @@ export const mainResolver: ResolveFn = async () => { } loadingService.stop(); - const currentUser = userService.currentUser; - tenantsService.storeTenant(currentUser.email ?? currentUser.username); + tenantsService.storeTenant(); logger.info('[ROUTES] Main resolver finished!'); }; diff --git a/apps/red-ui/src/assets/i18n/redact/en.json b/apps/red-ui/src/assets/i18n/redact/en.json index 98ef32760..da566c31c 100644 --- a/apps/red-ui/src/assets/i18n/redact/en.json +++ b/apps/red-ui/src/assets/i18n/redact/en.json @@ -2306,7 +2306,7 @@ "label": "Language" }, "logout": "Logout", - "select-tenant": "Switch account", + "select-tenant": "Switch workspace", "trash": "Trash" } } diff --git a/apps/red-ui/src/assets/i18n/scm/en.json b/apps/red-ui/src/assets/i18n/scm/en.json index 2ced4855b..d97d7cd16 100644 --- a/apps/red-ui/src/assets/i18n/scm/en.json +++ b/apps/red-ui/src/assets/i18n/scm/en.json @@ -2306,7 +2306,7 @@ "label": "Language" }, "logout": "Logout", - "select-tenant": "Switch account", + "select-tenant": "Switch workspace", "trash": "Trash" } } diff --git a/libs/common-ui b/libs/common-ui index c851ab139..04a69f5e6 160000 --- a/libs/common-ui +++ b/libs/common-ui @@ -1 +1 @@ -Subproject commit c851ab1394fae4863d60424792ea1f8f8f83b1a8 +Subproject commit 04a69f5e689cf4d90efbd550cbf6938ae7c0a200