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