@budibase/worker 2.6.8-alpha.2 → 2.6.8-alpha.6
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/worker",
|
|
3
3
|
"email": "hi@budibase.com",
|
|
4
|
-
"version": "2.6.8-alpha.
|
|
4
|
+
"version": "2.6.8-alpha.6",
|
|
5
5
|
"description": "Budibase background service",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"author": "Budibase",
|
|
38
38
|
"license": "GPL-3.0",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@budibase/backend-core": "2.6.8-alpha.
|
|
41
|
-
"@budibase/pro": "2.6.8-alpha.
|
|
42
|
-
"@budibase/string-templates": "2.6.8-alpha.
|
|
43
|
-
"@budibase/types": "2.6.8-alpha.
|
|
40
|
+
"@budibase/backend-core": "2.6.8-alpha.6",
|
|
41
|
+
"@budibase/pro": "2.6.8-alpha.6",
|
|
42
|
+
"@budibase/string-templates": "2.6.8-alpha.6",
|
|
43
|
+
"@budibase/types": "2.6.8-alpha.6",
|
|
44
44
|
"@koa/router": "8.0.8",
|
|
45
45
|
"@sentry/node": "6.17.7",
|
|
46
46
|
"@techpass/passport-openidconnect": "0.3.2",
|
|
@@ -102,5 +102,5 @@
|
|
|
102
102
|
"typescript": "4.7.3",
|
|
103
103
|
"update-dotenv": "1.1.1"
|
|
104
104
|
},
|
|
105
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "1f8cbc54b04c655b204813748d415400c886d9c5"
|
|
106
106
|
}
|
|
@@ -69,9 +69,11 @@ const bulkCreate = async (users: User[], groupIds: string[]) => {
|
|
|
69
69
|
return await userSdk.bulkCreate(users, groupIds)
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
export const bulkUpdate = async (
|
|
72
|
+
export const bulkUpdate = async (
|
|
73
|
+
ctx: Ctx<BulkUserRequest, BulkUserResponse>
|
|
74
|
+
) => {
|
|
73
75
|
const currentUserId = ctx.user._id
|
|
74
|
-
const input = ctx.request.body
|
|
76
|
+
const input = ctx.request.body
|
|
75
77
|
let created, deleted
|
|
76
78
|
try {
|
|
77
79
|
if (input.create) {
|
|
@@ -83,7 +85,7 @@ export const bulkUpdate = async (ctx: any) => {
|
|
|
83
85
|
} catch (err: any) {
|
|
84
86
|
ctx.throw(err.status || 400, err?.message || err)
|
|
85
87
|
}
|
|
86
|
-
ctx.body = { created, deleted }
|
|
88
|
+
ctx.body = { created, deleted }
|
|
87
89
|
}
|
|
88
90
|
|
|
89
91
|
const parseBooleanParam = (param: any) => {
|
|
@@ -184,15 +186,15 @@ export const destroy = async (ctx: any) => {
|
|
|
184
186
|
}
|
|
185
187
|
}
|
|
186
188
|
|
|
187
|
-
export const getAppUsers = async (ctx:
|
|
188
|
-
const body = ctx.request.body
|
|
189
|
+
export const getAppUsers = async (ctx: Ctx<SearchUsersRequest>) => {
|
|
190
|
+
const body = ctx.request.body
|
|
189
191
|
const users = await userSdk.getUsersByAppAccess(body?.appId)
|
|
190
192
|
|
|
191
193
|
ctx.body = { data: users }
|
|
192
194
|
}
|
|
193
195
|
|
|
194
|
-
export const search = async (ctx:
|
|
195
|
-
const body = ctx.request.body
|
|
196
|
+
export const search = async (ctx: Ctx<SearchUsersRequest>) => {
|
|
197
|
+
const body = ctx.request.body
|
|
196
198
|
|
|
197
199
|
if (body.paginated === false) {
|
|
198
200
|
await getAppUsers(ctx)
|
|
@@ -238,8 +240,8 @@ export const tenantUserLookup = async (ctx: any) => {
|
|
|
238
240
|
/*
|
|
239
241
|
Encapsulate the app user onboarding flows here.
|
|
240
242
|
*/
|
|
241
|
-
export const onboardUsers = async (ctx:
|
|
242
|
-
const request = ctx.request.body
|
|
243
|
+
export const onboardUsers = async (ctx: Ctx<InviteUsersRequest>) => {
|
|
244
|
+
const request = ctx.request.body
|
|
243
245
|
const isBulkCreate = "create" in request
|
|
244
246
|
|
|
245
247
|
const emailConfigured = await isEmailConfigured()
|
|
@@ -255,7 +257,7 @@ export const onboardUsers = async (ctx: any) => {
|
|
|
255
257
|
} else if (emailConfigured) {
|
|
256
258
|
onboardingResponse = await inviteMultiple(ctx)
|
|
257
259
|
} else if (!emailConfigured) {
|
|
258
|
-
const inviteRequest = ctx.request.body
|
|
260
|
+
const inviteRequest = ctx.request.body
|
|
259
261
|
|
|
260
262
|
let createdPasswords: any = {}
|
|
261
263
|
|
|
@@ -295,10 +297,10 @@ export const onboardUsers = async (ctx: any) => {
|
|
|
295
297
|
}
|
|
296
298
|
}
|
|
297
299
|
|
|
298
|
-
export const invite = async (ctx:
|
|
299
|
-
const request = ctx.request.body
|
|
300
|
+
export const invite = async (ctx: Ctx<InviteUserRequest>) => {
|
|
301
|
+
const request = ctx.request.body
|
|
300
302
|
|
|
301
|
-
let multiRequest = [request]
|
|
303
|
+
let multiRequest = [request]
|
|
302
304
|
const response = await userSdk.invite(multiRequest)
|
|
303
305
|
|
|
304
306
|
// explicitly throw for single user invite
|
|
@@ -318,8 +320,8 @@ export const invite = async (ctx: any) => {
|
|
|
318
320
|
}
|
|
319
321
|
}
|
|
320
322
|
|
|
321
|
-
export const inviteMultiple = async (ctx:
|
|
322
|
-
const request = ctx.request.body
|
|
323
|
+
export const inviteMultiple = async (ctx: Ctx<InviteUsersRequest>) => {
|
|
324
|
+
const request = ctx.request.body
|
|
323
325
|
ctx.body = await userSdk.invite(request)
|
|
324
326
|
}
|
|
325
327
|
|
|
@@ -424,7 +426,6 @@ export const inviteAccept = async (
|
|
|
424
426
|
if (err.code === ErrorCode.USAGE_LIMIT_EXCEEDED) {
|
|
425
427
|
// explicitly re-throw limit exceeded errors
|
|
426
428
|
ctx.throw(400, err)
|
|
427
|
-
return
|
|
428
429
|
}
|
|
429
430
|
console.warn("Error inviting user", err)
|
|
430
431
|
ctx.throw(400, "Unable to create new user, invitation invalid.")
|
|
@@ -13,6 +13,7 @@ describe("/api/global/groups", () => {
|
|
|
13
13
|
})
|
|
14
14
|
|
|
15
15
|
beforeEach(async () => {
|
|
16
|
+
jest.resetAllMocks()
|
|
16
17
|
mocks.licenses.useGroups()
|
|
17
18
|
})
|
|
18
19
|
|
|
@@ -24,6 +25,63 @@ describe("/api/global/groups", () => {
|
|
|
24
25
|
expect(events.group.updated).not.toBeCalled()
|
|
25
26
|
expect(events.group.permissionsEdited).not.toBeCalled()
|
|
26
27
|
})
|
|
28
|
+
|
|
29
|
+
it("should not allow undefined names", async () => {
|
|
30
|
+
const group = { ...structures.groups.UserGroup(), name: undefined } as any
|
|
31
|
+
const response = await config.api.groups.saveGroup(group, { expect: 400 })
|
|
32
|
+
expect(JSON.parse(response.text).message).toEqual(
|
|
33
|
+
'Invalid body - "name" is required'
|
|
34
|
+
)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it("should not allow empty names", async () => {
|
|
38
|
+
const group = { ...structures.groups.UserGroup(), name: "" }
|
|
39
|
+
const response = await config.api.groups.saveGroup(group, { expect: 400 })
|
|
40
|
+
expect(JSON.parse(response.text).message).toEqual(
|
|
41
|
+
'Invalid body - "name" is not allowed to be empty'
|
|
42
|
+
)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it("should not allow whitespace names", async () => {
|
|
46
|
+
const group = { ...structures.groups.UserGroup(), name: " " }
|
|
47
|
+
const response = await config.api.groups.saveGroup(group, { expect: 400 })
|
|
48
|
+
expect(JSON.parse(response.text).message).toEqual(
|
|
49
|
+
'Invalid body - "name" is not allowed to be empty'
|
|
50
|
+
)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it("should trim names", async () => {
|
|
54
|
+
const group = { ...structures.groups.UserGroup(), name: " group name " }
|
|
55
|
+
await config.api.groups.saveGroup(group)
|
|
56
|
+
expect(events.group.created).toBeCalledWith(
|
|
57
|
+
expect.objectContaining({ name: "group name" })
|
|
58
|
+
)
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
describe("name max length", () => {
|
|
62
|
+
const maxLength = 50
|
|
63
|
+
|
|
64
|
+
it(`should allow names shorter than ${maxLength} characters`, async () => {
|
|
65
|
+
const group = {
|
|
66
|
+
...structures.groups.UserGroup(),
|
|
67
|
+
name: structures.generator.word({ length: maxLength }),
|
|
68
|
+
}
|
|
69
|
+
await config.api.groups.saveGroup(group, { expect: 200 })
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it(`should not allow names longer than ${maxLength} characters`, async () => {
|
|
73
|
+
const group = {
|
|
74
|
+
...structures.groups.UserGroup(),
|
|
75
|
+
name: structures.generator.word({ length: maxLength + 1 }),
|
|
76
|
+
}
|
|
77
|
+
const response = await config.api.groups.saveGroup(group, {
|
|
78
|
+
expect: 400,
|
|
79
|
+
})
|
|
80
|
+
expect(JSON.parse(response.text).message).toEqual(
|
|
81
|
+
'Invalid body - "name" length must be less than or equal to 50 characters long'
|
|
82
|
+
)
|
|
83
|
+
})
|
|
84
|
+
})
|
|
27
85
|
})
|
|
28
86
|
|
|
29
87
|
describe("update", () => {
|
package/src/tests/api/groups.ts
CHANGED
|
@@ -7,13 +7,13 @@ export class GroupsAPI extends TestAPI {
|
|
|
7
7
|
super(config)
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
saveGroup = (group: UserGroup) => {
|
|
10
|
+
saveGroup = (group: UserGroup, { expect } = { expect: 200 }) => {
|
|
11
11
|
return this.request
|
|
12
12
|
.post(`/api/global/groups`)
|
|
13
13
|
.send(group)
|
|
14
14
|
.set(this.config.defaultHeaders())
|
|
15
15
|
.expect("Content-Type", /json/)
|
|
16
|
-
.expect(
|
|
16
|
+
.expect(expect)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
deleteGroup = (id: string, rev: string) => {
|