@nocobase/plugin-acl 1.2.12-alpha → 1.3.0-alpha.20240710084543

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 (67) hide show
  1. package/package.json +2 -2
  2. package/dist/client/NewRole.d.ts +0 -10
  3. package/dist/client/RolesManagement.d.ts +0 -10
  4. package/dist/client/RolesManagerProvider.d.ts +0 -13
  5. package/dist/client/RolesMenu.d.ts +0 -15
  6. package/dist/client/hooks/load-more-observer.d.ts +0 -15
  7. package/dist/client/index.d.ts +0 -16
  8. package/dist/client/index.js +0 -18
  9. package/dist/client/locale.d.ts +0 -9
  10. package/dist/client/permissions/ActionPermissions.d.ts +0 -12
  11. package/dist/client/permissions/AvailableActions.d.ts +0 -11
  12. package/dist/client/permissions/GeneralPermissions.d.ts +0 -12
  13. package/dist/client/permissions/MenuItemsProvider.d.ts +0 -12
  14. package/dist/client/permissions/MenuPermissions.d.ts +0 -12
  15. package/dist/client/permissions/Permissions.d.ts +0 -12
  16. package/dist/client/permissions/PluginPermissions.d.ts +0 -12
  17. package/dist/client/permissions/RolesResourcesActions.d.ts +0 -11
  18. package/dist/client/permissions/ScopeSelect.d.ts +0 -11
  19. package/dist/client/permissions/StrategyActions.d.ts +0 -10
  20. package/dist/client/permissions/style.d.ts +0 -9
  21. package/dist/client/roles-manager.d.ts +0 -18
  22. package/dist/client/schemas/roles.d.ts +0 -63
  23. package/dist/client/schemas/scopes.d.ts +0 -75
  24. package/dist/externalVersion.js +0 -31
  25. package/dist/index.d.ts +0 -10
  26. package/dist/index.js +0 -48
  27. package/dist/locale/en-US.json +0 -6
  28. package/dist/locale/ko_KR.json +0 -4
  29. package/dist/locale/zh-CN.json +0 -11
  30. package/dist/server/actions/available-actions.d.ts +0 -15
  31. package/dist/server/actions/available-actions.js +0 -51
  32. package/dist/server/actions/role-check.d.ts +0 -9
  33. package/dist/server/actions/role-check.js +0 -76
  34. package/dist/server/actions/role-collections.d.ts +0 -15
  35. package/dist/server/actions/role-collections.js +0 -84
  36. package/dist/server/actions/user-setDefaultRole.d.ts +0 -10
  37. package/dist/server/actions/user-setDefaultRole.js +0 -74
  38. package/dist/server/collections/roles-users.d.ts +0 -10
  39. package/dist/server/collections/roles-users.js +0 -39
  40. package/dist/server/collections/roles.d.ts +0 -10
  41. package/dist/server/collections/roles.js +0 -128
  42. package/dist/server/collections/rolesResources.d.ts +0 -10
  43. package/dist/server/collections/rolesResources.js +0 -64
  44. package/dist/server/collections/rolesResourcesActions.d.ts +0 -10
  45. package/dist/server/collections/rolesResourcesActions.js +0 -60
  46. package/dist/server/collections/rolesResourcesScopes.d.ts +0 -10
  47. package/dist/server/collections/rolesResourcesScopes.js +0 -54
  48. package/dist/server/collections/users.d.ts +0 -14
  49. package/dist/server/collections/users.js +0 -61
  50. package/dist/server/index.d.ts +0 -13
  51. package/dist/server/index.js +0 -56
  52. package/dist/server/middlewares/setCurrentRole.d.ts +0 -10
  53. package/dist/server/middlewares/setCurrentRole.js +0 -86
  54. package/dist/server/middlewares/with-acl-meta.d.ts +0 -10
  55. package/dist/server/middlewares/with-acl-meta.js +0 -255
  56. package/dist/server/migrations/20221214072638-set-role-snippets.d.ts +0 -14
  57. package/dist/server/migrations/20221214072638-set-role-snippets.js +0 -53
  58. package/dist/server/model/RoleModel.d.ts +0 -16
  59. package/dist/server/model/RoleModel.js +0 -55
  60. package/dist/server/model/RoleResourceActionModel.d.ts +0 -17
  61. package/dist/server/model/RoleResourceActionModel.js +0 -53
  62. package/dist/server/model/RoleResourceModel.d.ts +0 -20
  63. package/dist/server/model/RoleResourceModel.js +0 -72
  64. package/dist/server/server.d.ts +0 -24
  65. package/dist/server/server.js +0 -552
  66. package/dist/swagger/index.d.ts +0 -374
  67. package/dist/swagger/index.js +0 -404
@@ -1,10 +0,0 @@
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
- declare const _default: import("@nocobase/database").CollectionOptions;
10
- export default _default;
@@ -1,54 +0,0 @@
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 rolesResourcesScopes_exports = {};
28
- __export(rolesResourcesScopes_exports, {
29
- default: () => rolesResourcesScopes_default
30
- });
31
- module.exports = __toCommonJS(rolesResourcesScopes_exports);
32
- var import_database = require("@nocobase/database");
33
- var rolesResourcesScopes_default = (0, import_database.defineCollection)({
34
- dumpRules: "required",
35
- name: "rolesResourcesScopes",
36
- fields: [
37
- {
38
- type: "uid",
39
- name: "key"
40
- },
41
- {
42
- type: "string",
43
- name: "name"
44
- },
45
- {
46
- type: "string",
47
- name: "resourceName"
48
- },
49
- {
50
- type: "json",
51
- name: "scope"
52
- }
53
- ]
54
- });
@@ -1,14 +0,0 @@
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
- declare const _default: {
10
- collectionOptions: import("@nocobase/database").CollectionOptions;
11
- mergeOptions: import("deepmerge").Options;
12
- extend: boolean;
13
- };
14
- export default _default;
@@ -1,61 +0,0 @@
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 users_exports = {};
28
- __export(users_exports, {
29
- default: () => users_default
30
- });
31
- module.exports = __toCommonJS(users_exports);
32
- var import_database = require("@nocobase/database");
33
- var users_default = (0, import_database.extendCollection)({
34
- name: "users",
35
- fields: [
36
- {
37
- interface: "m2m",
38
- type: "belongsToMany",
39
- name: "roles",
40
- target: "roles",
41
- foreignKey: "userId",
42
- otherKey: "roleName",
43
- onDelete: "CASCADE",
44
- sourceKey: "id",
45
- targetKey: "name",
46
- through: "rolesUsers",
47
- uiSchema: {
48
- type: "array",
49
- title: '{{t("Roles")}}',
50
- "x-component": "AssociationField",
51
- "x-component-props": {
52
- multiple: true,
53
- fieldNames: {
54
- label: "title",
55
- value: "name"
56
- }
57
- }
58
- }
59
- }
60
- ]
61
- });
@@ -1,13 +0,0 @@
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
- export * from './middlewares/setCurrentRole';
10
- export * from './middlewares/with-acl-meta';
11
- export { RoleResourceActionModel } from './model/RoleResourceActionModel';
12
- export { RoleResourceModel } from './model/RoleResourceModel';
13
- export { default } from './server';
@@ -1,56 +0,0 @@
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
29
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
- // If the importer is in node compatibility mode or this is not an ESM
31
- // file that has been converted to a CommonJS file using a Babel-
32
- // compatible transform (i.e. "__esModule" has not been set), then set
33
- // "default" to the CommonJS "module.exports" for node compatibility.
34
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
- mod
36
- ));
37
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
- var server_exports = {};
39
- __export(server_exports, {
40
- RoleResourceActionModel: () => import_RoleResourceActionModel.RoleResourceActionModel,
41
- RoleResourceModel: () => import_RoleResourceModel.RoleResourceModel,
42
- default: () => import_server.default
43
- });
44
- module.exports = __toCommonJS(server_exports);
45
- __reExport(server_exports, require("./middlewares/setCurrentRole"), module.exports);
46
- __reExport(server_exports, require("./middlewares/with-acl-meta"), module.exports);
47
- var import_RoleResourceActionModel = require("./model/RoleResourceActionModel");
48
- var import_RoleResourceModel = require("./model/RoleResourceModel");
49
- var import_server = __toESM(require("./server"));
50
- // Annotate the CommonJS export names for ESM import in node:
51
- 0 && (module.exports = {
52
- RoleResourceActionModel,
53
- RoleResourceModel,
54
- ...require("./middlewares/setCurrentRole"),
55
- ...require("./middlewares/with-acl-meta")
56
- });
@@ -1,10 +0,0 @@
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 } from '@nocobase/actions';
10
- export declare function setCurrentRole(ctx: Context, next: any): Promise<any>;
@@ -1,86 +0,0 @@
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 setCurrentRole_exports = {};
28
- __export(setCurrentRole_exports, {
29
- setCurrentRole: () => setCurrentRole
30
- });
31
- module.exports = __toCommonJS(setCurrentRole_exports);
32
- async function setCurrentRole(ctx, next) {
33
- var _a, _b;
34
- const currentRole = ctx.get("X-Role");
35
- if (currentRole === "anonymous") {
36
- ctx.state.currentRole = currentRole;
37
- return next();
38
- }
39
- if (!ctx.state.currentUser) {
40
- return next();
41
- }
42
- const attachRoles = ctx.state.attachRoles || [];
43
- const cache = ctx.cache;
44
- const repository = ctx.db.getRepository("users.roles", ctx.state.currentUser.id);
45
- const roles = await cache.wrap(
46
- `roles:${ctx.state.currentUser.id}`,
47
- () => repository.find({
48
- raw: true
49
- })
50
- );
51
- if (!roles.length && !attachRoles.length) {
52
- ctx.state.currentRole = void 0;
53
- return ctx.throw(401, {
54
- code: "USER_HAS_NO_ROLES_ERR",
55
- message: ctx.t("The current user has no roles. Please try another account.", { ns: "acl" })
56
- });
57
- }
58
- const rolesMap = /* @__PURE__ */ new Map();
59
- attachRoles.forEach((role2) => rolesMap.set(role2.name, role2));
60
- roles.forEach((role2) => rolesMap.set(role2.name, role2));
61
- const userRoles = Array.from(rolesMap.values());
62
- ctx.state.currentUser.roles = userRoles;
63
- let role;
64
- if (currentRole) {
65
- role = (_a = userRoles.find((role2) => role2.name === currentRole)) == null ? void 0 : _a.name;
66
- }
67
- if (!role) {
68
- const defaultRole = userRoles.find((role2) => {
69
- var _a2;
70
- return (_a2 = role2 == null ? void 0 : role2.rolesUsers) == null ? void 0 : _a2.default;
71
- });
72
- role = (_b = defaultRole || userRoles[0]) == null ? void 0 : _b.name;
73
- }
74
- ctx.state.currentRole = role;
75
- if (!ctx.state.currentRole) {
76
- return ctx.throw(401, {
77
- code: "ROLE_NOT_FOUND_ERR",
78
- message: ctx.t("The user role does not exist. Please try signing in again", { ns: "acl" })
79
- });
80
- }
81
- await next();
82
- }
83
- // Annotate the CommonJS export names for ESM import in node:
84
- 0 && (module.exports = {
85
- setCurrentRole
86
- });
@@ -1,10 +0,0 @@
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
- declare function createWithACLMetaMiddleware(): (ctx: any, next: any) => Promise<void>;
10
- export { createWithACLMetaMiddleware };
@@ -1,255 +0,0 @@
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 with_acl_meta_exports = {};
38
- __export(with_acl_meta_exports, {
39
- createWithACLMetaMiddleware: () => createWithACLMetaMiddleware
40
- });
41
- module.exports = __toCommonJS(with_acl_meta_exports);
42
- var import_lodash = __toESM(require("lodash"));
43
- var import_database = require("@nocobase/database");
44
- var import_acl = require("@nocobase/acl");
45
- function createWithACLMetaMiddleware() {
46
- return async (ctx, next) => {
47
- var _a, _b, _c, _d;
48
- await next();
49
- const dataSourceKey = ctx.get("x-data-source");
50
- const dataSource = ctx.app.dataSourceManager.dataSources.get(dataSourceKey);
51
- const db = dataSource ? dataSource.collectionManager.db : ctx.db;
52
- if (!db) {
53
- return;
54
- }
55
- const acl = dataSource ? dataSource.acl : ctx.app.acl;
56
- if (!ctx.action || !ctx.get("X-With-ACL-Meta") || ctx.status !== 200) {
57
- return;
58
- }
59
- const { resourceName, actionName } = ctx.permission;
60
- if (!["list", "get"].includes(actionName)) {
61
- return;
62
- }
63
- const collection = db.getCollection(resourceName);
64
- if (!collection) {
65
- return;
66
- }
67
- const Model = collection.model;
68
- const primaryKeyField = Model.primaryKeyField || Model.primaryKeyAttribute;
69
- let listData;
70
- if ((_a = ctx.body) == null ? void 0 : _a.data) {
71
- listData = ctx.data;
72
- } else if ((_b = ctx.body) == null ? void 0 : _b.rows) {
73
- listData = ctx.body.rows;
74
- } else if (ctx.body) {
75
- listData = ctx.body;
76
- }
77
- if (!listData) {
78
- return;
79
- }
80
- if (actionName == "get") {
81
- listData = import_lodash.default.castArray(listData);
82
- }
83
- const inspectActions = ["view", "update", "destroy"];
84
- const actionsParams = [];
85
- for (const action of inspectActions) {
86
- const actionCtx = {
87
- db,
88
- get: () => {
89
- return void 0;
90
- },
91
- app: {
92
- getDb() {
93
- return db;
94
- }
95
- },
96
- getCurrentRepository: ctx.getCurrentRepository,
97
- action: {
98
- actionName: action,
99
- name: action,
100
- params: {},
101
- resourceName: ctx.action.resourceName,
102
- resourceOf: ctx.action.resourceOf,
103
- mergeParams() {
104
- }
105
- },
106
- state: {
107
- currentRole: ctx.state.currentRole,
108
- currentUser: (() => {
109
- var _a2;
110
- if (!ctx.state.currentUser) {
111
- return null;
112
- }
113
- if (ctx.state.currentUser.toJSON) {
114
- return (_a2 = ctx.state.currentUser) == null ? void 0 : _a2.toJSON();
115
- }
116
- return ctx.state.currentUser;
117
- })()
118
- },
119
- permission: {},
120
- throw(...args) {
121
- throw new import_acl.NoPermissionError(...args);
122
- }
123
- };
124
- try {
125
- await acl.getActionParams(actionCtx);
126
- } catch (e) {
127
- if (e instanceof import_acl.NoPermissionError) {
128
- continue;
129
- }
130
- throw e;
131
- }
132
- actionsParams.push([
133
- action,
134
- ((_c = actionCtx.permission) == null ? void 0 : _c.can) === null && !actionCtx.permission.skip ? null : ((_d = actionCtx.permission) == null ? void 0 : _d.parsedParams) || {},
135
- actionCtx
136
- ]);
137
- }
138
- const ids = (() => {
139
- if (collection.options.tree) {
140
- if (listData.length == 0)
141
- return [];
142
- const getAllNodeIds = (data) => [data[primaryKeyField], ...(data.children || []).flatMap(getAllNodeIds)];
143
- return listData.map((tree) => getAllNodeIds(tree.toJSON())).flat();
144
- }
145
- return listData.map((item) => item[primaryKeyField]);
146
- })();
147
- const conditions = [];
148
- const allAllowed = [];
149
- for (const [action, params, actionCtx] of actionsParams) {
150
- if (!params) {
151
- continue;
152
- }
153
- if (import_lodash.default.isEmpty(params) || import_lodash.default.isEmpty(params.filter)) {
154
- allAllowed.push(action);
155
- continue;
156
- }
157
- const queryParams = collection.repository.buildQueryOptions({
158
- ...params,
159
- context: actionCtx
160
- });
161
- const actionSql = ctx.db.sequelize.queryInterface.queryGenerator.selectQuery(
162
- Model.getTableName(),
163
- {
164
- where: (() => {
165
- const filterObj = queryParams.where;
166
- if (!db.options.underscored) {
167
- return filterObj;
168
- }
169
- const isAssociationKey = (key) => {
170
- return key.startsWith("$") && key.endsWith("$");
171
- };
172
- const iterate = (rootObj, path = []) => {
173
- const obj = path.length == 0 ? rootObj : import_lodash.default.get(rootObj, path);
174
- if (Array.isArray(obj)) {
175
- for (let i = 0; i < obj.length; i++) {
176
- if (obj[i] === null) {
177
- continue;
178
- }
179
- if (typeof obj[i] === "object") {
180
- iterate(rootObj, [...path, i]);
181
- }
182
- }
183
- return;
184
- }
185
- Reflect.ownKeys(obj).forEach((key) => {
186
- if (Array.isArray(obj) && key == "length") {
187
- return;
188
- }
189
- if (typeof obj[key] === "object" && obj[key] !== null || typeof obj[key] === "symbol") {
190
- iterate(rootObj, [...path, key]);
191
- }
192
- if (typeof key === "string" && key !== (0, import_database.snakeCase)(key)) {
193
- const setKey = isAssociationKey(key) ? (() => {
194
- const parts = key.split(".");
195
- parts[parts.length - 1] = import_lodash.default.snakeCase(parts[parts.length - 1]);
196
- const result = parts.join(".");
197
- return result.endsWith("$") ? result : `${result}$`;
198
- })() : (0, import_database.snakeCase)(key);
199
- const setValue = import_lodash.default.cloneDeep(obj[key]);
200
- import_lodash.default.unset(rootObj, [...path, key]);
201
- import_lodash.default.set(rootObj, [...path, setKey], setValue);
202
- }
203
- });
204
- };
205
- iterate(filterObj);
206
- return filterObj;
207
- })(),
208
- attributes: [primaryKeyField],
209
- includeIgnoreAttributes: false
210
- },
211
- Model
212
- );
213
- const whereCase = actionSql.match(/WHERE (.*?);/)[1];
214
- conditions.push({
215
- whereCase,
216
- action,
217
- include: queryParams.include
218
- });
219
- }
220
- const results = await collection.model.findAll({
221
- where: {
222
- [primaryKeyField]: ids
223
- },
224
- attributes: [
225
- primaryKeyField,
226
- ...conditions.map((condition) => {
227
- return [ctx.db.sequelize.literal(`CASE WHEN ${condition.whereCase} THEN 1 ELSE 0 END`), condition.action];
228
- })
229
- ],
230
- include: conditions.map((condition) => condition.include).flat()
231
- });
232
- const allowedActions = inspectActions.map((action) => {
233
- if (allAllowed.includes(action)) {
234
- return [action, ids];
235
- }
236
- return [action, results.filter((item) => Boolean(item.get(action))).map((item) => item.get(primaryKeyField))];
237
- }).reduce((acc, [action, ids2]) => {
238
- acc[action] = ids2;
239
- return acc;
240
- }, {});
241
- if (actionName == "get") {
242
- ctx.bodyMeta = {
243
- ...ctx.bodyMeta || {},
244
- allowedActions
245
- };
246
- }
247
- if (actionName == "list") {
248
- ctx.body.allowedActions = allowedActions;
249
- }
250
- };
251
- }
252
- // Annotate the CommonJS export names for ESM import in node:
253
- 0 && (module.exports = {
254
- createWithACLMetaMiddleware
255
- });
@@ -1,14 +0,0 @@
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 { Migration } from '@nocobase/server';
10
- export default class extends Migration {
11
- appVersion: string;
12
- up(): Promise<void>;
13
- down(): Promise<void>;
14
- }
@@ -1,53 +0,0 @@
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 set_role_snippets_exports = {};
28
- __export(set_role_snippets_exports, {
29
- default: () => set_role_snippets_default
30
- });
31
- module.exports = __toCommonJS(set_role_snippets_exports);
32
- var import_server = require("@nocobase/server");
33
- /* istanbul ignore file -- @preserve */
34
- class set_role_snippets_default extends import_server.Migration {
35
- appVersion = "<0.9.0-alpha.1";
36
- async up() {
37
- const result = await this.app.version.satisfies("<0.9.0-alpha.1");
38
- if (!result) {
39
- return;
40
- }
41
- await this.app.db.getRepository("roles").update({
42
- filter: {
43
- $or: [{ allowConfigure: true }, { name: "root" }]
44
- },
45
- values: {
46
- snippets: ["ui.*", "pm", "pm.*"],
47
- allowConfigure: false
48
- }
49
- });
50
- }
51
- async down() {
52
- }
53
- }
@@ -1,16 +0,0 @@
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 { Model } from '@nocobase/database';
10
- import { ACL } from '@nocobase/acl';
11
- export declare class RoleModel extends Model {
12
- writeToAcl(options: {
13
- acl: ACL;
14
- withOutStrategy?: boolean;
15
- }): void;
16
- }