@nocobase/plugin-acl 2.1.0-beta.8 → 2.2.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.
Files changed (50) hide show
  1. package/client-v2.d.ts +2 -0
  2. package/client-v2.js +1 -0
  3. package/dist/client/949.7ad4ad3b554e5452.js +10 -0
  4. package/dist/client/971.50ecf7b6ac572080.js +10 -0
  5. package/dist/client/index.js +1 -1
  6. package/dist/client-v2/336.c27dbbf4b362f3c2.js +10 -0
  7. package/dist/client-v2/532.be9165ee6b4d34c1.js +10 -0
  8. package/dist/client-v2/800.020212b7d7b3875d.js +10 -0
  9. package/dist/client-v2/870.1d9bac44ccd1f650.js +10 -0
  10. package/dist/client-v2/components/ResourceFormDrawer.d.ts +33 -0
  11. package/dist/client-v2/index.d.ts +12 -0
  12. package/dist/client-v2/index.js +10 -0
  13. package/dist/client-v2/locale.d.ts +11 -0
  14. package/dist/client-v2/models/user-center/SwitchRoleItemModel.d.ts +18 -0
  15. package/dist/client-v2/pages/RolesManagementPage.d.ts +10 -0
  16. package/dist/client-v2/pages/permissions/DesktopRoutesPermissionsTab.d.ts +11 -0
  17. package/dist/client-v2/pages/permissions/PluginPermissionsTable.d.ts +16 -0
  18. package/dist/client-v2/pages/permissions/SystemPermissionsTab.d.ts +11 -0
  19. package/dist/client-v2/pages/permissions/utils.d.ts +18 -0
  20. package/dist/client-v2/plugin.d.ts +16 -0
  21. package/dist/client-v2/registries.d.ts +60 -0
  22. package/dist/externalVersion.js +13 -10
  23. package/dist/locale/en-US.json +17 -2
  24. package/dist/locale/zh-CN.json +17 -2
  25. package/dist/server/actions/apply-data-permissions.d.ts +10 -0
  26. package/dist/server/actions/apply-data-permissions.js +208 -0
  27. package/dist/server/actions/data-source-compat.d.ts +13 -0
  28. package/dist/server/actions/data-source-compat.js +189 -0
  29. package/dist/server/collections/roles-users.js +1 -0
  30. package/dist/server/collections/roles.js +1 -0
  31. package/dist/server/collections/rolesResources.js +1 -0
  32. package/dist/server/collections/rolesResourcesActions.js +1 -0
  33. package/dist/server/collections/rolesResourcesScopes.js +1 -0
  34. package/dist/server/index.d.ts +3 -0
  35. package/dist/server/index.js +6 -0
  36. package/dist/server/middlewares/check-association-operate.js +9 -6
  37. package/dist/server/middlewares/check-change-with-association.d.ts +1 -0
  38. package/dist/server/middlewares/check-change-with-association.js +3 -1
  39. package/dist/server/middlewares/check-query-permission.d.ts +10 -0
  40. package/dist/server/middlewares/check-query-permission.js +64 -0
  41. package/dist/server/middlewares/setCurrentRole.js +2 -2
  42. package/dist/server/middlewares/with-acl-meta.js +1 -1
  43. package/dist/server/query/apply-query-permission.d.ts +27 -0
  44. package/dist/server/query/apply-query-permission.js +242 -0
  45. package/dist/server/server.js +18 -0
  46. package/dist/swagger/index.d.ts +1113 -145
  47. package/dist/swagger/index.js +986 -180
  48. package/package.json +4 -2
  49. package/dist/client/0655d5ded9f45bb1.js +0 -10
  50. package/dist/client/50204a14518b3a0d.js +0 -10
@@ -0,0 +1,189 @@
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 __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __export = (target, all) => {
17
+ for (var name in all)
18
+ __defProp(target, name, { get: all[name], enumerable: true });
19
+ };
20
+ var __copyProps = (to, from, except, desc) => {
21
+ if (from && typeof from === "object" || typeof from === "function") {
22
+ for (let key of __getOwnPropNames(from))
23
+ if (!__hasOwnProp.call(to, key) && key !== except)
24
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
+ }
26
+ return to;
27
+ };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ // If the importer is in node compatibility mode or this is not an ESM
30
+ // file that has been converted to a CommonJS file using a Babel-
31
+ // compatible transform (i.e. "__esModule" has not been set), then set
32
+ // "default" to the CommonJS "module.exports" for node compatibility.
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+ var data_source_compat_exports = {};
38
+ __export(data_source_compat_exports, {
39
+ guardRolesDataSourceResourcesCreate: () => guardRolesDataSourceResourcesCreate,
40
+ guardRolesDataSourceResourcesGet: () => guardRolesDataSourceResourcesGet,
41
+ guardRolesDataSourceResourcesUpdate: () => guardRolesDataSourceResourcesUpdate,
42
+ guardRolesDataSourcesCollectionsList: () => guardRolesDataSourcesCollectionsList
43
+ });
44
+ module.exports = __toCommonJS(data_source_compat_exports);
45
+ var import_lodash = __toESM(require("lodash"));
46
+ function normalizeString(value) {
47
+ if (typeof value !== "string") {
48
+ return void 0;
49
+ }
50
+ const trimmed = value.trim();
51
+ return trimmed ? trimmed : void 0;
52
+ }
53
+ function normalizeFilter(input) {
54
+ if (!import_lodash.default.isPlainObject(input)) {
55
+ return {};
56
+ }
57
+ return { ...input };
58
+ }
59
+ function applyLocatorFromQuery(params, filter) {
60
+ const dataSourceKeyFromQuery = normalizeString(params.dataSourceKey);
61
+ if (dataSourceKeyFromQuery) {
62
+ filter.dataSourceKey = filter.dataSourceKey || dataSourceKeyFromQuery;
63
+ }
64
+ const nameFromQuery = normalizeString(params.name);
65
+ if (nameFromQuery) {
66
+ filter.name = filter.name || nameFromQuery;
67
+ }
68
+ }
69
+ function normalizeNumericTk(value) {
70
+ if (typeof value === "number" && Number.isInteger(value) && value >= 0) {
71
+ return value;
72
+ }
73
+ const normalized = normalizeString(value);
74
+ if (!normalized || !/^\d+$/.test(normalized)) {
75
+ return void 0;
76
+ }
77
+ return normalized;
78
+ }
79
+ function deriveNameFromPrefixedTk(value) {
80
+ const normalized = normalizeString(value);
81
+ if (!normalized) {
82
+ return void 0;
83
+ }
84
+ const matched = normalized.match(/^[a-zA-Z]+_(.+)$/);
85
+ if (!matched) {
86
+ return void 0;
87
+ }
88
+ return normalizeString(matched[1]);
89
+ }
90
+ async function resolveLocatorFromFilterByTk(ctx, roleName, filter) {
91
+ const rawFilterByTk = ctx.action.params.filterByTk;
92
+ if (rawFilterByTk === void 0 || rawFilterByTk === null || rawFilterByTk === "") {
93
+ return;
94
+ }
95
+ const numericFilterByTk = normalizeNumericTk(rawFilterByTk);
96
+ if (numericFilterByTk === void 0) {
97
+ if (!normalizeString(filter.name)) {
98
+ const derivedName = deriveNameFromPrefixedTk(rawFilterByTk);
99
+ if (derivedName) {
100
+ filter.name = derivedName;
101
+ }
102
+ }
103
+ return;
104
+ }
105
+ const resource = await ctx.db.getRepository("dataSourcesRolesResources").findOne({
106
+ filterByTk: numericFilterByTk
107
+ });
108
+ if (!resource) {
109
+ ctx.throw(404, `Resource permission not found by filterByTk "${rawFilterByTk}"`);
110
+ return;
111
+ }
112
+ const targetRoleName = resource.get("roleName");
113
+ if (targetRoleName !== roleName) {
114
+ ctx.throw(400, `Resource permission "${rawFilterByTk}" does not belong to role "${roleName}"`);
115
+ return;
116
+ }
117
+ if (!normalizeString(filter.dataSourceKey)) {
118
+ filter.dataSourceKey = resource.get("dataSourceKey");
119
+ }
120
+ if (!normalizeString(filter.name)) {
121
+ filter.name = resource.get("name");
122
+ }
123
+ }
124
+ async function normalizeRoleDataSourceResourceLocator(ctx) {
125
+ const roleName = normalizeString(ctx.action.params.associatedIndex);
126
+ if (!roleName) {
127
+ ctx.throw(400, "Role name is required");
128
+ return;
129
+ }
130
+ const filter = normalizeFilter(ctx.action.params.filter);
131
+ applyLocatorFromQuery(ctx.action.params, filter);
132
+ await resolveLocatorFromFilterByTk(ctx, roleName, filter);
133
+ const dataSourceKey = normalizeString(filter.dataSourceKey);
134
+ const name = normalizeString(filter.name);
135
+ if (!dataSourceKey || !name) {
136
+ ctx.throw(
137
+ 400,
138
+ "Missing resource locator: provide --filter-by-tk, or both --data-source-key and --name (or filter.{dataSourceKey,name})"
139
+ );
140
+ return;
141
+ }
142
+ ctx.action.params.filter = {
143
+ ...filter,
144
+ dataSourceKey,
145
+ name
146
+ };
147
+ }
148
+ async function guardRolesDataSourcesCollectionsList(ctx, next) {
149
+ const filter = normalizeFilter(ctx.action.params.filter);
150
+ applyLocatorFromQuery(ctx.action.params, filter);
151
+ const dataSourceKey = normalizeString(filter.dataSourceKey);
152
+ if (!dataSourceKey) {
153
+ ctx.throw(400, "dataSourceKey is required: pass --data-source-key or filter.dataSourceKey");
154
+ return;
155
+ }
156
+ ctx.action.params.filter = {
157
+ ...filter,
158
+ dataSourceKey
159
+ };
160
+ await next();
161
+ }
162
+ async function guardRolesDataSourceResourcesCreate(ctx, next) {
163
+ const values = normalizeFilter(ctx.action.params.values);
164
+ const dataSourceKeyFromQuery = normalizeString(ctx.action.params.dataSourceKey);
165
+ if (!values.dataSourceKey && dataSourceKeyFromQuery) {
166
+ values.dataSourceKey = dataSourceKeyFromQuery;
167
+ }
168
+ if (!normalizeString(values.dataSourceKey)) {
169
+ ctx.throw(400, "dataSourceKey is required for roles.dataSourceResources:create");
170
+ return;
171
+ }
172
+ ctx.action.params.values = values;
173
+ await next();
174
+ }
175
+ async function guardRolesDataSourceResourcesGet(ctx, next) {
176
+ await normalizeRoleDataSourceResourceLocator(ctx);
177
+ await next();
178
+ }
179
+ async function guardRolesDataSourceResourcesUpdate(ctx, next) {
180
+ await normalizeRoleDataSourceResourceLocator(ctx);
181
+ await next();
182
+ }
183
+ // Annotate the CommonJS export names for ESM import in node:
184
+ 0 && (module.exports = {
185
+ guardRolesDataSourceResourcesCreate,
186
+ guardRolesDataSourceResourcesGet,
187
+ guardRolesDataSourceResourcesUpdate,
188
+ guardRolesDataSourcesCollectionsList
189
+ });
@@ -32,6 +32,7 @@ module.exports = __toCommonJS(roles_users_exports);
32
32
  var import_database = require("@nocobase/database");
33
33
  var roles_users_default = (0, import_database.defineCollection)({
34
34
  name: "rolesUsers",
35
+ dataCategory: "business",
35
36
  description: "User's roles",
36
37
  dumpRules: {
37
38
  group: "user"
@@ -36,6 +36,7 @@ var roles_default = (0, import_database.defineCollection)({
36
36
  description: "Role data",
37
37
  migrationRules: ["overwrite", "schema-only"],
38
38
  name: "roles",
39
+ dataCategory: "system",
39
40
  title: '{{t("Roles")}}',
40
41
  autoGenId: false,
41
42
  model: "RoleModel",
@@ -33,6 +33,7 @@ var import_database = require("@nocobase/database");
33
33
  var rolesResources_default = (0, import_database.defineCollection)({
34
34
  dumpRules: "required",
35
35
  name: "rolesResources",
36
+ dataCategory: "system",
36
37
  migrationRules: ["overwrite", "schema-only"],
37
38
  model: "RoleResourceModel",
38
39
  indexes: [
@@ -33,6 +33,7 @@ var import_database = require("@nocobase/database");
33
33
  var rolesResourcesActions_default = (0, import_database.defineCollection)({
34
34
  dumpRules: "required",
35
35
  name: "rolesResourcesActions",
36
+ dataCategory: "system",
36
37
  migrationRules: ["overwrite", "schema-only"],
37
38
  model: "RoleResourceActionModel",
38
39
  fields: [
@@ -33,6 +33,7 @@ var import_database = require("@nocobase/database");
33
33
  var rolesResourcesScopes_default = (0, import_database.defineCollection)({
34
34
  dumpRules: "required",
35
35
  name: "rolesResourcesScopes",
36
+ dataCategory: "system",
36
37
  migrationRules: ["overwrite", "schema-only"],
37
38
  fields: [
38
39
  {
@@ -8,6 +8,9 @@
8
8
  */
9
9
  export * from './middlewares/setCurrentRole';
10
10
  export * from './middlewares/with-acl-meta';
11
+ export * from './middlewares/check-association-operate';
12
+ export * from './middlewares/check-change-with-association';
13
+ export * from './query/apply-query-permission';
11
14
  export { RoleResourceActionModel } from './model/RoleResourceActionModel';
12
15
  export { RoleResourceModel } from './model/RoleResourceModel';
13
16
  export * from './constants';
@@ -44,6 +44,9 @@ __export(server_exports, {
44
44
  module.exports = __toCommonJS(server_exports);
45
45
  __reExport(server_exports, require("./middlewares/setCurrentRole"), module.exports);
46
46
  __reExport(server_exports, require("./middlewares/with-acl-meta"), module.exports);
47
+ __reExport(server_exports, require("./middlewares/check-association-operate"), module.exports);
48
+ __reExport(server_exports, require("./middlewares/check-change-with-association"), module.exports);
49
+ __reExport(server_exports, require("./query/apply-query-permission"), module.exports);
47
50
  var import_RoleResourceActionModel = require("./model/RoleResourceActionModel");
48
51
  var import_RoleResourceModel = require("./model/RoleResourceModel");
49
52
  __reExport(server_exports, require("./constants"), module.exports);
@@ -55,6 +58,9 @@ var import_server = __toESM(require("./server"));
55
58
  RoleResourceModel,
56
59
  ...require("./middlewares/setCurrentRole"),
57
60
  ...require("./middlewares/with-acl-meta"),
61
+ ...require("./middlewares/check-association-operate"),
62
+ ...require("./middlewares/check-change-with-association"),
63
+ ...require("./query/apply-query-permission"),
58
64
  ...require("./constants"),
59
65
  ...require("./enum")
60
66
  });
@@ -31,16 +31,19 @@ __export(check_association_operate_exports, {
31
31
  module.exports = __toCommonJS(check_association_operate_exports);
32
32
  var import_acl = require("@nocobase/acl");
33
33
  async function checkAssociationOperate(ctx, next) {
34
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
34
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
35
35
  const { actionName, resourceName, sourceId } = ctx.action;
36
36
  if (!(resourceName.includes(".") && ["add", "set", "remove", "toggle"].includes(actionName))) {
37
37
  return next();
38
38
  }
39
+ if ((_a = ctx.permission) == null ? void 0 : _a.skip) {
40
+ return next();
41
+ }
39
42
  const acl = ctx.acl;
40
43
  const roles = ctx.state.currentRoles;
41
44
  for (const role of roles) {
42
45
  const aclRole = acl.getRole(role);
43
- if (aclRole.snippetAllowed(`${resourceName}:${actionName}`)) {
46
+ if (aclRole == null ? void 0 : aclRole.snippetAllowed(`${resourceName}:${actionName}`)) {
44
47
  return next();
45
48
  }
46
49
  }
@@ -54,20 +57,20 @@ async function checkAssociationOperate(ctx, next) {
54
57
  ctx.throw(403, "No permissions");
55
58
  }
56
59
  const params = result.params || ctx.acl.fixedParamsManager.getParams(resourceName, actionName);
57
- if (params.whitelist && !((_a = params.whitelist) == null ? void 0 : _a.includes(association))) {
60
+ if (params.whitelist && !((_b = params.whitelist) == null ? void 0 : _b.includes(association))) {
58
61
  ctx.throw(403, "No permissions");
59
62
  }
60
63
  if (params.filter) {
61
64
  try {
62
- const timezone = ((_c = (_b = ctx.request) == null ? void 0 : _b.get) == null ? void 0 : _c.call(_b, "x-timezone")) ?? ((_e = (_d = ctx.request) == null ? void 0 : _d.header) == null ? void 0 : _e["x-timezone"]) ?? ((_g = (_f = ctx.req) == null ? void 0 : _f.headers) == null ? void 0 : _g["x-timezone"]);
63
- const collection = (_i = (_h = ctx.database) == null ? void 0 : _h.getCollection) == null ? void 0 : _i.call(_h, resource);
65
+ const timezone = ((_d = (_c = ctx.request) == null ? void 0 : _c.get) == null ? void 0 : _d.call(_c, "x-timezone")) ?? ((_f = (_e = ctx.request) == null ? void 0 : _e.header) == null ? void 0 : _f["x-timezone"]) ?? ((_h = (_g = ctx.req) == null ? void 0 : _g.headers) == null ? void 0 : _h["x-timezone"]);
66
+ const collection = (_j = (_i = ctx.database) == null ? void 0 : _i.getCollection) == null ? void 0 : _j.call(_i, resource);
64
67
  (0, import_acl.checkFilterParams)(collection, params.filter);
65
68
  const parsedFilter = await (0, import_acl.parseJsonTemplate)(params.filter, {
66
69
  state: ctx.state,
67
70
  timezone,
68
71
  userProvider: (0, import_acl.createUserProvider)({
69
72
  db: ctx.db,
70
- currentUser: (_j = ctx.state) == null ? void 0 : _j.currentUser
73
+ currentUser: (_k = ctx.state) == null ? void 0 : _k.currentUser
71
74
  })
72
75
  });
73
76
  const repo = ctx.database.getRepository(resource);
@@ -23,6 +23,7 @@ export type SanitizeAssociationValuesOptions = {
23
23
  collection?: Collection;
24
24
  db?: any;
25
25
  database?: any;
26
+ state?: Record<string, any>;
26
27
  timezone?: string;
27
28
  userProvider?: UserProvider;
28
29
  };
@@ -67,6 +67,7 @@ async function sanitizeAssociationValues(options) {
67
67
  timezone: options.timezone,
68
68
  userProvider: options.userProvider,
69
69
  state: {
70
+ ...options.state || {},
70
71
  currentRole: options.currentRole,
71
72
  currentRoles: options.roles,
72
73
  currentUser: options.currentUser
@@ -122,6 +123,7 @@ const checkChangesWithAssociation = async (ctx, next) => {
122
123
  roles,
123
124
  currentRole: ctx.state.currentRole,
124
125
  currentUser: ctx.state.currentUser,
126
+ state: import_lodash.default.clone(ctx.state),
125
127
  aclParams: (_k = (_j = ctx.permission) == null ? void 0 : _j.can) == null ? void 0 : _k.params,
126
128
  timezone,
127
129
  userProvider: (0, import_acl.createUserProvider)({
@@ -271,7 +273,7 @@ function normalizeAssociationValue(value, recordKey) {
271
273
  }
272
274
  if (Array.isArray(value)) {
273
275
  const result = value.map((v) => typeof v === "number" || typeof v === "string" ? v : v[recordKey]).filter((v) => v !== null && v !== void 0);
274
- return result.length > 0 ? result : void 0;
276
+ return result;
275
277
  }
276
278
  return typeof value === "number" || typeof value === "string" ? value : value[recordKey];
277
279
  }
@@ -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 type { Next } from '@nocobase/actions';
10
+ export declare function checkQueryPermission(ctx: any, next: Next): Promise<void>;
@@ -0,0 +1,64 @@
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_query_permission_exports = {};
28
+ __export(check_query_permission_exports, {
29
+ checkQueryPermission: () => checkQueryPermission
30
+ });
31
+ module.exports = __toCommonJS(check_query_permission_exports);
32
+ var import_acl = require("@nocobase/acl");
33
+ var import_apply_query_permission = require("../query/apply-query-permission");
34
+ async function checkQueryPermission(ctx, next) {
35
+ var _a, _b, _c, _d;
36
+ const query = { ...ctx.action.params.values };
37
+ try {
38
+ const result = await (0, import_apply_query_permission.applyQueryPermission)({
39
+ acl: ctx.acl,
40
+ db: ctx.database,
41
+ resourceName: ctx.action.resourceName,
42
+ query,
43
+ currentUser: (_a = ctx.state) == null ? void 0 : _a.currentUser,
44
+ currentRole: (_b = ctx.state) == null ? void 0 : _b.currentRole,
45
+ currentRoles: (_c = ctx.state) == null ? void 0 : _c.currentRoles,
46
+ timezone: (_d = ctx.get) == null ? void 0 : _d.call(ctx, "x-timezone"),
47
+ state: ctx.state
48
+ });
49
+ ctx.action.params = {
50
+ ...ctx.action.params,
51
+ values: result.query
52
+ };
53
+ } catch (error) {
54
+ if (error instanceof import_acl.NoPermissionError) {
55
+ ctx.throw(403, "No permissions");
56
+ }
57
+ throw error;
58
+ }
59
+ await next();
60
+ }
61
+ // Annotate the CommonJS export names for ESM import in node:
62
+ 0 && (module.exports = {
63
+ checkQueryPermission
64
+ });
@@ -43,7 +43,7 @@ var import_constants = require("../constants");
43
43
  var import_enum = require("../enum");
44
44
  var import_lodash = __toESM(require("lodash"));
45
45
  async function setCurrentRole(ctx, next) {
46
- var _a, _b, _c;
46
+ var _a, _b;
47
47
  let currentRole = ctx.get("X-Role");
48
48
  if (currentRole === "anonymous") {
49
49
  ctx.state.currentRole = currentRole;
@@ -114,7 +114,7 @@ async function setCurrentRole(ctx, next) {
114
114
  role = (defaultRoleModel == null ? void 0 : defaultRoleModel.roleName) || ((_b = userRoles[0]) == null ? void 0 : _b.name);
115
115
  }
116
116
  ctx.state.currentRole = role;
117
- ctx.state.currentRoles = role === import_constants.UNION_ROLE_KEY ? [(_c = userRoles[0]) == null ? void 0 : _c.name] : [role];
117
+ ctx.state.currentRoles = role === import_constants.UNION_ROLE_KEY ? userRoles.map((role2) => role2.name) : [role];
118
118
  if (!ctx.state.currentRoles.length) {
119
119
  return ctx.throw(401, {
120
120
  code: "ROLE_NOT_FOUND_ERR",
@@ -52,7 +52,7 @@ function createWithACLMetaMiddleware() {
52
52
  const dataSourceKey = ctx.get("x-data-source");
53
53
  const dataSource = ctx.app.dataSourceManager.dataSources.get(dataSourceKey);
54
54
  const db = dataSource ? dataSource.collectionManager.db : ctx.db;
55
- if (!db) {
55
+ if (!db || db.isDBInstance === false) {
56
56
  return;
57
57
  }
58
58
  const acl = dataSource ? dataSource.acl : ctx.app.acl;
@@ -0,0 +1,27 @@
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 { ACL } from '@nocobase/acl';
10
+ import type { QueryOptions } from '@nocobase/database';
11
+ import { Database } from '@nocobase/database';
12
+ export type QueryPermissionQuery = QueryOptions & Record<string, any>;
13
+ export type ApplyQueryPermissionOptions = {
14
+ acl: ACL;
15
+ db: Database;
16
+ resourceName: string;
17
+ query: QueryPermissionQuery;
18
+ currentUser?: any;
19
+ currentRole?: string;
20
+ currentRoles?: string[];
21
+ timezone?: string;
22
+ state?: any;
23
+ };
24
+ export declare function applyQueryPermission(options: ApplyQueryPermissionOptions): Promise<{
25
+ permission: import("@nocobase/acl").CanResult;
26
+ query: QueryPermissionQuery;
27
+ }>;