@budibase/worker 2.1.38 → 2.1.40-alpha.0
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/__mocks__/aws-sdk.ts +15 -0
- package/__mocks__/oauth.ts +57 -0
- package/coverage/clover.xml +2153 -0
- package/coverage/coverage-final.json +78 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +431 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov-report/src/api/controllers/global/auth.ts.html +925 -0
- package/coverage/lcov-report/src/api/controllers/global/configs.ts.html +1405 -0
- package/coverage/lcov-report/src/api/controllers/global/email.ts.html +196 -0
- package/coverage/lcov-report/src/api/controllers/global/index.html +236 -0
- package/coverage/lcov-report/src/api/controllers/global/license.ts.html +187 -0
- package/coverage/lcov-report/src/api/controllers/global/roles.ts.html +283 -0
- package/coverage/lcov-report/src/api/controllers/global/self.ts.html +577 -0
- package/coverage/lcov-report/src/api/controllers/global/templates.ts.html +316 -0
- package/coverage/lcov-report/src/api/controllers/global/users.ts.html +796 -0
- package/coverage/lcov-report/src/api/controllers/global/workspaces.ts.html +244 -0
- package/coverage/lcov-report/src/api/controllers/system/accounts.ts.html +148 -0
- package/coverage/lcov-report/src/api/controllers/system/environment.ts.html +124 -0
- package/coverage/lcov-report/src/api/controllers/system/index.html +191 -0
- package/coverage/lcov-report/src/api/controllers/system/migrations.ts.html +124 -0
- package/coverage/lcov-report/src/api/controllers/system/restore.ts.html +124 -0
- package/coverage/lcov-report/src/api/controllers/system/status.ts.html +133 -0
- package/coverage/lcov-report/src/api/controllers/system/tenants.ts.html +154 -0
- package/coverage/lcov-report/src/api/index.html +116 -0
- package/coverage/lcov-report/src/api/index.ts.html +583 -0
- package/coverage/lcov-report/src/api/routes/global/auth.ts.html +349 -0
- package/coverage/lcov-report/src/api/routes/global/configs.ts.html +457 -0
- package/coverage/lcov-report/src/api/routes/global/email.ts.html +193 -0
- package/coverage/lcov-report/src/api/routes/global/index.html +236 -0
- package/coverage/lcov-report/src/api/routes/global/license.ts.html +124 -0
- package/coverage/lcov-report/src/api/routes/global/roles.ts.html +133 -0
- package/coverage/lcov-report/src/api/routes/global/self.ts.html +139 -0
- package/coverage/lcov-report/src/api/routes/global/templates.ts.html +196 -0
- package/coverage/lcov-report/src/api/routes/global/users.ts.html +409 -0
- package/coverage/lcov-report/src/api/routes/global/workspaces.ts.html +196 -0
- package/coverage/lcov-report/src/api/routes/index.html +116 -0
- package/coverage/lcov-report/src/api/routes/index.ts.html +196 -0
- package/coverage/lcov-report/src/api/routes/system/accounts.ts.html +142 -0
- package/coverage/lcov-report/src/api/routes/system/environment.ts.html +109 -0
- package/coverage/lcov-report/src/api/routes/system/index.html +191 -0
- package/coverage/lcov-report/src/api/routes/system/migrations.ts.html +142 -0
- package/coverage/lcov-report/src/api/routes/system/restore.ts.html +109 -0
- package/coverage/lcov-report/src/api/routes/system/status.ts.html +109 -0
- package/coverage/lcov-report/src/api/routes/system/tenants.ts.html +124 -0
- package/coverage/lcov-report/src/api/routes/validation/index.html +131 -0
- package/coverage/lcov-report/src/api/routes/validation/index.ts.html +88 -0
- package/coverage/lcov-report/src/api/routes/validation/users.ts.html +235 -0
- package/coverage/lcov-report/src/constants/index.html +116 -0
- package/coverage/lcov-report/src/constants/index.ts.html +613 -0
- package/coverage/lcov-report/src/constants/templates/index.html +116 -0
- package/coverage/lcov-report/src/constants/templates/index.ts.html +316 -0
- package/coverage/lcov-report/src/db/index.html +116 -0
- package/coverage/lcov-report/src/db/index.ts.html +115 -0
- package/coverage/lcov-report/src/environment.ts.html +373 -0
- package/coverage/lcov-report/src/index.html +131 -0
- package/coverage/lcov-report/src/index.ts.html +394 -0
- package/coverage/lcov-report/src/middleware/cloudRestricted.ts.html +139 -0
- package/coverage/lcov-report/src/middleware/index.html +116 -0
- package/coverage/lcov-report/src/migrations/functions/globalInfoSyncUsers.ts.html +145 -0
- package/coverage/lcov-report/src/migrations/functions/index.html +116 -0
- package/coverage/lcov-report/src/migrations/index.html +116 -0
- package/coverage/lcov-report/src/migrations/index.ts.html +271 -0
- package/coverage/lcov-report/src/sdk/accounts/accounts.ts.html +262 -0
- package/coverage/lcov-report/src/sdk/accounts/index.html +131 -0
- package/coverage/lcov-report/src/sdk/accounts/index.ts.html +88 -0
- package/coverage/lcov-report/src/sdk/index.html +116 -0
- package/coverage/lcov-report/src/sdk/index.ts.html +106 -0
- package/coverage/lcov-report/src/sdk/users/events.ts.html +577 -0
- package/coverage/lcov-report/src/sdk/users/index.html +146 -0
- package/coverage/lcov-report/src/sdk/users/index.ts.html +88 -0
- package/coverage/lcov-report/src/sdk/users/users.ts.html +1903 -0
- package/coverage/lcov-report/src/tests/TestConfiguration.ts.html +1051 -0
- package/coverage/lcov-report/src/tests/api/accounts.ts.html +160 -0
- package/coverage/lcov-report/src/tests/api/auth.ts.html +220 -0
- package/coverage/lcov-report/src/tests/api/base.ts.html +133 -0
- package/coverage/lcov-report/src/tests/api/configs.ts.html +226 -0
- package/coverage/lcov-report/src/tests/api/email.ts.html +148 -0
- package/coverage/lcov-report/src/tests/api/environment.ts.html +130 -0
- package/coverage/lcov-report/src/tests/api/index.html +296 -0
- package/coverage/lcov-report/src/tests/api/index.ts.html +205 -0
- package/coverage/lcov-report/src/tests/api/migrations.ts.html +151 -0
- package/coverage/lcov-report/src/tests/api/restore.ts.html +127 -0
- package/coverage/lcov-report/src/tests/api/self.ts.html +163 -0
- package/coverage/lcov-report/src/tests/api/status.ts.html +121 -0
- package/coverage/lcov-report/src/tests/api/tenants.ts.html +130 -0
- package/coverage/lcov-report/src/tests/api/users.ts.html +511 -0
- package/coverage/lcov-report/src/tests/controllers.ts.html +100 -0
- package/coverage/lcov-report/src/tests/index.html +146 -0
- package/coverage/lcov-report/src/tests/index.ts.html +139 -0
- package/coverage/lcov-report/src/tests/mocks/email.js.html +115 -0
- package/coverage/lcov-report/src/tests/mocks/index.html +131 -0
- package/coverage/lcov-report/src/tests/mocks/index.ts.html +106 -0
- package/coverage/lcov-report/src/tests/structures/configs.ts.html +313 -0
- package/coverage/lcov-report/src/tests/structures/groups.ts.html +118 -0
- package/coverage/lcov-report/src/tests/structures/index.html +161 -0
- package/coverage/lcov-report/src/tests/structures/index.ts.html +151 -0
- package/coverage/lcov-report/src/tests/structures/users.ts.html +196 -0
- package/coverage/lcov-report/src/utilities/appService.ts.html +181 -0
- package/coverage/lcov-report/src/utilities/email.ts.html +850 -0
- package/coverage/lcov-report/src/utilities/fileSystem.ts.html +100 -0
- package/coverage/lcov-report/src/utilities/index.html +206 -0
- package/coverage/lcov-report/src/utilities/index.ts.html +112 -0
- package/coverage/lcov-report/src/utilities/redis.ts.html +424 -0
- package/coverage/lcov-report/src/utilities/templates.ts.html +232 -0
- package/coverage/lcov-report/src/utilities/users.ts.html +133 -0
- package/coverage/lcov.info +3958 -0
- package/jest.config.ts +29 -0
- package/package.json +13 -23
- package/scripts/localdomain.js +33 -7
- package/src/api/controllers/global/auth.ts +51 -43
- package/src/api/controllers/global/{configs.js → configs.ts} +119 -114
- package/src/api/controllers/global/{email.js → email.ts} +6 -5
- package/src/api/controllers/global/roles.ts +66 -0
- package/src/api/controllers/global/self.ts +2 -2
- package/src/api/controllers/global/users.ts +4 -2
- package/src/api/controllers/global/{workspaces.js → workspaces.ts} +15 -18
- package/src/api/controllers/system/{environment.js → environment.ts} +3 -2
- package/src/api/controllers/system/restore.ts +1 -1
- package/src/api/controllers/system/{status.js → status.ts} +4 -3
- package/src/api/controllers/system/tenants.ts +8 -51
- package/src/api/index.ts +31 -8
- package/src/api/routes/global/{auth.js → auth.ts} +31 -48
- package/src/api/routes/global/{configs.js → configs.ts} +22 -23
- package/src/api/routes/global/{email.js → email.ts} +9 -10
- package/src/api/routes/global/license.ts +1 -1
- package/src/api/routes/global/roles.ts +16 -0
- package/src/api/routes/global/self.ts +2 -2
- package/src/api/routes/global/templates.ts +4 -4
- package/src/api/routes/global/tests/auth.spec.ts +134 -64
- package/src/api/routes/global/tests/configs.spec.ts +34 -35
- package/src/api/routes/global/tests/email.spec.ts +4 -3
- package/src/api/routes/global/tests/license.spec.ts +31 -0
- package/src/api/routes/global/tests/realEmail.spec.ts +2 -3
- package/src/api/routes/global/tests/roles.spec.ts +27 -0
- package/src/api/routes/global/tests/self.spec.ts +3 -4
- package/src/api/routes/global/tests/templates.spec.ts +35 -0
- package/src/api/routes/global/tests/users.spec.ts +51 -43
- package/src/api/routes/global/tests/workspaces.spec.ts +29 -0
- package/src/api/routes/global/{users.js → users.ts} +26 -24
- package/src/api/routes/global/{workspaces.js → workspaces.ts} +9 -10
- package/src/api/routes/index.ts +2 -1
- package/src/api/routes/system/accounts.ts +1 -1
- package/src/api/routes/system/environment.ts +8 -0
- package/src/api/routes/system/migrations.ts +1 -1
- package/src/api/routes/system/restore.ts +1 -1
- package/src/api/routes/system/status.ts +8 -0
- package/src/api/routes/system/tenants.ts +13 -0
- package/src/api/routes/system/tests/accounts.spec.ts +5 -6
- package/src/api/routes/system/tests/environment.spec.ts +29 -0
- package/src/api/routes/system/tests/migrations.spec.ts +63 -0
- package/src/api/routes/system/tests/restore.spec.ts +36 -0
- package/src/api/routes/system/tests/status.spec.ts +48 -0
- package/src/api/routes/system/tests/tenants.spec.ts +61 -0
- package/src/api/routes/validation/users.ts +3 -3
- package/src/constants/{index.js → index.ts} +57 -64
- package/src/constants/templates/{index.js → index.ts} +23 -19
- package/src/db/index.ts +10 -0
- package/src/environment.ts +8 -6
- package/src/index.ts +15 -16
- package/src/middleware/{cloudRestricted.js → cloudRestricted.ts} +5 -4
- package/src/middleware/tests/tenancy.spec.ts +73 -0
- package/src/tests/TestConfiguration.ts +99 -50
- package/src/tests/api/accounts.ts +5 -8
- package/src/tests/api/auth.ts +3 -6
- package/src/tests/api/base.ts +16 -0
- package/src/tests/api/configs.ts +15 -8
- package/src/tests/api/email.ts +3 -6
- package/src/tests/api/environment.ts +15 -0
- package/src/tests/api/index.ts +15 -0
- package/src/tests/api/migrations.ts +22 -0
- package/src/tests/api/restore.ts +14 -0
- package/src/tests/api/self.ts +11 -6
- package/src/tests/api/status.ts +12 -0
- package/src/tests/api/tenants.ts +15 -0
- package/src/tests/api/users.ts +38 -6
- package/src/tests/controllers.ts +5 -0
- package/src/tests/index.ts +5 -1
- package/{scripts/jestSetup.js → src/tests/jestSetup.ts} +12 -3
- package/src/tests/structures/{configs.js → configs.ts} +11 -11
- package/src/tests/structures/index.ts +5 -3
- package/src/tests/structures/users.ts +1 -0
- package/src/utilities/appService.ts +32 -0
- package/src/utilities/{email.js → email.ts} +78 -45
- package/src/utilities/fileSystem.ts +5 -0
- package/src/utilities/{index.js → index.ts} +1 -1
- package/src/utilities/{redis.js → redis.ts} +29 -24
- package/src/utilities/templates.ts +49 -0
- package/src/utilities/users.ts +16 -0
- package/tsconfig.build.json +2 -3
- package/tsconfig.json +3 -1
- package/src/api/controllers/global/roles.js +0 -68
- package/src/api/routes/global/roles.js +0 -12
- package/src/api/routes/system/environment.js +0 -8
- package/src/api/routes/system/status.js +0 -8
- package/src/api/routes/system/tenants.js +0 -12
- package/src/db/index.js +0 -11
- package/src/tests/controllers.js +0 -7
- package/src/tests/structures/accounts.ts +0 -24
- package/src/utilities/appService.js +0 -33
- package/src/utilities/fileSystem.js +0 -5
- package/src/utilities/templates.js +0 -49
- package/src/utilities/users.js +0 -17
|
@@ -6,14 +6,12 @@ import {
|
|
|
6
6
|
mocks,
|
|
7
7
|
structures,
|
|
8
8
|
TENANT_1,
|
|
9
|
-
API,
|
|
10
9
|
} from "../../../../tests"
|
|
11
10
|
const sendMailMock = mocks.email.mock()
|
|
12
11
|
import { events, tenancy } from "@budibase/backend-core"
|
|
13
12
|
|
|
14
13
|
describe("/api/global/users", () => {
|
|
15
14
|
const config = new TestConfiguration()
|
|
16
|
-
const api = new API(config)
|
|
17
15
|
|
|
18
16
|
beforeAll(async () => {
|
|
19
17
|
await config.beforeAll()
|
|
@@ -30,7 +28,10 @@ describe("/api/global/users", () => {
|
|
|
30
28
|
describe("invite", () => {
|
|
31
29
|
it("should be able to generate an invitation", async () => {
|
|
32
30
|
const email = structures.users.newEmail()
|
|
33
|
-
const { code, res } = await api.users.sendUserInvite(
|
|
31
|
+
const { code, res } = await config.api.users.sendUserInvite(
|
|
32
|
+
sendMailMock,
|
|
33
|
+
email
|
|
34
|
+
)
|
|
34
35
|
|
|
35
36
|
expect(res.body).toEqual({ message: "Invitation has been sent." })
|
|
36
37
|
expect(sendMailMock).toHaveBeenCalled()
|
|
@@ -39,7 +40,7 @@ describe("/api/global/users", () => {
|
|
|
39
40
|
})
|
|
40
41
|
|
|
41
42
|
it("should not be able to generate an invitation for existing user", async () => {
|
|
42
|
-
const { code, res } = await api.users.sendUserInvite(
|
|
43
|
+
const { code, res } = await config.api.users.sendUserInvite(
|
|
43
44
|
sendMailMock,
|
|
44
45
|
config.defaultUser!.email,
|
|
45
46
|
400
|
|
@@ -53,9 +54,12 @@ describe("/api/global/users", () => {
|
|
|
53
54
|
|
|
54
55
|
it("should be able to create new user from invite", async () => {
|
|
55
56
|
const email = structures.users.newEmail()
|
|
56
|
-
const { code } = await api.users.sendUserInvite(
|
|
57
|
+
const { code } = await config.api.users.sendUserInvite(
|
|
58
|
+
sendMailMock,
|
|
59
|
+
email
|
|
60
|
+
)
|
|
57
61
|
|
|
58
|
-
const res = await api.users.acceptInvite(code)
|
|
62
|
+
const res = await config.api.users.acceptInvite(code)
|
|
59
63
|
|
|
60
64
|
expect(res.body._id).toBeDefined()
|
|
61
65
|
const user = await config.getUser(email)
|
|
@@ -74,7 +78,7 @@ describe("/api/global/users", () => {
|
|
|
74
78
|
})
|
|
75
79
|
const request = [newUserInvite(), newUserInvite()]
|
|
76
80
|
|
|
77
|
-
const res = await api.users.sendMultiUserInvite(request)
|
|
81
|
+
const res = await config.api.users.sendMultiUserInvite(request)
|
|
78
82
|
|
|
79
83
|
const body = res.body as InviteUsersResponse
|
|
80
84
|
expect(body.successful.length).toBe(2)
|
|
@@ -86,7 +90,7 @@ describe("/api/global/users", () => {
|
|
|
86
90
|
it("should not be able to generate an invitation for existing user", async () => {
|
|
87
91
|
const request = [{ email: config.defaultUser!.email, userInfo: {} }]
|
|
88
92
|
|
|
89
|
-
const res = await api.users.sendMultiUserInvite(request)
|
|
93
|
+
const res = await config.api.users.sendMultiUserInvite(request)
|
|
90
94
|
|
|
91
95
|
const body = res.body as InviteUsersResponse
|
|
92
96
|
expect(body.successful.length).toBe(0)
|
|
@@ -102,7 +106,7 @@ describe("/api/global/users", () => {
|
|
|
102
106
|
const user = await config.createUser()
|
|
103
107
|
jest.clearAllMocks()
|
|
104
108
|
|
|
105
|
-
const response = await api.users.bulkCreateUsers([user])
|
|
109
|
+
const response = await config.api.users.bulkCreateUsers([user])
|
|
106
110
|
|
|
107
111
|
expect(response.created?.successful.length).toBe(0)
|
|
108
112
|
expect(response.created?.unsuccessful.length).toBe(1)
|
|
@@ -115,7 +119,7 @@ describe("/api/global/users", () => {
|
|
|
115
119
|
jest.resetAllMocks()
|
|
116
120
|
|
|
117
121
|
await tenancy.doInTenant(TENANT_1, async () => {
|
|
118
|
-
const response = await api.users.bulkCreateUsers([user])
|
|
122
|
+
const response = await config.api.users.bulkCreateUsers([user])
|
|
119
123
|
|
|
120
124
|
expect(response.created?.successful.length).toBe(0)
|
|
121
125
|
expect(response.created?.unsuccessful.length).toBe(1)
|
|
@@ -126,11 +130,11 @@ describe("/api/global/users", () => {
|
|
|
126
130
|
|
|
127
131
|
it("should ignore accounts using the same email", async () => {
|
|
128
132
|
const account = structures.accounts.account()
|
|
129
|
-
const resp = await api.accounts.saveMetadata(account)
|
|
133
|
+
const resp = await config.api.accounts.saveMetadata(account)
|
|
130
134
|
const user = structures.users.user({ email: resp.email })
|
|
131
135
|
jest.clearAllMocks()
|
|
132
136
|
|
|
133
|
-
const response = await api.users.bulkCreateUsers([user])
|
|
137
|
+
const response = await config.api.users.bulkCreateUsers([user])
|
|
134
138
|
|
|
135
139
|
expect(response.created?.successful.length).toBe(0)
|
|
136
140
|
expect(response.created?.unsuccessful.length).toBe(1)
|
|
@@ -143,7 +147,11 @@ describe("/api/global/users", () => {
|
|
|
143
147
|
const admin = structures.users.adminUser()
|
|
144
148
|
const user = structures.users.user()
|
|
145
149
|
|
|
146
|
-
const response = await api.users.bulkCreateUsers([
|
|
150
|
+
const response = await config.api.users.bulkCreateUsers([
|
|
151
|
+
builder,
|
|
152
|
+
admin,
|
|
153
|
+
user,
|
|
154
|
+
])
|
|
147
155
|
|
|
148
156
|
expect(response.created?.successful.length).toBe(3)
|
|
149
157
|
expect(response.created?.successful[0].email).toBe(builder.email)
|
|
@@ -160,7 +168,7 @@ describe("/api/global/users", () => {
|
|
|
160
168
|
it("should be able to create a basic user", async () => {
|
|
161
169
|
const user = structures.users.user()
|
|
162
170
|
|
|
163
|
-
await api.users.saveUser(user)
|
|
171
|
+
await config.api.users.saveUser(user)
|
|
164
172
|
|
|
165
173
|
expect(events.user.created).toBeCalledTimes(1)
|
|
166
174
|
expect(events.user.updated).not.toBeCalled()
|
|
@@ -171,7 +179,7 @@ describe("/api/global/users", () => {
|
|
|
171
179
|
it("should be able to create an admin user", async () => {
|
|
172
180
|
const user = structures.users.adminUser()
|
|
173
181
|
|
|
174
|
-
await api.users.saveUser(user)
|
|
182
|
+
await config.api.users.saveUser(user)
|
|
175
183
|
|
|
176
184
|
expect(events.user.created).toBeCalledTimes(1)
|
|
177
185
|
expect(events.user.updated).not.toBeCalled()
|
|
@@ -182,7 +190,7 @@ describe("/api/global/users", () => {
|
|
|
182
190
|
it("should be able to create a builder user", async () => {
|
|
183
191
|
const user = structures.users.builderUser()
|
|
184
192
|
|
|
185
|
-
await api.users.saveUser(user)
|
|
193
|
+
await config.api.users.saveUser(user)
|
|
186
194
|
|
|
187
195
|
expect(events.user.created).toBeCalledTimes(1)
|
|
188
196
|
expect(events.user.updated).not.toBeCalled()
|
|
@@ -197,7 +205,7 @@ describe("/api/global/users", () => {
|
|
|
197
205
|
app_456: "role2",
|
|
198
206
|
}
|
|
199
207
|
|
|
200
|
-
await api.users.saveUser(user)
|
|
208
|
+
await config.api.users.saveUser(user)
|
|
201
209
|
|
|
202
210
|
const savedUser = await config.getUser(user.email)
|
|
203
211
|
expect(events.user.created).toBeCalledTimes(1)
|
|
@@ -213,7 +221,7 @@ describe("/api/global/users", () => {
|
|
|
213
221
|
delete user._id
|
|
214
222
|
delete user._rev
|
|
215
223
|
|
|
216
|
-
const response = await api.users.saveUser(user, 400)
|
|
224
|
+
const response = await config.api.users.saveUser(user, 400)
|
|
217
225
|
|
|
218
226
|
expect(response.body.message).toBe(`Unavailable`)
|
|
219
227
|
expect(events.user.created).toBeCalledTimes(0)
|
|
@@ -225,7 +233,7 @@ describe("/api/global/users", () => {
|
|
|
225
233
|
|
|
226
234
|
await tenancy.doInTenant(TENANT_1, async () => {
|
|
227
235
|
delete user._id
|
|
228
|
-
const response = await api.users.saveUser(user, 400)
|
|
236
|
+
const response = await config.api.users.saveUser(user, 400)
|
|
229
237
|
|
|
230
238
|
expect(response.body.message).toBe(`Unavailable`)
|
|
231
239
|
expect(events.user.created).toBeCalledTimes(0)
|
|
@@ -237,7 +245,7 @@ describe("/api/global/users", () => {
|
|
|
237
245
|
const account = structures.accounts.cloudAccount()
|
|
238
246
|
mocks.accounts.getAccount.mockReturnValueOnce(account)
|
|
239
247
|
|
|
240
|
-
const response = await api.users.saveUser(user, 400)
|
|
248
|
+
const response = await config.api.users.saveUser(user, 400)
|
|
241
249
|
|
|
242
250
|
expect(response.body.message).toBe(`Unavailable`)
|
|
243
251
|
expect(events.user.created).toBeCalledTimes(0)
|
|
@@ -245,20 +253,20 @@ describe("/api/global/users", () => {
|
|
|
245
253
|
|
|
246
254
|
it("should not be able to create a user with the same email and different casing", async () => {
|
|
247
255
|
const user = structures.users.user()
|
|
248
|
-
await api.users.saveUser(user)
|
|
256
|
+
await config.api.users.saveUser(user)
|
|
249
257
|
|
|
250
258
|
user.email = user.email.toUpperCase()
|
|
251
|
-
await api.users.saveUser(user, 400)
|
|
259
|
+
await config.api.users.saveUser(user, 400)
|
|
252
260
|
|
|
253
261
|
expect(events.user.created).toBeCalledTimes(1)
|
|
254
262
|
})
|
|
255
263
|
|
|
256
264
|
it("should not be able to bulk create a user with the same email and different casing", async () => {
|
|
257
265
|
const user = structures.users.user()
|
|
258
|
-
await api.users.saveUser(user)
|
|
266
|
+
await config.api.users.saveUser(user)
|
|
259
267
|
|
|
260
268
|
user.email = user.email.toUpperCase()
|
|
261
|
-
await api.users.bulkCreateUsers([user])
|
|
269
|
+
await config.api.users.bulkCreateUsers([user])
|
|
262
270
|
|
|
263
271
|
expect(events.user.created).toBeCalledTimes(1)
|
|
264
272
|
})
|
|
@@ -269,7 +277,7 @@ describe("/api/global/users", () => {
|
|
|
269
277
|
const user = await config.createUser()
|
|
270
278
|
jest.clearAllMocks()
|
|
271
279
|
|
|
272
|
-
await api.users.saveUser(user)
|
|
280
|
+
await config.api.users.saveUser(user)
|
|
273
281
|
|
|
274
282
|
expect(events.user.created).not.toBeCalled()
|
|
275
283
|
expect(events.user.updated).toBeCalledTimes(1)
|
|
@@ -284,7 +292,7 @@ describe("/api/global/users", () => {
|
|
|
284
292
|
|
|
285
293
|
user.forceResetPassword = true
|
|
286
294
|
user.password = "tempPassword"
|
|
287
|
-
await api.users.saveUser(user)
|
|
295
|
+
await config.api.users.saveUser(user)
|
|
288
296
|
|
|
289
297
|
expect(events.user.created).not.toBeCalled()
|
|
290
298
|
expect(events.user.updated).toBeCalledTimes(1)
|
|
@@ -297,7 +305,7 @@ describe("/api/global/users", () => {
|
|
|
297
305
|
const user = await config.createUser()
|
|
298
306
|
jest.clearAllMocks()
|
|
299
307
|
|
|
300
|
-
await api.users.saveUser(structures.users.adminUser(user))
|
|
308
|
+
await config.api.users.saveUser(structures.users.adminUser(user))
|
|
301
309
|
|
|
302
310
|
expect(events.user.created).not.toBeCalled()
|
|
303
311
|
expect(events.user.updated).toBeCalledTimes(1)
|
|
@@ -309,7 +317,7 @@ describe("/api/global/users", () => {
|
|
|
309
317
|
const user = await config.createUser()
|
|
310
318
|
jest.clearAllMocks()
|
|
311
319
|
|
|
312
|
-
await api.users.saveUser(structures.users.builderUser(user))
|
|
320
|
+
await config.api.users.saveUser(structures.users.builderUser(user))
|
|
313
321
|
|
|
314
322
|
expect(events.user.created).not.toBeCalled()
|
|
315
323
|
expect(events.user.updated).toBeCalledTimes(1)
|
|
@@ -323,7 +331,7 @@ describe("/api/global/users", () => {
|
|
|
323
331
|
user.admin!.global = false
|
|
324
332
|
user.builder!.global = false
|
|
325
333
|
|
|
326
|
-
await api.users.saveUser(user)
|
|
334
|
+
await config.api.users.saveUser(user)
|
|
327
335
|
|
|
328
336
|
expect(events.user.created).not.toBeCalled()
|
|
329
337
|
expect(events.user.updated).toBeCalledTimes(1)
|
|
@@ -336,7 +344,7 @@ describe("/api/global/users", () => {
|
|
|
336
344
|
jest.clearAllMocks()
|
|
337
345
|
user.builder!.global = false
|
|
338
346
|
|
|
339
|
-
await api.users.saveUser(user)
|
|
347
|
+
await config.api.users.saveUser(user)
|
|
340
348
|
|
|
341
349
|
expect(events.user.created).not.toBeCalled()
|
|
342
350
|
expect(events.user.updated).toBeCalledTimes(1)
|
|
@@ -352,7 +360,7 @@ describe("/api/global/users", () => {
|
|
|
352
360
|
app_456: "role2",
|
|
353
361
|
}
|
|
354
362
|
|
|
355
|
-
await api.users.saveUser(user)
|
|
363
|
+
await config.api.users.saveUser(user)
|
|
356
364
|
|
|
357
365
|
const savedUser = await config.getUser(user.email)
|
|
358
366
|
expect(events.user.created).not.toBeCalled()
|
|
@@ -372,7 +380,7 @@ describe("/api/global/users", () => {
|
|
|
372
380
|
jest.clearAllMocks()
|
|
373
381
|
user.roles = {}
|
|
374
382
|
|
|
375
|
-
await api.users.saveUser(user)
|
|
383
|
+
await config.api.users.saveUser(user)
|
|
376
384
|
|
|
377
385
|
const savedUser = await config.getUser(user.email)
|
|
378
386
|
expect(events.user.created).not.toBeCalled()
|
|
@@ -395,7 +403,7 @@ describe("/api/global/users", () => {
|
|
|
395
403
|
app_456: "role2-edit",
|
|
396
404
|
}
|
|
397
405
|
|
|
398
|
-
await api.users.saveUser(user)
|
|
406
|
+
await config.api.users.saveUser(user)
|
|
399
407
|
|
|
400
408
|
const savedUser = await config.getUser(user.email)
|
|
401
409
|
expect(events.user.created).not.toBeCalled()
|
|
@@ -411,7 +419,7 @@ describe("/api/global/users", () => {
|
|
|
411
419
|
const user = await config.createUser(structures.users.user({ email }))
|
|
412
420
|
user.email = "new@test.com"
|
|
413
421
|
|
|
414
|
-
const response = await api.users.saveUser(user, 400)
|
|
422
|
+
const response = await config.api.users.saveUser(user, 400)
|
|
415
423
|
|
|
416
424
|
const dbUser = await config.getUser(email)
|
|
417
425
|
user.email = email
|
|
@@ -424,7 +432,7 @@ describe("/api/global/users", () => {
|
|
|
424
432
|
it("should not be able to bulk delete current user", async () => {
|
|
425
433
|
const user = await config.defaultUser!
|
|
426
434
|
|
|
427
|
-
const response = await api.users.bulkDeleteUsers([user._id!], 400)
|
|
435
|
+
const response = await config.api.users.bulkDeleteUsers([user._id!], 400)
|
|
428
436
|
|
|
429
437
|
expect(response.message).toBe("Unable to delete self.")
|
|
430
438
|
expect(events.user.deleted).not.toBeCalled()
|
|
@@ -436,7 +444,7 @@ describe("/api/global/users", () => {
|
|
|
436
444
|
account.budibaseUserId = user._id!
|
|
437
445
|
mocks.accounts.getAccountByTenantId.mockReturnValue(account)
|
|
438
446
|
|
|
439
|
-
const response = await api.users.bulkDeleteUsers([user._id!])
|
|
447
|
+
const response = await config.api.users.bulkDeleteUsers([user._id!])
|
|
440
448
|
|
|
441
449
|
expect(response.deleted?.successful.length).toBe(0)
|
|
442
450
|
expect(response.deleted?.unsuccessful.length).toBe(1)
|
|
@@ -454,7 +462,7 @@ describe("/api/global/users", () => {
|
|
|
454
462
|
const builder = structures.users.builderUser()
|
|
455
463
|
const admin = structures.users.adminUser()
|
|
456
464
|
const user = structures.users.user()
|
|
457
|
-
const createdUsers = await api.users.bulkCreateUsers([
|
|
465
|
+
const createdUsers = await config.api.users.bulkCreateUsers([
|
|
458
466
|
builder,
|
|
459
467
|
admin,
|
|
460
468
|
user,
|
|
@@ -463,7 +471,7 @@ describe("/api/global/users", () => {
|
|
|
463
471
|
const toDelete = createdUsers.created?.successful.map(
|
|
464
472
|
u => u._id!
|
|
465
473
|
) as string[]
|
|
466
|
-
const response = await api.users.bulkDeleteUsers(toDelete)
|
|
474
|
+
const response = await config.api.users.bulkDeleteUsers(toDelete)
|
|
467
475
|
|
|
468
476
|
expect(response.deleted?.successful.length).toBe(3)
|
|
469
477
|
expect(response.deleted?.unsuccessful.length).toBe(0)
|
|
@@ -478,7 +486,7 @@ describe("/api/global/users", () => {
|
|
|
478
486
|
const user = await config.createUser()
|
|
479
487
|
jest.clearAllMocks()
|
|
480
488
|
|
|
481
|
-
await api.users.deleteUser(user._id!)
|
|
489
|
+
await config.api.users.deleteUser(user._id!)
|
|
482
490
|
|
|
483
491
|
expect(events.user.deleted).toBeCalledTimes(1)
|
|
484
492
|
expect(events.user.permissionBuilderRemoved).not.toBeCalled()
|
|
@@ -489,7 +497,7 @@ describe("/api/global/users", () => {
|
|
|
489
497
|
const user = await config.createUser(structures.users.adminUser())
|
|
490
498
|
jest.clearAllMocks()
|
|
491
499
|
|
|
492
|
-
await api.users.deleteUser(user._id!)
|
|
500
|
+
await config.api.users.deleteUser(user._id!)
|
|
493
501
|
|
|
494
502
|
expect(events.user.deleted).toBeCalledTimes(1)
|
|
495
503
|
expect(events.user.permissionBuilderRemoved).toBeCalledTimes(1)
|
|
@@ -500,7 +508,7 @@ describe("/api/global/users", () => {
|
|
|
500
508
|
const user = await config.createUser(structures.users.builderUser())
|
|
501
509
|
jest.clearAllMocks()
|
|
502
510
|
|
|
503
|
-
await api.users.deleteUser(user._id!)
|
|
511
|
+
await config.api.users.deleteUser(user._id!)
|
|
504
512
|
|
|
505
513
|
expect(events.user.deleted).toBeCalledTimes(1)
|
|
506
514
|
expect(events.user.permissionBuilderRemoved).toBeCalledTimes(1)
|
|
@@ -512,7 +520,7 @@ describe("/api/global/users", () => {
|
|
|
512
520
|
const account = structures.accounts.cloudAccount()
|
|
513
521
|
mocks.accounts.getAccount.mockReturnValueOnce(account)
|
|
514
522
|
|
|
515
|
-
const response = await api.users.deleteUser(user._id!, 400)
|
|
523
|
+
const response = await config.api.users.deleteUser(user._id!, 400)
|
|
516
524
|
|
|
517
525
|
expect(response.body.message).toBe("Account holder cannot be deleted")
|
|
518
526
|
})
|
|
@@ -523,7 +531,7 @@ describe("/api/global/users", () => {
|
|
|
523
531
|
account.email = user.email
|
|
524
532
|
mocks.accounts.getAccount.mockReturnValueOnce(account)
|
|
525
533
|
|
|
526
|
-
const response = await api.users.deleteUser(user._id!, 400)
|
|
534
|
+
const response = await config.api.users.deleteUser(user._id!, 400)
|
|
527
535
|
|
|
528
536
|
expect(response.body.message).toBe("Unable to delete self.")
|
|
529
537
|
})
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { TestConfiguration } from "../../../../tests"
|
|
2
|
+
|
|
3
|
+
// TODO
|
|
4
|
+
|
|
5
|
+
describe("/api/global/workspaces", () => {
|
|
6
|
+
const config = new TestConfiguration()
|
|
7
|
+
|
|
8
|
+
beforeAll(async () => {
|
|
9
|
+
await config.beforeAll()
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
afterAll(async () => {
|
|
13
|
+
await config.afterAll()
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
jest.clearAllMocks()
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
describe("GET /api/global/workspaces", () => {
|
|
21
|
+
it("retrieves workspaces", () => {})
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
describe("DELETE /api/global/workspaces/:id", () => {})
|
|
25
|
+
|
|
26
|
+
describe("GET /api/global/workspaces", () => {})
|
|
27
|
+
|
|
28
|
+
describe("GET /api/global/workspaces/:id", () => {})
|
|
29
|
+
})
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const selfController = require("../../controllers/global/self")
|
|
9
|
-
const { builderOrAdmin } = require("@budibase/backend-core/auth")
|
|
1
|
+
import Router from "@koa/router"
|
|
2
|
+
import * as controller from "../../controllers/global/users"
|
|
3
|
+
import { auth } from "@budibase/backend-core"
|
|
4
|
+
import Joi from "joi"
|
|
5
|
+
import cloudRestricted from "../../../middleware/cloudRestricted"
|
|
6
|
+
import { users } from "../validation"
|
|
7
|
+
import * as selfController from "../../controllers/global/self"
|
|
10
8
|
|
|
11
|
-
const router = new Router()
|
|
9
|
+
const router: Router = new Router()
|
|
12
10
|
|
|
13
11
|
function buildAdminInitValidation() {
|
|
14
|
-
return joiValidator.body(
|
|
12
|
+
return auth.joiValidator.body(
|
|
15
13
|
Joi.object({
|
|
16
14
|
email: Joi.string().required(),
|
|
17
15
|
password: Joi.string(),
|
|
@@ -24,7 +22,7 @@ function buildAdminInitValidation() {
|
|
|
24
22
|
|
|
25
23
|
function buildInviteValidation() {
|
|
26
24
|
// prettier-ignore
|
|
27
|
-
return joiValidator.body(Joi.object({
|
|
25
|
+
return auth.joiValidator.body(Joi.object({
|
|
28
26
|
email: Joi.string().required(),
|
|
29
27
|
userInfo: Joi.object().optional(),
|
|
30
28
|
}).required())
|
|
@@ -32,7 +30,7 @@ function buildInviteValidation() {
|
|
|
32
30
|
|
|
33
31
|
function buildInviteMultipleValidation() {
|
|
34
32
|
// prettier-ignore
|
|
35
|
-
return joiValidator.body(Joi.array().required().items(
|
|
33
|
+
return auth.joiValidator.body(Joi.array().required().items(
|
|
36
34
|
Joi.object({
|
|
37
35
|
email: Joi.string(),
|
|
38
36
|
userInfo: Joi.object().optional(),
|
|
@@ -42,7 +40,7 @@ function buildInviteMultipleValidation() {
|
|
|
42
40
|
|
|
43
41
|
function buildInviteAcceptValidation() {
|
|
44
42
|
// prettier-ignore
|
|
45
|
-
return joiValidator.body(Joi.object({
|
|
43
|
+
return auth.joiValidator.body(Joi.object({
|
|
46
44
|
inviteCode: Joi.string().required(),
|
|
47
45
|
password: Joi.string().required(),
|
|
48
46
|
}).required().unknown(true))
|
|
@@ -51,31 +49,35 @@ function buildInviteAcceptValidation() {
|
|
|
51
49
|
router
|
|
52
50
|
.post(
|
|
53
51
|
"/api/global/users",
|
|
54
|
-
adminOnly,
|
|
52
|
+
auth.adminOnly,
|
|
55
53
|
users.buildUserSaveValidation(),
|
|
56
54
|
controller.save
|
|
57
55
|
)
|
|
58
56
|
.post(
|
|
59
57
|
"/api/global/users/bulk",
|
|
60
|
-
adminOnly,
|
|
58
|
+
auth.adminOnly,
|
|
61
59
|
users.buildUserBulkUserValidation(),
|
|
62
60
|
controller.bulkUpdate
|
|
63
61
|
)
|
|
64
62
|
|
|
65
|
-
.get("/api/global/users", builderOrAdmin, controller.fetch)
|
|
66
|
-
.post("/api/global/users/search", builderOrAdmin, controller.search)
|
|
67
|
-
.delete("/api/global/users/:id", adminOnly, controller.destroy)
|
|
68
|
-
.get(
|
|
63
|
+
.get("/api/global/users", auth.builderOrAdmin, controller.fetch)
|
|
64
|
+
.post("/api/global/users/search", auth.builderOrAdmin, controller.search)
|
|
65
|
+
.delete("/api/global/users/:id", auth.adminOnly, controller.destroy)
|
|
66
|
+
.get(
|
|
67
|
+
"/api/global/users/count/:appId",
|
|
68
|
+
auth.builderOrAdmin,
|
|
69
|
+
controller.countByApp
|
|
70
|
+
)
|
|
69
71
|
.get("/api/global/roles/:appId")
|
|
70
72
|
.post(
|
|
71
73
|
"/api/global/users/invite",
|
|
72
|
-
adminOnly,
|
|
74
|
+
auth.adminOnly,
|
|
73
75
|
buildInviteValidation(),
|
|
74
76
|
controller.invite
|
|
75
77
|
)
|
|
76
78
|
.post(
|
|
77
79
|
"/api/global/users/multi/invite",
|
|
78
|
-
adminOnly,
|
|
80
|
+
auth.adminOnly,
|
|
79
81
|
buildInviteMultipleValidation(),
|
|
80
82
|
controller.inviteMultiple
|
|
81
83
|
)
|
|
@@ -94,7 +96,7 @@ router
|
|
|
94
96
|
)
|
|
95
97
|
.get("/api/global/users/tenant/:id", controller.tenantUserLookup)
|
|
96
98
|
// global endpoint but needs to come at end (blocks other endpoints otherwise)
|
|
97
|
-
.get("/api/global/users/:id", builderOrAdmin, controller.find)
|
|
99
|
+
.get("/api/global/users/:id", auth.builderOrAdmin, controller.find)
|
|
98
100
|
// DEPRECATED - use new versions with self API
|
|
99
101
|
.get("/api/global/users/self", selfController.getSelf)
|
|
100
102
|
.post(
|
|
@@ -103,4 +105,4 @@ router
|
|
|
103
105
|
selfController.updateSelf
|
|
104
106
|
)
|
|
105
107
|
|
|
106
|
-
|
|
108
|
+
export = router
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const Joi = require("joi")
|
|
1
|
+
import Router from "@koa/router"
|
|
2
|
+
import * as controller from "../../controllers/global/workspaces"
|
|
3
|
+
import { auth } from "@budibase/backend-core"
|
|
4
|
+
import Joi from "joi"
|
|
6
5
|
|
|
7
|
-
const router = new Router()
|
|
6
|
+
const router: Router = new Router()
|
|
8
7
|
|
|
9
8
|
function buildWorkspaceSaveValidation() {
|
|
10
9
|
// prettier-ignore
|
|
11
|
-
return joiValidator.body(Joi.object({
|
|
10
|
+
return auth.joiValidator.body(Joi.object({
|
|
12
11
|
_id: Joi.string().optional(),
|
|
13
12
|
_rev: Joi.string().optional(),
|
|
14
13
|
name: Joi.string().required(),
|
|
@@ -27,12 +26,12 @@ function buildWorkspaceSaveValidation() {
|
|
|
27
26
|
router
|
|
28
27
|
.post(
|
|
29
28
|
"/api/global/workspaces",
|
|
30
|
-
adminOnly,
|
|
29
|
+
auth.adminOnly,
|
|
31
30
|
buildWorkspaceSaveValidation(),
|
|
32
31
|
controller.save
|
|
33
32
|
)
|
|
34
|
-
.delete("/api/global/workspaces/:id", adminOnly, controller.destroy)
|
|
33
|
+
.delete("/api/global/workspaces/:id", auth.adminOnly, controller.destroy)
|
|
35
34
|
.get("/api/global/workspaces", controller.fetch)
|
|
36
35
|
.get("/api/global/workspaces/:id", controller.find)
|
|
37
36
|
|
|
38
|
-
|
|
37
|
+
export = router
|
package/src/api/routes/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import Router from "@koa/router"
|
|
1
2
|
import { api } from "@budibase/pro"
|
|
2
3
|
import userRoutes from "./global/users"
|
|
3
4
|
import configRoutes from "./global/configs"
|
|
@@ -16,7 +17,7 @@ import accountRoutes from "./system/accounts"
|
|
|
16
17
|
import restoreRoutes from "./system/restore"
|
|
17
18
|
|
|
18
19
|
let userGroupRoutes = api.groups
|
|
19
|
-
export const routes = [
|
|
20
|
+
export const routes: Router[] = [
|
|
20
21
|
configRoutes,
|
|
21
22
|
userRoutes,
|
|
22
23
|
workspaceRoutes,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import Router from "@koa/router"
|
|
2
|
+
import * as controller from "../../controllers/system/tenants"
|
|
3
|
+
import { middleware } from "@budibase/backend-core"
|
|
4
|
+
|
|
5
|
+
const router: Router = new Router()
|
|
6
|
+
|
|
7
|
+
router.delete(
|
|
8
|
+
"/api/system/tenants/:tenantId",
|
|
9
|
+
middleware.adminOnly,
|
|
10
|
+
controller.delete
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
export = router
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import sdk from "../../../../sdk"
|
|
2
|
-
import { TestConfiguration, structures
|
|
2
|
+
import { TestConfiguration, structures } from "../../../../tests"
|
|
3
3
|
import { v4 as uuid } from "uuid"
|
|
4
4
|
|
|
5
5
|
describe("accounts", () => {
|
|
6
6
|
const config = new TestConfiguration()
|
|
7
|
-
const api = new API(config)
|
|
8
7
|
|
|
9
8
|
beforeAll(async () => {
|
|
10
9
|
await config.beforeAll()
|
|
@@ -23,7 +22,7 @@ describe("accounts", () => {
|
|
|
23
22
|
it("saves account metadata", async () => {
|
|
24
23
|
let account = structures.accounts.account()
|
|
25
24
|
|
|
26
|
-
const response = await api.accounts.saveMetadata(account)
|
|
25
|
+
const response = await config.api.accounts.saveMetadata(account)
|
|
27
26
|
|
|
28
27
|
const id = sdk.accounts.formatAccountMetadataId(account.accountId)
|
|
29
28
|
const metadata = await sdk.accounts.getMetadata(id)
|
|
@@ -34,9 +33,9 @@ describe("accounts", () => {
|
|
|
34
33
|
describe("destroyMetadata", () => {
|
|
35
34
|
it("destroys account metadata", async () => {
|
|
36
35
|
const account = structures.accounts.account()
|
|
37
|
-
await api.accounts.saveMetadata(account)
|
|
36
|
+
await config.api.accounts.saveMetadata(account)
|
|
38
37
|
|
|
39
|
-
await api.accounts.destroyMetadata(account.accountId)
|
|
38
|
+
await config.api.accounts.destroyMetadata(account.accountId)
|
|
40
39
|
|
|
41
40
|
const deleted = await sdk.accounts.getMetadata(account.accountId)
|
|
42
41
|
expect(deleted).toBe(undefined)
|
|
@@ -45,7 +44,7 @@ describe("accounts", () => {
|
|
|
45
44
|
it("destroys account metadata that does not exist", async () => {
|
|
46
45
|
const id = uuid()
|
|
47
46
|
|
|
48
|
-
const response = await api.accounts.destroyMetadata(id)
|
|
47
|
+
const response = await config.api.accounts.destroyMetadata(id)
|
|
49
48
|
|
|
50
49
|
expect(response.status).toBe(204)
|
|
51
50
|
})
|