@nocobase/plugin-users 0.12.0-alpha.5 → 0.13.0-alpha.1

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.
@@ -33,6 +33,19 @@ var users_default = {
33
33
  "x-component": "Input"
34
34
  }
35
35
  },
36
+ {
37
+ interface: "username",
38
+ type: "string",
39
+ name: "username",
40
+ unique: true,
41
+ uiSchema: {
42
+ type: "string",
43
+ title: '{{t("Username")}}',
44
+ "x-component": "Input",
45
+ "x-validator": { username: true },
46
+ required: true
47
+ }
48
+ },
36
49
  {
37
50
  interface: "email",
38
51
  type: "string",
@@ -0,0 +1,5 @@
1
+ import { Migration } from '@nocobase/server';
2
+ export default class AddUserNameMigration extends Migration {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
@@ -0,0 +1,43 @@
1
+ 'use strict';
2
+
3
+ var server = require('@nocobase/server');
4
+
5
+ class AddUserNameMigration extends server.Migration {
6
+ async up() {
7
+ const match = await this.app.version.satisfies("<=0.12.0-alpha.4");
8
+ if (!match) {
9
+ return;
10
+ }
11
+ const Field = this.context.db.getRepository("fields");
12
+ const existed = await Field.count({
13
+ filter: {
14
+ name: "username",
15
+ collectionName: "users"
16
+ }
17
+ });
18
+ if (!existed) {
19
+ await Field.create({
20
+ values: {
21
+ name: "username",
22
+ collectionName: "users",
23
+ type: "string",
24
+ unique: true,
25
+ interface: "input",
26
+ uiSchema: {
27
+ type: "string",
28
+ title: '{{t("Username")}}',
29
+ "x-component": "Input",
30
+ "x-validator": { username: true },
31
+ required: true
32
+ }
33
+ },
34
+ // NOTE: to trigger hook
35
+ context: {}
36
+ });
37
+ }
38
+ }
39
+ async down() {
40
+ }
41
+ }
42
+
43
+ module.exports = AddUserNameMigration;
@@ -0,0 +1,5 @@
1
+ import { Migration } from '@nocobase/server';
2
+ export default class UpdateUserNameMigration extends Migration {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+
3
+ var server = require('@nocobase/server');
4
+
5
+ class UpdateUserNameMigration extends server.Migration {
6
+ async up() {
7
+ const match = await this.app.version.satisfies("<=0.12.0-alpha.4");
8
+ if (!match) {
9
+ return;
10
+ }
11
+ const repo = this.context.db.getRepository("users");
12
+ const user = await repo.findOne({
13
+ filter: {
14
+ email: "admin@nocobase.com",
15
+ username: null
16
+ }
17
+ });
18
+ if (user) {
19
+ await repo.update({
20
+ values: {
21
+ username: process.env.INIT_ROOT_USERNAME || "nocobase"
22
+ },
23
+ filter: {
24
+ id: user.id
25
+ }
26
+ });
27
+ }
28
+ }
29
+ async down() {
30
+ }
31
+ }
32
+
33
+ module.exports = UpdateUserNameMigration;
@@ -16,6 +16,7 @@ export default class UsersPlugin extends Plugin<UserPluginConfig> {
16
16
  rootEmail: any;
17
17
  rootPassword: any;
18
18
  rootNickname: any;
19
+ rootUsername: any;
19
20
  };
20
21
  install(options: any): Promise<void>;
21
22
  initVerification(): Promise<void>;
@@ -45,6 +45,7 @@ class UsersPlugin extends server.Plugin {
45
45
  this.app.i18n.addResources("en-US", _.namespace, locale.enUS);
46
46
  const cmd = this.app.findCommand("install");
47
47
  if (cmd) {
48
+ cmd.requiredOption("-u, --root-username <rootUsername>", "", process.env.INIT_ROOT_USERNAME);
48
49
  cmd.requiredOption("-e, --root-email <rootEmail>", "", process.env.INIT_ROOT_EMAIL);
49
50
  cmd.requiredOption("-p, --root-password <rootPassword>", "", process.env.INIT_ROOT_PASSWORD);
50
51
  cmd.option("-n, --root-nickname <rootNickname>");
@@ -142,20 +143,22 @@ class UsersPlugin extends server.Plugin {
142
143
  }
143
144
  getInstallingData(options = {}) {
144
145
  var _a;
145
- const { INIT_ROOT_NICKNAME, INIT_ROOT_PASSWORD, INIT_ROOT_EMAIL } = process.env;
146
+ const { INIT_ROOT_NICKNAME, INIT_ROOT_PASSWORD, INIT_ROOT_EMAIL, INIT_ROOT_USERNAME } = process.env;
146
147
  const {
147
148
  rootEmail = INIT_ROOT_EMAIL,
148
149
  rootPassword = INIT_ROOT_PASSWORD,
149
- rootNickname = INIT_ROOT_NICKNAME || "Super Admin"
150
+ rootNickname = INIT_ROOT_NICKNAME || "Super Admin",
151
+ rootUsername = INIT_ROOT_USERNAME || "nocobase"
150
152
  } = options.users || ((_a = options == null ? void 0 : options.cliArgs) == null ? void 0 : _a[0]) || {};
151
153
  return {
152
154
  rootEmail,
153
155
  rootPassword,
154
- rootNickname
156
+ rootNickname,
157
+ rootUsername
155
158
  };
156
159
  }
157
160
  async install(options) {
158
- const { rootNickname, rootPassword, rootEmail } = this.getInstallingData(options);
161
+ const { rootNickname, rootPassword, rootEmail, rootUsername } = this.getInstallingData(options);
159
162
  const User = this.db.getCollection("users");
160
163
  if (await User.repository.findOne({ filter: { email: rootEmail } })) {
161
164
  return;
@@ -164,7 +167,8 @@ class UsersPlugin extends server.Plugin {
164
167
  values: {
165
168
  email: rootEmail,
166
169
  password: rootPassword,
167
- nickname: rootNickname
170
+ nickname: rootNickname,
171
+ username: rootUsername
168
172
  }
169
173
  });
170
174
  const repo = this.db.getRepository("collections");
@@ -0,0 +1,131 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var openapi = "3.0.2";
6
+ var info = {
7
+ title: "NocoBase API - Users plugin"
8
+ };
9
+ var tags = [];
10
+ var paths = {
11
+ "/users:list": {
12
+ get: {
13
+ tags: ["users"],
14
+ description: "",
15
+ parameters: [],
16
+ responses: {
17
+ "200": {
18
+ description: "OK"
19
+ }
20
+ }
21
+ }
22
+ },
23
+ "/users:get": {
24
+ get: {
25
+ tags: ["users"],
26
+ description: "",
27
+ parameters: [],
28
+ responses: {
29
+ "200": {
30
+ description: "OK"
31
+ }
32
+ }
33
+ }
34
+ },
35
+ "/users:create": {
36
+ post: {
37
+ tags: ["users"],
38
+ description: "",
39
+ parameters: [],
40
+ responses: {
41
+ "200": {
42
+ description: "OK"
43
+ }
44
+ }
45
+ }
46
+ },
47
+ "/users:update": {
48
+ post: {
49
+ tags: ["users"],
50
+ description: "",
51
+ parameters: [],
52
+ responses: {
53
+ "200": {
54
+ description: "OK"
55
+ }
56
+ }
57
+ }
58
+ },
59
+ "/users:updateProfile": {
60
+ post: {
61
+ tags: ["users"],
62
+ description: "",
63
+ parameters: [],
64
+ responses: {
65
+ "200": {
66
+ description: "OK"
67
+ }
68
+ }
69
+ }
70
+ },
71
+ "/users:changePassword": {
72
+ post: {
73
+ tags: ["users"],
74
+ description: "",
75
+ parameters: [],
76
+ responses: {
77
+ "200": {
78
+ description: "OK"
79
+ }
80
+ }
81
+ }
82
+ },
83
+ "/users:destroy": {
84
+ post: {
85
+ tags: ["users"],
86
+ description: "",
87
+ parameters: [],
88
+ responses: {
89
+ "200": {
90
+ description: "OK"
91
+ }
92
+ }
93
+ }
94
+ },
95
+ "/{collectionName}/{collectionIndex}/createdBy:get": {
96
+ post: {
97
+ tags: ["$collection.createdBy"],
98
+ description: "",
99
+ parameters: [],
100
+ responses: {
101
+ "200": {
102
+ description: "OK"
103
+ }
104
+ }
105
+ }
106
+ },
107
+ "/{collectionName}/{collectionIndex}/updatedBy:get": {
108
+ post: {
109
+ tags: ["$collection.updatedBy"],
110
+ description: "",
111
+ parameters: [],
112
+ responses: {
113
+ "200": {
114
+ description: "OK"
115
+ }
116
+ }
117
+ }
118
+ }
119
+ };
120
+ var swagger_default = {
121
+ openapi,
122
+ info,
123
+ tags,
124
+ paths
125
+ };
126
+
127
+ exports.default = swagger_default;
128
+ exports.info = info;
129
+ exports.openapi = openapi;
130
+ exports.paths = paths;
131
+ exports.tags = tags;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "用户",
5
5
  "description": "Provide a basic user model and a password-based user authentication type, and extended the createdBy and updatedBy field types",
6
6
  "description.zh-CN": "提供了基础的用户模型和基于密码的用户认证方式,并拓展了创建人和最后更新人字段类型",
7
- "version": "0.12.0-alpha.5",
7
+ "version": "0.13.0-alpha.1",
8
8
  "license": "AGPL-3.0",
9
9
  "main": "./dist/server/index.js",
10
10
  "devDependencies": {
@@ -22,5 +22,5 @@
22
22
  "@nocobase/test": "0.x",
23
23
  "@nocobase/utils": "0.x"
24
24
  },
25
- "gitHead": "689cc16e83361c4d0b91907e0deac30bdb907692"
25
+ "gitHead": "0ebd4e85a1b0b0d0943768ab6cb5c3d824562239"
26
26
  }