@tachybase/module-user 0.23.8
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/.turbo/turbo-build.log +14 -0
- package/LICENSE +201 -0
- package/README.md +9 -0
- package/README.zh-CN.md +9 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/PasswordField.d.ts +2 -0
- package/dist/client/RoleUsersManager.d.ts +2 -0
- package/dist/client/UserChangePassword.d.ts +2 -0
- package/dist/client/UserProfile.d.ts +2 -0
- package/dist/client/UserRolesField.d.ts +2 -0
- package/dist/client/UsersManagement.d.ts +2 -0
- package/dist/client/hooks.d.ts +5 -0
- package/dist/client/index.d.ts +5 -0
- package/dist/client/index.js +1 -0
- package/dist/client/locale.d.ts +1 -0
- package/dist/client/schemas/users.d.ts +165 -0
- package/dist/client/utils.d.ts +1 -0
- package/dist/externalVersion.js +13 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +39 -0
- package/dist/locale/en-US.json +9 -0
- package/dist/locale/zh-CN.json +9 -0
- package/dist/server/actions/users.d.ts +3 -0
- package/dist/server/actions/users.js +78 -0
- package/dist/server/collections/users.d.ts +2 -0
- package/dist/server/collections/users.js +127 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +40 -0
- package/dist/server/locale/en-US.d.ts +9 -0
- package/dist/server/locale/en-US.js +30 -0
- package/dist/server/locale/es-ES.d.ts +9 -0
- package/dist/server/locale/es-ES.js +30 -0
- package/dist/server/locale/fr-FR.d.ts +9 -0
- package/dist/server/locale/fr-FR.js +30 -0
- package/dist/server/locale/index.d.ts +3 -0
- package/dist/server/locale/index.js +43 -0
- package/dist/server/locale/ja-JP.d.ts +5 -0
- package/dist/server/locale/ja-JP.js +26 -0
- package/dist/server/locale/pt-BR.d.ts +9 -0
- package/dist/server/locale/pt-BR.js +30 -0
- package/dist/server/locale/zh-CN.d.ts +9 -0
- package/dist/server/locale/zh-CN.js +30 -0
- package/dist/server/migrations/20220818072639-add-users-phone-constraint.d.ts +7 -0
- package/dist/server/migrations/20220818072639-add-users-phone-constraint.js +57 -0
- package/dist/server/migrations/20220818072639-add-users-phone.d.ts +6 -0
- package/dist/server/migrations/20220818072639-add-users-phone.js +55 -0
- package/dist/server/migrations/20230802170800-add-username-constraint.d.ts +6 -0
- package/dist/server/migrations/20230802170800-add-username-constraint.js +55 -0
- package/dist/server/migrations/20230802170800-add-username.d.ts +5 -0
- package/dist/server/migrations/20230802170800-add-username.js +53 -0
- package/dist/server/migrations/20230802183100-update-username.d.ts +6 -0
- package/dist/server/migrations/20230802183100-update-username.js +47 -0
- package/dist/server/migrations/20230908164036-update-username-interface.d.ts +6 -0
- package/dist/server/migrations/20230908164036-update-username-interface.js +46 -0
- package/dist/server/migrations/20240722114514-add-users-specialRole.d.ts +7 -0
- package/dist/server/migrations/20240722114514-add-users-specialRole.js +38 -0
- package/dist/server/models/UserModel.d.ts +4 -0
- package/dist/server/models/UserModel.js +40 -0
- package/dist/server/server.d.ts +12 -0
- package/dist/server/server.js +207 -0
- package/dist/swagger/index.json +117 -0
- package/package.json +35 -0
- package/server.d.ts +2 -0
- package/server.js +1 -0
|
@@ -0,0 +1,55 @@
|
|
|
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 add_users_phone_exports = {};
|
|
19
|
+
__export(add_users_phone_exports, {
|
|
20
|
+
default: () => AddUsersPhoneMigration
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(add_users_phone_exports);
|
|
23
|
+
var import_server = require("@tachybase/server");
|
|
24
|
+
class AddUsersPhoneMigration extends import_server.Migration {
|
|
25
|
+
appVersion = "<0.7.5-alpha.1";
|
|
26
|
+
async up() {
|
|
27
|
+
const Field = this.context.db.getRepository("fields");
|
|
28
|
+
const existed = await Field.count({
|
|
29
|
+
filter: {
|
|
30
|
+
name: "phone",
|
|
31
|
+
collectionName: "users"
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
if (!existed) {
|
|
35
|
+
await Field.create({
|
|
36
|
+
values: {
|
|
37
|
+
name: "phone",
|
|
38
|
+
collectionName: "users",
|
|
39
|
+
type: "string",
|
|
40
|
+
unique: true,
|
|
41
|
+
interface: "phone",
|
|
42
|
+
uiSchema: {
|
|
43
|
+
type: "string",
|
|
44
|
+
title: '{{t("Phone")}}',
|
|
45
|
+
"x-component": "Input",
|
|
46
|
+
"x-validator": "phone",
|
|
47
|
+
require: true
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async down() {
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
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 add_username_constraint_exports = {};
|
|
19
|
+
__export(add_username_constraint_exports, {
|
|
20
|
+
default: () => AddUserNameMigration
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(add_username_constraint_exports);
|
|
23
|
+
var import_database = require("@tachybase/database");
|
|
24
|
+
var import_server = require("@tachybase/server");
|
|
25
|
+
class AddUserNameMigration extends import_server.Migration {
|
|
26
|
+
on = "beforeLoad";
|
|
27
|
+
appVersion = "<0.13.0-alpha.1";
|
|
28
|
+
async up() {
|
|
29
|
+
const collection = this.db.collection({
|
|
30
|
+
name: "users",
|
|
31
|
+
fields: [
|
|
32
|
+
{
|
|
33
|
+
type: "string",
|
|
34
|
+
name: "username"
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
});
|
|
38
|
+
const tableNameWithSchema = collection.getTableNameWithSchema();
|
|
39
|
+
const field = collection.getField("username");
|
|
40
|
+
const exists = await field.existsInDb();
|
|
41
|
+
if (!exists) {
|
|
42
|
+
await this.db.sequelize.getQueryInterface().addColumn(tableNameWithSchema, field.columnName(), {
|
|
43
|
+
type: import_database.DataTypes.STRING
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
await this.db.sequelize.getQueryInterface().addConstraint(tableNameWithSchema, {
|
|
48
|
+
type: "unique",
|
|
49
|
+
fields: [field.columnName()]
|
|
50
|
+
});
|
|
51
|
+
} catch (error) {
|
|
52
|
+
}
|
|
53
|
+
this.db.removeCollection("users");
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
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 add_username_exports = {};
|
|
19
|
+
__export(add_username_exports, {
|
|
20
|
+
default: () => AddUserNameMigration
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(add_username_exports);
|
|
23
|
+
var import_server = require("@tachybase/server");
|
|
24
|
+
class AddUserNameMigration extends import_server.Migration {
|
|
25
|
+
appVersion = "<0.13.0-alpha.1";
|
|
26
|
+
async up() {
|
|
27
|
+
const Field = this.context.db.getRepository("fields");
|
|
28
|
+
const existed = await Field.count({
|
|
29
|
+
filter: {
|
|
30
|
+
name: "username",
|
|
31
|
+
collectionName: "users"
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
if (!existed) {
|
|
35
|
+
await Field.create({
|
|
36
|
+
values: {
|
|
37
|
+
name: "username",
|
|
38
|
+
collectionName: "users",
|
|
39
|
+
type: "string",
|
|
40
|
+
unique: true,
|
|
41
|
+
interface: "input",
|
|
42
|
+
uiSchema: {
|
|
43
|
+
type: "string",
|
|
44
|
+
title: '{{t("Username")}}',
|
|
45
|
+
"x-component": "Input",
|
|
46
|
+
"x-validator": { username: true },
|
|
47
|
+
required: true
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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_username_exports = {};
|
|
19
|
+
__export(update_username_exports, {
|
|
20
|
+
default: () => UpdateUserNameMigration
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(update_username_exports);
|
|
23
|
+
var import_server = require("@tachybase/server");
|
|
24
|
+
class UpdateUserNameMigration extends import_server.Migration {
|
|
25
|
+
appVersion = "<0.13.0-alpha.1";
|
|
26
|
+
async up() {
|
|
27
|
+
const repo = this.context.db.getRepository("users");
|
|
28
|
+
const user = await repo.findOne({
|
|
29
|
+
filter: {
|
|
30
|
+
email: "admin@tachybase.com",
|
|
31
|
+
username: null
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
if (user) {
|
|
35
|
+
await repo.update({
|
|
36
|
+
values: {
|
|
37
|
+
username: process.env.INIT_ROOT_USERNAME || "tachybase"
|
|
38
|
+
},
|
|
39
|
+
filter: {
|
|
40
|
+
id: user.id
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async down() {
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
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_username_interface_exports = {};
|
|
19
|
+
__export(update_username_interface_exports, {
|
|
20
|
+
default: () => UpdateUserNameInterfaceMigration
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(update_username_interface_exports);
|
|
23
|
+
var import_server = require("@tachybase/server");
|
|
24
|
+
class UpdateUserNameInterfaceMigration extends import_server.Migration {
|
|
25
|
+
appVersion = "<0.13.0-alpha.10";
|
|
26
|
+
async up() {
|
|
27
|
+
const match = await this.app.version.satisfies("<=0.13.0-alpha.8");
|
|
28
|
+
if (!match) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const Field = this.context.db.getRepository("fields");
|
|
32
|
+
const field = await Field.findOne({
|
|
33
|
+
filter: {
|
|
34
|
+
name: "username",
|
|
35
|
+
collectionName: "users",
|
|
36
|
+
interface: "username"
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
if (!field) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
await field.update({ interface: "input" });
|
|
43
|
+
}
|
|
44
|
+
async down() {
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -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 add_users_specialRole_exports = {};
|
|
19
|
+
__export(add_users_specialRole_exports, {
|
|
20
|
+
default: () => AddUsersSpecialRoleMigration
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(add_users_specialRole_exports);
|
|
23
|
+
var import_server = require("@tachybase/server");
|
|
24
|
+
class AddUsersSpecialRoleMigration extends import_server.Migration {
|
|
25
|
+
on = "afterLoad";
|
|
26
|
+
appVersion = "<0.21.88";
|
|
27
|
+
async up() {
|
|
28
|
+
const repo = this.context.db.getRepository("users");
|
|
29
|
+
await repo.update({
|
|
30
|
+
filter: { $and: [{ roles: { title: { $includes: "root" } } }] },
|
|
31
|
+
values: {
|
|
32
|
+
specialRole: "root"
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
async down() {
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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 UserModel_exports = {};
|
|
19
|
+
__export(UserModel_exports, {
|
|
20
|
+
UserModel: () => UserModel
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(UserModel_exports);
|
|
23
|
+
var import_database = require("@tachybase/database");
|
|
24
|
+
class UserModel extends import_database.Model {
|
|
25
|
+
desensitize() {
|
|
26
|
+
const { fields } = this.constructor.collection;
|
|
27
|
+
const result = this.constructor.build({}, { isNewRecord: this.isNewRecord });
|
|
28
|
+
for (const [name, value] of Object.entries(this.get())) {
|
|
29
|
+
const field = fields.get(name);
|
|
30
|
+
if (field && !field.options.hidden) {
|
|
31
|
+
result.set(name, value);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
+
0 && (module.exports = {
|
|
39
|
+
UserModel
|
|
40
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Plugin } from '@tachybase/server';
|
|
2
|
+
export default class PluginUsersServer extends Plugin {
|
|
3
|
+
beforeLoad(): Promise<void>;
|
|
4
|
+
load(): Promise<void>;
|
|
5
|
+
getInstallingData(options?: any): {
|
|
6
|
+
rootEmail: any;
|
|
7
|
+
rootPassword: any;
|
|
8
|
+
rootNickname: any;
|
|
9
|
+
rootUsername: any;
|
|
10
|
+
};
|
|
11
|
+
install(options: any): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var server_exports = {};
|
|
29
|
+
__export(server_exports, {
|
|
30
|
+
default: () => PluginUsersServer
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(server_exports);
|
|
33
|
+
var import_path = require("path");
|
|
34
|
+
var import_worker_threads = require("worker_threads");
|
|
35
|
+
var import_database = require("@tachybase/database");
|
|
36
|
+
var import_server = require("@tachybase/server");
|
|
37
|
+
var import_utils = require("@tachybase/utils");
|
|
38
|
+
var actions = __toESM(require("./actions/users"));
|
|
39
|
+
var import_UserModel = require("./models/UserModel");
|
|
40
|
+
class PluginUsersServer extends import_server.Plugin {
|
|
41
|
+
async beforeLoad() {
|
|
42
|
+
this.db.registerModels({
|
|
43
|
+
UserModel: import_UserModel.UserModel
|
|
44
|
+
});
|
|
45
|
+
this.db.registerOperators({
|
|
46
|
+
$isCurrentUser(_, ctx) {
|
|
47
|
+
var _a, _b, _c, _d;
|
|
48
|
+
return {
|
|
49
|
+
[import_database.Op.eq]: ((_d = (_c = (_b = (_a = ctx == null ? void 0 : ctx.app) == null ? void 0 : _a.ctx) == null ? void 0 : _b.state) == null ? void 0 : _c.currentUser) == null ? void 0 : _d.id) || -1
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
$isNotCurrentUser(_, ctx) {
|
|
53
|
+
var _a, _b, _c, _d;
|
|
54
|
+
return {
|
|
55
|
+
[import_database.Op.ne]: ((_d = (_c = (_b = (_a = ctx == null ? void 0 : ctx.app) == null ? void 0 : _a.ctx) == null ? void 0 : _b.state) == null ? void 0 : _c.currentUser) == null ? void 0 : _d.id) || -1
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
$isVar(val, ctx) {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
const obj = (0, import_utils.parse)({ val: `{{${val}}}` })(JSON.parse(JSON.stringify((_b = (_a = ctx == null ? void 0 : ctx.app) == null ? void 0 : _a.ctx) == null ? void 0 : _b.state)));
|
|
61
|
+
return {
|
|
62
|
+
[import_database.Op.eq]: obj.val
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
this.db.on("field.afterAdd", ({ collection, field }) => {
|
|
67
|
+
if (field.options.interface === "createdBy") {
|
|
68
|
+
collection.setField("createdById", {
|
|
69
|
+
type: "context",
|
|
70
|
+
dataType: "bigInt",
|
|
71
|
+
dataIndex: "state.currentUser.id",
|
|
72
|
+
createOnly: true,
|
|
73
|
+
visible: true,
|
|
74
|
+
index: true
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
if (field.options.interface === "updatedBy") {
|
|
78
|
+
collection.setField("updatedById", {
|
|
79
|
+
type: "context",
|
|
80
|
+
dataType: "bigInt",
|
|
81
|
+
dataIndex: "state.currentUser.id",
|
|
82
|
+
visible: true,
|
|
83
|
+
index: true
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
this.db.on("afterDefineCollection", (collection) => {
|
|
88
|
+
const { createdBy, updatedBy } = collection.options;
|
|
89
|
+
if (createdBy === true) {
|
|
90
|
+
collection.setField("createdById", {
|
|
91
|
+
type: "context",
|
|
92
|
+
dataType: "bigInt",
|
|
93
|
+
dataIndex: "state.currentUser.id",
|
|
94
|
+
createOnly: true,
|
|
95
|
+
visible: true,
|
|
96
|
+
index: true
|
|
97
|
+
});
|
|
98
|
+
collection.setField("createdBy", {
|
|
99
|
+
type: "belongsTo",
|
|
100
|
+
target: "users",
|
|
101
|
+
foreignKey: "createdById",
|
|
102
|
+
targetKey: "id"
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
if (updatedBy === true) {
|
|
106
|
+
collection.setField("updatedById", {
|
|
107
|
+
type: "context",
|
|
108
|
+
dataType: "bigInt",
|
|
109
|
+
dataIndex: "state.currentUser.id",
|
|
110
|
+
visible: true,
|
|
111
|
+
index: true
|
|
112
|
+
});
|
|
113
|
+
collection.setField("updatedBy", {
|
|
114
|
+
type: "belongsTo",
|
|
115
|
+
target: "users",
|
|
116
|
+
foreignKey: "updatedById",
|
|
117
|
+
targetKey: "id"
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
for (const [key, action] of Object.entries(actions)) {
|
|
122
|
+
this.app.resourcer.registerActionHandler(`users:${key}`, action);
|
|
123
|
+
}
|
|
124
|
+
this.app.acl.addFixedParams("users", "destroy", () => {
|
|
125
|
+
return {
|
|
126
|
+
filter: {
|
|
127
|
+
"specialRole.$ne": "root"
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
this.app.acl.addFixedParams("collections", "destroy", () => {
|
|
132
|
+
return {
|
|
133
|
+
filter: {
|
|
134
|
+
"name.$ne": "users"
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
const loggedInActions = ["updateProfile"];
|
|
139
|
+
loggedInActions.forEach((action) => this.app.acl.allow("users", action, "loggedIn"));
|
|
140
|
+
this.app.acl.registerSnippet({
|
|
141
|
+
name: `pm.${this.name}.*`,
|
|
142
|
+
actions: ["users:listExcludeRole", "users:list"]
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
async load() {
|
|
146
|
+
await this.importCollections((0, import_path.resolve)(__dirname, "collections"));
|
|
147
|
+
this.db.addMigrations({
|
|
148
|
+
namespace: "users",
|
|
149
|
+
directory: (0, import_path.resolve)(__dirname, "migrations"),
|
|
150
|
+
context: {
|
|
151
|
+
plugin: this
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
if (import_worker_threads.isMainThread) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
this.app.resourcer.use(
|
|
158
|
+
async (ctx, next) => {
|
|
159
|
+
await next();
|
|
160
|
+
const { associatedName, resourceName, actionName, values } = ctx.action.params;
|
|
161
|
+
const cache = ctx.app.cache;
|
|
162
|
+
if (associatedName === "roles" && resourceName === "users" && ["add", "remove", "set"].includes(actionName) && (values == null ? void 0 : values.length)) {
|
|
163
|
+
for (const userId of values) {
|
|
164
|
+
await cache.del(`roles:${userId}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
{ tag: "roleCacheInvalidation" }
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
getInstallingData(options = {}) {
|
|
172
|
+
var _a;
|
|
173
|
+
const { INIT_ROOT_NICKNAME, INIT_ROOT_PASSWORD, INIT_ROOT_EMAIL, INIT_ROOT_USERNAME } = process.env;
|
|
174
|
+
const {
|
|
175
|
+
rootEmail = INIT_ROOT_EMAIL || "admin@tachybase.com",
|
|
176
|
+
rootPassword = INIT_ROOT_PASSWORD || "admin123",
|
|
177
|
+
rootNickname = INIT_ROOT_NICKNAME || "Super Admin",
|
|
178
|
+
rootUsername = INIT_ROOT_USERNAME || "tachybase"
|
|
179
|
+
} = options.users || ((_a = options == null ? void 0 : options.cliArgs) == null ? void 0 : _a[0]) || {};
|
|
180
|
+
return {
|
|
181
|
+
rootEmail,
|
|
182
|
+
rootPassword,
|
|
183
|
+
rootNickname,
|
|
184
|
+
rootUsername
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
async install(options) {
|
|
188
|
+
const { rootNickname, rootPassword, rootEmail, rootUsername } = this.getInstallingData(options);
|
|
189
|
+
const User = this.db.getCollection("users");
|
|
190
|
+
if (await User.repository.findOne({ filter: { email: rootEmail } })) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
await User.repository.create({
|
|
194
|
+
values: {
|
|
195
|
+
email: rootEmail,
|
|
196
|
+
password: rootPassword,
|
|
197
|
+
nickname: rootNickname,
|
|
198
|
+
username: rootUsername,
|
|
199
|
+
specialRole: "root"
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
const repo = this.db.getRepository("collections");
|
|
203
|
+
if (repo) {
|
|
204
|
+
await repo.db2cm("users");
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|