@nocobase/plugin-acl 2.0.0-alpha.4 → 2.0.0-alpha.41

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.
@@ -8,7 +8,7 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/client": "2.0.0-alpha.4",
11
+ "@nocobase/client": "2.0.0-alpha.41",
12
12
  "antd": "5.24.2",
13
13
  "react": "18.2.0",
14
14
  "react-i18next": "11.18.6",
@@ -17,14 +17,14 @@ module.exports = {
17
17
  "@formily/react": "2.3.7",
18
18
  "@ant-design/icons": "5.6.1",
19
19
  "lodash": "4.17.21",
20
- "@nocobase/utils": "2.0.0-alpha.4",
21
- "@nocobase/actions": "2.0.0-alpha.4",
22
- "@nocobase/cache": "2.0.0-alpha.4",
23
- "@nocobase/database": "2.0.0-alpha.4",
24
- "@nocobase/server": "2.0.0-alpha.4",
25
- "@nocobase/test": "2.0.0-alpha.4",
20
+ "@nocobase/utils": "2.0.0-alpha.41",
21
+ "@nocobase/actions": "2.0.0-alpha.41",
22
+ "@nocobase/cache": "2.0.0-alpha.41",
23
+ "@nocobase/database": "2.0.0-alpha.41",
24
+ "@nocobase/server": "2.0.0-alpha.41",
25
+ "@nocobase/test": "2.0.0-alpha.41",
26
26
  "@formily/core": "2.3.7",
27
27
  "@formily/antd-v5": "1.2.3",
28
28
  "antd-style": "3.7.1",
29
- "@nocobase/acl": "2.0.0-alpha.4"
29
+ "@nocobase/acl": "2.0.0-alpha.41"
30
30
  };
@@ -29,6 +29,7 @@ __export(user_setDefaultRole_exports, {
29
29
  setDefaultRole: () => setDefaultRole
30
30
  });
31
31
  module.exports = __toCommonJS(user_setDefaultRole_exports);
32
+ var import_constants = require("../constants");
32
33
  async function setDefaultRole(ctx, next) {
33
34
  const {
34
35
  values: { roleName }
@@ -72,7 +73,7 @@ async function setDefaultRole(ctx, next) {
72
73
  if (targetUserRole) {
73
74
  await repository.model.update({ default: true }, { where: { userId: currentUser.id, roleName }, transaction });
74
75
  model = targetUserRole.set("default", true);
75
- } else {
76
+ } else if (roleName === import_constants.UNION_ROLE_KEY) {
76
77
  model = await repository.create({
77
78
  values: {
78
79
  userId: currentUser.id,
@@ -82,7 +83,9 @@ async function setDefaultRole(ctx, next) {
82
83
  transaction
83
84
  });
84
85
  }
85
- db.emitAsync("rolesUsers.afterSave", model);
86
+ if (model) {
87
+ db.emitAsync("rolesUsers.afterSave", model);
88
+ }
86
89
  });
87
90
  ctx.body = "ok";
88
91
  await next();
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import { Context, Next } from '@nocobase/actions';
10
+ export declare function checkAssociationOperate(ctx: Context, next: Next): Promise<any>;
@@ -0,0 +1,68 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var check_association_operate_exports = {};
28
+ __export(check_association_operate_exports, {
29
+ checkAssociationOperate: () => checkAssociationOperate
30
+ });
31
+ module.exports = __toCommonJS(check_association_operate_exports);
32
+ async function checkAssociationOperate(ctx, next) {
33
+ var _a;
34
+ const { actionName, resourceName } = ctx.action;
35
+ if (!(resourceName.includes(".") && ["add", "set", "remove", "toggle"].includes(actionName))) {
36
+ return next();
37
+ }
38
+ const acl = ctx.acl;
39
+ const roles = ctx.state.currentRoles;
40
+ for (const role of roles) {
41
+ const aclRole = acl.getRole(role);
42
+ if (aclRole.snippetAllowed(`${resourceName}:${actionName}`)) {
43
+ return next();
44
+ }
45
+ }
46
+ const [resource, association] = resourceName.split(".");
47
+ const result = ctx.can({
48
+ roles,
49
+ resource,
50
+ action: "update"
51
+ });
52
+ if (!result) {
53
+ ctx.throw(403, "No permissions");
54
+ }
55
+ const params = result.params || ctx.acl.fixedParamsManager.getParams(resourceName, actionName);
56
+ if (params.whitelist && !((_a = params.whitelist) == null ? void 0 : _a.includes(association))) {
57
+ ctx.throw(403, "No permissions");
58
+ }
59
+ ctx.permission = {
60
+ ...ctx.permission,
61
+ skip: true
62
+ };
63
+ await next();
64
+ }
65
+ // Annotate the CommonJS export names for ESM import in node:
66
+ 0 && (module.exports = {
67
+ checkAssociationOperate
68
+ });
@@ -55,6 +55,7 @@ var import_RoleModel = require("./model/RoleModel");
55
55
  var import_RoleResourceActionModel = require("./model/RoleResourceActionModel");
56
56
  var import_RoleResourceModel = require("./model/RoleResourceModel");
57
57
  var import_union_role = require("./actions/union-role");
58
+ var import_check_association_operate = require("./middlewares/check-association-operate");
58
59
  class PluginACLServer extends import_server.Plugin {
59
60
  get acl() {
60
61
  return this.app.acl;
@@ -485,8 +486,9 @@ class PluginACLServer extends import_server.Plugin {
485
486
  } else {
486
487
  collection = ctx.db.getCollection(resourceName);
487
488
  }
488
- if (collection && collection.hasField("createdById")) {
489
- ctx.permission.can.params.fields.push("createdById");
489
+ const fields = ctx.permission.can.params.fields;
490
+ if (collection && collection.hasField("createdById") && !fields.includes("createdById")) {
491
+ fields.push("createdById");
490
492
  }
491
493
  }
492
494
  return next();
@@ -559,6 +561,9 @@ class PluginACLServer extends import_server.Plugin {
559
561
  },
560
562
  { after: "dataSource", group: "with-acl-meta" }
561
563
  );
564
+ this.app.acl.use(import_check_association_operate.checkAssociationOperate, {
565
+ before: "core"
566
+ });
562
567
  this.db.on("afterUpdateCollection", async (collection) => {
563
568
  if (collection.options.loadedFromCollectionManager || collection.options.asStrategyResource) {
564
569
  this.app.acl.appendStrategyResource(collection.name);
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "权限控制",
5
5
  "description": "Based on roles, resources, and actions, access control can precisely manage interface configuration permissions, data operation permissions, menu access permissions, and plugin permissions.",
6
6
  "description.zh-CN": "基于角色、资源和操作的权限控制,可以精确控制界面配置权限、数据操作权限、菜单访问权限、插件权限。",
7
- "version": "2.0.0-alpha.4",
7
+ "version": "2.0.0-alpha.41",
8
8
  "license": "AGPL-3.0",
9
9
  "main": "./dist/server/index.js",
10
10
  "homepage": "https://docs.nocobase.com/handbook/acl",
@@ -12,6 +12,9 @@
12
12
  "keywords": [
13
13
  "Users & permissions"
14
14
  ],
15
+ "nocobase": {
16
+ "defaultEnabled": true
17
+ },
15
18
  "devDependencies": {
16
19
  "@types/jsonwebtoken": "^9.0.9",
17
20
  "jsonwebtoken": "^9.0.2",
@@ -33,5 +36,5 @@
33
36
  "url": "git+https://github.com/nocobase/nocobase.git",
34
37
  "directory": "packages/plugins/acl"
35
38
  },
36
- "gitHead": "54f3cab47e7efbdc73377014d05f5fc66a4affbb"
39
+ "gitHead": "889e81eef0280c2e45571bd0a4b2db6aa004f8c1"
37
40
  }