[Library]: Added whitelist in HttpInterceptorService, so that 'uoa-monitor-service/stakeholder' request is not stored in TransferState and logged in users can see the stakeholders they are members or managers. - previous commit was wrong!!!

This commit is contained in:
Konstantina Galouni 2021-11-08 15:01:31 +02:00
parent 23dc2cc074
commit fcf29d801f
1 changed files with 18 additions and 2 deletions

View File

@ -4,15 +4,17 @@ import { Observable, of } from 'rxjs';
import { tap } from 'rxjs/operators';
import { TransferState, makeStateKey, StateKey } from '@angular/platform-browser';
import { isPlatformServer } from '@angular/common';
import {properties} from "../../environments/environment";
@Injectable()
export class HttpInterceptorService implements HttpInterceptor {
private static HTTP_WHITELIST = [ properties.monitorServiceAPIURL + '/stakeholder' ];
constructor(private transferState: TransferState, @Inject(PLATFORM_ID) private platformId: any) {}
public intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
//console.info("intercept transferstate");
if (request.method !== 'GET') {
if (request.method !== 'GET' || this.isService(request, HttpInterceptorService.HTTP_WHITELIST)) {
return next.handle(request);
}
@ -38,4 +40,18 @@ export class HttpInterceptorService implements HttpInterceptor {
}
}
}
isService(req: HttpRequest<any>, service: string | string[]):boolean {
if(Array.isArray(service)) {
return !!service.find(element => req.url.indexOf(element) !== -1);
} else {
return req.url.indexOf(service) !== -1;
}
}
// public cleanRequest(requestUrl: string) {
// console.log("cleaned");
// const key: StateKey<string> = makeStateKey<string>(requestUrl);
// this.transferState.remove(key);
// }
}