Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | 31x 31x 31x 31x 31x 31x 31x 31x 34x 34x 131x 141x 36x 31x 187x | import { ModuleWithProviders, NgModule } from '@angular/core';
import { ReplaySubject } from 'rxjs';
import { map } from 'rxjs/operators';
import { AuthorizationToggleDirective } from './directives/authorization-toggle.directive';
import { AuthorizationToggleService, checkPermission } from './utils/authorization-toggle/authorization-toggle.service';
import { whenTruthy } from './utils/operators';
@NgModule({
declarations: [AuthorizationToggleDirective],
exports: [AuthorizationToggleDirective],
})
export class AuthorizationToggleModule {
private static permissions$ = new ReplaySubject<string[]>(1);
static forTesting(...permissions: string[]): ModuleWithProviders<AuthorizationToggleModule> {
AuthorizationToggleModule.switchTestingPermissions(...permissions);
return {
ngModule: AuthorizationToggleModule,
providers: [
{
provide: AuthorizationToggleService,
useValue: {
isAuthorizedTo: (permission: string) =>
AuthorizationToggleModule.permissions$.pipe(
whenTruthy(),
map(perms => checkPermission(perms, permission))
),
},
},
],
};
}
static switchTestingPermissions(...permissions: string[]) {
AuthorizationToggleModule.permissions$.next(permissions);
}
}
export { AuthorizationToggleService } from './utils/authorization-toggle/authorization-toggle.service';
export { authorizationToggleGuard } from './guards/authorization-toggle.guard';
|