@kne/fastify-account 1.0.0-alpha.0 → 1.0.0-alpha.10
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/README.md +636 -5
- package/index.js +13 -4
- package/libs/controllers/account.js +8 -7
- package/libs/controllers/admin.js +16 -15
- package/libs/controllers/adminPermission.js +42 -35
- package/libs/controllers/adminRole.js +13 -12
- package/libs/controllers/adminTenant.js +39 -36
- package/libs/controllers/tenant.js +16 -4
- package/libs/controllers/user.js +23 -1
- package/libs/models/admin-role.js +4 -8
- package/libs/models/application.js +16 -10
- package/libs/models/login-log.js +4 -8
- package/libs/models/permission.js +7 -9
- package/libs/models/tenant-application.js +8 -10
- package/libs/models/tenant-org.js +5 -9
- package/libs/models/tenant-permission.js +7 -9
- package/libs/models/tenant-role-application.js +15 -10
- package/libs/models/tenant-role-permission.js +11 -9
- package/libs/models/tenant-role.js +5 -9
- package/libs/models/tenant-share-group-permission.js +5 -9
- package/libs/models/tenant-share-group.js +5 -9
- package/libs/models/tenant-source-user-share-group.js +5 -9
- package/libs/models/tenant-token.js +7 -9
- package/libs/models/tenant-user-org.js +11 -10
- package/libs/models/tenant-user-role.js +11 -10
- package/libs/models/tenant-user-share-group.js +6 -10
- package/libs/models/tenant-user.js +35 -16
- package/libs/models/tenant.js +17 -9
- package/libs/models/user-account.js +17 -9
- package/libs/models/user.js +27 -17
- package/libs/models/verification-code.js +4 -8
- package/libs/services/account.js +34 -16
- package/libs/services/admin.js +17 -121
- package/libs/services/application.js +151 -0
- package/libs/services/permission.js +47 -145
- package/libs/services/tenant-invite.js +62 -0
- package/libs/services/tenant-org.js +97 -0
- package/libs/services/tenant-role.js +108 -0
- package/libs/services/tenant-user.js +555 -0
- package/libs/services/tenant.js +68 -512
- package/libs/services/user.js +69 -30
- package/package.json +4 -3
package/index.js
CHANGED
|
@@ -2,6 +2,7 @@ const fp = require('fastify-plugin');
|
|
|
2
2
|
const packageJson = require('./package.json');
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const merge = require('lodash/merge');
|
|
5
|
+
const { Unauthorized } = require('http-errors');
|
|
5
6
|
|
|
6
7
|
module.exports = fp(
|
|
7
8
|
async function (fastify, options) {
|
|
@@ -9,6 +10,7 @@ module.exports = fp(
|
|
|
9
10
|
options = merge(
|
|
10
11
|
{
|
|
11
12
|
prefix: `/api/v${packageJson.version.split('.')[0]}/account`, //如果为true,发送邮件和短信将不调用,验证码随response返回
|
|
13
|
+
dbTableNamePrefix: 't_account_',
|
|
12
14
|
isTest: false,
|
|
13
15
|
jwt: {
|
|
14
16
|
secret: 'super-secret'
|
|
@@ -23,7 +25,12 @@ module.exports = fp(
|
|
|
23
25
|
options,
|
|
24
26
|
name: 'account',
|
|
25
27
|
modules: [
|
|
26
|
-
[
|
|
28
|
+
[
|
|
29
|
+
'models',
|
|
30
|
+
await fastify.sequelize.addModels(path.resolve(__dirname, './libs/models'), {
|
|
31
|
+
prefix: options.dbTableNamePrefix
|
|
32
|
+
})
|
|
33
|
+
],
|
|
27
34
|
['services', path.resolve(__dirname, './libs/services')],
|
|
28
35
|
['controllers', path.resolve(__dirname, './libs/controllers')],
|
|
29
36
|
[
|
|
@@ -34,13 +41,15 @@ module.exports = fp(
|
|
|
34
41
|
//这里判断失效时间
|
|
35
42
|
//info.iat
|
|
36
43
|
request.authenticatePayload = info.payload;
|
|
37
|
-
request.userInfo = await fastify.account.services.user.
|
|
44
|
+
request.userInfo = await fastify.account.services.user.getUser(request.authenticatePayload);
|
|
38
45
|
},
|
|
39
46
|
tenant: async request => {
|
|
40
|
-
request.tenantInfo = await fastify.account.services.
|
|
47
|
+
request.tenantInfo = await fastify.account.services.tenantUser.getTenantUserByUserId(request.userInfo);
|
|
41
48
|
},
|
|
42
49
|
admin: async request => {
|
|
43
|
-
|
|
50
|
+
if (!(await fastify.account.services.admin.checkIsSuperAdmin(request.userInfo))) {
|
|
51
|
+
throw Unauthorized('不能执行该操作,需要超级管理员权限');
|
|
52
|
+
}
|
|
44
53
|
}
|
|
45
54
|
}
|
|
46
55
|
]
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const fp = require('fastify-plugin');
|
|
2
2
|
module.exports = fp(async (fastify, options) => {
|
|
3
|
+
const { services } = fastify.account;
|
|
3
4
|
fastify.post(
|
|
4
5
|
`${options.prefix}/sendEmailCode`,
|
|
5
6
|
{
|
|
@@ -36,7 +37,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
36
37
|
},
|
|
37
38
|
async request => {
|
|
38
39
|
const { email } = request.body;
|
|
39
|
-
const code = await
|
|
40
|
+
const code = await services.account.sendEmailCode({ email });
|
|
40
41
|
return options.isTest ? { code } : {};
|
|
41
42
|
}
|
|
42
43
|
);
|
|
@@ -56,7 +57,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
56
57
|
},
|
|
57
58
|
async request => {
|
|
58
59
|
const { phone } = request.body;
|
|
59
|
-
const code = await
|
|
60
|
+
const code = await services.account.sendSMSCode({ phone });
|
|
60
61
|
return options.isTest ? { code } : {};
|
|
61
62
|
}
|
|
62
63
|
);
|
|
@@ -78,7 +79,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
78
79
|
},
|
|
79
80
|
async request => {
|
|
80
81
|
const { name, type, code } = request.body;
|
|
81
|
-
const isPass = await
|
|
82
|
+
const isPass = await services.account.verificationCodeValidate({
|
|
82
83
|
name,
|
|
83
84
|
type,
|
|
84
85
|
code
|
|
@@ -116,7 +117,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
116
117
|
},
|
|
117
118
|
async request => {
|
|
118
119
|
const { phone, email } = request.body;
|
|
119
|
-
return { isExists: await
|
|
120
|
+
return { isExists: await services.user.accountIsExists({ phone, email }) };
|
|
120
121
|
}
|
|
121
122
|
);
|
|
122
123
|
|
|
@@ -162,7 +163,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
162
163
|
},
|
|
163
164
|
async request => {
|
|
164
165
|
const account = request.body;
|
|
165
|
-
return await
|
|
166
|
+
return await services.account.register(account);
|
|
166
167
|
}
|
|
167
168
|
);
|
|
168
169
|
|
|
@@ -182,8 +183,8 @@ module.exports = fp(async (fastify, options) => {
|
|
|
182
183
|
},
|
|
183
184
|
async request => {
|
|
184
185
|
const { username, password } = request.body;
|
|
185
|
-
const token = await
|
|
186
|
-
return { token };
|
|
186
|
+
const { token, user } = await services.account.login({ username, password, ip: request.ip });
|
|
187
|
+
return { token, currentTenantId: user.currentTenantId };
|
|
187
188
|
}
|
|
188
189
|
);
|
|
189
190
|
});
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
const fp = require('fastify-plugin');
|
|
2
2
|
|
|
3
3
|
module.exports = fp(async (fastify, options) => {
|
|
4
|
+
const { authenticate, services } = fastify.account;
|
|
4
5
|
// 用于系统初始化时,设置第一个用户,只能使用一次,其他用户由该用户创建
|
|
5
6
|
fastify.post(
|
|
6
7
|
`${options.prefix}/initSuperAdmin`,
|
|
7
8
|
{
|
|
8
|
-
onRequest: [
|
|
9
|
+
onRequest: [authenticate.user]
|
|
9
10
|
},
|
|
10
11
|
async request => {
|
|
11
|
-
await
|
|
12
|
+
await services.admin.initSuperAdmin(await services.user.getUser(request.authenticatePayload));
|
|
12
13
|
return {};
|
|
13
14
|
}
|
|
14
15
|
);
|
|
@@ -16,7 +17,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
16
17
|
fastify.get(
|
|
17
18
|
`${options.prefix}/admin/getSuperAdminInfo`,
|
|
18
19
|
{
|
|
19
|
-
onRequest: [
|
|
20
|
+
onRequest: [authenticate.user, authenticate.admin]
|
|
20
21
|
},
|
|
21
22
|
async request => {
|
|
22
23
|
return { userInfo: request.userInfo };
|
|
@@ -26,14 +27,14 @@ module.exports = fp(async (fastify, options) => {
|
|
|
26
27
|
fastify.post(
|
|
27
28
|
`${options.prefix}/admin/addUser`,
|
|
28
29
|
{
|
|
29
|
-
onRequest: [
|
|
30
|
+
onRequest: [authenticate.user, authenticate.admin],
|
|
30
31
|
schema: {
|
|
31
32
|
body: {}
|
|
32
33
|
}
|
|
33
34
|
},
|
|
34
35
|
async request => {
|
|
35
36
|
const userInfo = request.body;
|
|
36
|
-
await
|
|
37
|
+
await services.admin.addUser(Object.assign({}, userInfo, { password: services.account.md5(options.defaultPassword) }));
|
|
37
38
|
return {};
|
|
38
39
|
}
|
|
39
40
|
);
|
|
@@ -41,7 +42,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
41
42
|
fastify.get(
|
|
42
43
|
`${options.prefix}/admin/getAllUserList`,
|
|
43
44
|
{
|
|
44
|
-
onRequest: [
|
|
45
|
+
onRequest: [authenticate.user, authenticate.admin],
|
|
45
46
|
schema: {
|
|
46
47
|
query: {}
|
|
47
48
|
}
|
|
@@ -54,7 +55,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
54
55
|
},
|
|
55
56
|
request.query
|
|
56
57
|
);
|
|
57
|
-
return await
|
|
58
|
+
return await services.user.getAllUserList({
|
|
58
59
|
filter,
|
|
59
60
|
perPage,
|
|
60
61
|
currentPage
|
|
@@ -65,7 +66,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
65
66
|
fastify.post(
|
|
66
67
|
`${options.prefix}/admin/resetUserPassword`,
|
|
67
68
|
{
|
|
68
|
-
onRequest: [
|
|
69
|
+
onRequest: [authenticate.user, authenticate.admin],
|
|
69
70
|
schema: {
|
|
70
71
|
body: {
|
|
71
72
|
type: 'object',
|
|
@@ -78,7 +79,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
78
79
|
}
|
|
79
80
|
},
|
|
80
81
|
async request => {
|
|
81
|
-
await
|
|
82
|
+
await services.admin.resetUserPassword(request.body);
|
|
82
83
|
return {};
|
|
83
84
|
}
|
|
84
85
|
);
|
|
@@ -86,7 +87,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
86
87
|
fastify.post(
|
|
87
88
|
`${options.prefix}/admin/saveUser`,
|
|
88
89
|
{
|
|
89
|
-
onRequest: [
|
|
90
|
+
onRequest: [authenticate.user, authenticate.admin],
|
|
90
91
|
schema: {
|
|
91
92
|
body: {
|
|
92
93
|
type: 'object',
|
|
@@ -104,7 +105,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
104
105
|
},
|
|
105
106
|
async request => {
|
|
106
107
|
const user = request.body;
|
|
107
|
-
await
|
|
108
|
+
await services.user.saveUser(user);
|
|
108
109
|
return {};
|
|
109
110
|
}
|
|
110
111
|
);
|
|
@@ -112,7 +113,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
112
113
|
fastify.post(
|
|
113
114
|
`${options.prefix}/admin/closeUser`,
|
|
114
115
|
{
|
|
115
|
-
onRequest: [
|
|
116
|
+
onRequest: [authenticate.user, authenticate.admin],
|
|
116
117
|
schema: {
|
|
117
118
|
body: {
|
|
118
119
|
type: 'object',
|
|
@@ -125,7 +126,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
125
126
|
},
|
|
126
127
|
async request => {
|
|
127
128
|
const { id } = request.body;
|
|
128
|
-
await
|
|
129
|
+
await services.user.closeUser({ id });
|
|
129
130
|
return {};
|
|
130
131
|
}
|
|
131
132
|
);
|
|
@@ -133,7 +134,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
133
134
|
fastify.post(
|
|
134
135
|
`${options.prefix}/admin/openUser`,
|
|
135
136
|
{
|
|
136
|
-
onRequest: [
|
|
137
|
+
onRequest: [authenticate.user, authenticate.admin],
|
|
137
138
|
schema: {
|
|
138
139
|
body: {
|
|
139
140
|
type: 'object',
|
|
@@ -146,7 +147,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
146
147
|
},
|
|
147
148
|
async request => {
|
|
148
149
|
const { id } = request.body;
|
|
149
|
-
await
|
|
150
|
+
await services.user.openUser({ id });
|
|
150
151
|
return {};
|
|
151
152
|
}
|
|
152
153
|
);
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
const fp = require('fastify-plugin');
|
|
2
2
|
|
|
3
3
|
module.exports = fp(async (fastify, options) => {
|
|
4
|
+
const { authenticate, services } = fastify.account;
|
|
4
5
|
fastify.post(
|
|
5
6
|
`${options.prefix}/admin/addApplication`,
|
|
6
7
|
{
|
|
7
|
-
onRequest: [
|
|
8
|
+
onRequest: [authenticate.user, authenticate.admin],
|
|
8
9
|
schema: {
|
|
9
10
|
body: {
|
|
10
11
|
type: 'object',
|
|
@@ -20,7 +21,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
20
21
|
}
|
|
21
22
|
},
|
|
22
23
|
async request => {
|
|
23
|
-
await
|
|
24
|
+
await services.application.addApplication(request.body);
|
|
24
25
|
return {};
|
|
25
26
|
}
|
|
26
27
|
);
|
|
@@ -28,7 +29,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
28
29
|
fastify.post(
|
|
29
30
|
`${options.prefix}/admin/saveApplication`,
|
|
30
31
|
{
|
|
31
|
-
onRequest: [
|
|
32
|
+
onRequest: [authenticate.user, authenticate.admin],
|
|
32
33
|
schema: {
|
|
33
34
|
body: {
|
|
34
35
|
type: 'object',
|
|
@@ -45,7 +46,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
45
46
|
}
|
|
46
47
|
},
|
|
47
48
|
async request => {
|
|
48
|
-
await
|
|
49
|
+
await services.application.saveApplication(request.body);
|
|
49
50
|
return {};
|
|
50
51
|
}
|
|
51
52
|
);
|
|
@@ -53,7 +54,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
53
54
|
fastify.post(
|
|
54
55
|
`${options.prefix}/admin/deleteApplication`,
|
|
55
56
|
{
|
|
56
|
-
onRequest: [
|
|
57
|
+
onRequest: [authenticate.user, authenticate.admin],
|
|
57
58
|
schema: {
|
|
58
59
|
body: {
|
|
59
60
|
type: 'object',
|
|
@@ -66,7 +67,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
66
67
|
},
|
|
67
68
|
async request => {
|
|
68
69
|
const { id } = request.body;
|
|
69
|
-
await
|
|
70
|
+
await services.application.deleteApplication({ id });
|
|
70
71
|
return {};
|
|
71
72
|
}
|
|
72
73
|
);
|
|
@@ -74,7 +75,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
74
75
|
fastify.get(
|
|
75
76
|
`${options.prefix}/admin/getApplicationList`,
|
|
76
77
|
{
|
|
77
|
-
onRequest: [
|
|
78
|
+
onRequest: [authenticate.user, authenticate.admin],
|
|
78
79
|
schema: {
|
|
79
80
|
query: {
|
|
80
81
|
type: 'object',
|
|
@@ -86,14 +87,14 @@ module.exports = fp(async (fastify, options) => {
|
|
|
86
87
|
},
|
|
87
88
|
async request => {
|
|
88
89
|
const { tenantId } = request.query;
|
|
89
|
-
return await
|
|
90
|
+
return await services.application.getApplicationList({ tenantId });
|
|
90
91
|
}
|
|
91
92
|
);
|
|
92
93
|
|
|
93
94
|
fastify.post(
|
|
94
95
|
`${options.prefix}/admin/addPermission`,
|
|
95
96
|
{
|
|
96
|
-
onRequest: [
|
|
97
|
+
onRequest: [authenticate.user, authenticate.admin],
|
|
97
98
|
schema: {
|
|
98
99
|
body: {
|
|
99
100
|
type: 'object',
|
|
@@ -112,7 +113,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
112
113
|
}
|
|
113
114
|
},
|
|
114
115
|
async request => {
|
|
115
|
-
await
|
|
116
|
+
await services.permission.addPermission(request.body);
|
|
116
117
|
return {};
|
|
117
118
|
}
|
|
118
119
|
);
|
|
@@ -120,7 +121,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
120
121
|
fastify.get(
|
|
121
122
|
`${options.prefix}/admin/getPermissionList`,
|
|
122
123
|
{
|
|
123
|
-
onRequest: [
|
|
124
|
+
onRequest: [authenticate.user, authenticate.admin],
|
|
124
125
|
schema: {
|
|
125
126
|
query: {
|
|
126
127
|
type: 'object',
|
|
@@ -134,14 +135,14 @@ module.exports = fp(async (fastify, options) => {
|
|
|
134
135
|
},
|
|
135
136
|
async request => {
|
|
136
137
|
const { applicationId, tenantId } = request.query;
|
|
137
|
-
return await
|
|
138
|
+
return await services.permission.getPermissionList({ applicationId, tenantId });
|
|
138
139
|
}
|
|
139
140
|
);
|
|
140
141
|
|
|
141
142
|
fastify.post(
|
|
142
143
|
`${options.prefix}/admin/deletePermission`,
|
|
143
144
|
{
|
|
144
|
-
onRequest: [
|
|
145
|
+
onRequest: [authenticate.user, authenticate.admin],
|
|
145
146
|
schema: {
|
|
146
147
|
body: {
|
|
147
148
|
type: 'object',
|
|
@@ -155,7 +156,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
155
156
|
async request => {
|
|
156
157
|
const { id } = request.body;
|
|
157
158
|
|
|
158
|
-
await
|
|
159
|
+
await services.permission.deletePermission({ id });
|
|
159
160
|
|
|
160
161
|
return {};
|
|
161
162
|
}
|
|
@@ -164,7 +165,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
164
165
|
fastify.post(
|
|
165
166
|
`${options.prefix}/admin/savePermission`,
|
|
166
167
|
{
|
|
167
|
-
onRequest: [
|
|
168
|
+
onRequest: [authenticate.user, authenticate.admin],
|
|
168
169
|
schema: {
|
|
169
170
|
body: {
|
|
170
171
|
type: 'object',
|
|
@@ -180,7 +181,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
180
181
|
}
|
|
181
182
|
},
|
|
182
183
|
async request => {
|
|
183
|
-
await
|
|
184
|
+
await services.permission.savePermission(request.body);
|
|
184
185
|
return {};
|
|
185
186
|
}
|
|
186
187
|
);
|
|
@@ -188,24 +189,27 @@ module.exports = fp(async (fastify, options) => {
|
|
|
188
189
|
fastify.post(
|
|
189
190
|
`${options.prefix}/admin/saveTenantPermissionList`,
|
|
190
191
|
{
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
type: '
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
192
|
+
onRequest: [authenticate.user, authenticate.admin],
|
|
193
|
+
schema: {
|
|
194
|
+
body: {
|
|
195
|
+
type: 'object',
|
|
196
|
+
required: ['tenantId', 'applications', 'permissions'],
|
|
197
|
+
properties: {
|
|
198
|
+
tenantId: { type: 'string' },
|
|
199
|
+
applications: {
|
|
200
|
+
type: 'array',
|
|
201
|
+
items: { type: 'string' }
|
|
202
|
+
},
|
|
203
|
+
permissions: {
|
|
204
|
+
type: 'array',
|
|
205
|
+
items: { type: 'number' }
|
|
206
|
+
}
|
|
203
207
|
}
|
|
204
208
|
}
|
|
205
209
|
}
|
|
206
210
|
},
|
|
207
211
|
async request => {
|
|
208
|
-
await
|
|
212
|
+
await services.permission.saveTenantPermissionList(request.body);
|
|
209
213
|
|
|
210
214
|
return {};
|
|
211
215
|
}
|
|
@@ -214,17 +218,20 @@ module.exports = fp(async (fastify, options) => {
|
|
|
214
218
|
fastify.get(
|
|
215
219
|
`${options.prefix}/admin/getTenantPermissionList`,
|
|
216
220
|
{
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
221
|
+
onRequest: [authenticate.user, authenticate.admin],
|
|
222
|
+
schema: {
|
|
223
|
+
query: {
|
|
224
|
+
type: 'object',
|
|
225
|
+
required: ['tenantId'],
|
|
226
|
+
properties: {
|
|
227
|
+
tenantId: { type: 'string' }
|
|
228
|
+
}
|
|
222
229
|
}
|
|
223
230
|
}
|
|
224
231
|
},
|
|
225
232
|
async request => {
|
|
226
233
|
const { tenantId } = request.query;
|
|
227
|
-
return await
|
|
234
|
+
return await services.permission.getTenantPermissionList({ tenantId });
|
|
228
235
|
}
|
|
229
236
|
);
|
|
230
237
|
});
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
const fp = require('fastify-plugin');
|
|
2
2
|
|
|
3
3
|
module.exports = fp(async (fastify, options) => {
|
|
4
|
+
const { authenticate, services } = fastify.account;
|
|
4
5
|
fastify.get(
|
|
5
6
|
`${options.prefix}/admin/getRoleList`,
|
|
6
7
|
{
|
|
7
|
-
onRequest: [
|
|
8
|
+
onRequest: [authenticate.user, authenticate.admin],
|
|
8
9
|
schema: {
|
|
9
10
|
query: {
|
|
10
11
|
type: 'object',
|
|
@@ -30,14 +31,14 @@ module.exports = fp(async (fastify, options) => {
|
|
|
30
31
|
},
|
|
31
32
|
request.query
|
|
32
33
|
);
|
|
33
|
-
return await
|
|
34
|
+
return await services.tenantRole.getTenantRoleList({ tenantId, perPage, currentPage, filter });
|
|
34
35
|
}
|
|
35
36
|
);
|
|
36
37
|
|
|
37
38
|
fastify.post(
|
|
38
39
|
`${options.prefix}/admin/addRole`,
|
|
39
40
|
{
|
|
40
|
-
onRequest: [
|
|
41
|
+
onRequest: [authenticate.user, authenticate.admin],
|
|
41
42
|
schema: {
|
|
42
43
|
body: {
|
|
43
44
|
type: 'object',
|
|
@@ -52,7 +53,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
52
53
|
},
|
|
53
54
|
async request => {
|
|
54
55
|
const { tenantId, name, description } = request.body;
|
|
55
|
-
await
|
|
56
|
+
await services.tenantRole.addTenantRole({ tenantId, name, description });
|
|
56
57
|
|
|
57
58
|
return {};
|
|
58
59
|
}
|
|
@@ -61,7 +62,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
61
62
|
fastify.post(
|
|
62
63
|
`${options.prefix}/admin/saveRole`,
|
|
63
64
|
{
|
|
64
|
-
onRequest: [
|
|
65
|
+
onRequest: [authenticate.user, authenticate.admin],
|
|
65
66
|
schema: {
|
|
66
67
|
body: {
|
|
67
68
|
type: 'object',
|
|
@@ -75,7 +76,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
75
76
|
}
|
|
76
77
|
},
|
|
77
78
|
async request => {
|
|
78
|
-
await
|
|
79
|
+
await services.tenantRole.saveTenantRole(request.body);
|
|
79
80
|
return {};
|
|
80
81
|
}
|
|
81
82
|
);
|
|
@@ -83,7 +84,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
83
84
|
fastify.post(
|
|
84
85
|
`${options.prefix}/admin/removeRole`,
|
|
85
86
|
{
|
|
86
|
-
onRequest: [
|
|
87
|
+
onRequest: [authenticate.user, authenticate.admin],
|
|
87
88
|
schema: {
|
|
88
89
|
body: {
|
|
89
90
|
type: 'object',
|
|
@@ -96,7 +97,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
96
97
|
},
|
|
97
98
|
async request => {
|
|
98
99
|
const { id } = request.body;
|
|
99
|
-
await
|
|
100
|
+
await services.tenantRole.removeTenantRole({ id });
|
|
100
101
|
return {};
|
|
101
102
|
}
|
|
102
103
|
);
|
|
@@ -104,7 +105,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
104
105
|
fastify.get(
|
|
105
106
|
`${options.prefix}/admin/getRolePermissionList`,
|
|
106
107
|
{
|
|
107
|
-
onRequest: [
|
|
108
|
+
onRequest: [authenticate.user, authenticate.admin],
|
|
108
109
|
schema: {
|
|
109
110
|
query: {
|
|
110
111
|
type: 'object',
|
|
@@ -117,14 +118,14 @@ module.exports = fp(async (fastify, options) => {
|
|
|
117
118
|
},
|
|
118
119
|
async request => {
|
|
119
120
|
const { id } = request.query;
|
|
120
|
-
return await
|
|
121
|
+
return await services.permission.getRolePermissionList({ roleId: id });
|
|
121
122
|
}
|
|
122
123
|
);
|
|
123
124
|
|
|
124
125
|
fastify.post(
|
|
125
126
|
`${options.prefix}/admin/saveRolePermissionList`,
|
|
126
127
|
{
|
|
127
|
-
onRequest: [
|
|
128
|
+
onRequest: [authenticate.user, authenticate.admin],
|
|
128
129
|
schema: {
|
|
129
130
|
roleId: { type: 'string' },
|
|
130
131
|
applications: {
|
|
@@ -138,7 +139,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
138
139
|
}
|
|
139
140
|
},
|
|
140
141
|
async request => {
|
|
141
|
-
await
|
|
142
|
+
await services.permission.saveRolePermissionList(request.body);
|
|
142
143
|
return {};
|
|
143
144
|
}
|
|
144
145
|
);
|