@nocobase/plugin-acl 1.7.6 → 1.7.8

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": "1.7.6",
11
+ "@nocobase/client": "1.7.8",
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.0",
18
18
  "@ant-design/icons": "5.6.1",
19
19
  "lodash": "4.17.21",
20
- "@nocobase/utils": "1.7.6",
21
- "@nocobase/actions": "1.7.6",
22
- "@nocobase/cache": "1.7.6",
23
- "@nocobase/database": "1.7.6",
24
- "@nocobase/server": "1.7.6",
25
- "@nocobase/test": "1.7.6",
20
+ "@nocobase/utils": "1.7.8",
21
+ "@nocobase/actions": "1.7.8",
22
+ "@nocobase/cache": "1.7.8",
23
+ "@nocobase/database": "1.7.8",
24
+ "@nocobase/server": "1.7.8",
25
+ "@nocobase/test": "1.7.8",
26
26
  "@formily/core": "2.3.0",
27
27
  "@formily/antd-v5": "1.2.3",
28
28
  "antd-style": "3.7.1",
29
- "@nocobase/acl": "1.7.6"
29
+ "@nocobase/acl": "1.7.8"
30
30
  };
@@ -44,7 +44,7 @@ var import_database = require("@nocobase/database");
44
44
  var import_acl = require("@nocobase/acl");
45
45
  function createWithACLMetaMiddleware() {
46
46
  return async (ctx, next) => {
47
- var _a, _b, _c, _d;
47
+ var _a, _b, _c, _d, _e, _f, _g, _h;
48
48
  await next();
49
49
  const dataSourceKey = ctx.get("x-data-source");
50
50
  const dataSource = ctx.app.dataSourceManager.dataSources.get(dataSourceKey);
@@ -64,11 +64,11 @@ function createWithACLMetaMiddleware() {
64
64
  if (!collection) {
65
65
  return;
66
66
  }
67
- const Model = collection.model;
67
+ const Model2 = collection.model;
68
68
  if (collection.isMultiFilterTargetKey()) {
69
69
  return;
70
70
  }
71
- const primaryKeyField = Model.primaryKeyField || Model.primaryKeyAttribute;
71
+ const primaryKeyField = Model2.primaryKeyField || Model2.primaryKeyAttribute;
72
72
  let listData;
73
73
  if ((_a = ctx.body) == null ? void 0 : _a.data) {
74
74
  listData = ctx.data;
@@ -164,8 +164,15 @@ function createWithACLMetaMiddleware() {
164
164
  ...params,
165
165
  context: actionCtx
166
166
  });
167
+ if (((_f = (_e = ctx.action) == null ? void 0 : _e.params) == null ? void 0 : _f.appends) || (queryParams == null ? void 0 : queryParams.appends)) {
168
+ const queryParamsWithAppends = (queryParams == null ? void 0 : queryParams.appends) || [];
169
+ const ctxActionParamsWithAppends = ((_h = (_g = ctx.action) == null ? void 0 : _g.params) == null ? void 0 : _h.appends) || [];
170
+ const appends = queryParamsWithAppends.filter((x) => ctxActionParamsWithAppends.includes(x));
171
+ queryParams.include = appends;
172
+ queryParams.appends = appends;
173
+ }
167
174
  const actionSql = ctx.db.sequelize.queryInterface.queryGenerator.selectQuery(
168
- Model.getTableName(),
175
+ Model2.getTableName(),
169
176
  {
170
177
  where: (() => {
171
178
  const filterObj = queryParams.where;
@@ -214,7 +221,7 @@ function createWithACLMetaMiddleware() {
214
221
  attributes: [primaryKeyField],
215
222
  includeIgnoreAttributes: false
216
223
  },
217
- Model
224
+ Model2
218
225
  );
219
226
  const whereCaseMatch = actionSql.match(/WHERE (.*?);/);
220
227
  if (!whereCaseMatch) {
@@ -232,6 +239,7 @@ function createWithACLMetaMiddleware() {
232
239
  });
233
240
  }
234
241
  }
242
+ const includes = conditions.map((c) => c.include).flat().map((x) => processIncludes(collection.model, x || []));
235
243
  const results = await collection.model.findAll({
236
244
  where: {
237
245
  [primaryKeyField]: ids
@@ -242,7 +250,7 @@ function createWithACLMetaMiddleware() {
242
250
  return [ctx.db.sequelize.literal(`CASE WHEN ${condition.whereCase} THEN 1 ELSE 0 END`), condition.action];
243
251
  })
244
252
  ],
245
- include: conditions.map((condition) => condition.include).flat(),
253
+ include: includes,
246
254
  raw: true
247
255
  });
248
256
  const allowedActions = inspectActions.map((action) => {
@@ -267,6 +275,19 @@ function createWithACLMetaMiddleware() {
267
275
  }
268
276
  };
269
277
  }
278
+ function processIncludes(model, include) {
279
+ const association = model.associations[include];
280
+ if (association == null ? void 0 : association["generateInclude"]) {
281
+ const newInclude = {
282
+ association: include,
283
+ attributes: [],
284
+ // out put empty fields by default
285
+ ...association["generateInclude"]()
286
+ };
287
+ return newInclude;
288
+ }
289
+ return include;
290
+ }
270
291
  // Annotate the CommonJS export names for ESM import in node:
271
292
  0 && (module.exports = {
272
293
  createWithACLMetaMiddleware
@@ -554,6 +554,7 @@ class PluginACLServer extends import_server.Plugin {
554
554
  await withACLMeta(ctx, next);
555
555
  } catch (error) {
556
556
  ctx.logger.error(error);
557
+ throw error;
557
558
  }
558
559
  },
559
560
  { after: "dataSource", group: "with-acl-meta" }
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.7.6",
7
+ "version": "1.7.8",
8
8
  "license": "AGPL-3.0",
9
9
  "main": "./dist/server/index.js",
10
10
  "homepage": "https://docs.nocobase.com/handbook/acl",
@@ -33,5 +33,5 @@
33
33
  "url": "git+https://github.com/nocobase/nocobase.git",
34
34
  "directory": "packages/plugins/acl"
35
35
  },
36
- "gitHead": "c9eb617eb076a548b5096b411ec2e484df563e06"
36
+ "gitHead": "296bc481271c7b295f1d653b430858ff33bd11e8"
37
37
  }