diff --git a/dmp-frontend/src/app/ui/user-profile/user-profile.component.ts b/dmp-frontend/src/app/ui/user-profile/user-profile.component.ts
index 5cf2730ea..1562e8347 100644
--- a/dmp-frontend/src/app/ui/user-profile/user-profile.component.ts
+++ b/dmp-frontend/src/app/ui/user-profile/user-profile.component.ts
@@ -1,6 +1,6 @@
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { Component, OnDestroy, OnInit } from '@angular/core';
-import { UntypedFormArray, UntypedFormGroup } from '@angular/forms';
+import { FormBuilder, UntypedFormArray, UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
import { MatDialog } from '@angular/material/dialog';
import { ActivatedRoute, Params, Router } from '@angular/router';
import { RoleOrganizationType } from '@app/core/common/enum/role-organization-type';
@@ -22,12 +22,16 @@ import { FormValidationErrorsDialogComponent } from '@common/forms/form-validati
import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component';
import { TranslateService } from '@ngx-translate/core';
import * as moment from 'moment-timezone';
-import { Observable, of } from 'rxjs';
+import { Observable, from, of } from 'rxjs';
import { map, takeUntil } from 'rxjs/operators';
import { AddAccountDialogComponent } from './add-account/add-account-dialog.component';
import { UserProfileEditorModel } from './user-profile-editor.model';
import { nameof } from 'ts-simple-nameof';
import { Guid } from '@common/types/guid';
+import { BaseHttpParams } from '@common/http/base-http-params';
+import { InterceptorType } from '@common/http/interceptors/interceptor-type';
+import { PrincipalService } from '@app/core/services/http/principal.service';
+import { KeycloakService } from 'keycloak-angular';
@Component({
selector: 'app-user-profile',
@@ -51,6 +55,7 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes
errorMessages = [];
nestedCount = [];
nestedIndex = 0;
+ tenants: Observable
>;
organisationsAutoCompleteConfiguration: MultipleAutoCompleteConfiguration = {
filterFn: this.filterOrganisations.bind(this),
@@ -61,6 +66,8 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes
};
formGroup: UntypedFormGroup;
+ tenantFormGroup: UntypedFormGroup;
+
constructor(
private userService: UserService,
private route: ActivatedRoute,
@@ -75,7 +82,10 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes
private dialog: MatDialog,
public enumUtils: EnumUtils,
private httpClient: HttpClient,
- private matomoService: MatomoService
+ private matomoService: MatomoService,
+ private formBuilder: UntypedFormBuilder,
+ private keycloakService: KeycloakService,
+ private principalService: PrincipalService
) {
super();
this.languages = this.languageService.getAvailableLanguagesCodes();
@@ -100,6 +110,9 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes
}
ngOnInit() {
+ this.tenantFormGroup = this.formBuilder.group({
+ tenantCode: [this.authService.selectedTenant(), [Validators.required]]
+ });
this.matomoService.trackPageView('User Profile');
this.route.params
.pipe(takeUntil(this._destroyed))
@@ -149,6 +162,8 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes
.pipe(takeUntil(this._destroyed))
.subscribe(x => { if (x) { this.cultures = this._filterCulture(x); } });
// this.initializeDisabledFormGroup();
+
+ this.tenants = this.loadUserTenants();
this.unlock();
return result;
}));
@@ -407,4 +422,29 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes
}
}
+ // Switch Tenant
+ loadUserTenants(): Observable> {
+ const params = new BaseHttpParams();
+ params.interceptorContext = {
+ excludedInterceptors: [InterceptorType.TenantHeaderInterceptor]
+ };
+ return this.principalService.myTenants({ params: params });
+ }
+
+ switchTenant(): void {
+ if (this.tenantFormGroup.valid === false) return;
+
+ const selectedTenant = this.tenantFormGroup.get('tenantCode').value;
+ this.formSubmit(selectedTenant);
+ this.loadUser();
+ }
+
+ formSubmit(selectedTenant: string): void {
+ this.authService.selectedTenant(selectedTenant);
+ }
+
+ loadUser(): void {
+ const returnUrl = '/profile';
+ this.authService.prepareAuthRequest(from(this.keycloakService.getToken()), {}).pipe(takeUntil(this._destroyed)).subscribe(() => this.authService.onAuthenticateSuccess(returnUrl), (error) => this.authService.onAuthenticateError(error));
+ }
}