@kne/fastify-account 1.0.0-alpha.1 → 1.0.0-alpha.3
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 +101 -5
- package/index.js +10 -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 +14 -10
- package/libs/models/tenant-role-permission.js +10 -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 +26 -16
- package/libs/services/admin.js +14 -116
- 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 +84 -0
- package/libs/services/tenant-role.js +108 -0
- package/libs/services/tenant-user.js +486 -0
- package/libs/services/tenant.js +68 -512
- package/libs/services/user.js +69 -30
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ npm i --save @kne/fastify-account
|
|
|
22
22
|
### API
|
|
23
23
|
|
|
24
24
|
---
|
|
25
|
-
title: "@kne/fastify-account v1.0.0-alpha.
|
|
25
|
+
title: "@kne/fastify-account v1.0.0-alpha.3"
|
|
26
26
|
language_tabs:
|
|
27
27
|
- shell: Shell
|
|
28
28
|
- http: HTTP
|
|
@@ -42,7 +42,7 @@ headingLevel: 2
|
|
|
42
42
|
|
|
43
43
|
<!-- Generator: Widdershins v4.0.1 -->
|
|
44
44
|
|
|
45
|
-
<h1 id="-kne-fastify-account">@kne/fastify-account v1.0.0-alpha.
|
|
45
|
+
<h1 id="-kne-fastify-account">@kne/fastify-account v1.0.0-alpha.3</h1>
|
|
46
46
|
|
|
47
47
|
> Scroll down for code samples, example requests and responses. Select a language for code samples from the tabs above or the mobile navigation menu.
|
|
48
48
|
|
|
@@ -1008,6 +1008,45 @@ This operation does not require authentication
|
|
|
1008
1008
|
|
|
1009
1009
|
`POST /api/v1/account/admin/saveTenantPermissionList`
|
|
1010
1010
|
|
|
1011
|
+
> Body parameter
|
|
1012
|
+
|
|
1013
|
+
```json
|
|
1014
|
+
{
|
|
1015
|
+
"type": "object",
|
|
1016
|
+
"required": [
|
|
1017
|
+
"tenantId",
|
|
1018
|
+
"applications",
|
|
1019
|
+
"permissions"
|
|
1020
|
+
],
|
|
1021
|
+
"properties": {
|
|
1022
|
+
"tenantId": {
|
|
1023
|
+
"type": "string"
|
|
1024
|
+
},
|
|
1025
|
+
"applications": {
|
|
1026
|
+
"type": "array",
|
|
1027
|
+
"items": {
|
|
1028
|
+
"type": "string"
|
|
1029
|
+
}
|
|
1030
|
+
},
|
|
1031
|
+
"permissions": {
|
|
1032
|
+
"type": "array",
|
|
1033
|
+
"items": {
|
|
1034
|
+
"type": "number"
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
```
|
|
1040
|
+
|
|
1041
|
+
<h3 id="post__api_v1_account_admin_savetenantpermissionlist-parameters">Parameters</h3>
|
|
1042
|
+
|
|
1043
|
+
|Name|In|Type|Required|Description|
|
|
1044
|
+
|---|---|---|---|---|
|
|
1045
|
+
|body|body|object|true|none|
|
|
1046
|
+
|» tenantId|body|string|true|none|
|
|
1047
|
+
|» applications|body|[string]|true|none|
|
|
1048
|
+
|» permissions|body|[number]|true|none|
|
|
1049
|
+
|
|
1011
1050
|
<h3 id="post__api_v1_account_admin_savetenantpermissionlist-responses">Responses</h3>
|
|
1012
1051
|
|
|
1013
1052
|
|Status|Meaning|Description|Schema|
|
|
@@ -1022,6 +1061,12 @@ This operation does not require authentication
|
|
|
1022
1061
|
|
|
1023
1062
|
`GET /api/v1/account/admin/getTenantPermissionList`
|
|
1024
1063
|
|
|
1064
|
+
<h3 id="get__api_v1_account_admin_gettenantpermissionlist-parameters">Parameters</h3>
|
|
1065
|
+
|
|
1066
|
+
|Name|In|Type|Required|Description|
|
|
1067
|
+
|---|---|---|---|---|
|
|
1068
|
+
|tenantId|query|string|true|none|
|
|
1069
|
+
|
|
1025
1070
|
<h3 id="get__api_v1_account_admin_gettenantpermissionlist-responses">Responses</h3>
|
|
1026
1071
|
|
|
1027
1072
|
|Status|Meaning|Description|Schema|
|
|
@@ -1938,11 +1983,25 @@ This operation does not require authentication
|
|
|
1938
1983
|
This operation does not require authentication
|
|
1939
1984
|
</aside>
|
|
1940
1985
|
|
|
1941
|
-
##
|
|
1986
|
+
## get__api_v1_account_tenant_getTenantUserInfo
|
|
1987
|
+
|
|
1988
|
+
`GET /api/v1/account/tenant/getTenantUserInfo`
|
|
1989
|
+
|
|
1990
|
+
<h3 id="get__api_v1_account_tenant_gettenantuserinfo-responses">Responses</h3>
|
|
1991
|
+
|
|
1992
|
+
|Status|Meaning|Description|Schema|
|
|
1993
|
+
|---|---|---|---|
|
|
1994
|
+
|200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|Default Response|None|
|
|
1995
|
+
|
|
1996
|
+
<aside class="success">
|
|
1997
|
+
This operation does not require authentication
|
|
1998
|
+
</aside>
|
|
1999
|
+
|
|
2000
|
+
## get__api_v1_account_tenant_orgList
|
|
1942
2001
|
|
|
1943
|
-
`GET /api/v1/account/tenant/
|
|
2002
|
+
`GET /api/v1/account/tenant/orgList`
|
|
1944
2003
|
|
|
1945
|
-
<h3 id="
|
|
2004
|
+
<h3 id="get__api_v1_account_tenant_orglist-responses">Responses</h3>
|
|
1946
2005
|
|
|
1947
2006
|
|Status|Meaning|Description|Schema|
|
|
1948
2007
|
|---|---|---|---|
|
|
@@ -1966,6 +2025,43 @@ This operation does not require authentication
|
|
|
1966
2025
|
This operation does not require authentication
|
|
1967
2026
|
</aside>
|
|
1968
2027
|
|
|
2028
|
+
## post__api_v1_account_setCurrentTenantId
|
|
2029
|
+
|
|
2030
|
+
`POST /api/v1/account/setCurrentTenantId`
|
|
2031
|
+
|
|
2032
|
+
> Body parameter
|
|
2033
|
+
|
|
2034
|
+
```json
|
|
2035
|
+
{
|
|
2036
|
+
"type": "object",
|
|
2037
|
+
"required": [
|
|
2038
|
+
"tenantId"
|
|
2039
|
+
],
|
|
2040
|
+
"properties": {
|
|
2041
|
+
"tenantId": {
|
|
2042
|
+
"type": "string"
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
```
|
|
2047
|
+
|
|
2048
|
+
<h3 id="post__api_v1_account_setcurrenttenantid-parameters">Parameters</h3>
|
|
2049
|
+
|
|
2050
|
+
|Name|In|Type|Required|Description|
|
|
2051
|
+
|---|---|---|---|---|
|
|
2052
|
+
|body|body|object|true|none|
|
|
2053
|
+
|» tenantId|body|string|true|none|
|
|
2054
|
+
|
|
2055
|
+
<h3 id="post__api_v1_account_setcurrenttenantid-responses">Responses</h3>
|
|
2056
|
+
|
|
2057
|
+
|Status|Meaning|Description|Schema|
|
|
2058
|
+
|---|---|---|---|
|
|
2059
|
+
|200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|Default Response|None|
|
|
2060
|
+
|
|
2061
|
+
<aside class="success">
|
|
2062
|
+
This operation does not require authentication
|
|
2063
|
+
</aside>
|
|
2064
|
+
|
|
1969
2065
|
# Schemas
|
|
1970
2066
|
|
|
1971
2067
|
|
package/index.js
CHANGED
|
@@ -9,6 +9,7 @@ module.exports = fp(
|
|
|
9
9
|
options = merge(
|
|
10
10
|
{
|
|
11
11
|
prefix: `/api/v${packageJson.version.split('.')[0]}/account`, //如果为true,发送邮件和短信将不调用,验证码随response返回
|
|
12
|
+
dbTableNamePrefix: 't_account_',
|
|
12
13
|
isTest: false,
|
|
13
14
|
jwt: {
|
|
14
15
|
secret: 'super-secret'
|
|
@@ -23,7 +24,12 @@ module.exports = fp(
|
|
|
23
24
|
options,
|
|
24
25
|
name: 'account',
|
|
25
26
|
modules: [
|
|
26
|
-
[
|
|
27
|
+
[
|
|
28
|
+
'models',
|
|
29
|
+
await fastify.sequelize.addModels(path.resolve(__dirname, './libs/models'), {
|
|
30
|
+
prefix: options.dbTableNamePrefix
|
|
31
|
+
})
|
|
32
|
+
],
|
|
27
33
|
['services', path.resolve(__dirname, './libs/services')],
|
|
28
34
|
['controllers', path.resolve(__dirname, './libs/controllers')],
|
|
29
35
|
[
|
|
@@ -34,13 +40,13 @@ module.exports = fp(
|
|
|
34
40
|
//这里判断失效时间
|
|
35
41
|
//info.iat
|
|
36
42
|
request.authenticatePayload = info.payload;
|
|
37
|
-
request.userInfo = await fastify.account.services.user.
|
|
43
|
+
request.userInfo = await fastify.account.services.user.getUser(request.authenticatePayload);
|
|
38
44
|
},
|
|
39
45
|
tenant: async request => {
|
|
40
|
-
request.tenantInfo = await fastify.account.services.
|
|
46
|
+
request.tenantInfo = await fastify.account.services.tenantUser.getTenantUserByUserId(request.userInfo);
|
|
41
47
|
},
|
|
42
48
|
admin: async request => {
|
|
43
|
-
request.adminInfo = await fastify.account.services.admin.
|
|
49
|
+
request.adminInfo = await fastify.account.services.admin.checkSuperAdmin(request.userInfo);
|
|
44
50
|
}
|
|
45
51
|
}
|
|
46
52
|
]
|
|
@@ -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: 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
|
});
|