File
Index
Properties
|
|
Methods
|
|
Accessors
|
|
Methods
_addGlobalRule
|
_addGlobalRule(rule: AclRule)
|
|
Makes it possible to inject new global acl rules during runtime.
This should only be used for development purposes, like the ACL Inspector.
We might remove this from the public API at any time.
|
_setGlobalRules
|
_setGlobalRules(rules: AclRule[])
|
|
Allows to completely swap the global rules for a new one.
This should only be used for development purposes, like from inside the ACL Inspector.
We might remove this from the public API at any time.
|
addDynamicFormRules
|
addDynamicFormRules(formId: string, aclRules: AclRule[])
|
|
|
canEdit
|
canEdit(aclPath: string)
|
|
Parameters :
Name |
Type |
Optional |
aclPath |
string
|
No
|
|
canEdit$
|
canEdit$(aclPath: string)
|
|
Parameters :
Name |
Type |
Optional |
aclPath |
string
|
No
|
|
canShow
|
Use `!aclService.isHidden(aclPath)` instead
|
canShow(aclPath: string)
|
|
Parameters :
Name |
Type |
Optional |
aclPath |
string
|
No
|
|
canShow$
|
Use `aclService.isHidden$(aclPath).pipe(map((value) => !value))` instead
|
canShow$(aclPath: string)
|
|
Parameters :
Name |
Type |
Optional |
aclPath |
string
|
No
|
|
currentState$
|
currentState$(aclPath: string)
|
|
Parameters :
Name |
Type |
Optional |
aclPath |
string
|
No
|
|
isDisabled
|
isDisabled(aclPath: string)
|
|
Parameters :
Name |
Type |
Optional |
aclPath |
string
|
No
|
|
isDisabled$
|
isDisabled$(aclPath: string)
|
|
Parameters :
Name |
Type |
Optional |
aclPath |
string
|
No
|
Returns : Observable<boolean>
|
isHidden
|
isHidden(aclPath: string)
|
|
Parameters :
Name |
Type |
Optional |
aclPath |
string
|
No
|
|
isHidden$
|
isHidden$(aclPath: string)
|
|
Parameters :
Name |
Type |
Optional |
aclPath |
string
|
No
|
Returns : Observable<boolean>
|
isReadonly
|
isReadonly(aclPath: string)
|
|
Parameters :
Name |
Type |
Optional |
aclPath |
string
|
No
|
|
isReadonly$
|
isReadonly$(aclPath: string)
|
|
Parameters :
Name |
Type |
Optional |
aclPath |
string
|
No
|
Returns : Observable<boolean>
|
removeDynamicFormRules
|
removeDynamicFormRules(formId: string)
|
|
Parameters :
Name |
Type |
Optional |
formId |
string
|
No
|
|
setEnvironmentValue
|
setEnvironmentValue(key: string, value: string)
|
|
|
import {
AclEngine,
AclEvaluationInterface,
AclRule,
AclRuleState,
ExpressionStoreAdapter
} from '@allianz/taly-acl';
import { Inject, Injectable, Optional } from '@angular/core';
import { Observable, ReplaySubject, combineLatest } from 'rxjs';
import { map } from 'rxjs/operators';
import { ACL_POLICY_CONTENT_TOKEN, ACL_STORE_ADAPTER_TOKEN } from '../tokens/public-api';
import { missingPolicyWarning } from './missing-policy-warning';
@Injectable()
export class AclService implements AclEvaluationInterface {
currentPolicy$: ReplaySubject<AclRule[]> = new ReplaySubject<AclRule[]>(1);
aclEngine: AclEngine;
constructor(
@Optional() @Inject(ACL_POLICY_CONTENT_TOKEN) injectedPolicyTxtContent?: string,
@Optional() @Inject(ACL_STORE_ADAPTER_TOKEN) aclStoreAdapter?: ExpressionStoreAdapter
) {
const initialPolicy = injectedPolicyTxtContent ?? '# empty';
if (injectedPolicyTxtContent === undefined || injectedPolicyTxtContent === null) {
missingPolicyWarning();
}
this.aclEngine = new AclEngine(aclStoreAdapter);
this.aclEngine.setGlobalRulesFromPolicyTxtFile(initialPolicy);
this.currentPolicy$.next(this.aclEngine.rules);
}
/**
* Allows to completely swap the global rules for a new one.
* This should only be used for development purposes, like from inside the ACL Inspector.
* We might remove this from the public API at any time.
*/
_setGlobalRules(rules: AclRule[]) {
this.aclEngine._setGlobalRules(rules);
this.currentPolicy$.next(this.aclEngine.rules);
}
/**
* Makes it possible to inject new global acl rules during runtime.
* This should only be used for development purposes, like the ACL Inspector.
* We might remove this from the public API at any time.
*/
_addGlobalRule(rule: AclRule) {
this._setGlobalRules([rule, ...this.aclEngine.rules]);
}
addDynamicFormRules(formId: string, aclRules: AclRule[]) {
this.aclEngine.setDynamicFormRules(formId, aclRules);
this.currentPolicy$.next(this.aclEngine.rules);
}
removeDynamicFormRules(formId: string) {
this.aclEngine.removeDynamicFormRules(formId);
this.currentPolicy$.next(this.aclEngine.rules);
}
setEnvironmentValue(key: string, value: string) {
this.aclEngine.setEnvironmentValue(key, value);
}
/**
* @deprecated Use `aclService.isHidden$(aclPath).pipe(map((value) => !value))` instead
*/
canShow$(aclPath: string) {
return this.isHidden$(aclPath).pipe(map((value) => !value));
}
canEdit$(aclPath: string) {
return this.aclEngine.canEdit$(aclPath);
}
/**
* @deprecated Use `!aclService.isHidden(aclPath)` instead
*/
canShow(aclPath: string) {
return !this.isHidden(aclPath);
}
canEdit(aclPath: string) {
return !this.aclEngine.canEdit(aclPath);
}
isReadonly$(aclPath: string): Observable<boolean> {
return this.aclEngine.isReadonly$(aclPath);
}
isReadonly(aclPath: string): boolean {
return this.aclEngine.isReadonly(aclPath);
}
isDisabled$(aclPath: string): Observable<boolean> {
return this.aclEngine.isDisabled$(aclPath);
}
isDisabled(aclPath: string): boolean {
return this.aclEngine.isDisabled(aclPath);
}
isHidden$(aclPath: string): Observable<boolean> {
return this.aclEngine.isHidden$(aclPath);
}
isHidden(aclPath: string): boolean {
return this.aclEngine.isHidden(aclPath);
}
currentState$(aclPath: string): Observable<AclRuleState> {
return combineLatest([
this.isHidden$(aclPath),
this.isDisabled$(aclPath),
this.isReadonly$(aclPath)
]).pipe(
map(([isHidden, isDisabled, isReadonly]) => {
if (isHidden) {
return 'hidden';
} else if (isDisabled) {
return 'disabled';
} else if (isReadonly) {
return 'readonly';
} else {
return 'editable';
}
})
);
}
get unscoped() {
return this;
}
}