| import { Pipe, PipeTransform } from '@angular/core'; |
| import { AuthenticationService } from './authentication.service'; |
| import { forkJoin, Observable, of } from 'rxjs'; |
| import { map } from 'rxjs/operators'; |
| |
| |
| @Pipe({ |
| name: 'authPipe', |
| pure: true |
| }) |
| export class AuthPipe implements PipeTransform { |
| constructor(private authService: AuthenticationService) { |
| } |
| |
| transform(linksWithRoles: { roles: string }[]): Observable<{ roles: string }[]> { |
| if (!linksWithRoles) { |
| return of(linksWithRoles); |
| } |
| |
| return forkJoin(linksWithRoles.map(l => this.authService.isUserInRole(l.roles))).pipe( |
| map(booleanFilter => linksWithRoles.filter((l, i) => booleanFilter[i])) |
| ); |
| } |
| } |