@nocobase/plugin-acl 1.4.0-beta.1 → 1.5.0-alpha.1

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.
@@ -11,21 +11,20 @@ module.exports = {
11
11
  "antd": "5.12.8",
12
12
  "react": "18.2.0",
13
13
  "react-i18next": "11.18.6",
14
- "@nocobase/client": "1.4.0-beta.1",
14
+ "@nocobase/client": "1.5.0-alpha.1",
15
15
  "@formily/shared": "2.3.2",
16
16
  "@formily/react": "2.3.0",
17
17
  "@ant-design/icons": "5.2.6",
18
- "@nocobase/utils": "1.4.0-beta.1",
19
- "@nocobase/actions": "1.4.0-beta.1",
20
- "@nocobase/cache": "1.4.0-beta.1",
21
- "@nocobase/database": "1.4.0-beta.1",
22
- "@nocobase/server": "1.4.0-beta.1",
23
- "async-mutex": "0.3.2",
18
+ "@nocobase/utils": "1.5.0-alpha.1",
19
+ "@nocobase/actions": "1.5.0-alpha.1",
20
+ "@nocobase/cache": "1.5.0-alpha.1",
21
+ "@nocobase/database": "1.5.0-alpha.1",
22
+ "@nocobase/server": "1.5.0-alpha.1",
24
23
  "lodash": "4.17.21",
25
- "@nocobase/test": "1.4.0-beta.1",
24
+ "@nocobase/test": "1.5.0-alpha.1",
26
25
  "@formily/core": "2.3.0",
27
26
  "ahooks": "3.7.8",
28
27
  "@formily/antd-v5": "1.1.9",
29
28
  "antd-style": "3.7.1",
30
- "@nocobase/acl": "1.4.0-beta.1"
29
+ "@nocobase/acl": "1.5.0-alpha.1"
31
30
  };
@@ -15,6 +15,6 @@ export declare class RoleResourceModel extends Model {
15
15
  }): Promise<void>;
16
16
  writeToACL(options: {
17
17
  acl: ACL;
18
- transaction: any;
18
+ transaction?: any;
19
19
  }): Promise<void>;
20
20
  }
@@ -15,6 +15,7 @@ export declare class PluginACLServer extends Plugin {
15
15
  get acl(): import("@nocobase/acl").ACL;
16
16
  writeResourceToACL(resourceModel: RoleResourceModel, transaction: Transaction): Promise<void>;
17
17
  writeActionToACL(actionModel: RoleResourceActionModel, transaction: Transaction): Promise<void>;
18
+ handleSyncMessage(message: any): Promise<void>;
18
19
  writeRolesToACL(options: any): Promise<void>;
19
20
  writeRoleToACL(role: RoleModel, options?: any): Promise<void>;
20
21
  beforeLoad(): Promise<void>;
@@ -43,7 +43,6 @@ module.exports = __toCommonJS(server_exports);
43
43
  var import_actions = require("@nocobase/actions");
44
44
  var import_database = require("@nocobase/database");
45
45
  var import_server = require("@nocobase/server");
46
- var import_async_mutex = require("async-mutex");
47
46
  var import_lodash = __toESM(require("lodash"));
48
47
  var import_path = require("path");
49
48
  var import_available_actions = require("./actions/available-actions");
@@ -74,6 +73,23 @@ class PluginACLServer extends import_server.Plugin {
74
73
  resourceName: resource.get("name")
75
74
  });
76
75
  }
76
+ async handleSyncMessage(message) {
77
+ const { type } = message;
78
+ if (type === "syncRole") {
79
+ const { roleName } = message;
80
+ const role = await this.app.db.getRepository("roles").findOne({
81
+ filter: {
82
+ name: roleName
83
+ }
84
+ });
85
+ await this.writeRoleToACL(role, {
86
+ withOutResources: true
87
+ });
88
+ await this.app.emitAsync("acl:writeResources", {
89
+ roleName: role.get("name")
90
+ });
91
+ }
92
+ }
77
93
  async writeRolesToACL(options) {
78
94
  const roles = await this.app.db.getRepository("roles").find({
79
95
  appends: ["resources", "resources.actions"]
@@ -211,6 +227,15 @@ class PluginACLServer extends import_server.Plugin {
211
227
  transaction
212
228
  });
213
229
  }
230
+ this.sendSyncMessage(
231
+ {
232
+ type: "syncRole",
233
+ roleName: model.get("name")
234
+ },
235
+ {
236
+ transaction: options.transaction
237
+ }
238
+ );
214
239
  });
215
240
  this.app.db.on("roles.afterDestroy", (model) => {
216
241
  const roleName = model.get("name");
@@ -260,9 +285,9 @@ class PluginACLServer extends import_server.Plugin {
260
285
  });
261
286
  }
262
287
  });
263
- const mutex = new import_async_mutex.Mutex();
264
288
  this.app.db.on("fields.afterDestroy", async (model, options) => {
265
- await mutex.runExclusive(async () => {
289
+ const lockKey = `${this.name}:fields.afterDestroy:${model.get("collectionName")}:${model.get("name")}`;
290
+ await this.app.lockManager.runExclusive(lockKey, async () => {
266
291
  const collectionName = model.get("collectionName");
267
292
  const fieldName = model.get("name");
268
293
  const resourceActions = await this.app.db.getRepository("dataSourcesRolesResourcesActions").find({
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": "1.4.0-beta.1",
7
+ "version": "1.5.0-alpha.1",
8
8
  "license": "AGPL-3.0",
9
9
  "main": "./dist/server/index.js",
10
10
  "homepage": "https://docs.nocobase.com/handbook/acl",
@@ -14,7 +14,6 @@
14
14
  ],
15
15
  "devDependencies": {
16
16
  "@types/jsonwebtoken": "^8.5.8",
17
- "async-mutex": "^0.3.2",
18
17
  "jsonwebtoken": "^8.5.1",
19
18
  "react": "^18.2.0",
20
19
  "react-dom": "^18.2.0"
@@ -34,5 +33,5 @@
34
33
  "url": "git+https://github.com/nocobase/nocobase.git",
35
34
  "directory": "packages/plugins/acl"
36
35
  },
37
- "gitHead": "1ece4e558ba445088dbb658bd458eb0004295326"
36
+ "gitHead": "abe58fad69534a13c2502a47da86425a597c3ba3"
38
37
  }