remove emails from stored tenants

This commit is contained in:
Dan Percic 2023-08-08 11:28:58 +03:00
parent c831e29fe4
commit e373d13e14
8 changed files with 65 additions and 58 deletions

View File

@ -1,17 +1,18 @@
<div id="tenants-menu-items">
<ng-container *ngFor="let item of storedTenants; trackBy: trackBy">
<div class="label">{{ item.key }}</div>
<a
(click)="!stored.isCurrent && selectTenant(stored.tenantId)"
*ngFor="let stored of storedTenants; trackBy: trackBy"
[class.disabled]="stored.isCurrent"
[id]="stored.tenantId"
[iqserStopPropagation]="stored.isCurrent"
class="little-padding reverse-icon"
mat-menu-item
>
{{ stored.tenantId }}
<mat-icon *ngIf="stored.isCurrent" [svgIcon]="'iqser:check'"></mat-icon>
</a>
<a
(click)="selectTenant(stored.tenantId, stored.email)"
*ngFor="let stored of item.value"
[id]="stored.tenantId + stored.email"
mat-menu-item
>
{{ stored.email }}
</a>
<mat-divider class="pb-3 pt-3"></mat-divider>
</ng-container>
<mat-divider class="pb-3 pt-3"></mat-divider>
<a (click)="selectTenant()" mat-menu-item>
<span translate="top-bar.navigation-items.my-account.children.join-another-tenant"> </span>

View File

@ -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;
}

View File

@ -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<User>();
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 }));
}
}

View File

@ -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',

View File

@ -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<void> = 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<void> = async () => {
}
loadingService.stop();
const currentUser = userService.currentUser;
tenantsService.storeTenant(currentUser.email ?? currentUser.username);
tenantsService.storeTenant();
logger.info('[ROUTES] Main resolver finished!');
};

View File

@ -2306,7 +2306,7 @@
"label": "Language"
},
"logout": "Logout",
"select-tenant": "Switch account",
"select-tenant": "Switch workspace",
"trash": "Trash"
}
}

View File

@ -2306,7 +2306,7 @@
"label": "Language"
},
"logout": "Logout",
"select-tenant": "Switch account",
"select-tenant": "Switch workspace",
"trash": "Trash"
}
}

@ -1 +1 @@
Subproject commit c851ab1394fae4863d60424792ea1f8f8f83b1a8
Subproject commit 04a69f5e689cf4d90efbd550cbf6938ae7c0a200