Skip to content

Commit

Permalink
set tenant and save it to avoid bug multi tenant (#1380)
Browse files Browse the repository at this point in the history
  • Loading branch information
laedanrex authored Jun 27, 2023
1 parent 43b4f9b commit 76d18b7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { Tenant } from '../../../models';
@Injectable({
providedIn: 'root'
})
/** @deprecated: use tenant-selection.service */
export class TenantMenuService {

// tslint:disable-next-line:variable-name
Expand Down Expand Up @@ -73,7 +74,7 @@ export class TenantMenuService {
}

public setDefaultTenant(tenantIdentifier: number): Observable<User> {
return this.userApiService.analytics({lastTenantIdentifier: tenantIdentifier});
return this.userApiService.analytics({ lastTenantIdentifier: tenantIdentifier });
}

public sendSelectedTenant(tenantIdentifier: number): void {
Expand Down
13 changes: 11 additions & 2 deletions ui/ui-frontend-common/src/app/modules/startup.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { AppConfiguration, AttachmentType, AuthUser, UserInfo } from './models';
import { ThemeService } from './theme.service';

const WARNING_DURATION = 2000;

@Injectable({
providedIn: 'root',
})
Expand Down Expand Up @@ -120,16 +121,24 @@ export class StartupService {
});
}

/**
* @deprecated: use tenant-selection.service
*/
setTenantIdentifier(tenantIdentifier?: string) {
this.CURRENT_TENANT_IDENTIFIER = tenantIdentifier;
if (tenantIdentifier) {
this.CURRENT_TENANT_IDENTIFIER = tenantIdentifier;
}
}

/**
* return the tenant ID saved in CURRENT_TENANT_IDENTIFIER or the user's proof tenant.
* @deprecated: use tenant-selection.service
*/
getTenantIdentifier() {
let tenantIdentifier = this.CURRENT_TENANT_IDENTIFIER;
if (!tenantIdentifier && this.authService.user) {
tenantIdentifier = this.authService.user.proofTenantIdentifier;
}

return tenantIdentifier;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import { ENVIRONMENT, WINDOW_LOCATION } from './injection-tokens';
import { Logger } from './logger/logger';
import { StartupService } from './startup.service';

import { VitamUISnackBarService } from './components/vitamui-snack-bar/vitamui-snack-bar.service';
import { VitamUISnackBarService } from './components/vitamui-snack-bar';
import { SKIP_ERROR_NOTIFICATION } from './utils';

import { VitamUITimeoutError } from './models/http-interceptor/vitamui-timeout-error';
Expand All @@ -70,6 +70,7 @@ const ERROR_NOTIFICATION_MESSAGE_BY_HTTP_STATUS: Map<number, string> = new Map([
[412, 'EXCEPTIONS.HTTP_INTERCEPTOR.HTTP_STATUS_PRECONDITION_FAILED_EXCEPTION'],
[408, 'EXCEPTIONS.HTTP_INTERCEPTOR.HTTP_STATUS_CODE_REQUEST_TIMEOUT'],
]);

@Injectable()
export class VitamUIHttpInterceptor implements HttpInterceptor {
private errorDialog: MatDialogRef<ErrorDialogComponent>;
Expand All @@ -92,7 +93,8 @@ export class VitamUIHttpInterceptor implements HttpInterceptor {
this.initSnackBarService();

let tenantIdentifier = request.headers.get('X-Tenant-Id');
if ((!tenantIdentifier || tenantIdentifier === undefined || tenantIdentifier === '') && this.authService.user) {
if ((!tenantIdentifier || tenantIdentifier === '') && this.authService.user) {
// TODO: change to tenant-selection.service
tenantIdentifier = this.startupService.getTenantIdentifier();
}
let requestId = request.headers.get('X-Request-Id');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class ArchiveCollectService extends SearchService<any> {
}

searchArchiveUnitsByCriteria(criteriaDto: SearchCriteriaDto, transactionId: string): Observable<PagedResult> {
let headers = new HttpHeaders().append('Content-Type', 'application/json');
let headers = new HttpHeaders().append('Content-Type', 'application/json');
if (!!transactionId) {
return this.transactionApiService.searchArchiveUnitsByCriteria(criteriaDto, transactionId, headers).pipe(
// timeout(TIMEOUT_SEC),
Expand Down Expand Up @@ -151,7 +151,7 @@ export class ArchiveCollectService extends SearchService<any> {

getAccessContractById(accessContract: string): Observable<AccessContract> {
let headers = new HttpHeaders().append('Content-Type', 'application/json');

return this.accessContractApiService.getAccessContractById(accessContract, headers);
}

Expand All @@ -170,7 +170,7 @@ export class ArchiveCollectService extends SearchService<any> {
launchDownloadObjectFromUnit(
unitId: string,
objectId: string,
tenantIdentifier: number,
tenantIdentifier: number,
qualifier?: string,
version?: number
) {
Expand Down Expand Up @@ -204,7 +204,7 @@ export class ArchiveCollectService extends SearchService<any> {

exportCsvSearchArchiveUnitsByCriteria(criteriaDto: SearchCriteriaDto, projectId: string) {
let headers = new HttpHeaders().append('Content-Type', 'application/json');

return this.transactionApiService.exportCsvSearchArchiveUnitsByCriteria(criteriaDto, projectId, headers).subscribe(
(file) => {
const element = document.createElement('a');
Expand Down Expand Up @@ -246,13 +246,13 @@ export class ArchiveCollectService extends SearchService<any> {

getReferentialUnitDetails(unitId: string): Observable<SearchResponse> {
let headers = new HttpHeaders().append('Content-Type', 'application/json');

return this.searchUnitApiService.getById(unitId, headers);
}

getCollectUnitDetails(unitId: string): Observable<Unit> {
let headers = new HttpHeaders().append('Content-Type', 'application/json');

return this.transactionApiService.getCollectUnitById(unitId, headers);
}

Expand Down Expand Up @@ -308,7 +308,7 @@ export class ArchiveCollectService extends SearchService<any> {

selectUnitWithInheritedRules(transactionId: string, criteriaDto: SearchCriteriaDto): Observable<Unit> {
let headers = new HttpHeaders().append('Content-Type', 'application/json');

return this.transactionApiService.selectUnitWithInheritedRules(transactionId, criteriaDto, headers);
}
}
Expand Down

0 comments on commit 76d18b7

Please sign in to comment.