@nocobase/plugin-departments 2.1.0-alpha.20 → 2.1.0-alpha.22
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/dist/externalVersion.js
CHANGED
|
@@ -8,24 +8,24 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
module.exports = {
|
|
11
|
-
"@nocobase/client": "2.1.0-alpha.
|
|
11
|
+
"@nocobase/client": "2.1.0-alpha.22",
|
|
12
12
|
"react": "18.2.0",
|
|
13
13
|
"@formily/react": "2.3.7",
|
|
14
14
|
"@formily/core": "2.3.7",
|
|
15
|
-
"@nocobase/utils": "2.1.0-alpha.
|
|
16
|
-
"@nocobase/plugin-acl": "2.1.0-alpha.
|
|
15
|
+
"@nocobase/utils": "2.1.0-alpha.22",
|
|
16
|
+
"@nocobase/plugin-acl": "2.1.0-alpha.22",
|
|
17
17
|
"react-i18next": "11.18.6",
|
|
18
|
-
"@nocobase/database": "2.1.0-alpha.
|
|
18
|
+
"@nocobase/database": "2.1.0-alpha.22",
|
|
19
19
|
"lodash": "4.18.1",
|
|
20
|
-
"@nocobase/plugin-user-data-sync": "2.1.0-alpha.
|
|
21
|
-
"@nocobase/cache": "2.1.0-alpha.
|
|
22
|
-
"@nocobase/server": "2.1.0-alpha.
|
|
23
|
-
"@nocobase/data-source-manager": "2.1.0-alpha.
|
|
24
|
-
"@nocobase/plugin-error-handler": "2.1.0-alpha.
|
|
20
|
+
"@nocobase/plugin-user-data-sync": "2.1.0-alpha.22",
|
|
21
|
+
"@nocobase/cache": "2.1.0-alpha.22",
|
|
22
|
+
"@nocobase/server": "2.1.0-alpha.22",
|
|
23
|
+
"@nocobase/data-source-manager": "2.1.0-alpha.22",
|
|
24
|
+
"@nocobase/plugin-error-handler": "2.1.0-alpha.22",
|
|
25
25
|
"sequelize": "6.35.2",
|
|
26
26
|
"antd": "5.24.2",
|
|
27
27
|
"@ant-design/icons": "5.6.1",
|
|
28
28
|
"@formily/shared": "2.3.7",
|
|
29
29
|
"@emotion/css": "11.13.0",
|
|
30
|
-
"@nocobase/actions": "2.1.0-alpha.
|
|
30
|
+
"@nocobase/actions": "2.1.0-alpha.22"
|
|
31
31
|
};
|
|
@@ -16,6 +16,8 @@ export declare class DepartmentDataSyncResource extends UserDataResource {
|
|
|
16
16
|
get deptRepo(): import("@nocobase/database").Repository<any, any>;
|
|
17
17
|
get deptUserRepo(): import("@nocobase/database").Repository<any, any>;
|
|
18
18
|
getFlteredSourceDepartment(sourceDepartment: FormatDepartment): lodash.Omit<FormatDepartment, string>;
|
|
19
|
+
updateDepartmentIsLeaf(parentId: PrimaryKey | null | undefined): Promise<void>;
|
|
20
|
+
markDepartmentAsNonLeaf(parentId: PrimaryKey | null | undefined): Promise<void>;
|
|
19
21
|
update(record: OriginRecord, resourcePks: PrimaryKey[]): Promise<RecordResourceChanged[]>;
|
|
20
22
|
create(record: OriginRecord): Promise<RecordResourceChanged[]>;
|
|
21
23
|
getDepartmentIdsBySourceUks(sourceUks: PrimaryKey[], sourceName: string): Promise<any>;
|
|
@@ -59,7 +59,6 @@ class DepartmentDataSyncResource extends import_plugin_user_data_sync.UserDataRe
|
|
|
59
59
|
"uid",
|
|
60
60
|
"createdAt",
|
|
61
61
|
"updatedAt",
|
|
62
|
-
"sort",
|
|
63
62
|
"createdById",
|
|
64
63
|
"updatedById",
|
|
65
64
|
"isDeleted",
|
|
@@ -68,6 +67,33 @@ class DepartmentDataSyncResource extends import_plugin_user_data_sync.UserDataRe
|
|
|
68
67
|
];
|
|
69
68
|
return import_lodash.default.omit(sourceDepartment, deleteProps);
|
|
70
69
|
}
|
|
70
|
+
async updateDepartmentIsLeaf(parentId) {
|
|
71
|
+
if (!parentId) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const hasChild = await this.deptRepo.count({
|
|
75
|
+
filter: {
|
|
76
|
+
parentId
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
await this.deptRepo.update({
|
|
80
|
+
filterByTk: parentId,
|
|
81
|
+
values: {
|
|
82
|
+
isLeaf: !hasChild
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
async markDepartmentAsNonLeaf(parentId) {
|
|
87
|
+
if (!parentId) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
await this.deptRepo.update({
|
|
91
|
+
filterByTk: parentId,
|
|
92
|
+
values: {
|
|
93
|
+
isLeaf: false
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
71
97
|
async update(record, resourcePks) {
|
|
72
98
|
const { dataType, metaData, sourceName } = record;
|
|
73
99
|
if (dataType === "user") {
|
|
@@ -267,7 +293,9 @@ class DepartmentDataSyncResource extends import_plugin_user_data_sync.UserDataRe
|
|
|
267
293
|
}
|
|
268
294
|
async updateDepartment(department, sourceDepartment, sourceName) {
|
|
269
295
|
if (sourceDepartment.isDeleted) {
|
|
296
|
+
const parentId = department.get("parentId");
|
|
270
297
|
await department.destroy();
|
|
298
|
+
await this.updateDepartmentIsLeaf(parentId);
|
|
271
299
|
return;
|
|
272
300
|
}
|
|
273
301
|
let dataChanged = false;
|
|
@@ -286,17 +314,22 @@ class DepartmentDataSyncResource extends import_plugin_user_data_sync.UserDataRe
|
|
|
286
314
|
async createDepartment(sourceDepartment, sourceName) {
|
|
287
315
|
const filteredSourceDepartment = this.getFlteredSourceDepartment(sourceDepartment);
|
|
288
316
|
const department = await this.deptRepo.create({
|
|
289
|
-
values:
|
|
317
|
+
values: {
|
|
318
|
+
isLeaf: true,
|
|
319
|
+
...filteredSourceDepartment
|
|
320
|
+
}
|
|
290
321
|
});
|
|
291
322
|
await this.updateParentDepartment(department, sourceDepartment.parentUid, sourceName);
|
|
292
323
|
return department.id;
|
|
293
324
|
}
|
|
294
325
|
async updateParentDepartment(department, parentUid, sourceName) {
|
|
295
326
|
var _a;
|
|
327
|
+
const oldParentId = department.get("parentId");
|
|
296
328
|
if (!parentUid) {
|
|
297
329
|
const parentDepartment = await department.getParent();
|
|
298
330
|
if (parentDepartment) {
|
|
299
331
|
await department.setParent(null);
|
|
332
|
+
await this.updateDepartmentIsLeaf(oldParentId);
|
|
300
333
|
}
|
|
301
334
|
} else {
|
|
302
335
|
const syncDepartmentRecord = await this.syncRecordRepo.findOne({
|
|
@@ -314,18 +347,25 @@ class DepartmentDataSyncResource extends import_plugin_user_data_sync.UserDataRe
|
|
|
314
347
|
});
|
|
315
348
|
if (!parentDepartment) {
|
|
316
349
|
await department.setParent(null);
|
|
350
|
+
await this.updateDepartmentIsLeaf(oldParentId);
|
|
317
351
|
return;
|
|
318
352
|
}
|
|
319
353
|
const parent = await department.getParent();
|
|
320
354
|
if (parent) {
|
|
321
355
|
if (parentDepartment.id !== parent.id) {
|
|
322
356
|
await department.setParent(parentDepartment);
|
|
357
|
+
await Promise.all([
|
|
358
|
+
this.updateDepartmentIsLeaf(oldParentId),
|
|
359
|
+
this.markDepartmentAsNonLeaf(parentDepartment.id)
|
|
360
|
+
]);
|
|
323
361
|
}
|
|
324
362
|
} else {
|
|
325
363
|
await department.setParent(parentDepartment);
|
|
364
|
+
await this.markDepartmentAsNonLeaf(parentDepartment.id);
|
|
326
365
|
}
|
|
327
366
|
} else {
|
|
328
367
|
await department.setParent(null);
|
|
368
|
+
await this.updateDepartmentIsLeaf(oldParentId);
|
|
329
369
|
}
|
|
330
370
|
}
|
|
331
371
|
}
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"description": "Organize users by departments, set hierarchical relationships, link roles to control permissions, and use departments as variables in workflows and expressions.",
|
|
7
7
|
"description.ru-RU": "Организация пользователей по подразделениям, установление иерархических связей, привязка ролей для управления правами и использование подразделений в качестве переменных в рабочих процессах и выражениях.",
|
|
8
8
|
"description.zh-CN": "以部门来组织用户,设定上下级关系,绑定角色控制权限,并支持作为变量用于工作流和表达式。",
|
|
9
|
-
"version": "2.1.0-alpha.
|
|
9
|
+
"version": "2.1.0-alpha.22",
|
|
10
10
|
"main": "dist/server/index.js",
|
|
11
11
|
"peerDependencies": {
|
|
12
12
|
"@nocobase/actions": "2.x",
|
|
@@ -20,6 +20,6 @@
|
|
|
20
20
|
"keywords": [
|
|
21
21
|
"Users & permissions"
|
|
22
22
|
],
|
|
23
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "81ed83f158f172cca607b36beaf8428b14ba16ad",
|
|
24
24
|
"license": "Apache-2.0"
|
|
25
25
|
}
|