@yelon/acl 12.0.19 → 13.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/acl.d.ts +1 -0
- package/{esm2015/acl.js → esm2020/acl.mjs} +0 -0
- package/{esm2015/index.js → esm2020/index.mjs} +0 -0
- package/esm2020/src/acl-guard.mjs +58 -0
- package/esm2020/src/acl-if.directive.mjs +79 -0
- package/{esm2015/src/acl.config.js → esm2020/src/acl.config.mjs} +0 -0
- package/esm2020/src/acl.directive.mjs +48 -0
- package/esm2020/src/acl.module.mjs +27 -0
- package/esm2020/src/acl.service.mjs +195 -0
- package/{esm2015/src/acl.type.js → esm2020/src/acl.type.mjs} +0 -0
- package/fesm2015/{acl.js → acl.mjs} +57 -64
- package/fesm2015/acl.mjs.map +1 -0
- package/fesm2020/acl.mjs +406 -0
- package/fesm2020/acl.mjs.map +1 -0
- package/package.json +21 -9
- package/src/acl-guard.d.ts +3 -0
- package/src/acl-if.directive.d.ts +3 -0
- package/src/acl.directive.d.ts +3 -0
- package/src/acl.module.d.ts +7 -0
- package/src/acl.service.d.ts +3 -0
- package/acl.metadata.json +0 -1
- package/bundles/acl.umd.js +0 -839
- package/bundles/acl.umd.js.map +0 -1
- package/esm2015/src/acl-guard.js +0 -59
- package/esm2015/src/acl-if.directive.js +0 -78
- package/esm2015/src/acl.directive.js +0 -47
- package/esm2015/src/acl.module.js +0 -22
- package/esm2015/src/acl.service.js +0 -195
- package/fesm2015/acl.js.map +0 -1
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { Injectable, Directive,
|
|
2
|
+
import { Injectable, Directive, Input, NgModule } from '@angular/core';
|
|
3
3
|
import { BehaviorSubject, Observable, of } from 'rxjs';
|
|
4
|
-
import
|
|
4
|
+
import * as i1 from '@yelon/util/config';
|
|
5
5
|
import { filter, map, tap } from 'rxjs/operators';
|
|
6
6
|
import * as i2 from '@angular/router';
|
|
7
|
-
import { Router } from '@angular/router';
|
|
8
7
|
import { CommonModule } from '@angular/common';
|
|
9
8
|
|
|
10
9
|
const ACL_DEFAULT_CONFIG = {
|
|
@@ -195,12 +194,11 @@ class ACLService {
|
|
|
195
194
|
return this.can(this.parseAbility(value));
|
|
196
195
|
}
|
|
197
196
|
}
|
|
198
|
-
ACLService
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
];
|
|
197
|
+
ACLService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ACLService, deps: [{ token: i1.YunzaiConfigService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
198
|
+
ACLService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ACLService });
|
|
199
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ACLService, decorators: [{
|
|
200
|
+
type: Injectable
|
|
201
|
+
}], ctorParameters: function () { return [{ type: i1.YunzaiConfigService }]; } });
|
|
204
202
|
|
|
205
203
|
class ACLIfDirective {
|
|
206
204
|
constructor(templateRef, srv, _viewContainer) {
|
|
@@ -259,23 +257,23 @@ class ACLIfDirective {
|
|
|
259
257
|
this._change$.unsubscribe();
|
|
260
258
|
}
|
|
261
259
|
}
|
|
262
|
-
ACLIfDirective
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
]
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
]
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
};
|
|
260
|
+
ACLIfDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ACLIfDirective, deps: [{ token: i0.TemplateRef }, { token: ACLService }, { token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive });
|
|
261
|
+
ACLIfDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: ACLIfDirective, selector: "[aclIf]", inputs: { aclIf: "aclIf", aclIfThen: "aclIfThen", aclIfElse: "aclIfElse", except: "except" }, exportAs: ["aclIf"], ngImport: i0 });
|
|
262
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ACLIfDirective, decorators: [{
|
|
263
|
+
type: Directive,
|
|
264
|
+
args: [{
|
|
265
|
+
selector: '[aclIf]',
|
|
266
|
+
exportAs: 'aclIf'
|
|
267
|
+
}]
|
|
268
|
+
}], ctorParameters: function () { return [{ type: i0.TemplateRef }, { type: ACLService }, { type: i0.ViewContainerRef }]; }, propDecorators: { aclIf: [{
|
|
269
|
+
type: Input
|
|
270
|
+
}], aclIfThen: [{
|
|
271
|
+
type: Input
|
|
272
|
+
}], aclIfElse: [{
|
|
273
|
+
type: Input
|
|
274
|
+
}], except: [{
|
|
275
|
+
type: Input
|
|
276
|
+
}] } });
|
|
279
277
|
|
|
280
278
|
class ACLDirective {
|
|
281
279
|
constructor(el, renderer, srv) {
|
|
@@ -305,27 +303,21 @@ class ACLDirective {
|
|
|
305
303
|
this.change$.unsubscribe();
|
|
306
304
|
}
|
|
307
305
|
}
|
|
308
|
-
ACLDirective
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
]
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
]
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
};
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* NOTE:`ACLType` 类型可能会被其他类库所引用,为了减少类库间彼此的依赖性,其他类库会以复制的形式存在
|
|
326
|
-
* 当这里有变化时,请务必同步更新,涉及:`MenuService.acl`、`util.YunzaiACLType`
|
|
327
|
-
* TODO: 尝试增加 `@yelon/core` 类库用于处理这种通用型
|
|
328
|
-
*/
|
|
306
|
+
ACLDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ACLDirective, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }, { token: ACLService }], target: i0.ɵɵFactoryTarget.Directive });
|
|
307
|
+
ACLDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: ACLDirective, selector: "[acl]", inputs: { acl: "acl", ability: ["acl-ability", "ability"] }, exportAs: ["acl"], ngImport: i0 });
|
|
308
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ACLDirective, decorators: [{
|
|
309
|
+
type: Directive,
|
|
310
|
+
args: [{
|
|
311
|
+
selector: '[acl]',
|
|
312
|
+
exportAs: 'acl'
|
|
313
|
+
}]
|
|
314
|
+
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.Renderer2 }, { type: ACLService }]; }, propDecorators: { acl: [{
|
|
315
|
+
type: Input,
|
|
316
|
+
args: ['acl']
|
|
317
|
+
}], ability: [{
|
|
318
|
+
type: Input,
|
|
319
|
+
args: ['acl-ability']
|
|
320
|
+
}] } });
|
|
329
321
|
|
|
330
322
|
/**
|
|
331
323
|
* Routing guard prevent unauthorized users visit the page, [ACL Document](https://ng.yunzainfo.com/acl).
|
|
@@ -368,15 +360,12 @@ class ACLGuard {
|
|
|
368
360
|
return this.process(route.data);
|
|
369
361
|
}
|
|
370
362
|
}
|
|
371
|
-
ACLGuard.ɵ
|
|
372
|
-
ACLGuard
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
{ type: Router },
|
|
378
|
-
{ type: Injector }
|
|
379
|
-
];
|
|
363
|
+
ACLGuard.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ACLGuard, deps: [{ token: ACLService }, { token: i2.Router }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
364
|
+
ACLGuard.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ACLGuard, providedIn: 'root' });
|
|
365
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ACLGuard, decorators: [{
|
|
366
|
+
type: Injectable,
|
|
367
|
+
args: [{ providedIn: 'root' }]
|
|
368
|
+
}], ctorParameters: function () { return [{ type: ACLService }, { type: i2.Router }, { type: i0.Injector }]; } });
|
|
380
369
|
|
|
381
370
|
const COMPONENTS = [ACLDirective, ACLIfDirective];
|
|
382
371
|
class YelonACLModule {
|
|
@@ -387,17 +376,21 @@ class YelonACLModule {
|
|
|
387
376
|
};
|
|
388
377
|
}
|
|
389
378
|
}
|
|
390
|
-
YelonACLModule
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
]
|
|
379
|
+
YelonACLModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: YelonACLModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
380
|
+
YelonACLModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: YelonACLModule, declarations: [ACLDirective, ACLIfDirective], imports: [CommonModule], exports: [ACLDirective, ACLIfDirective] });
|
|
381
|
+
YelonACLModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: YelonACLModule, imports: [[CommonModule]] });
|
|
382
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: YelonACLModule, decorators: [{
|
|
383
|
+
type: NgModule,
|
|
384
|
+
args: [{
|
|
385
|
+
imports: [CommonModule],
|
|
386
|
+
declarations: COMPONENTS,
|
|
387
|
+
exports: COMPONENTS
|
|
388
|
+
}]
|
|
389
|
+
}] });
|
|
397
390
|
|
|
398
391
|
/**
|
|
399
392
|
* Generated bundle index. Do not edit.
|
|
400
393
|
*/
|
|
401
394
|
|
|
402
395
|
export { ACLDirective, ACLGuard, ACLIfDirective, ACLService, ACL_DEFAULT_CONFIG, YelonACLModule };
|
|
403
|
-
//# sourceMappingURL=acl.
|
|
396
|
+
//# sourceMappingURL=acl.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acl.mjs","sources":["../../../../packages/acl/src/acl.config.ts","../../../../packages/acl/src/acl.service.ts","../../../../packages/acl/src/acl-if.directive.ts","../../../../packages/acl/src/acl.directive.ts","../../../../packages/acl/src/acl-guard.ts","../../../../packages/acl/src/acl.module.ts","../../../../packages/acl/acl.ts"],"sourcesContent":["import { YunzaiACLConfig } from '@yelon/util/config';\n\nexport const ACL_DEFAULT_CONFIG: YunzaiACLConfig = {\n guard_url: `/403`\n};\n","import { Injectable } from '@angular/core';\nimport { BehaviorSubject, Observable } from 'rxjs';\n\nimport { YunzaiACLConfig, YunzaiConfigService } from '@yelon/util/config';\n\nimport { ACL_DEFAULT_CONFIG } from './acl.config';\nimport { ACLCanType, ACLType } from './acl.type';\n\n/**\n * ACL 控制服务,[在线文档](https://ng.yunzainfo.com/acl)\n *\n * 务必在根目录注册 `YelonACLModule.forRoot()` 才能使用服务\n */\n@Injectable()\nexport class ACLService {\n private options: YunzaiACLConfig;\n private roles: string[] = [];\n private abilities: Array<number | string> = [];\n private full = false;\n private aclChange = new BehaviorSubject<ACLType | boolean | null>(null);\n\n /** ACL变更通知 */\n get change(): Observable<ACLType | boolean | null> {\n return this.aclChange.asObservable();\n }\n\n /** 获取所有数据 */\n get data(): { full: boolean; roles: string[]; abilities: Array<string | number> } {\n return {\n full: this.full,\n roles: this.roles,\n abilities: this.abilities\n };\n }\n\n get guard_url(): string {\n return this.options.guard_url!;\n }\n\n constructor(configSrv: YunzaiConfigService) {\n this.options = configSrv.merge('acl', ACL_DEFAULT_CONFIG)!;\n }\n\n private parseACLType(val: string | string[] | number | number[] | ACLType | null): ACLType {\n let t: ACLType;\n if (typeof val === 'number') {\n t = { ability: [val] };\n } else if (Array.isArray(val) && val.length > 0 && typeof val[0] === 'number') {\n t = { ability: val };\n } else if (typeof val === 'object' && !Array.isArray(val)) {\n t = { ...val };\n } else if (Array.isArray(val)) {\n t = { role: val as string[] };\n } else {\n t = { role: val == null ? [] : [val] };\n }\n\n return { except: false, ...t };\n }\n\n /**\n * 设置当前用户角色或权限能力(会先清除所有)\n */\n set(value: ACLType): void {\n this.full = false;\n this.abilities = [];\n this.roles = [];\n this.add(value);\n this.aclChange.next(value);\n }\n\n /**\n * 标识当前用户为全量,即不受限\n */\n setFull(val: boolean): void {\n this.full = val;\n this.aclChange.next(val);\n }\n\n /**\n * 设置当前用户权限能力(会先清除所有)\n */\n setAbility(abilities: Array<number | string>): void {\n this.set({ ability: abilities } as ACLType);\n }\n\n /**\n * 设置当前用户角色(会先清除所有)\n */\n setRole(roles: string[]): void {\n this.set({ role: roles } as ACLType);\n }\n\n /**\n * 为当前用户增加角色或权限能力\n */\n add(value: ACLType): void {\n if (value.role && value.role.length > 0) {\n this.roles.push(...value.role);\n }\n if (value.ability && value.ability.length > 0) {\n this.abilities.push(...value.ability);\n }\n }\n\n /**\n * 为当前用户附加角色\n */\n attachRole(roles: string[]): void {\n for (const val of roles) {\n if (!this.roles.includes(val)) {\n this.roles.push(val);\n }\n }\n this.aclChange.next(this.data);\n }\n\n /**\n * 为当前用户附加权限\n */\n attachAbility(abilities: Array<number | string>): void {\n for (const val of abilities) {\n if (!this.abilities.includes(val)) {\n this.abilities.push(val);\n }\n }\n this.aclChange.next(this.data);\n }\n\n /**\n * 为当前用户移除角色\n */\n removeRole(roles: string[]): void {\n for (const val of roles) {\n const idx = this.roles.indexOf(val);\n if (idx !== -1) {\n this.roles.splice(idx, 1);\n }\n }\n this.aclChange.next(this.data);\n }\n\n /**\n * 为当前用户移除权限\n */\n removeAbility(abilities: Array<number | string>): void {\n for (const val of abilities) {\n const idx = this.abilities.indexOf(val);\n if (idx !== -1) {\n this.abilities.splice(idx, 1);\n }\n }\n this.aclChange.next(this.data);\n }\n\n /**\n * 当前用户是否有对应角色,其实 `number` 表示Ability\n *\n * - 当 `full: true` 或参数 `null` 时返回 `true`\n * - 若使用 `ACLType` 参数,可以指定 `mode` 校验模式\n */\n can(roleOrAbility: ACLCanType | null): boolean {\n const { preCan } = this.options;\n if (preCan) {\n roleOrAbility = preCan(roleOrAbility!);\n }\n\n const t = this.parseACLType(roleOrAbility);\n let result = false;\n if (this.full === true || !roleOrAbility) {\n result = true;\n } else {\n if (t.role && t.role.length > 0) {\n if (t.mode === 'allOf') {\n result = t.role.every(v => this.roles.includes(v));\n } else {\n result = t.role.some(v => this.roles.includes(v));\n }\n }\n if (t.ability && t.ability.length > 0) {\n if (t.mode === 'allOf') {\n result = (t.ability as Array<number | string>).every(v => this.abilities.includes(v));\n } else {\n result = (t.ability as Array<number | string>).some(v => this.abilities.includes(v));\n }\n }\n }\n\n return t.except === true ? !result : result;\n }\n\n /** @inner */\n parseAbility(value: ACLCanType): ACLCanType {\n if (typeof value === 'number' || typeof value === 'string' || Array.isArray(value)) {\n value = { ability: Array.isArray(value) ? value : [value] } as ACLType;\n }\n delete value.role;\n return value;\n }\n\n /**\n * 当前用户是否有对应权限点\n */\n canAbility(value: ACLCanType): boolean {\n return this.can(this.parseAbility(value));\n }\n}\n","import { Directive, EmbeddedViewRef, Input, OnDestroy, TemplateRef, ViewContainerRef } from '@angular/core';\nimport { Subscription } from 'rxjs';\nimport { filter } from 'rxjs/operators';\n\nimport { ACLService } from './acl.service';\nimport { ACLCanType } from './acl.type';\n\n@Directive({\n selector: '[aclIf]',\n exportAs: 'aclIf'\n})\nexport class ACLIfDirective implements OnDestroy {\n static ngAcceptInputType_except: boolean | string | undefined | null;\n\n private _value!: ACLCanType;\n private _change$: Subscription;\n private _thenTemplateRef: TemplateRef<void> | null = null;\n private _elseTemplateRef: TemplateRef<void> | null = null;\n private _thenViewRef: EmbeddedViewRef<void> | null = null;\n private _elseViewRef: EmbeddedViewRef<void> | null = null;\n private _except = false;\n\n constructor(templateRef: TemplateRef<void>, private srv: ACLService, private _viewContainer: ViewContainerRef) {\n this._change$ = this.srv.change.pipe(filter(r => r != null)).subscribe(() => this._updateView());\n this._thenTemplateRef = templateRef;\n }\n\n @Input()\n set aclIf(value: ACLCanType) {\n this._value = value;\n this._updateView();\n }\n\n @Input()\n set aclIfThen(templateRef: TemplateRef<void> | null) {\n this._thenTemplateRef = templateRef;\n this._thenViewRef = null;\n this._updateView();\n }\n\n @Input()\n set aclIfElse(templateRef: TemplateRef<void> | null) {\n this._elseTemplateRef = templateRef;\n this._elseViewRef = null;\n this._updateView();\n }\n\n @Input()\n set except(value: boolean) {\n this._except = value != null && `${value}` !== 'false';\n }\n get except(): boolean {\n return this._except;\n }\n\n protected _updateView(): void {\n const res = this.srv.can(this._value);\n if ((res && !this.except) || (!res && this.except)) {\n if (!this._thenViewRef) {\n this._viewContainer.clear();\n this._elseViewRef = null;\n if (this._thenTemplateRef) {\n this._thenViewRef = this._viewContainer.createEmbeddedView(this._thenTemplateRef);\n }\n }\n } else {\n if (!this._elseViewRef) {\n this._viewContainer.clear();\n this._thenViewRef = null;\n if (this._elseTemplateRef) {\n this._elseViewRef = this._viewContainer.createEmbeddedView(this._elseTemplateRef);\n }\n }\n }\n }\n\n ngOnDestroy(): void {\n this._change$.unsubscribe();\n }\n}\n","import { Directive, ElementRef, Input, OnDestroy, Renderer2 } from '@angular/core';\nimport { Subscription } from 'rxjs';\nimport { filter } from 'rxjs/operators';\n\nimport { ACLService } from './acl.service';\nimport { ACLCanType } from './acl.type';\n\n@Directive({\n selector: '[acl]',\n exportAs: 'acl'\n})\nexport class ACLDirective implements OnDestroy {\n private _value!: ACLCanType;\n private change$: Subscription;\n\n @Input('acl')\n set acl(value: ACLCanType) {\n this.set(value);\n }\n\n @Input('acl-ability')\n set ability(value: ACLCanType) {\n this.set(this.srv.parseAbility(value));\n }\n\n private set(value: ACLCanType): void {\n this._value = value;\n const CLS = 'acl__hide';\n const el = this.el.nativeElement;\n if (this.srv.can(this._value)) {\n this.renderer.removeClass(el, CLS);\n } else {\n this.renderer.addClass(el, CLS);\n }\n }\n\n constructor(private el: ElementRef, private renderer: Renderer2, protected srv: ACLService) {\n this.change$ = this.srv.change.pipe(filter(r => r != null)).subscribe(() => this.set(this._value));\n }\n\n ngOnDestroy(): void {\n this.change$.unsubscribe();\n }\n}\n","import { Injectable, Injector } from '@angular/core';\nimport {\n ActivatedRouteSnapshot,\n CanActivate,\n CanActivateChild,\n CanLoad,\n Data,\n Route,\n Router,\n RouterStateSnapshot\n} from '@angular/router';\nimport { Observable, of } from 'rxjs';\nimport { map, tap } from 'rxjs/operators';\n\nimport { ACLService } from './acl.service';\nimport { ACLCanType, ACLGuardType } from './acl.type';\n\n/**\n * Routing guard prevent unauthorized users visit the page, [ACL Document](https://ng.yunzainfo.com/acl).\n *\n * ```ts\n * data: {\n * path: 'home',\n * canActivate: [ ACLGuard ],\n * data: { guard: 'user1' }\n * }\n * ```\n */\n@Injectable({ providedIn: 'root' })\nexport class ACLGuard implements CanActivate, CanActivateChild, CanLoad {\n constructor(private srv: ACLService, private router: Router, private injector: Injector) {}\n\n private process(data: Data): Observable<boolean> {\n data = {\n guard: null,\n guard_url: this.srv.guard_url,\n ...data\n };\n let guard: ACLGuardType = data.guard;\n if (typeof guard === 'function') guard = guard(this.srv, this.injector);\n return (guard && guard instanceof Observable ? guard : of(guard != null ? (guard as ACLCanType) : null)).pipe(\n map(v => this.srv.can(v)),\n tap(v => {\n if (v) return;\n this.router.navigateByUrl(data.guard_url);\n })\n );\n }\n\n // lazy loading\n canLoad(route: Route): Observable<boolean> {\n return this.process(route.data!);\n }\n // all children route\n canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {\n return this.canActivate(childRoute, state);\n }\n // route\n canActivate(route: ActivatedRouteSnapshot, _state: RouterStateSnapshot | null): Observable<boolean> {\n return this.process(route.data);\n }\n}\n","import { CommonModule } from '@angular/common';\nimport { ModuleWithProviders, NgModule } from '@angular/core';\n\nimport { ACLIfDirective } from './acl-if.directive';\nimport { ACLDirective } from './acl.directive';\nimport { ACLService } from './acl.service';\n\nconst COMPONENTS = [ACLDirective, ACLIfDirective];\n\n@NgModule({\n imports: [CommonModule],\n declarations: COMPONENTS,\n exports: COMPONENTS\n})\nexport class YelonACLModule {\n static forRoot(): ModuleWithProviders<YelonACLModule> {\n return {\n ngModule: YelonACLModule,\n providers: [ACLService]\n };\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;MAEa,kBAAkB,GAAoB;IACjD,SAAS,EAAE,MAAM;;;ACKnB;;;;;MAMa,UAAU;IAyBrB,YAAY,SAA8B;QAvBlC,UAAK,GAAa,EAAE,CAAC;QACrB,cAAS,GAA2B,EAAE,CAAC;QACvC,SAAI,GAAG,KAAK,CAAC;QACb,cAAS,GAAG,IAAI,eAAe,CAA2B,IAAI,CAAC,CAAC;QAqBtE,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,kBAAkB,CAAE,CAAC;KAC5D;;IAnBD,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,CAAC;KACtC;;IAGD,IAAI,IAAI;QACN,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,SAAS,EAAE,IAAI,CAAC,SAAS;SAC1B,CAAC;KACH;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,OAAO,CAAC,SAAU,CAAC;KAChC;IAMO,YAAY,CAAC,GAA2D;QAC9E,IAAI,CAAU,CAAC;QACf,IAAI,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,YAAY,EAAE,cAAc,aAGpC,YAAY,aAHJ,YAAY,EAAE,cAAc;4GAOnC,cAAc,YAJhB,CAAC,YAAY,CAAC;2FAIZ,cAAc;kBAL1B,QAAQ;mBAAC;oBACR,OAAO,EAAE,CAAC,YAAY,CAAC;oBACvB,YAAY,EAAE,UAAU;oBACxB,OAAO,EAAE,UAAU;iBACpB;;;ACbD;;;;;;"}
|
package/fesm2020/acl.mjs
ADDED
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { Injectable, Directive, Input, NgModule } from '@angular/core';
|
|
3
|
+
import { BehaviorSubject, Observable, of } from 'rxjs';
|
|
4
|
+
import * as i1 from '@yelon/util/config';
|
|
5
|
+
import { filter, map, tap } from 'rxjs/operators';
|
|
6
|
+
import * as i2 from '@angular/router';
|
|
7
|
+
import { CommonModule } from '@angular/common';
|
|
8
|
+
|
|
9
|
+
const ACL_DEFAULT_CONFIG = {
|
|
10
|
+
guard_url: `/403`
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* ACL 控制服务,[在线文档](https://ng.yunzainfo.com/acl)
|
|
15
|
+
*
|
|
16
|
+
* 务必在根目录注册 `YelonACLModule.forRoot()` 才能使用服务
|
|
17
|
+
*/
|
|
18
|
+
class ACLService {
|
|
19
|
+
constructor(configSrv) {
|
|
20
|
+
this.roles = [];
|
|
21
|
+
this.abilities = [];
|
|
22
|
+
this.full = false;
|
|
23
|
+
this.aclChange = new BehaviorSubject(null);
|
|
24
|
+
this.options = configSrv.merge('acl', ACL_DEFAULT_CONFIG);
|
|
25
|
+
}
|
|
26
|
+
/** ACL变更通知 */
|
|
27
|
+
get change() {
|
|
28
|
+
return this.aclChange.asObservable();
|
|
29
|
+
}
|
|
30
|
+
/** 获取所有数据 */
|
|
31
|
+
get data() {
|
|
32
|
+
return {
|
|
33
|
+
full: this.full,
|
|
34
|
+
roles: this.roles,
|
|
35
|
+
abilities: this.abilities
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
get guard_url() {
|
|
39
|
+
return this.options.guard_url;
|
|
40
|
+
}
|
|
41
|
+
parseACLType(val) {
|
|
42
|
+
let t;
|
|
43
|
+
if (typeof val === 'number') {
|
|
44
|
+
t = { ability: [val] };
|
|
45
|
+
}
|
|
46
|
+
else if (Array.isArray(val) && val.length > 0 && typeof val[0] === 'number') {
|
|
47
|
+
t = { ability: val };
|
|
48
|
+
}
|
|
49
|
+
else if (typeof val === 'object' && !Array.isArray(val)) {
|
|
50
|
+
t = { ...val };
|
|
51
|
+
}
|
|
52
|
+
else if (Array.isArray(val)) {
|
|
53
|
+
t = { role: val };
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
t = { role: val == null ? [] : [val] };
|
|
57
|
+
}
|
|
58
|
+
return { except: false, ...t };
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 设置当前用户角色或权限能力(会先清除所有)
|
|
62
|
+
*/
|
|
63
|
+
set(value) {
|
|
64
|
+
this.full = false;
|
|
65
|
+
this.abilities = [];
|
|
66
|
+
this.roles = [];
|
|
67
|
+
this.add(value);
|
|
68
|
+
this.aclChange.next(value);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 标识当前用户为全量,即不受限
|
|
72
|
+
*/
|
|
73
|
+
setFull(val) {
|
|
74
|
+
this.full = val;
|
|
75
|
+
this.aclChange.next(val);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 设置当前用户权限能力(会先清除所有)
|
|
79
|
+
*/
|
|
80
|
+
setAbility(abilities) {
|
|
81
|
+
this.set({ ability: abilities });
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* 设置当前用户角色(会先清除所有)
|
|
85
|
+
*/
|
|
86
|
+
setRole(roles) {
|
|
87
|
+
this.set({ role: roles });
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 为当前用户增加角色或权限能力
|
|
91
|
+
*/
|
|
92
|
+
add(value) {
|
|
93
|
+
if (value.role && value.role.length > 0) {
|
|
94
|
+
this.roles.push(...value.role);
|
|
95
|
+
}
|
|
96
|
+
if (value.ability && value.ability.length > 0) {
|
|
97
|
+
this.abilities.push(...value.ability);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* 为当前用户附加角色
|
|
102
|
+
*/
|
|
103
|
+
attachRole(roles) {
|
|
104
|
+
for (const val of roles) {
|
|
105
|
+
if (!this.roles.includes(val)) {
|
|
106
|
+
this.roles.push(val);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
this.aclChange.next(this.data);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* 为当前用户附加权限
|
|
113
|
+
*/
|
|
114
|
+
attachAbility(abilities) {
|
|
115
|
+
for (const val of abilities) {
|
|
116
|
+
if (!this.abilities.includes(val)) {
|
|
117
|
+
this.abilities.push(val);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
this.aclChange.next(this.data);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* 为当前用户移除角色
|
|
124
|
+
*/
|
|
125
|
+
removeRole(roles) {
|
|
126
|
+
for (const val of roles) {
|
|
127
|
+
const idx = this.roles.indexOf(val);
|
|
128
|
+
if (idx !== -1) {
|
|
129
|
+
this.roles.splice(idx, 1);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
this.aclChange.next(this.data);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* 为当前用户移除权限
|
|
136
|
+
*/
|
|
137
|
+
removeAbility(abilities) {
|
|
138
|
+
for (const val of abilities) {
|
|
139
|
+
const idx = this.abilities.indexOf(val);
|
|
140
|
+
if (idx !== -1) {
|
|
141
|
+
this.abilities.splice(idx, 1);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
this.aclChange.next(this.data);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* 当前用户是否有对应角色,其实 `number` 表示Ability
|
|
148
|
+
*
|
|
149
|
+
* - 当 `full: true` 或参数 `null` 时返回 `true`
|
|
150
|
+
* - 若使用 `ACLType` 参数,可以指定 `mode` 校验模式
|
|
151
|
+
*/
|
|
152
|
+
can(roleOrAbility) {
|
|
153
|
+
const { preCan } = this.options;
|
|
154
|
+
if (preCan) {
|
|
155
|
+
roleOrAbility = preCan(roleOrAbility);
|
|
156
|
+
}
|
|
157
|
+
const t = this.parseACLType(roleOrAbility);
|
|
158
|
+
let result = false;
|
|
159
|
+
if (this.full === true || !roleOrAbility) {
|
|
160
|
+
result = true;
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
if (t.role && t.role.length > 0) {
|
|
164
|
+
if (t.mode === 'allOf') {
|
|
165
|
+
result = t.role.every(v => this.roles.includes(v));
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
result = t.role.some(v => this.roles.includes(v));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (t.ability && t.ability.length > 0) {
|
|
172
|
+
if (t.mode === 'allOf') {
|
|
173
|
+
result = t.ability.every(v => this.abilities.includes(v));
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
result = t.ability.some(v => this.abilities.includes(v));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return t.except === true ? !result : result;
|
|
181
|
+
}
|
|
182
|
+
/** @inner */
|
|
183
|
+
parseAbility(value) {
|
|
184
|
+
if (typeof value === 'number' || typeof value === 'string' || Array.isArray(value)) {
|
|
185
|
+
value = { ability: Array.isArray(value) ? value : [value] };
|
|
186
|
+
}
|
|
187
|
+
delete value.role;
|
|
188
|
+
return value;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* 当前用户是否有对应权限点
|
|
192
|
+
*/
|
|
193
|
+
canAbility(value) {
|
|
194
|
+
return this.can(this.parseAbility(value));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
ACLService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ACLService, deps: [{ token: i1.YunzaiConfigService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
198
|
+
ACLService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ACLService });
|
|
199
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ACLService, decorators: [{
|
|
200
|
+
type: Injectable
|
|
201
|
+
}], ctorParameters: function () { return [{ type: i1.YunzaiConfigService }]; } });
|
|
202
|
+
|
|
203
|
+
class ACLIfDirective {
|
|
204
|
+
constructor(templateRef, srv, _viewContainer) {
|
|
205
|
+
this.srv = srv;
|
|
206
|
+
this._viewContainer = _viewContainer;
|
|
207
|
+
this._thenTemplateRef = null;
|
|
208
|
+
this._elseTemplateRef = null;
|
|
209
|
+
this._thenViewRef = null;
|
|
210
|
+
this._elseViewRef = null;
|
|
211
|
+
this._except = false;
|
|
212
|
+
this._change$ = this.srv.change.pipe(filter(r => r != null)).subscribe(() => this._updateView());
|
|
213
|
+
this._thenTemplateRef = templateRef;
|
|
214
|
+
}
|
|
215
|
+
set aclIf(value) {
|
|
216
|
+
this._value = value;
|
|
217
|
+
this._updateView();
|
|
218
|
+
}
|
|
219
|
+
set aclIfThen(templateRef) {
|
|
220
|
+
this._thenTemplateRef = templateRef;
|
|
221
|
+
this._thenViewRef = null;
|
|
222
|
+
this._updateView();
|
|
223
|
+
}
|
|
224
|
+
set aclIfElse(templateRef) {
|
|
225
|
+
this._elseTemplateRef = templateRef;
|
|
226
|
+
this._elseViewRef = null;
|
|
227
|
+
this._updateView();
|
|
228
|
+
}
|
|
229
|
+
set except(value) {
|
|
230
|
+
this._except = value != null && `${value}` !== 'false';
|
|
231
|
+
}
|
|
232
|
+
get except() {
|
|
233
|
+
return this._except;
|
|
234
|
+
}
|
|
235
|
+
_updateView() {
|
|
236
|
+
const res = this.srv.can(this._value);
|
|
237
|
+
if ((res && !this.except) || (!res && this.except)) {
|
|
238
|
+
if (!this._thenViewRef) {
|
|
239
|
+
this._viewContainer.clear();
|
|
240
|
+
this._elseViewRef = null;
|
|
241
|
+
if (this._thenTemplateRef) {
|
|
242
|
+
this._thenViewRef = this._viewContainer.createEmbeddedView(this._thenTemplateRef);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
if (!this._elseViewRef) {
|
|
248
|
+
this._viewContainer.clear();
|
|
249
|
+
this._thenViewRef = null;
|
|
250
|
+
if (this._elseTemplateRef) {
|
|
251
|
+
this._elseViewRef = this._viewContainer.createEmbeddedView(this._elseTemplateRef);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
ngOnDestroy() {
|
|
257
|
+
this._change$.unsubscribe();
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
ACLIfDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ACLIfDirective, deps: [{ token: i0.TemplateRef }, { token: ACLService }, { token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive });
|
|
261
|
+
ACLIfDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: ACLIfDirective, selector: "[aclIf]", inputs: { aclIf: "aclIf", aclIfThen: "aclIfThen", aclIfElse: "aclIfElse", except: "except" }, exportAs: ["aclIf"], ngImport: i0 });
|
|
262
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ACLIfDirective, decorators: [{
|
|
263
|
+
type: Directive,
|
|
264
|
+
args: [{
|
|
265
|
+
selector: '[aclIf]',
|
|
266
|
+
exportAs: 'aclIf'
|
|
267
|
+
}]
|
|
268
|
+
}], ctorParameters: function () { return [{ type: i0.TemplateRef }, { type: ACLService }, { type: i0.ViewContainerRef }]; }, propDecorators: { aclIf: [{
|
|
269
|
+
type: Input
|
|
270
|
+
}], aclIfThen: [{
|
|
271
|
+
type: Input
|
|
272
|
+
}], aclIfElse: [{
|
|
273
|
+
type: Input
|
|
274
|
+
}], except: [{
|
|
275
|
+
type: Input
|
|
276
|
+
}] } });
|
|
277
|
+
|
|
278
|
+
class ACLDirective {
|
|
279
|
+
constructor(el, renderer, srv) {
|
|
280
|
+
this.el = el;
|
|
281
|
+
this.renderer = renderer;
|
|
282
|
+
this.srv = srv;
|
|
283
|
+
this.change$ = this.srv.change.pipe(filter(r => r != null)).subscribe(() => this.set(this._value));
|
|
284
|
+
}
|
|
285
|
+
set acl(value) {
|
|
286
|
+
this.set(value);
|
|
287
|
+
}
|
|
288
|
+
set ability(value) {
|
|
289
|
+
this.set(this.srv.parseAbility(value));
|
|
290
|
+
}
|
|
291
|
+
set(value) {
|
|
292
|
+
this._value = value;
|
|
293
|
+
const CLS = 'acl__hide';
|
|
294
|
+
const el = this.el.nativeElement;
|
|
295
|
+
if (this.srv.can(this._value)) {
|
|
296
|
+
this.renderer.removeClass(el, CLS);
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
this.renderer.addClass(el, CLS);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
ngOnDestroy() {
|
|
303
|
+
this.change$.unsubscribe();
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
ACLDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ACLDirective, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }, { token: ACLService }], target: i0.ɵɵFactoryTarget.Directive });
|
|
307
|
+
ACLDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: ACLDirective, selector: "[acl]", inputs: { acl: "acl", ability: ["acl-ability", "ability"] }, exportAs: ["acl"], ngImport: i0 });
|
|
308
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ACLDirective, decorators: [{
|
|
309
|
+
type: Directive,
|
|
310
|
+
args: [{
|
|
311
|
+
selector: '[acl]',
|
|
312
|
+
exportAs: 'acl'
|
|
313
|
+
}]
|
|
314
|
+
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.Renderer2 }, { type: ACLService }]; }, propDecorators: { acl: [{
|
|
315
|
+
type: Input,
|
|
316
|
+
args: ['acl']
|
|
317
|
+
}], ability: [{
|
|
318
|
+
type: Input,
|
|
319
|
+
args: ['acl-ability']
|
|
320
|
+
}] } });
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* NOTE:`ACLType` 类型可能会被其他类库所引用,为了减少类库间彼此的依赖性,其他类库会以复制的形式存在
|
|
324
|
+
* 当这里有变化时,请务必同步更新,涉及:`MenuService.acl`、`util.YunzaiACLType`
|
|
325
|
+
* TODO: 尝试增加 `@yelon/core` 类库用于处理这种通用型
|
|
326
|
+
*/
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Routing guard prevent unauthorized users visit the page, [ACL Document](https://ng.yunzainfo.com/acl).
|
|
330
|
+
*
|
|
331
|
+
* ```ts
|
|
332
|
+
* data: {
|
|
333
|
+
* path: 'home',
|
|
334
|
+
* canActivate: [ ACLGuard ],
|
|
335
|
+
* data: { guard: 'user1' }
|
|
336
|
+
* }
|
|
337
|
+
* ```
|
|
338
|
+
*/
|
|
339
|
+
class ACLGuard {
|
|
340
|
+
constructor(srv, router, injector) {
|
|
341
|
+
this.srv = srv;
|
|
342
|
+
this.router = router;
|
|
343
|
+
this.injector = injector;
|
|
344
|
+
}
|
|
345
|
+
process(data) {
|
|
346
|
+
data = {
|
|
347
|
+
guard: null,
|
|
348
|
+
guard_url: this.srv.guard_url,
|
|
349
|
+
...data
|
|
350
|
+
};
|
|
351
|
+
let guard = data.guard;
|
|
352
|
+
if (typeof guard === 'function')
|
|
353
|
+
guard = guard(this.srv, this.injector);
|
|
354
|
+
return (guard && guard instanceof Observable ? guard : of(guard != null ? guard : null)).pipe(map(v => this.srv.can(v)), tap(v => {
|
|
355
|
+
if (v)
|
|
356
|
+
return;
|
|
357
|
+
this.router.navigateByUrl(data.guard_url);
|
|
358
|
+
}));
|
|
359
|
+
}
|
|
360
|
+
// lazy loading
|
|
361
|
+
canLoad(route) {
|
|
362
|
+
return this.process(route.data);
|
|
363
|
+
}
|
|
364
|
+
// all children route
|
|
365
|
+
canActivateChild(childRoute, state) {
|
|
366
|
+
return this.canActivate(childRoute, state);
|
|
367
|
+
}
|
|
368
|
+
// route
|
|
369
|
+
canActivate(route, _state) {
|
|
370
|
+
return this.process(route.data);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
ACLGuard.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ACLGuard, deps: [{ token: ACLService }, { token: i2.Router }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
374
|
+
ACLGuard.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ACLGuard, providedIn: 'root' });
|
|
375
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: ACLGuard, decorators: [{
|
|
376
|
+
type: Injectable,
|
|
377
|
+
args: [{ providedIn: 'root' }]
|
|
378
|
+
}], ctorParameters: function () { return [{ type: ACLService }, { type: i2.Router }, { type: i0.Injector }]; } });
|
|
379
|
+
|
|
380
|
+
const COMPONENTS = [ACLDirective, ACLIfDirective];
|
|
381
|
+
class YelonACLModule {
|
|
382
|
+
static forRoot() {
|
|
383
|
+
return {
|
|
384
|
+
ngModule: YelonACLModule,
|
|
385
|
+
providers: [ACLService]
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
YelonACLModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: YelonACLModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
390
|
+
YelonACLModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: YelonACLModule, declarations: [ACLDirective, ACLIfDirective], imports: [CommonModule], exports: [ACLDirective, ACLIfDirective] });
|
|
391
|
+
YelonACLModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: YelonACLModule, imports: [[CommonModule]] });
|
|
392
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: YelonACLModule, decorators: [{
|
|
393
|
+
type: NgModule,
|
|
394
|
+
args: [{
|
|
395
|
+
imports: [CommonModule],
|
|
396
|
+
declarations: COMPONENTS,
|
|
397
|
+
exports: COMPONENTS
|
|
398
|
+
}]
|
|
399
|
+
}] });
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Generated bundle index. Do not edit.
|
|
403
|
+
*/
|
|
404
|
+
|
|
405
|
+
export { ACLDirective, ACLGuard, ACLIfDirective, ACLService, ACL_DEFAULT_CONFIG, YelonACLModule };
|
|
406
|
+
//# sourceMappingURL=acl.mjs.map
|