@tachybase/plugin-department 0.23.35
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 +201 -0
- package/README.md +1 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/common/DepartmentTable.schema.d.ts +50 -0
- package/dist/client/common/DepartmentTable.view.d.ts +4 -0
- package/dist/client/common/FilterKeys.context.d.ts +10 -0
- package/dist/client/common/InternalDepartmentTable.d.ts +5 -0
- package/dist/client/common/Request.povider.d.ts +1 -0
- package/dist/client/common/UserDepartmentsFieldNotSupport.d.ts +2 -0
- package/dist/client/common/scopes/useDepartmentFilterActionProps.d.ts +5 -0
- package/dist/client/common/scopes/useFilterActionProps.d.ts +5 -0
- package/dist/client/index.d.ts +6 -0
- package/dist/client/index.js +12 -0
- package/dist/client/locale.d.ts +9 -0
- package/dist/client/main-tab/DepartmentIndex.d.ts +5 -0
- package/dist/client/main-tab/DepartmentIndex.provider.d.ts +3 -0
- package/dist/client/main-tab/DepartmentManagement.component.d.ts +1 -0
- package/dist/client/main-tab/DepartmentManagement.schema.d.ts +10 -0
- package/dist/client/main-tab/DepartmentManagement.view.d.ts +1 -0
- package/dist/client/main-tab/collections/departments.collection.d.ts +128 -0
- package/dist/client/main-tab/collections/users.collection.d.ts +189 -0
- package/dist/client/main-tab/components/DepartmentSelect.d.ts +1 -0
- package/dist/client/main-tab/components/InternalSuperiorDepartmentSelect.d.ts +1 -0
- package/dist/client/main-tab/components/SuperiorDepartmentSelect.d.ts +1 -0
- package/dist/client/main-tab/context/Department.context.d.ts +23 -0
- package/dist/client/main-tab/context/DepartmentsExpanded.context.d.ts +17 -0
- package/dist/client/main-tab/departments-block/AddNewDepartment.schema.d.ts +67 -0
- package/dist/client/main-tab/departments-block/AddNewDepartment.view.d.ts +1 -0
- package/dist/client/main-tab/departments-block/DepartmentOwnersField.component.d.ts +5 -0
- package/dist/client/main-tab/departments-block/DepartmentsBlock.d.ts +1 -0
- package/dist/client/main-tab/departments-block/DepartmentsSearch.component.d.ts +1 -0
- package/dist/client/main-tab/departments-block/DepartmentsTree.component.d.ts +8 -0
- package/dist/client/main-tab/departments-block/Request.provider.d.ts +1 -0
- package/dist/client/main-tab/departments-block/UnknownOwerns.schema.d.ts +136 -0
- package/dist/client/main-tab/departments-block/UnknownOwerns.view.d.ts +1 -0
- package/dist/client/main-tab/departments-block/schemas/schemaDepartmentEdit.d.ts +62 -0
- package/dist/client/main-tab/departments-block/schemas/schemaDepartmentNewSub.d.ts +57 -0
- package/dist/client/main-tab/departments-block/scopes/useCreateDepartment.d.ts +3 -0
- package/dist/client/main-tab/departments-block/scopes/useUpdateDepartment.d.ts +3 -0
- package/dist/client/main-tab/departments-users-block/AddMembers.schema.d.ts +148 -0
- package/dist/client/main-tab/departments-users-block/AddMembers.view.d.ts +1 -0
- package/dist/client/main-tab/departments-users-block/DepartmentField.component.d.ts +1 -0
- package/dist/client/main-tab/departments-users-block/DepartmentsUsersBlock.d.ts +1 -0
- package/dist/client/main-tab/departments-users-block/DepartmentsUsersBlock.schema.d.ts +676 -0
- package/dist/client/main-tab/departments-users-block/IsOwnerField.component.d.ts +1 -0
- package/dist/client/main-tab/departments-users-block/MemberActions.schema.d.ts +49 -0
- package/dist/client/main-tab/departments-users-block/MemberActions.view.d.ts +1 -0
- package/dist/client/main-tab/departments-users-block/RowRemoveAction.schema.d.ts +16 -0
- package/dist/client/main-tab/departments-users-block/RowRemoveAction.view.d.ts +1 -0
- package/dist/client/main-tab/departments-users-block/UserDepartmentsField.component.d.ts +1 -0
- package/dist/client/main-tab/departments-users-block/UserSelectDepartment.schema.d.ts +42 -0
- package/dist/client/main-tab/departments-users-block/UserSelectDepartment.view.d.ts +1 -0
- package/dist/client/main-tab/departments-users-block/scopes/useBulkRemoveMembersAction.d.ts +3 -0
- package/dist/client/main-tab/departments-users-block/scopes/useDataSource.d.ts +40 -0
- package/dist/client/main-tab/departments-users-block/scopes/useMembersDataSource.d.ts +6 -0
- package/dist/client/main-tab/departments-users-block/scopes/usePropsAddMember.d.ts +1 -0
- package/dist/client/main-tab/departments-users-block/scopes/useRefreshActionProps.d.ts +3 -0
- package/dist/client/main-tab/departments-users-block/scopes/useRemoveMemberAction.d.ts +3 -0
- package/dist/client/main-tab/departments-users-block/scopes/useShowTotal.d.ts +1 -0
- package/dist/client/main-tab/hooks/useDeepTree.d.ts +14 -0
- package/dist/client/main-tab/hooks/useGetDepTree.d.ts +18 -0
- package/dist/client/main-tab/kit.d.ts +4 -0
- package/dist/client/main-tab/providers/DepartmentsResource.provider.d.ts +3 -0
- package/dist/client/main-tab/providers/UserResource.provider.d.ts +3 -0
- package/dist/client/role-auth/DepartmentTitle.component.d.ts +1 -0
- package/dist/client/role-auth/Departments.d.ts +1 -0
- package/dist/client/role-auth/Departments.schema.d.ts +227 -0
- package/dist/client/role-auth/kit.d.ts +4 -0
- package/dist/client/role-auth/scopes/useAddDepartments.d.ts +3 -0
- package/dist/client/role-auth/scopes/useBulkRemoveDepartments.d.ts +3 -0
- package/dist/client/role-auth/scopes/useDataSource.d.ts +40 -0
- package/dist/client/role-auth/scopes/useDisabled.d.ts +3 -0
- package/dist/client/role-auth/scopes/useRemoveDepartment.d.ts +3 -0
- package/dist/client/settings/DepartmentOwnersFieldSetting.d.ts +2 -0
- package/dist/client/settings/UserDepartmentsFieldSetting.d.ts +2 -0
- package/dist/client/settings/UserMainDepartmentFieldSetting.d.ts +2 -0
- package/dist/client/settings/items/enableLinkItem.d.ts +2 -0
- package/dist/client/settings/items/modeSelectItem.d.ts +2 -0
- package/dist/client/settings/items/titleFieldItem.d.ts +2 -0
- package/dist/client/utils/getDepartmentStr.d.ts +1 -0
- package/dist/client/utils/getUserListByDepartment.d.ts +1 -0
- package/dist/externalVersion.js +14 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +39 -0
- package/dist/locale/en-US.json +51 -0
- package/dist/locale/zh-CN.json +51 -0
- package/dist/server/actions/departments.d.ts +5 -0
- package/dist/server/actions/departments.js +105 -0
- package/dist/server/actions/index.d.ts +2 -0
- package/dist/server/actions/index.js +23 -0
- package/dist/server/actions/users.d.ts +4 -0
- package/dist/server/actions/users.js +142 -0
- package/dist/server/collections/departmentRoles.d.ts +2 -0
- package/dist/server/collections/departmentRoles.js +27 -0
- package/dist/server/collections/departments.d.ts +29 -0
- package/dist/server/collections/departments.js +162 -0
- package/dist/server/collections/departmentsUsers.d.ts +2 -0
- package/dist/server/collections/departmentsUsers.js +43 -0
- package/dist/server/collections/roles.d.ts +2 -0
- package/dist/server/collections/roles.js +39 -0
- package/dist/server/collections/users.d.ts +55 -0
- package/dist/server/collections/users.js +87 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +33 -0
- package/dist/server/middlewares/destroy-department-check.d.ts +2 -0
- package/dist/server/middlewares/destroy-department-check.js +53 -0
- package/dist/server/middlewares/index.d.ts +6 -0
- package/dist/server/middlewares/index.js +31 -0
- package/dist/server/middlewares/list-users-include-child-department.d.ts +2 -0
- package/dist/server/middlewares/list-users-include-child-department.js +77 -0
- package/dist/server/middlewares/reset-user-departments-cache.d.ts +2 -0
- package/dist/server/middlewares/reset-user-departments-cache.js +39 -0
- package/dist/server/middlewares/set-department-owners.d.ts +2 -0
- package/dist/server/middlewares/set-department-owners.js +74 -0
- package/dist/server/middlewares/set-departments-roles.d.ts +2 -0
- package/dist/server/middlewares/set-departments-roles.js +64 -0
- package/dist/server/middlewares/set-main-department.d.ts +2 -0
- package/dist/server/middlewares/set-main-department.js +105 -0
- package/dist/server/middlewares/update-department-isleaf.d.ts +2 -0
- package/dist/server/middlewares/update-department-isleaf.js +84 -0
- package/dist/server/models/department.d.ts +4 -0
- package/dist/server/models/department.js +38 -0
- package/dist/server/plugin.d.ts +8 -0
- package/dist/server/plugin.js +134 -0
- package/package.json +27 -0
- package/server.d.ts +2 -0
- package/server.js +1 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var set_main_department_exports = {};
|
|
19
|
+
__export(set_main_department_exports, {
|
|
20
|
+
setMainDepartment: () => setMainDepartment
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(set_main_department_exports);
|
|
23
|
+
const setMainDepartment = async (ctx, next) => {
|
|
24
|
+
await next();
|
|
25
|
+
const { associatedName, resourceName, associatedIndex, actionName, values } = ctx.action.params;
|
|
26
|
+
if (associatedName === "departments" && resourceName === "members" && (values == null ? void 0 : values.length)) {
|
|
27
|
+
const throughRepo = ctx.db.getRepository("departmentsUsers");
|
|
28
|
+
const usersHasMain = await throughRepo.find({
|
|
29
|
+
filter: {
|
|
30
|
+
userId: {
|
|
31
|
+
$in: values
|
|
32
|
+
},
|
|
33
|
+
isMain: true
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
const userIdsHasMain = usersHasMain.map((item) => item.userId);
|
|
37
|
+
if (actionName === "add" || actionName === "set") {
|
|
38
|
+
await throughRepo.update({
|
|
39
|
+
filter: {
|
|
40
|
+
userId: {
|
|
41
|
+
$in: values.filter((id) => !userIdsHasMain.includes(id))
|
|
42
|
+
},
|
|
43
|
+
departmentId: associatedIndex
|
|
44
|
+
},
|
|
45
|
+
values: {
|
|
46
|
+
isMain: true
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (actionName === "remove") {
|
|
52
|
+
const userIdsHasNoMain = values.filter((id) => !userIdsHasMain.includes(id));
|
|
53
|
+
for (const userId of userIdsHasNoMain) {
|
|
54
|
+
const firstDept = await throughRepo.findOne({
|
|
55
|
+
filter: {
|
|
56
|
+
userId
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
if (firstDept) {
|
|
60
|
+
await throughRepo.update({
|
|
61
|
+
filter: {
|
|
62
|
+
userId,
|
|
63
|
+
departmentId: firstDept.departmentId
|
|
64
|
+
},
|
|
65
|
+
values: {
|
|
66
|
+
isMain: true
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (associatedName === "users" && resourceName === "departments" && ["add", "remove", "set"].includes(actionName)) {
|
|
74
|
+
const throughRepo = ctx.db.getRepository("departmentsUsers");
|
|
75
|
+
const hasMain = await throughRepo.findOne({
|
|
76
|
+
filter: {
|
|
77
|
+
userId: associatedIndex,
|
|
78
|
+
isMain: true
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
if (hasMain) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const firstDept = await throughRepo.findOne({
|
|
85
|
+
filter: {
|
|
86
|
+
userId: associatedIndex
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
if (firstDept) {
|
|
90
|
+
await throughRepo.update({
|
|
91
|
+
filter: {
|
|
92
|
+
userId: associatedIndex,
|
|
93
|
+
departmentId: firstDept.departmentId
|
|
94
|
+
},
|
|
95
|
+
values: {
|
|
96
|
+
isMain: true
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
103
|
+
0 && (module.exports = {
|
|
104
|
+
setMainDepartment
|
|
105
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var update_department_isleaf_exports = {};
|
|
19
|
+
__export(update_department_isleaf_exports, {
|
|
20
|
+
updateDepartmentIsLeaf: () => updateDepartmentIsLeaf
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(update_department_isleaf_exports);
|
|
23
|
+
const updateIsLeafWhenAddChild = async (repo, parent) => {
|
|
24
|
+
if (parent && parent.isLeaf !== false) {
|
|
25
|
+
await repo.update({
|
|
26
|
+
filter: {
|
|
27
|
+
id: parent.id
|
|
28
|
+
},
|
|
29
|
+
values: {
|
|
30
|
+
isLeaf: false
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const updateIsLeafWhenChangeChild = async (repo, oldParentId, newParentId) => {
|
|
36
|
+
if (oldParentId && oldParentId !== newParentId) {
|
|
37
|
+
const hasChild = await repo.count({
|
|
38
|
+
filter: {
|
|
39
|
+
parentId: oldParentId
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
if (!hasChild) {
|
|
43
|
+
await repo.update({
|
|
44
|
+
filter: {
|
|
45
|
+
id: oldParentId
|
|
46
|
+
},
|
|
47
|
+
values: {
|
|
48
|
+
isLeaf: true
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const updateDepartmentIsLeaf = async (ctx, next) => {
|
|
55
|
+
const { filterByTk, values = {}, resourceName, actionName } = ctx.action.params;
|
|
56
|
+
const repo = ctx.db.getRepository("departments");
|
|
57
|
+
const { parent } = values;
|
|
58
|
+
if (resourceName === "departments" && actionName === "create") {
|
|
59
|
+
ctx.action.params.values = { ...values, isLeaf: true };
|
|
60
|
+
await next();
|
|
61
|
+
await updateIsLeafWhenAddChild(repo, parent);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (resourceName === "departments" && actionName === "update") {
|
|
65
|
+
const department = await repo.findOne({ filterByTk });
|
|
66
|
+
await next();
|
|
67
|
+
await Promise.all([
|
|
68
|
+
updateIsLeafWhenChangeChild(repo, department.parentId, parent == null ? void 0 : parent.id),
|
|
69
|
+
updateIsLeafWhenAddChild(repo, parent)
|
|
70
|
+
]);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (resourceName === "departments" && actionName === "destroy") {
|
|
74
|
+
const department = await repo.findOne({ filterByTk });
|
|
75
|
+
await next();
|
|
76
|
+
await updateIsLeafWhenChangeChild(repo, department.parentId, null);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
return next();
|
|
80
|
+
};
|
|
81
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
82
|
+
0 && (module.exports = {
|
|
83
|
+
updateDepartmentIsLeaf
|
|
84
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var department_exports = {};
|
|
19
|
+
__export(department_exports, {
|
|
20
|
+
DepartmentModel: () => DepartmentModel
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(department_exports);
|
|
23
|
+
var import_database = require("@tachybase/database");
|
|
24
|
+
class DepartmentModel extends import_database.Model {
|
|
25
|
+
getOwners() {
|
|
26
|
+
return this.getMembers({
|
|
27
|
+
through: {
|
|
28
|
+
where: {
|
|
29
|
+
isOwner: true
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
DepartmentModel
|
|
38
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { InstallOptions, Plugin } from '@tachybase/server';
|
|
2
|
+
export declare class PluginDepartmentServer extends Plugin {
|
|
3
|
+
beforeLoad(): void;
|
|
4
|
+
load(): Promise<void>;
|
|
5
|
+
upgrade(): Promise<void>;
|
|
6
|
+
install(options?: InstallOptions): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export default PluginDepartmentServer;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var plugin_exports = {};
|
|
19
|
+
__export(plugin_exports, {
|
|
20
|
+
PluginDepartmentServer: () => PluginDepartmentServer,
|
|
21
|
+
default: () => plugin_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
24
|
+
var import_server = require("@tachybase/server");
|
|
25
|
+
var import_actions = require("./actions");
|
|
26
|
+
var import_users = require("./collections/users");
|
|
27
|
+
var import_middlewares = require("./middlewares");
|
|
28
|
+
var import_list_users_include_child_department = require("./middlewares/list-users-include-child-department");
|
|
29
|
+
var import_department = require("./models/department");
|
|
30
|
+
class PluginDepartmentServer extends import_server.Plugin {
|
|
31
|
+
beforeLoad() {
|
|
32
|
+
this.app.db.registerModels({ DepartmentModel: import_department.DepartmentModel });
|
|
33
|
+
this.app.acl.addFixedParams("collections", "destroy", () => {
|
|
34
|
+
return {
|
|
35
|
+
filter: {
|
|
36
|
+
"name.$notIn": ["departments", "departmentsUsers", "departmentsRoles"]
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async load() {
|
|
42
|
+
this.app.resourcer.define({
|
|
43
|
+
name: "users",
|
|
44
|
+
actions: {
|
|
45
|
+
listExcludeDept: import_actions.listExcludeDept,
|
|
46
|
+
setMainDepartment: import_actions.setMainDepartment
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
this.app.resourcer.define({
|
|
50
|
+
name: "departments",
|
|
51
|
+
actions: {
|
|
52
|
+
aggregateSearch: import_actions.aggregateSearch,
|
|
53
|
+
setOwner: import_actions.setOwner,
|
|
54
|
+
removeOwner: import_actions.removeOwner
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
this.app.acl.allow("users", ["setMainDepartment", "listExcludeDept"], "loggedIn");
|
|
58
|
+
this.app.acl.registerSnippet({
|
|
59
|
+
name: `pm.${this.name}.*`,
|
|
60
|
+
actions: [
|
|
61
|
+
"departments:*",
|
|
62
|
+
"roles:list",
|
|
63
|
+
"users:list",
|
|
64
|
+
"users:listExcludeDept",
|
|
65
|
+
"users:setMainDepartment",
|
|
66
|
+
"roles.departments:add",
|
|
67
|
+
"roles.departments:remove",
|
|
68
|
+
"users.departments:add",
|
|
69
|
+
"users.departments:remove"
|
|
70
|
+
]
|
|
71
|
+
});
|
|
72
|
+
this.app.resourcer.use(import_middlewares.setDepartmentsInfo, {
|
|
73
|
+
tag: "setDepartmentsInfo",
|
|
74
|
+
before: "setCurrentRole",
|
|
75
|
+
after: "auth"
|
|
76
|
+
});
|
|
77
|
+
this.app.resourcer.use(import_middlewares.setDepartmentOwners, { tag: "setDepartmentOwners" });
|
|
78
|
+
this.app.resourcer.use(import_middlewares.destroyDepartmentCheck, { tag: "destroyDepartmentCheck" });
|
|
79
|
+
this.app.resourcer.use(import_middlewares.updateDepartmentIsLeaf, { tag: "updateDepartmentIsLeaf" });
|
|
80
|
+
this.app.resourcer.use(import_middlewares.resetUserDepartmentsCache, { tag: "resetUserDepartmentsCache" });
|
|
81
|
+
this.app.resourcer.use(import_middlewares.setMainDepartment, { tag: "setMainDepartment" });
|
|
82
|
+
this.app.resourcer.use(import_list_users_include_child_department.listUsersIncludeChildDepartment, { tag: "listUsersIncludeChildDepartment" });
|
|
83
|
+
this.app.db.on("departmentsUsers.afterSave", async (model) => {
|
|
84
|
+
const cache = this.app.cache;
|
|
85
|
+
await cache.del(`departments:${model.get("userId")}`);
|
|
86
|
+
});
|
|
87
|
+
this.app.db.on("departmentsUsers.afterDestroy", async (model) => {
|
|
88
|
+
const cache = this.app.cache;
|
|
89
|
+
await cache.del(`departments:${model.get("userId")}`);
|
|
90
|
+
});
|
|
91
|
+
this.app.on("beforeSignOut", ({ userId }) => {
|
|
92
|
+
this.app.cache.del(`departments:${userId}`);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
async upgrade() {
|
|
96
|
+
await this.install();
|
|
97
|
+
}
|
|
98
|
+
async install(options) {
|
|
99
|
+
const collectionRepo = this.db.getRepository("collections");
|
|
100
|
+
if (collectionRepo) {
|
|
101
|
+
await collectionRepo.db2cm("departments");
|
|
102
|
+
}
|
|
103
|
+
const fieldRepo = this.db.getRepository("fields");
|
|
104
|
+
if (fieldRepo) {
|
|
105
|
+
const isDepartmentsFieldExists = await fieldRepo.count({
|
|
106
|
+
filter: {
|
|
107
|
+
name: "departments",
|
|
108
|
+
collectionName: "users"
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
if (!isDepartmentsFieldExists) {
|
|
112
|
+
await fieldRepo.create({
|
|
113
|
+
values: import_users.departmentsField
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
const isMainDepartmentFieldExists = await fieldRepo.count({
|
|
117
|
+
filter: {
|
|
118
|
+
name: "mainDepartment",
|
|
119
|
+
collectionName: "users"
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
if (!isMainDepartmentFieldExists) {
|
|
123
|
+
await fieldRepo.create({
|
|
124
|
+
values: import_users.mainDepartmentField
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
var plugin_default = PluginDepartmentServer;
|
|
131
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
132
|
+
0 && (module.exports = {
|
|
133
|
+
PluginDepartmentServer
|
|
134
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tachybase/plugin-department",
|
|
3
|
+
"version": "0.23.35",
|
|
4
|
+
"description": "Organize users into a hierarchical tree structure of departments, and assign roles to departments as well.",
|
|
5
|
+
"main": "dist/server/index.js",
|
|
6
|
+
"dependencies": {},
|
|
7
|
+
"devDependencies": {
|
|
8
|
+
"@ant-design/icons": "~5.3.7",
|
|
9
|
+
"@types/lodash": "~4.17.13",
|
|
10
|
+
"ahooks": "^3.8.4",
|
|
11
|
+
"antd": "5.22.5",
|
|
12
|
+
"lodash": "4.17.21",
|
|
13
|
+
"react": "^18.3.1",
|
|
14
|
+
"@tachybase/schema": "0.23.35"
|
|
15
|
+
},
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"@tachybase/actions": "0.23.35",
|
|
18
|
+
"@tachybase/client": "0.23.35",
|
|
19
|
+
"@tachybase/module-acl": "0.23.35",
|
|
20
|
+
"@tachybase/database": "0.23.35",
|
|
21
|
+
"@tachybase/module-collection": "0.23.35",
|
|
22
|
+
"@tachybase/schema": "0.23.35",
|
|
23
|
+
"@tachybase/server": "0.23.35"
|
|
24
|
+
},
|
|
25
|
+
"description.zh-CN": "将用户划分在树状的部门里,也可以给部门分配角色",
|
|
26
|
+
"displayName.zh-CN": "部门"
|
|
27
|
+
}
|
package/server.d.ts
ADDED
package/server.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/server/index.js');
|