mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-27 22:48:52 +00:00
# Which Problems Are Solved # How the Problems Are Solved # Additional Changes # Additional Context - Closes #10690
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { computed, Injector, Pipe, PipeTransform } from '@angular/core';
|
||||
import { delay, Observable } from 'rxjs';
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { delay, map, Observable } from 'rxjs';
|
||||
import { GrpcAuthService } from 'src/app/services/grpc-auth.service';
|
||||
import { NewAuthService } from '../../services/new-auth.service';
|
||||
import { toObservable } from '@angular/core/rxjs-interop';
|
||||
@@ -7,28 +7,24 @@ import { filter } from 'rxjs/operators';
|
||||
|
||||
@Pipe({
|
||||
name: 'hasRole',
|
||||
standalone: false,
|
||||
})
|
||||
export class HasRolePipe implements PipeTransform {
|
||||
private readonly permissions = this.newAuthService.listMyZitadelPermissionsQuery();
|
||||
private readonly permissions$ = toObservable(this.newAuthService.listMyZitadelPermissionsQuery().data);
|
||||
|
||||
constructor(
|
||||
private readonly authService: GrpcAuthService,
|
||||
private readonly newAuthService: NewAuthService,
|
||||
private readonly injector: Injector,
|
||||
) {}
|
||||
|
||||
public transform(values: string[], requiresAll: boolean = false): Observable<boolean> {
|
||||
const signal = computed(() => {
|
||||
const permissions = this.permissions.data();
|
||||
if (!permissions) {
|
||||
return undefined;
|
||||
}
|
||||
return this.authService.hasRoles(permissions, values, requiresAll);
|
||||
});
|
||||
|
||||
return toObservable(signal, {
|
||||
injector: this.injector,
|
||||
}).pipe(
|
||||
return this.permissions$.pipe(
|
||||
map((permissions) => {
|
||||
if (!permissions) {
|
||||
return undefined;
|
||||
}
|
||||
return this.authService.hasRoles(permissions, values, requiresAll);
|
||||
}),
|
||||
filter((hasRole): hasRole is Exclude<typeof hasRole, undefined> => hasRole !== undefined),
|
||||
delay(0),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user