@nocobase/plugin-departments 1.6.20

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 (84) hide show
  1. package/LICENSE.txt +161 -0
  2. package/README.md +1 -0
  3. package/client.d.ts +2 -0
  4. package/client.js +1 -0
  5. package/dist/client/ResourcesProvider.d.ts +20 -0
  6. package/dist/client/collections/departments.d.ts +144 -0
  7. package/dist/client/collections/users.d.ts +205 -0
  8. package/dist/client/components/DepartmentOwnersField.d.ts +18 -0
  9. package/dist/client/components/ReadOnlyAssociationField.d.ts +18 -0
  10. package/dist/client/components/UserDepartmentsField.d.ts +18 -0
  11. package/dist/client/components/UserMainDepartmentField.d.ts +18 -0
  12. package/dist/client/components/fieldSettings.d.ts +22 -0
  13. package/dist/client/components/index.d.ts +20 -0
  14. package/dist/client/departments/AggregateSearch.d.ts +18 -0
  15. package/dist/client/departments/Department.d.ts +45 -0
  16. package/dist/client/departments/DepartmentBlock.d.ts +18 -0
  17. package/dist/client/departments/DepartmentField.d.ts +18 -0
  18. package/dist/client/departments/DepartmentManagement.d.ts +18 -0
  19. package/dist/client/departments/DepartmentOwnersField.d.ts +10 -0
  20. package/dist/client/departments/DepartmentTable.d.ts +18 -0
  21. package/dist/client/departments/DepartmentTree.d.ts +30 -0
  22. package/dist/client/departments/DepartmentTreeSelect.d.ts +24 -0
  23. package/dist/client/departments/IsOwnerField.d.ts +18 -0
  24. package/dist/client/departments/Member.d.ts +19 -0
  25. package/dist/client/departments/NewDepartment.d.ts +10 -0
  26. package/dist/client/departments/UserDepartmentsField.d.ts +10 -0
  27. package/dist/client/departments/schemas/departments.d.ts +257 -0
  28. package/dist/client/departments/schemas/users.d.ts +443 -0
  29. package/dist/client/hooks/departments-manager.d.ts +37 -0
  30. package/dist/client/hooks/index.d.ts +18 -0
  31. package/dist/client/hooks/tree-manager.d.ts +38 -0
  32. package/dist/client/hooks/useTableBlockProps.d.ts +28 -0
  33. package/dist/client/index.d.ts +23 -0
  34. package/dist/client/index.js +10 -0
  35. package/dist/client/locale.d.ts +9 -0
  36. package/dist/client/roles/RoleDepartmentsManager.d.ts +18 -0
  37. package/dist/client/roles/schemas/departments.d.ts +235 -0
  38. package/dist/client/utils.d.ts +17 -0
  39. package/dist/externalVersion.js +29 -0
  40. package/dist/index.d.ts +18 -0
  41. package/dist/index.js +48 -0
  42. package/dist/locale/en-US.json +35 -0
  43. package/dist/locale/zh-CN.json +35 -0
  44. package/dist/server/actions/departments.d.ts +21 -0
  45. package/dist/server/actions/departments.js +114 -0
  46. package/dist/server/actions/users.d.ts +20 -0
  47. package/dist/server/actions/users.js +151 -0
  48. package/dist/server/collections/departmentRoles.d.ts +10 -0
  49. package/dist/server/collections/departmentRoles.js +37 -0
  50. package/dist/server/collections/departments.d.ts +37 -0
  51. package/dist/server/collections/departments.js +172 -0
  52. package/dist/server/collections/departmentsUsers.d.ts +10 -0
  53. package/dist/server/collections/departmentsUsers.js +53 -0
  54. package/dist/server/collections/roles.d.ts +14 -0
  55. package/dist/server/collections/roles.js +48 -0
  56. package/dist/server/collections/users.d.ts +67 -0
  57. package/dist/server/collections/users.js +96 -0
  58. package/dist/server/department-data-sync-resource.d.ts +27 -0
  59. package/dist/server/department-data-sync-resource.js +339 -0
  60. package/dist/server/index.d.ts +17 -0
  61. package/dist/server/index.js +42 -0
  62. package/dist/server/middlewares/destroy-department-check.d.ts +18 -0
  63. package/dist/server/middlewares/destroy-department-check.js +62 -0
  64. package/dist/server/middlewares/index.d.ts +22 -0
  65. package/dist/server/middlewares/index.js +40 -0
  66. package/dist/server/middlewares/reset-user-departments-cache.d.ts +18 -0
  67. package/dist/server/middlewares/reset-user-departments-cache.js +48 -0
  68. package/dist/server/middlewares/set-department-owners.d.ts +18 -0
  69. package/dist/server/middlewares/set-department-owners.js +83 -0
  70. package/dist/server/middlewares/set-departments-roles.d.ts +18 -0
  71. package/dist/server/middlewares/set-departments-roles.js +71 -0
  72. package/dist/server/middlewares/set-main-department.d.ts +18 -0
  73. package/dist/server/middlewares/set-main-department.js +114 -0
  74. package/dist/server/middlewares/update-department-isleaf.d.ts +18 -0
  75. package/dist/server/middlewares/update-department-isleaf.js +93 -0
  76. package/dist/server/migrations/update-field-uischemas-20240307124823.d.ts +20 -0
  77. package/dist/server/migrations/update-field-uischemas-20240307124823.js +106 -0
  78. package/dist/server/models/department.d.ts +20 -0
  79. package/dist/server/models/department.js +47 -0
  80. package/dist/server/plugin.d.ts +19 -0
  81. package/dist/server/plugin.js +154 -0
  82. package/package.json +22 -0
  83. package/server.d.ts +2 -0
  84. package/server.js +1 -0
@@ -0,0 +1,42 @@
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 server_exports = {};
38
+ __export(server_exports, {
39
+ default: () => import_plugin.default
40
+ });
41
+ module.exports = __toCommonJS(server_exports);
42
+ var import_plugin = __toESM(require("./plugin"));
@@ -0,0 +1,18 @@
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
+ * This file is part of the NocoBase (R) project.
11
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
12
+ * Authors: NocoBase Team.
13
+ *
14
+ * This program is offered under a commercial license.
15
+ * For more information, see <https://www.nocobase.com/agreement>
16
+ */
17
+ import { Context, Next } from '@nocobase/actions';
18
+ export declare const destroyDepartmentCheck: (ctx: Context, next: Next) => Promise<void>;
@@ -0,0 +1,62 @@
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 destroy_department_check_exports = {};
28
+ __export(destroy_department_check_exports, {
29
+ destroyDepartmentCheck: () => destroyDepartmentCheck
30
+ });
31
+ module.exports = __toCommonJS(destroy_department_check_exports);
32
+ const destroyCheck = async (ctx) => {
33
+ const { filterByTk } = ctx.action.params;
34
+ const repo = ctx.db.getRepository("departments");
35
+ const children = await repo.count({
36
+ filter: {
37
+ parentId: filterByTk
38
+ }
39
+ });
40
+ if (children) {
41
+ ctx.throw(400, ctx.t("The department has sub-departments, please delete them first", { ns: "departments" }));
42
+ }
43
+ const members = await ctx.db.getRepository("departmentsUsers").count({
44
+ filter: {
45
+ departmentId: filterByTk
46
+ }
47
+ });
48
+ if (members) {
49
+ ctx.throw(400, ctx.t("The department has members, please remove them first", { ns: "departments" }));
50
+ }
51
+ };
52
+ const destroyDepartmentCheck = async (ctx, next) => {
53
+ const { resourceName, actionName } = ctx.action.params;
54
+ if (resourceName === "departments" && actionName === "destroy") {
55
+ await destroyCheck(ctx);
56
+ }
57
+ await next();
58
+ };
59
+ // Annotate the CommonJS export names for ESM import in node:
60
+ 0 && (module.exports = {
61
+ destroyDepartmentCheck
62
+ });
@@ -0,0 +1,22 @@
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
+ * This file is part of the NocoBase (R) project.
11
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
12
+ * Authors: NocoBase Team.
13
+ *
14
+ * This program is offered under a commercial license.
15
+ * For more information, see <https://www.nocobase.com/agreement>
16
+ */
17
+ export * from './destroy-department-check';
18
+ export * from './reset-user-departments-cache';
19
+ export * from './set-department-owners';
20
+ export * from './update-department-isleaf';
21
+ export * from './set-departments-roles';
22
+ export * from './set-main-department';
@@ -0,0 +1,40 @@
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 __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
23
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
+ var middlewares_exports = {};
25
+ module.exports = __toCommonJS(middlewares_exports);
26
+ __reExport(middlewares_exports, require("./destroy-department-check"), module.exports);
27
+ __reExport(middlewares_exports, require("./reset-user-departments-cache"), module.exports);
28
+ __reExport(middlewares_exports, require("./set-department-owners"), module.exports);
29
+ __reExport(middlewares_exports, require("./update-department-isleaf"), module.exports);
30
+ __reExport(middlewares_exports, require("./set-departments-roles"), module.exports);
31
+ __reExport(middlewares_exports, require("./set-main-department"), module.exports);
32
+ // Annotate the CommonJS export names for ESM import in node:
33
+ 0 && (module.exports = {
34
+ ...require("./destroy-department-check"),
35
+ ...require("./reset-user-departments-cache"),
36
+ ...require("./set-department-owners"),
37
+ ...require("./update-department-isleaf"),
38
+ ...require("./set-departments-roles"),
39
+ ...require("./set-main-department")
40
+ });
@@ -0,0 +1,18 @@
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
+ * This file is part of the NocoBase (R) project.
11
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
12
+ * Authors: NocoBase Team.
13
+ *
14
+ * This program is offered under a commercial license.
15
+ * For more information, see <https://www.nocobase.com/agreement>
16
+ */
17
+ import { Context, Next } from '@nocobase/actions';
18
+ export declare const resetUserDepartmentsCache: (ctx: Context, next: Next) => Promise<void>;
@@ -0,0 +1,48 @@
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 reset_user_departments_cache_exports = {};
28
+ __export(reset_user_departments_cache_exports, {
29
+ resetUserDepartmentsCache: () => resetUserDepartmentsCache
30
+ });
31
+ module.exports = __toCommonJS(reset_user_departments_cache_exports);
32
+ const resetUserDepartmentsCache = async (ctx, next) => {
33
+ await next();
34
+ const { associatedName, resourceName, associatedIndex, actionName, values } = ctx.action.params;
35
+ const cache = ctx.app.cache;
36
+ if (associatedName === "departments" && resourceName === "members" && ["add", "remove", "set"].includes(actionName) && (values == null ? void 0 : values.length)) {
37
+ for (const memberId of values) {
38
+ await cache.del(`departments:${memberId}`);
39
+ }
40
+ }
41
+ if (associatedName === "users" && resourceName === "departments" && ["add", "remove", "set"].includes(actionName)) {
42
+ await cache.del(`departments:${associatedIndex}`);
43
+ }
44
+ };
45
+ // Annotate the CommonJS export names for ESM import in node:
46
+ 0 && (module.exports = {
47
+ resetUserDepartmentsCache
48
+ });
@@ -0,0 +1,18 @@
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
+ * This file is part of the NocoBase (R) project.
11
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
12
+ * Authors: NocoBase Team.
13
+ *
14
+ * This program is offered under a commercial license.
15
+ * For more information, see <https://www.nocobase.com/agreement>
16
+ */
17
+ import { Context, Next } from '@nocobase/actions';
18
+ export declare const setDepartmentOwners: (ctx: Context, next: Next) => Promise<any>;
@@ -0,0 +1,83 @@
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 set_department_owners_exports = {};
38
+ __export(set_department_owners_exports, {
39
+ setDepartmentOwners: () => setDepartmentOwners
40
+ });
41
+ module.exports = __toCommonJS(set_department_owners_exports);
42
+ var import_lodash = __toESM(require("lodash"));
43
+ const setOwners = async (ctx, filterByTk, owners) => {
44
+ const throughRepo = ctx.db.getRepository("departmentsUsers");
45
+ await ctx.db.sequelize.transaction(async (t) => {
46
+ await throughRepo.update({
47
+ filter: {
48
+ departmentId: filterByTk
49
+ },
50
+ values: {
51
+ isOwner: false
52
+ },
53
+ transaction: t
54
+ });
55
+ await throughRepo.update({
56
+ filter: {
57
+ departmentId: filterByTk,
58
+ userId: {
59
+ $in: owners.map((owner) => owner.id)
60
+ }
61
+ },
62
+ values: {
63
+ isOwner: true
64
+ },
65
+ transaction: t
66
+ });
67
+ });
68
+ };
69
+ const setDepartmentOwners = async (ctx, next) => {
70
+ const { filterByTk, values = {}, resourceName, actionName } = ctx.action.params;
71
+ const { owners } = values;
72
+ if (resourceName === "departments" && actionName === "update" && owners) {
73
+ ctx.action.params.values = import_lodash.default.omit(values, ["owners"]);
74
+ await next();
75
+ await setOwners(ctx, filterByTk, owners);
76
+ } else {
77
+ return next();
78
+ }
79
+ };
80
+ // Annotate the CommonJS export names for ESM import in node:
81
+ 0 && (module.exports = {
82
+ setDepartmentOwners
83
+ });
@@ -0,0 +1,18 @@
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
+ * This file is part of the NocoBase (R) project.
11
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
12
+ * Authors: NocoBase Team.
13
+ *
14
+ * This program is offered under a commercial license.
15
+ * For more information, see <https://www.nocobase.com/agreement>
16
+ */
17
+ import { Context, Next } from '@nocobase/actions';
18
+ export declare const setDepartmentsInfo: (ctx: Context, next: Next) => Promise<any>;
@@ -0,0 +1,71 @@
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_departments_roles_exports = {};
28
+ __export(set_departments_roles_exports, {
29
+ setDepartmentsInfo: () => setDepartmentsInfo
30
+ });
31
+ module.exports = __toCommonJS(set_departments_roles_exports);
32
+ const setDepartmentsInfo = async (ctx, next) => {
33
+ const currentUser = ctx.state.currentUser;
34
+ if (!currentUser) {
35
+ return next();
36
+ }
37
+ const cache = ctx.cache;
38
+ const repo = ctx.db.getRepository("users.departments", currentUser.id);
39
+ const departments = await cache.wrap(
40
+ `departments:${currentUser.id}`,
41
+ () => repo.find({
42
+ appends: ["owners", "roles", "parent(recursively=true)"],
43
+ raw: true
44
+ })
45
+ );
46
+ if (!departments.length) {
47
+ return next();
48
+ }
49
+ ctx.state.currentUser.departments = departments;
50
+ ctx.state.currentUser.mainDeparmtent = departments.find((dept) => dept.isMain);
51
+ const departmentIds = departments.map((dept) => dept.id);
52
+ const roleRepo = ctx.db.getRepository("roles");
53
+ const roles = await roleRepo.find({
54
+ filter: {
55
+ "departments.id": {
56
+ $in: departmentIds
57
+ }
58
+ }
59
+ });
60
+ if (!roles.length) {
61
+ return next();
62
+ }
63
+ const rolesMap = /* @__PURE__ */ new Map();
64
+ roles.forEach((role) => rolesMap.set(role.name, role));
65
+ ctx.state.attachRoles = Array.from(rolesMap.values());
66
+ await next();
67
+ };
68
+ // Annotate the CommonJS export names for ESM import in node:
69
+ 0 && (module.exports = {
70
+ setDepartmentsInfo
71
+ });
@@ -0,0 +1,18 @@
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
+ * This file is part of the NocoBase (R) project.
11
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
12
+ * Authors: NocoBase Team.
13
+ *
14
+ * This program is offered under a commercial license.
15
+ * For more information, see <https://www.nocobase.com/agreement>
16
+ */
17
+ import { Context, Next } from '@nocobase/actions';
18
+ export declare const setMainDepartment: (ctx: Context, next: Next) => Promise<void>;
@@ -0,0 +1,114 @@
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_main_department_exports = {};
28
+ __export(set_main_department_exports, {
29
+ setMainDepartment: () => setMainDepartment
30
+ });
31
+ module.exports = __toCommonJS(set_main_department_exports);
32
+ const setMainDepartment = async (ctx, next) => {
33
+ await next();
34
+ const { associatedName, resourceName, associatedIndex, actionName, values } = ctx.action.params;
35
+ if (associatedName === "departments" && resourceName === "members" && (values == null ? void 0 : values.length)) {
36
+ const throughRepo = ctx.db.getRepository("departmentsUsers");
37
+ const usersHasMain = await throughRepo.find({
38
+ filter: {
39
+ userId: {
40
+ $in: values
41
+ },
42
+ isMain: true
43
+ }
44
+ });
45
+ const userIdsHasMain = usersHasMain.map((item) => item.userId);
46
+ if (actionName === "add" || actionName === "set") {
47
+ await throughRepo.update({
48
+ filter: {
49
+ userId: {
50
+ $in: values.filter((id) => !userIdsHasMain.includes(id))
51
+ },
52
+ departmentId: associatedIndex
53
+ },
54
+ values: {
55
+ isMain: true
56
+ }
57
+ });
58
+ return;
59
+ }
60
+ if (actionName === "remove") {
61
+ const userIdsHasNoMain = values.filter((id) => !userIdsHasMain.includes(id));
62
+ for (const userId of userIdsHasNoMain) {
63
+ const firstDept = await throughRepo.findOne({
64
+ filter: {
65
+ userId
66
+ }
67
+ });
68
+ if (firstDept) {
69
+ await throughRepo.update({
70
+ filter: {
71
+ userId,
72
+ departmentId: firstDept.departmentId
73
+ },
74
+ values: {
75
+ isMain: true
76
+ }
77
+ });
78
+ }
79
+ }
80
+ }
81
+ }
82
+ if (associatedName === "users" && resourceName === "departments" && ["add", "remove", "set"].includes(actionName)) {
83
+ const throughRepo = ctx.db.getRepository("departmentsUsers");
84
+ const hasMain = await throughRepo.findOne({
85
+ filter: {
86
+ userId: associatedIndex,
87
+ isMain: true
88
+ }
89
+ });
90
+ if (hasMain) {
91
+ return;
92
+ }
93
+ const firstDept = await throughRepo.findOne({
94
+ filter: {
95
+ userId: associatedIndex
96
+ }
97
+ });
98
+ if (firstDept) {
99
+ await throughRepo.update({
100
+ filter: {
101
+ userId: associatedIndex,
102
+ departmentId: firstDept.departmentId
103
+ },
104
+ values: {
105
+ isMain: true
106
+ }
107
+ });
108
+ }
109
+ }
110
+ };
111
+ // Annotate the CommonJS export names for ESM import in node:
112
+ 0 && (module.exports = {
113
+ setMainDepartment
114
+ });
@@ -0,0 +1,18 @@
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
+ * This file is part of the NocoBase (R) project.
11
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
12
+ * Authors: NocoBase Team.
13
+ *
14
+ * This program is offered under a commercial license.
15
+ * For more information, see <https://www.nocobase.com/agreement>
16
+ */
17
+ import { Context, Next } from '@nocobase/actions';
18
+ export declare const updateDepartmentIsLeaf: (ctx: Context, next: Next) => Promise<any>;