@nocobase/plugin-users 1.3.4-beta → 1.4.0-alpha.20240826214041
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
|
@@ -10,16 +10,17 @@
|
|
|
10
10
|
module.exports = {
|
|
11
11
|
"react": "18.2.0",
|
|
12
12
|
"antd": "5.12.8",
|
|
13
|
-
"@nocobase/client": "1.
|
|
13
|
+
"@nocobase/client": "1.4.0-alpha.20240826214041",
|
|
14
14
|
"@formily/react": "2.3.0",
|
|
15
15
|
"@formily/core": "2.3.0",
|
|
16
|
-
"@nocobase/plugin-acl": "1.
|
|
17
|
-
"@nocobase/utils": "1.
|
|
16
|
+
"@nocobase/plugin-acl": "1.4.0-alpha.20240826214041",
|
|
17
|
+
"@nocobase/utils": "1.4.0-alpha.20240826214041",
|
|
18
18
|
"react-i18next": "11.18.6",
|
|
19
|
-
"@nocobase/database": "1.
|
|
20
|
-
"@nocobase/server": "1.
|
|
21
|
-
"@nocobase/cache": "1.
|
|
19
|
+
"@nocobase/database": "1.4.0-alpha.20240826214041",
|
|
20
|
+
"@nocobase/server": "1.4.0-alpha.20240826214041",
|
|
21
|
+
"@nocobase/cache": "1.4.0-alpha.20240826214041",
|
|
22
|
+
"@nocobase/plugin-user-data-sync": "1.4.0-alpha.20240826214041",
|
|
22
23
|
"@formily/shared": "2.3.0",
|
|
23
|
-
"@nocobase/actions": "1.
|
|
24
|
+
"@nocobase/actions": "1.4.0-alpha.20240826214041",
|
|
24
25
|
"lodash": "4.17.21"
|
|
25
26
|
};
|
package/dist/server/server.js
CHANGED
|
@@ -45,6 +45,7 @@ var import_utils = require("@nocobase/utils");
|
|
|
45
45
|
var import_path = require("path");
|
|
46
46
|
var actions = __toESM(require("./actions/users"));
|
|
47
47
|
var import_UserModel = require("./models/UserModel");
|
|
48
|
+
var import_user_data_sync_resource = require("./user-data-sync-resource");
|
|
48
49
|
class PluginUsersServer extends import_server.Plugin {
|
|
49
50
|
async beforeLoad() {
|
|
50
51
|
this.db.registerModels({
|
|
@@ -195,6 +196,10 @@ class PluginUsersServer extends import_server.Plugin {
|
|
|
195
196
|
}
|
|
196
197
|
}
|
|
197
198
|
});
|
|
199
|
+
const userDataSyncPlugin = this.app.pm.get("user-data-sync");
|
|
200
|
+
if (userDataSyncPlugin) {
|
|
201
|
+
userDataSyncPlugin.resourceManager.registerResource(new import_user_data_sync_resource.UserDataSyncResource(this.db, this.app.logger));
|
|
202
|
+
}
|
|
198
203
|
}
|
|
199
204
|
getInstallingData(options = {}) {
|
|
200
205
|
var _a;
|
|
@@ -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
|
+
import { Model } from '@nocobase/database';
|
|
10
|
+
import { FormatUser, OriginRecord, PrimaryKey, RecordResourceChanged, SyncAccept, UserDataResource } from '@nocobase/plugin-user-data-sync';
|
|
11
|
+
export declare class UserDataSyncResource extends UserDataResource {
|
|
12
|
+
name: string;
|
|
13
|
+
accepts: SyncAccept[];
|
|
14
|
+
get userRepo(): import("@nocobase/database").Repository<any, any>;
|
|
15
|
+
updateUser(user: Model, sourceUser: FormatUser): Promise<void>;
|
|
16
|
+
update(record: OriginRecord, resourcePks: PrimaryKey[], matchKey: string): Promise<RecordResourceChanged[]>;
|
|
17
|
+
create(record: OriginRecord, matchKey: string): Promise<RecordResourceChanged[]>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
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 user_data_sync_resource_exports = {};
|
|
28
|
+
__export(user_data_sync_resource_exports, {
|
|
29
|
+
UserDataSyncResource: () => UserDataSyncResource
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(user_data_sync_resource_exports);
|
|
32
|
+
var import_plugin_user_data_sync = require("@nocobase/plugin-user-data-sync");
|
|
33
|
+
class UserDataSyncResource extends import_plugin_user_data_sync.UserDataResource {
|
|
34
|
+
name = "users";
|
|
35
|
+
accepts = ["user"];
|
|
36
|
+
get userRepo() {
|
|
37
|
+
return this.db.getRepository("users");
|
|
38
|
+
}
|
|
39
|
+
async updateUser(user, sourceUser) {
|
|
40
|
+
if (sourceUser.isDeleted) {
|
|
41
|
+
const roles = await user.getRoles();
|
|
42
|
+
for (const role of roles) {
|
|
43
|
+
if (role.name === "root") {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
await user.destroy();
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
let dataChanged = false;
|
|
51
|
+
if (sourceUser.username !== void 0 && user.username !== sourceUser.username) {
|
|
52
|
+
user.username = sourceUser.username;
|
|
53
|
+
dataChanged = true;
|
|
54
|
+
}
|
|
55
|
+
if (sourceUser.phone !== void 0 && user.phone !== sourceUser.phone) {
|
|
56
|
+
user.phone = sourceUser.phone;
|
|
57
|
+
dataChanged = true;
|
|
58
|
+
}
|
|
59
|
+
if (sourceUser.email !== void 0 && user.email !== sourceUser.email) {
|
|
60
|
+
user.email = sourceUser.email;
|
|
61
|
+
dataChanged = true;
|
|
62
|
+
}
|
|
63
|
+
if (sourceUser.nickname !== void 0 && user.nickname !== sourceUser.nickname) {
|
|
64
|
+
user.nickname = sourceUser.nickname;
|
|
65
|
+
dataChanged = true;
|
|
66
|
+
}
|
|
67
|
+
if (dataChanged) {
|
|
68
|
+
await user.save();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async update(record, resourcePks, matchKey) {
|
|
72
|
+
const { metaData: sourceUser } = record;
|
|
73
|
+
const resourcePk = resourcePks[0];
|
|
74
|
+
const user = await this.userRepo.findOne({
|
|
75
|
+
filterByTk: resourcePk
|
|
76
|
+
});
|
|
77
|
+
if (!user) {
|
|
78
|
+
const result = await this.create(record, matchKey);
|
|
79
|
+
return [...result, { resourcesPk: resourcePk, isDeleted: true }];
|
|
80
|
+
}
|
|
81
|
+
await this.updateUser(user, sourceUser);
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
async create(record, matchKey) {
|
|
85
|
+
const { metaData: sourceUser } = record;
|
|
86
|
+
const filter = {};
|
|
87
|
+
let user;
|
|
88
|
+
if (["phone", "email", "username"].includes(matchKey)) {
|
|
89
|
+
filter[matchKey] = sourceUser[matchKey];
|
|
90
|
+
user = await this.userRepo.findOne({
|
|
91
|
+
filter
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (user) {
|
|
95
|
+
await this.updateUser(user, sourceUser);
|
|
96
|
+
} else {
|
|
97
|
+
user = await this.userRepo.create({
|
|
98
|
+
values: {
|
|
99
|
+
nickname: sourceUser.nickname,
|
|
100
|
+
phone: sourceUser.phone,
|
|
101
|
+
email: sourceUser.email,
|
|
102
|
+
username: sourceUser.username
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return [{ resourcesPk: user.id, isDeleted: false }];
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
110
|
+
0 && (module.exports = {
|
|
111
|
+
UserDataSyncResource
|
|
112
|
+
});
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"displayName.zh-CN": "用户",
|
|
5
5
|
"description": "Provides basic user model, as well as created by and updated by fields.",
|
|
6
6
|
"description.zh-CN": "提供了基础的用户模型,以及创建人和最后更新人字段。",
|
|
7
|
-
"version": "1.
|
|
7
|
+
"version": "1.4.0-alpha.20240826214041",
|
|
8
8
|
"license": "AGPL-3.0",
|
|
9
9
|
"main": "./dist/server/index.js",
|
|
10
10
|
"homepage": "https://docs.nocobase.com/handbook/users",
|
|
@@ -19,12 +19,13 @@
|
|
|
19
19
|
"@nocobase/database": "1.x",
|
|
20
20
|
"@nocobase/plugin-acl": "1.x",
|
|
21
21
|
"@nocobase/plugin-auth": "1.x",
|
|
22
|
+
"@nocobase/plugin-user-data-sync": "1.x",
|
|
22
23
|
"@nocobase/resourcer": "1.x",
|
|
23
24
|
"@nocobase/server": "1.x",
|
|
24
25
|
"@nocobase/test": "1.x",
|
|
25
26
|
"@nocobase/utils": "1.x"
|
|
26
27
|
},
|
|
27
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "05146e0a96cda923d2c95a92b0fe1bc53390af7a",
|
|
28
29
|
"keywords": [
|
|
29
30
|
"Users & permissions"
|
|
30
31
|
]
|