@nocobase/acl 2.0.0-alpha.50 → 2.0.0-alpha.52

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.js CHANGED
@@ -48,9 +48,9 @@ var import_acl_available_action = require("./acl-available-action");
48
48
  var import_acl_available_strategy = require("./acl-available-strategy");
49
49
  var import_acl_role = require("./acl-role");
50
50
  var import_allow_manager = require("./allow-manager");
51
+ var import_no_permission_error = require("./errors/no-permission-error");
51
52
  var import_fixed_params_manager = __toESM(require("./fixed-params-manager"));
52
53
  var import_snippet_manager = __toESM(require("./snippet-manager"));
53
- var import_no_permission_error = require("./errors/no-permission-error");
54
54
  var import_utils2 = require("./utils");
55
55
  const _ACL = class _ACL extends import_events.default {
56
56
  /**
@@ -262,6 +262,9 @@ const _ACL = class _ACL extends import_events.default {
262
262
  * @deprecated
263
263
  */
264
264
  skip(resourceName, actionNames, condition) {
265
+ if (!condition) {
266
+ condition = "public";
267
+ }
265
268
  if (!Array.isArray(actionNames)) {
266
269
  actionNames = [actionNames];
267
270
  }
@@ -12,10 +12,12 @@ export declare class AllowManager {
12
12
  acl: ACL;
13
13
  protected skipActions: Map<string, Map<string, string | true | ConditionFunc>>;
14
14
  protected registeredCondition: Map<string, ConditionFunc>;
15
+ isPublicCondition: () => boolean;
15
16
  constructor(acl: ACL);
16
17
  allow(resourceName: string, actionName: string, condition?: string | ConditionFunc): void;
17
18
  getAllowedConditions(resourceName: string, actionName: string): Array<ConditionFunc | true>;
18
19
  registerAllowCondition(name: string, condition: ConditionFunc): void;
20
+ isPublic(resourceName: string, actionName: string, ctx: any): Promise<boolean>;
19
21
  isAllowed(resourceName: string, actionName: string, ctx: any): Promise<boolean>;
20
22
  aclMiddleware(): (ctx: any, next: any) => Promise<void>;
21
23
  }
@@ -36,9 +36,7 @@ const _AllowManager = class _AllowManager {
36
36
  this.registerAllowCondition("loggedIn", (ctx) => {
37
37
  return ctx.state.currentUser;
38
38
  });
39
- this.registerAllowCondition("public", (ctx) => {
40
- return true;
41
- });
39
+ this.registerAllowCondition("public", this.isPublicCondition);
42
40
  this.registerAllowCondition("allowConfigure", async (ctx) => {
43
41
  var _a;
44
42
  const roleName = ctx.state.currentRole;
@@ -54,6 +52,9 @@ const _AllowManager = class _AllowManager {
54
52
  }
55
53
  skipActions = /* @__PURE__ */ new Map();
56
54
  registeredCondition = /* @__PURE__ */ new Map();
55
+ isPublicCondition = /* @__PURE__ */ __name(() => {
56
+ return true;
57
+ }, "isPublicCondition");
57
58
  allow(resourceName, actionName, condition) {
58
59
  const actionMap = this.skipActions.get(resourceName) || /* @__PURE__ */ new Map();
59
60
  actionMap.set(actionName, condition || true);
@@ -78,6 +79,15 @@ const _AllowManager = class _AllowManager {
78
79
  registerAllowCondition(name, condition) {
79
80
  this.registeredCondition.set(name, condition);
80
81
  }
82
+ async isPublic(resourceName, actionName, ctx) {
83
+ const skippedConditions = this.getAllowedConditions(resourceName, actionName);
84
+ for (const skippedCondition of skippedConditions) {
85
+ if (skippedCondition === this.isPublicCondition) {
86
+ return true;
87
+ }
88
+ }
89
+ return false;
90
+ }
81
91
  async isAllowed(resourceName, actionName, ctx) {
82
92
  const skippedConditions = this.getAllowedConditions(resourceName, actionName);
83
93
  for (const skippedCondition of skippedConditions) {
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@nocobase/acl",
3
- "version": "2.0.0-alpha.50",
3
+ "version": "2.0.0-alpha.52",
4
4
  "description": "",
5
5
  "license": "AGPL-3.0",
6
6
  "main": "./lib/index.js",
7
7
  "types": "./lib/index.d.ts",
8
8
  "dependencies": {
9
- "@nocobase/resourcer": "2.0.0-alpha.50",
10
- "@nocobase/utils": "2.0.0-alpha.50",
9
+ "@nocobase/resourcer": "2.0.0-alpha.52",
10
+ "@nocobase/utils": "2.0.0-alpha.52",
11
11
  "minimatch": "^5.1.1"
12
12
  },
13
13
  "repository": {
@@ -15,5 +15,5 @@
15
15
  "url": "git+https://github.com/nocobase/nocobase.git",
16
16
  "directory": "packages/acl"
17
17
  },
18
- "gitHead": "a6eb64abf3632e116ad0b295a7f410270a1059d1"
18
+ "gitHead": "b32992d8baeb4ca6616d839ca2f9c023d49476a9"
19
19
  }