RED-6162 - tenant context

This commit is contained in:
Timo Bejan 2023-03-21 13:58:52 +02:00
parent 37524e1543
commit f9308f0e13
3 changed files with 19 additions and 4 deletions

View File

@ -1,15 +1,17 @@
import { Injectable } from '@angular/core';
import { inject, Injectable } from '@angular/core';
import { DownloadStatus, IDownloadStatus, IDownloadStatusResponse, IPrepareDownloadRequest, IRemoveDownloadRequest } from '@red/domain';
import { firstValueFrom, Observable } from 'rxjs';
import { ConfigService } from '@services/config.service';
import { map, tap } from 'rxjs/operators';
import { EntitiesService, mapEach, RequiredParam, Validate } from '@iqser/common-ui';
import { NGXLogger } from 'ngx-logger';
import { TenantContext } from '@utils/tenant-context';
@Injectable()
export class FileDownloadService extends EntitiesService<IDownloadStatus, DownloadStatus> {
protected readonly _defaultModelPath = 'async/download';
protected readonly _entityClass = DownloadStatus;
protected readonly _tenantContext = inject(TenantContext);
constructor(private readonly _configService: ConfigService, private readonly _logger: NGXLogger) {
super();
@ -34,7 +36,9 @@ export class FileDownloadService extends EntitiesService<IDownloadStatus, Downlo
async performDownload(status: DownloadStatus) {
const token = await this.generateToken(status.storageId);
const anchor = document.createElement('a');
anchor.href = `${this._configService.values.API_URL}/async/download/with-ott/${token.value}`;
anchor.href = `${this._configService.values.API_URL}/async/download/with-ott/${token.value}?tenantId?=${encodeURIComponent(
this._tenantContext.getTenant(),
)}`;
anchor.download = status.filename;
anchor.target = '_blank';
this._logger.info('[DOWNLOAD] Downloading with link: ', anchor.href);

View File

@ -0,0 +1,8 @@
import { Injectable } from '@angular/core';
@Injectable({ providedIn: 'root' })
export class TenantContext {
getTenant(): string {
return 'redaction';
}
}

View File

@ -1,12 +1,15 @@
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { inject, Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { TenantContext } from '@utils/tenant-context';
@Injectable()
export class TenantIdInterceptor implements HttpInterceptor {
protected readonly _tenantContext = inject(TenantContext);
intercept(req: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
const updatedRequest = req.clone({
setHeaders: { 'X-TENANT-ID': 'redaction' },
setHeaders: { 'X-TENANT-ID': this._tenantContext.getTenant() },
});
return next.handle(updatedRequest);
}