@tachybase/acl 1.6.13-alpha.5 → 1.6.13-alpha.7

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.
@@ -22,5 +22,6 @@ export declare class ACLAvailableStrategy {
22
22
  allowConfigure: boolean;
23
23
  constructor(acl: ACL, options: AvailableStrategyOptions);
24
24
  matchAction(actionName: string): any;
25
+ isWildcard(): boolean;
25
26
  allow(resourceName: string, actionName: string): any;
26
27
  }
@@ -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
@@ -164,6 +164,18 @@ const _ACL = class _ACL extends import_node_events.default {
164
164
  getAvailableActions() {
165
165
  return this.availableActions;
166
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
+ }
167
179
  setAvailableStrategy(name, options) {
168
180
  this.availableStrategy.set(name, new import_acl_available_strategy.ACLAvailableStrategy(this, options));
169
181
  }
@@ -208,8 +220,9 @@ const _ACL = class _ACL extends import_node_events.default {
208
220
  return null;
209
221
  }
210
222
  let roleStrategyParams;
211
- if (this.strategyResources === null || this.strategyResources.has(resource)) {
212
- roleStrategyParams = roleStrategy == null ? void 0 : roleStrategy.allow(resource, this.resolveActionAlias(action));
223
+ const resolvedAction = this.resolveActionAlias(action);
224
+ if (this.canUseStrategyForResource(resource, resolvedAction, roleStrategy)) {
225
+ roleStrategyParams = roleStrategy == null ? void 0 : roleStrategy.allow(resource, resolvedAction);
213
226
  }
214
227
  if (!roleStrategyParams && snippetAllowed) {
215
228
  roleStrategyParams = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tachybase/acl",
3
- "version": "1.6.13-alpha.5",
3
+ "version": "1.6.13-alpha.7",
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.5",
22
- "@tachybase/utils": "1.6.13-alpha.5",
23
- "@tachybase/resourcer": "1.6.13-alpha.5"
21
+ "@tachybase/actions": "1.6.13-alpha.7",
22
+ "@tachybase/resourcer": "1.6.13-alpha.7",
23
+ "@tachybase/utils": "1.6.13-alpha.7"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/lodash": "4.17.20",