@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.
- package/LICENSE.txt +161 -0
- package/README.md +1 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/ResourcesProvider.d.ts +20 -0
- package/dist/client/collections/departments.d.ts +144 -0
- package/dist/client/collections/users.d.ts +205 -0
- package/dist/client/components/DepartmentOwnersField.d.ts +18 -0
- package/dist/client/components/ReadOnlyAssociationField.d.ts +18 -0
- package/dist/client/components/UserDepartmentsField.d.ts +18 -0
- package/dist/client/components/UserMainDepartmentField.d.ts +18 -0
- package/dist/client/components/fieldSettings.d.ts +22 -0
- package/dist/client/components/index.d.ts +20 -0
- package/dist/client/departments/AggregateSearch.d.ts +18 -0
- package/dist/client/departments/Department.d.ts +45 -0
- package/dist/client/departments/DepartmentBlock.d.ts +18 -0
- package/dist/client/departments/DepartmentField.d.ts +18 -0
- package/dist/client/departments/DepartmentManagement.d.ts +18 -0
- package/dist/client/departments/DepartmentOwnersField.d.ts +10 -0
- package/dist/client/departments/DepartmentTable.d.ts +18 -0
- package/dist/client/departments/DepartmentTree.d.ts +30 -0
- package/dist/client/departments/DepartmentTreeSelect.d.ts +24 -0
- package/dist/client/departments/IsOwnerField.d.ts +18 -0
- package/dist/client/departments/Member.d.ts +19 -0
- package/dist/client/departments/NewDepartment.d.ts +10 -0
- package/dist/client/departments/UserDepartmentsField.d.ts +10 -0
- package/dist/client/departments/schemas/departments.d.ts +257 -0
- package/dist/client/departments/schemas/users.d.ts +443 -0
- package/dist/client/hooks/departments-manager.d.ts +37 -0
- package/dist/client/hooks/index.d.ts +18 -0
- package/dist/client/hooks/tree-manager.d.ts +38 -0
- package/dist/client/hooks/useTableBlockProps.d.ts +28 -0
- package/dist/client/index.d.ts +23 -0
- package/dist/client/index.js +10 -0
- package/dist/client/locale.d.ts +9 -0
- package/dist/client/roles/RoleDepartmentsManager.d.ts +18 -0
- package/dist/client/roles/schemas/departments.d.ts +235 -0
- package/dist/client/utils.d.ts +17 -0
- package/dist/externalVersion.js +29 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +48 -0
- package/dist/locale/en-US.json +35 -0
- package/dist/locale/zh-CN.json +35 -0
- package/dist/server/actions/departments.d.ts +21 -0
- package/dist/server/actions/departments.js +114 -0
- package/dist/server/actions/users.d.ts +20 -0
- package/dist/server/actions/users.js +151 -0
- package/dist/server/collections/departmentRoles.d.ts +10 -0
- package/dist/server/collections/departmentRoles.js +37 -0
- package/dist/server/collections/departments.d.ts +37 -0
- package/dist/server/collections/departments.js +172 -0
- package/dist/server/collections/departmentsUsers.d.ts +10 -0
- package/dist/server/collections/departmentsUsers.js +53 -0
- package/dist/server/collections/roles.d.ts +14 -0
- package/dist/server/collections/roles.js +48 -0
- package/dist/server/collections/users.d.ts +67 -0
- package/dist/server/collections/users.js +96 -0
- package/dist/server/department-data-sync-resource.d.ts +27 -0
- package/dist/server/department-data-sync-resource.js +339 -0
- package/dist/server/index.d.ts +17 -0
- package/dist/server/index.js +42 -0
- package/dist/server/middlewares/destroy-department-check.d.ts +18 -0
- package/dist/server/middlewares/destroy-department-check.js +62 -0
- package/dist/server/middlewares/index.d.ts +22 -0
- package/dist/server/middlewares/index.js +40 -0
- package/dist/server/middlewares/reset-user-departments-cache.d.ts +18 -0
- package/dist/server/middlewares/reset-user-departments-cache.js +48 -0
- package/dist/server/middlewares/set-department-owners.d.ts +18 -0
- package/dist/server/middlewares/set-department-owners.js +83 -0
- package/dist/server/middlewares/set-departments-roles.d.ts +18 -0
- package/dist/server/middlewares/set-departments-roles.js +71 -0
- package/dist/server/middlewares/set-main-department.d.ts +18 -0
- package/dist/server/middlewares/set-main-department.js +114 -0
- package/dist/server/middlewares/update-department-isleaf.d.ts +18 -0
- package/dist/server/middlewares/update-department-isleaf.js +93 -0
- package/dist/server/migrations/update-field-uischemas-20240307124823.d.ts +20 -0
- package/dist/server/migrations/update-field-uischemas-20240307124823.js +106 -0
- package/dist/server/models/department.d.ts +20 -0
- package/dist/server/models/department.js +47 -0
- package/dist/server/plugin.d.ts +19 -0
- package/dist/server/plugin.js +154 -0
- package/package.json +22 -0
- package/server.d.ts +2 -0
- package/server.js +1 -0
|
@@ -0,0 +1,93 @@
|
|
|
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 update_department_isleaf_exports = {};
|
|
28
|
+
__export(update_department_isleaf_exports, {
|
|
29
|
+
updateDepartmentIsLeaf: () => updateDepartmentIsLeaf
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(update_department_isleaf_exports);
|
|
32
|
+
const updateIsLeafWhenAddChild = async (repo, parent) => {
|
|
33
|
+
if (parent && parent.isLeaf !== false) {
|
|
34
|
+
await repo.update({
|
|
35
|
+
filter: {
|
|
36
|
+
id: parent.id
|
|
37
|
+
},
|
|
38
|
+
values: {
|
|
39
|
+
isLeaf: false
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const updateIsLeafWhenChangeChild = async (repo, oldParentId, newParentId) => {
|
|
45
|
+
if (oldParentId && oldParentId !== newParentId) {
|
|
46
|
+
const hasChild = await repo.count({
|
|
47
|
+
filter: {
|
|
48
|
+
parentId: oldParentId
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
if (!hasChild) {
|
|
52
|
+
await repo.update({
|
|
53
|
+
filter: {
|
|
54
|
+
id: oldParentId
|
|
55
|
+
},
|
|
56
|
+
values: {
|
|
57
|
+
isLeaf: true
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const updateDepartmentIsLeaf = async (ctx, next) => {
|
|
64
|
+
const { filterByTk, values = {}, resourceName, actionName } = ctx.action.params;
|
|
65
|
+
const repo = ctx.db.getRepository("departments");
|
|
66
|
+
const { parent } = values;
|
|
67
|
+
if (resourceName === "departments" && actionName === "create") {
|
|
68
|
+
ctx.action.params.values = { ...values, isLeaf: true };
|
|
69
|
+
await next();
|
|
70
|
+
await updateIsLeafWhenAddChild(repo, parent);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (resourceName === "departments" && actionName === "update") {
|
|
74
|
+
const department = await repo.findOne({ filterByTk });
|
|
75
|
+
await next();
|
|
76
|
+
await Promise.all([
|
|
77
|
+
updateIsLeafWhenChangeChild(repo, department.parentId, parent == null ? void 0 : parent.id),
|
|
78
|
+
updateIsLeafWhenAddChild(repo, parent)
|
|
79
|
+
]);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (resourceName === "departments" && actionName === "destroy") {
|
|
83
|
+
const department = await repo.findOne({ filterByTk });
|
|
84
|
+
await next();
|
|
85
|
+
await updateIsLeafWhenChangeChild(repo, department.parentId, null);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
return next();
|
|
89
|
+
};
|
|
90
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
91
|
+
0 && (module.exports = {
|
|
92
|
+
updateDepartmentIsLeaf
|
|
93
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
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 { Migration } from '@nocobase/server';
|
|
18
|
+
export default class UpdateFieldUISchemasMigration extends Migration {
|
|
19
|
+
up(): Promise<void>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
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 update_field_uischemas_20240307124823_exports = {};
|
|
28
|
+
__export(update_field_uischemas_20240307124823_exports, {
|
|
29
|
+
default: () => UpdateFieldUISchemasMigration
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(update_field_uischemas_20240307124823_exports);
|
|
32
|
+
var import_server = require("@nocobase/server");
|
|
33
|
+
var import_users = require("../collections/users");
|
|
34
|
+
var import_departments = require("../collections/departments");
|
|
35
|
+
class UpdateFieldUISchemasMigration extends import_server.Migration {
|
|
36
|
+
async up() {
|
|
37
|
+
const result = await this.app.version.satisfies("<=0.20.0-alpha.6");
|
|
38
|
+
if (!result) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const fieldRepo = this.db.getRepository("fields");
|
|
42
|
+
const departmentsFieldInstance = await fieldRepo.findOne({
|
|
43
|
+
filter: {
|
|
44
|
+
name: "departments",
|
|
45
|
+
collectionName: "users"
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
if (departmentsFieldInstance) {
|
|
49
|
+
const options = {
|
|
50
|
+
...departmentsFieldInstance.options,
|
|
51
|
+
uiSchema: import_users.departmentsField.uiSchema
|
|
52
|
+
};
|
|
53
|
+
await fieldRepo.update({
|
|
54
|
+
filter: {
|
|
55
|
+
name: "departments",
|
|
56
|
+
collectionName: "users"
|
|
57
|
+
},
|
|
58
|
+
values: {
|
|
59
|
+
options
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
const mainDepartmentFieldInstance = await fieldRepo.findOne({
|
|
64
|
+
filter: {
|
|
65
|
+
name: "mainDepartment",
|
|
66
|
+
collectionName: "users"
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
if (mainDepartmentFieldInstance) {
|
|
70
|
+
const options = {
|
|
71
|
+
...mainDepartmentFieldInstance.options,
|
|
72
|
+
uiSchema: import_users.mainDepartmentField.uiSchema
|
|
73
|
+
};
|
|
74
|
+
await fieldRepo.update({
|
|
75
|
+
filter: {
|
|
76
|
+
name: "mainDepartment",
|
|
77
|
+
collectionName: "users"
|
|
78
|
+
},
|
|
79
|
+
values: {
|
|
80
|
+
options
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
const ownersFieldInstance = await fieldRepo.findOne({
|
|
85
|
+
filter: {
|
|
86
|
+
name: "owners",
|
|
87
|
+
collectionName: "departments"
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
if (ownersFieldInstance) {
|
|
91
|
+
const options = {
|
|
92
|
+
...ownersFieldInstance.options,
|
|
93
|
+
uiSchema: import_departments.ownersField.uiSchema
|
|
94
|
+
};
|
|
95
|
+
await fieldRepo.update({
|
|
96
|
+
filter: {
|
|
97
|
+
name: "owners",
|
|
98
|
+
collectionName: "departments"
|
|
99
|
+
},
|
|
100
|
+
values: {
|
|
101
|
+
options
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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 { Model } from '@nocobase/database';
|
|
18
|
+
export declare class DepartmentModel extends Model {
|
|
19
|
+
getOwners(): any;
|
|
20
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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 department_exports = {};
|
|
28
|
+
__export(department_exports, {
|
|
29
|
+
DepartmentModel: () => DepartmentModel
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(department_exports);
|
|
32
|
+
var import_database = require("@nocobase/database");
|
|
33
|
+
class DepartmentModel extends import_database.Model {
|
|
34
|
+
getOwners() {
|
|
35
|
+
return this.getMembers({
|
|
36
|
+
through: {
|
|
37
|
+
where: {
|
|
38
|
+
isOwner: true
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
DepartmentModel
|
|
47
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
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 { InstallOptions, Plugin } from '@nocobase/server';
|
|
10
|
+
export declare class PluginDepartmentsServer extends Plugin {
|
|
11
|
+
afterAdd(): void;
|
|
12
|
+
beforeLoad(): void;
|
|
13
|
+
load(): Promise<void>;
|
|
14
|
+
install(options?: InstallOptions): Promise<void>;
|
|
15
|
+
afterEnable(): Promise<void>;
|
|
16
|
+
afterDisable(): Promise<void>;
|
|
17
|
+
remove(): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
export default PluginDepartmentsServer;
|
|
@@ -0,0 +1,154 @@
|
|
|
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 plugin_exports = {};
|
|
28
|
+
__export(plugin_exports, {
|
|
29
|
+
PluginDepartmentsServer: () => PluginDepartmentsServer,
|
|
30
|
+
default: () => plugin_default
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
33
|
+
var import_server = require("@nocobase/server");
|
|
34
|
+
var import_departments = require("./actions/departments");
|
|
35
|
+
var import_users = require("./actions/users");
|
|
36
|
+
var import_users2 = require("./collections/users");
|
|
37
|
+
var import_middlewares = require("./middlewares");
|
|
38
|
+
var import_set_departments_roles = require("./middlewares/set-departments-roles");
|
|
39
|
+
var import_department = require("./models/department");
|
|
40
|
+
var import_department_data_sync_resource = require("./department-data-sync-resource");
|
|
41
|
+
class PluginDepartmentsServer extends import_server.Plugin {
|
|
42
|
+
afterAdd() {
|
|
43
|
+
}
|
|
44
|
+
beforeLoad() {
|
|
45
|
+
this.app.db.registerModels({ DepartmentModel: import_department.DepartmentModel });
|
|
46
|
+
this.app.acl.addFixedParams("collections", "destroy", () => {
|
|
47
|
+
return {
|
|
48
|
+
filter: {
|
|
49
|
+
"name.$notIn": ["departments", "departmentsUsers", "departmentsRoles"]
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
async load() {
|
|
55
|
+
this.app.resourceManager.registerActionHandlers({
|
|
56
|
+
"users:listExcludeDept": import_users.listExcludeDept,
|
|
57
|
+
"users:setMainDepartment": import_users.setMainDepartment,
|
|
58
|
+
"departments:aggregateSearch": import_departments.aggregateSearch,
|
|
59
|
+
"departments:setOwner": import_departments.setOwner,
|
|
60
|
+
"departments:removeOwner": import_departments.removeOwner
|
|
61
|
+
});
|
|
62
|
+
this.app.acl.allow("users", ["setMainDepartment", "listExcludeDept"], "loggedIn");
|
|
63
|
+
this.app.acl.registerSnippet({
|
|
64
|
+
name: `pm.${this.name}`,
|
|
65
|
+
actions: [
|
|
66
|
+
"departments:*",
|
|
67
|
+
"roles:list",
|
|
68
|
+
"users:list",
|
|
69
|
+
"users:listExcludeDept",
|
|
70
|
+
"users:setMainDepartment",
|
|
71
|
+
"users.departments:*",
|
|
72
|
+
"roles.departments:*",
|
|
73
|
+
"departments.members:*"
|
|
74
|
+
]
|
|
75
|
+
});
|
|
76
|
+
this.app.resourceManager.use(import_set_departments_roles.setDepartmentsInfo, {
|
|
77
|
+
tag: "setDepartmentsInfo",
|
|
78
|
+
before: "setCurrentRole",
|
|
79
|
+
after: "auth"
|
|
80
|
+
});
|
|
81
|
+
this.app.dataSourceManager.afterAddDataSource((dataSource) => {
|
|
82
|
+
dataSource.resourceManager.use(import_set_departments_roles.setDepartmentsInfo, {
|
|
83
|
+
tag: "setDepartmentsInfo",
|
|
84
|
+
before: "setCurrentRole",
|
|
85
|
+
after: "auth"
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
this.app.resourceManager.use(import_middlewares.setDepartmentOwners);
|
|
89
|
+
this.app.resourceManager.use(import_middlewares.destroyDepartmentCheck);
|
|
90
|
+
this.app.resourceManager.use(import_middlewares.updateDepartmentIsLeaf);
|
|
91
|
+
this.app.resourceManager.use(import_middlewares.resetUserDepartmentsCache);
|
|
92
|
+
this.app.resourceManager.use(import_middlewares.setMainDepartment);
|
|
93
|
+
this.app.db.on("departmentsUsers.afterSave", async (model) => {
|
|
94
|
+
const cache = this.app.cache;
|
|
95
|
+
await cache.del(`departments:${model.get("userId")}`);
|
|
96
|
+
});
|
|
97
|
+
this.app.db.on("departmentsUsers.afterDestroy", async (model) => {
|
|
98
|
+
const cache = this.app.cache;
|
|
99
|
+
await cache.del(`departments:${model.get("userId")}`);
|
|
100
|
+
});
|
|
101
|
+
this.app.on("beforeSignOut", ({ userId }) => {
|
|
102
|
+
this.app.cache.del(`departments:${userId}`);
|
|
103
|
+
});
|
|
104
|
+
const userDataSyncPlugin = this.app.pm.get("user-data-sync");
|
|
105
|
+
if (userDataSyncPlugin && userDataSyncPlugin.enabled) {
|
|
106
|
+
userDataSyncPlugin.resourceManager.registerResource(new import_department_data_sync_resource.DepartmentDataSyncResource(this.db, this.app.logger), {
|
|
107
|
+
// write department records after writing user records
|
|
108
|
+
after: "users"
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async install(options) {
|
|
113
|
+
const collectionRepo = this.db.getRepository("collections");
|
|
114
|
+
if (collectionRepo) {
|
|
115
|
+
await collectionRepo.db2cm("departments");
|
|
116
|
+
}
|
|
117
|
+
const fieldRepo = this.db.getRepository("fields");
|
|
118
|
+
if (fieldRepo) {
|
|
119
|
+
const isDepartmentsFieldExists = await fieldRepo.count({
|
|
120
|
+
filter: {
|
|
121
|
+
name: "departments",
|
|
122
|
+
collectionName: "users"
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
if (!isDepartmentsFieldExists) {
|
|
126
|
+
await fieldRepo.create({
|
|
127
|
+
values: import_users2.departmentsField
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
const isMainDepartmentFieldExists = await fieldRepo.count({
|
|
131
|
+
filter: {
|
|
132
|
+
name: "mainDepartment",
|
|
133
|
+
collectionName: "users"
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
if (!isMainDepartmentFieldExists) {
|
|
137
|
+
await fieldRepo.create({
|
|
138
|
+
values: import_users2.mainDepartmentField
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async afterEnable() {
|
|
144
|
+
}
|
|
145
|
+
async afterDisable() {
|
|
146
|
+
}
|
|
147
|
+
async remove() {
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
var plugin_default = PluginDepartmentsServer;
|
|
151
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
152
|
+
0 && (module.exports = {
|
|
153
|
+
PluginDepartmentsServer
|
|
154
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nocobase/plugin-departments",
|
|
3
|
+
"displayName": "Departments",
|
|
4
|
+
"displayName.zh-CN": "部门",
|
|
5
|
+
"description": "Organize users by departments, set hierarchical relationships, link roles to control permissions, and use departments as variables in workflows and expressions.",
|
|
6
|
+
"description.zh-CN": "以部门来组织用户,设定上下级关系,绑定角色控制权限,并支持作为变量用于工作流和表达式。",
|
|
7
|
+
"version": "1.6.20",
|
|
8
|
+
"main": "dist/server/index.js",
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"@nocobase/plugin-user-data-sync": "1.6.20"
|
|
11
|
+
},
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"@nocobase/actions": "1.x",
|
|
14
|
+
"@nocobase/client": "1.x",
|
|
15
|
+
"@nocobase/server": "1.x",
|
|
16
|
+
"@nocobase/test": "1.x"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"Users & permissions"
|
|
20
|
+
],
|
|
21
|
+
"gitHead": "fe915073be058f8d256000b16d7c1735dc08c23b"
|
|
22
|
+
}
|
package/server.d.ts
ADDED
package/server.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/server/index.js');
|