@tachybase/acl 1.6.13-alpha.4 → 1.6.13-alpha.6
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/lib/acl-available-strategy.d.ts +1 -0
- package/lib/acl-available-strategy.js +3 -0
- package/lib/acl.d.ts +1 -0
- package/lib/acl.js +18 -4
- package/package.json +4 -4
|
@@ -71,6 +71,9 @@ const _ACLAvailableStrategy = class _ACLAvailableStrategy {
|
|
|
71
71
|
}
|
|
72
72
|
return false;
|
|
73
73
|
}
|
|
74
|
+
isWildcard() {
|
|
75
|
+
return this.options.actions === "*";
|
|
76
|
+
}
|
|
74
77
|
allow(resourceName, actionName) {
|
|
75
78
|
return this.matchAction(this.acl.resolveActionAlias(actionName));
|
|
76
79
|
}
|
package/lib/acl.d.ts
CHANGED
|
@@ -90,6 +90,7 @@ export declare class ACL extends EventEmitter {
|
|
|
90
90
|
setAvailableAction(name: string, options?: AvailableActionOptions): void;
|
|
91
91
|
getAvailableAction(name: string): ACLAvailableAction;
|
|
92
92
|
getAvailableActions(): Map<string, ACLAvailableAction>;
|
|
93
|
+
protected canUseStrategyForResource(resource: string, action: string, strategy: ACLAvailableStrategy | null): boolean;
|
|
93
94
|
setAvailableStrategy(name: string, options: AvailableStrategyOptions): void;
|
|
94
95
|
beforeGrantAction(listener?: Listener): void;
|
|
95
96
|
can(options: CanArgs): CanResult | null;
|
package/lib/acl.js
CHANGED
|
@@ -96,7 +96,7 @@ const _ACL = class _ACL extends import_node_events.default {
|
|
|
96
96
|
this.addCoreMiddleware();
|
|
97
97
|
}
|
|
98
98
|
setStrategyResources(resources) {
|
|
99
|
-
this.strategyResources = new Set(resources);
|
|
99
|
+
this.strategyResources = resources === null ? null : new Set(resources);
|
|
100
100
|
}
|
|
101
101
|
getStrategyResources() {
|
|
102
102
|
return this.strategyResources ? [...this.strategyResources] : null;
|
|
@@ -108,7 +108,8 @@ const _ACL = class _ACL extends import_node_events.default {
|
|
|
108
108
|
this.strategyResources.add(resource);
|
|
109
109
|
}
|
|
110
110
|
removeStrategyResource(resource) {
|
|
111
|
-
|
|
111
|
+
var _a;
|
|
112
|
+
(_a = this.strategyResources) == null ? void 0 : _a.delete(resource);
|
|
112
113
|
}
|
|
113
114
|
define(options) {
|
|
114
115
|
const roleName = options.role;
|
|
@@ -163,6 +164,18 @@ const _ACL = class _ACL extends import_node_events.default {
|
|
|
163
164
|
getAvailableActions() {
|
|
164
165
|
return this.availableActions;
|
|
165
166
|
}
|
|
167
|
+
canUseStrategyForResource(resource, action, strategy) {
|
|
168
|
+
var _a;
|
|
169
|
+
if (this.strategyResources === null || this.strategyResources.has(resource)) {
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
if (!strategy || strategy.isWildcard()) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
const availableAction = this.getAvailableAction(action);
|
|
176
|
+
const actionResource = (_a = availableAction == null ? void 0 : availableAction.options) == null ? void 0 : _a.resource;
|
|
177
|
+
return !!availableAction && (!actionResource || actionResource === "*" || actionResource === resource);
|
|
178
|
+
}
|
|
166
179
|
setAvailableStrategy(name, options) {
|
|
167
180
|
this.availableStrategy.set(name, new import_acl_available_strategy.ACLAvailableStrategy(this, options));
|
|
168
181
|
}
|
|
@@ -207,8 +220,9 @@ const _ACL = class _ACL extends import_node_events.default {
|
|
|
207
220
|
return null;
|
|
208
221
|
}
|
|
209
222
|
let roleStrategyParams;
|
|
210
|
-
|
|
211
|
-
|
|
223
|
+
const resolvedAction = this.resolveActionAlias(action);
|
|
224
|
+
if (this.canUseStrategyForResource(resource, resolvedAction, roleStrategy)) {
|
|
225
|
+
roleStrategyParams = roleStrategy == null ? void 0 : roleStrategy.allow(resource, resolvedAction);
|
|
212
226
|
}
|
|
213
227
|
if (!roleStrategyParams && snippetAllowed) {
|
|
214
228
|
roleStrategyParams = {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tachybase/acl",
|
|
3
|
-
"version": "1.6.13-alpha.
|
|
3
|
+
"version": "1.6.13-alpha.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"homepage": "https://github.com/tegojs/tego#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
"koa-compose": "^4.1.0",
|
|
19
19
|
"lodash": "4.17.21",
|
|
20
20
|
"minimatch": "^5.1.6",
|
|
21
|
-
"@tachybase/actions": "1.6.13-alpha.
|
|
22
|
-
"@tachybase/
|
|
23
|
-
"@tachybase/
|
|
21
|
+
"@tachybase/actions": "1.6.13-alpha.6",
|
|
22
|
+
"@tachybase/resourcer": "1.6.13-alpha.6",
|
|
23
|
+
"@tachybase/utils": "1.6.13-alpha.6"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/lodash": "4.17.20",
|