@budibase/worker 3.31.3 → 3.31.5
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": "3.31.
|
|
4
|
+
"version": "3.31.5",
|
|
5
5
|
"description": "Budibase background service",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"@govtechsg/passport-openidconnect": "1.0.3",
|
|
38
38
|
"@koa/router": "15.3.0",
|
|
39
39
|
"@types/global-agent": "2.1.1",
|
|
40
|
+
"aws-sdk": "2.1692.0",
|
|
40
41
|
"bcrypt": "6.0.0",
|
|
41
42
|
"bull": "4.10.1",
|
|
42
43
|
"dd-trace": "5.63.0",
|
|
@@ -47,19 +48,28 @@
|
|
|
47
48
|
"ical-generator": "4.1.0",
|
|
48
49
|
"joi": "17.6.0",
|
|
49
50
|
"jsonwebtoken": "9.0.2",
|
|
51
|
+
"knex": "2.4.2",
|
|
50
52
|
"koa": "2.15.4",
|
|
51
53
|
"koa-body": "4.2.0",
|
|
52
54
|
"koa-compress": "4.0.1",
|
|
55
|
+
"koa-passport": "4.1.4",
|
|
53
56
|
"koa-redis": "^4.0.1",
|
|
57
|
+
"koa-send": "5.0.1",
|
|
54
58
|
"koa-session": "5.13.1",
|
|
59
|
+
"koa-static": "5.0.0",
|
|
55
60
|
"koa-useragent": "^4.1.0",
|
|
56
61
|
"lodash": "4.17.23",
|
|
57
62
|
"marked": "^15.0.11",
|
|
58
63
|
"node-fetch": "2.6.7",
|
|
59
64
|
"nodemailer": "7.0.11",
|
|
65
|
+
"passport-google-oauth": "2.0.0",
|
|
66
|
+
"passport-local": "1.0.0",
|
|
60
67
|
"pouchdb": "9.0.0",
|
|
68
|
+
"pouchdb-all-dbs": "1.1.1",
|
|
61
69
|
"scim-patch": "^0.8.1",
|
|
62
70
|
"scim2-parse-filter": "^0.2.8",
|
|
71
|
+
"server-destroy": "1.0.1",
|
|
72
|
+
"undici": "^7.16.0",
|
|
63
73
|
"uuid": "^8.3.2",
|
|
64
74
|
"yaml": "^2.8.2"
|
|
65
75
|
},
|
|
@@ -69,6 +79,7 @@
|
|
|
69
79
|
"@types/maildev": "^0.0.7",
|
|
70
80
|
"@types/node-fetch": "2.6.4",
|
|
71
81
|
"@types/nodemailer": "^6.4.17",
|
|
82
|
+
"@types/server-destroy": "1.0.1",
|
|
72
83
|
"@types/supertest": "2.0.14",
|
|
73
84
|
"@types/uuid": "8.3.4",
|
|
74
85
|
"cheerio": "^1.0.0",
|
|
@@ -80,5 +91,5 @@
|
|
|
80
91
|
"supertest": "6.3.3",
|
|
81
92
|
"timekeeper": "2.2.0"
|
|
82
93
|
},
|
|
83
|
-
"gitHead": "
|
|
94
|
+
"gitHead": "8b6307f21fc1e0496119295b4417d57e13857c6a"
|
|
84
95
|
}
|
|
@@ -14,6 +14,19 @@ import {
|
|
|
14
14
|
} from "@budibase/types"
|
|
15
15
|
import { db, groups, users as usersSdk } from "@budibase/pro"
|
|
16
16
|
|
|
17
|
+
const DEFAULT_PAGE_SIZE = 10
|
|
18
|
+
|
|
19
|
+
function parsePageSize(pageSize: unknown) {
|
|
20
|
+
if (pageSize === undefined || pageSize === null) {
|
|
21
|
+
return DEFAULT_PAGE_SIZE
|
|
22
|
+
}
|
|
23
|
+
const parsedPageSize = Number(pageSize)
|
|
24
|
+
if (!Number.isFinite(parsedPageSize) || parsedPageSize < 1) {
|
|
25
|
+
return DEFAULT_PAGE_SIZE
|
|
26
|
+
}
|
|
27
|
+
return Math.floor(parsedPageSize)
|
|
28
|
+
}
|
|
29
|
+
|
|
17
30
|
export async function save(ctx: UserCtx) {
|
|
18
31
|
const group: UserGroup = ctx.request.body
|
|
19
32
|
group.name = group.name.trim()
|
|
@@ -101,7 +114,8 @@ export async function find(ctx: UserCtx) {
|
|
|
101
114
|
}
|
|
102
115
|
|
|
103
116
|
export async function searchUsers(ctx: Ctx<{}, SearchUserGroupResponse>) {
|
|
104
|
-
const {
|
|
117
|
+
const { bookmark, emailSearch } = ctx.request.query as any
|
|
118
|
+
const pageSize = parsePageSize((ctx.request.query as any).pageSize)
|
|
105
119
|
const groupId = ctx.params.groupId
|
|
106
120
|
|
|
107
121
|
const params: DatabaseQueryOpts = { limit: pageSize + 1 }
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
jest.mock("@budibase/pro", () => ({
|
|
2
|
+
db: {
|
|
3
|
+
groups: {
|
|
4
|
+
getGroupUsers: jest.fn(),
|
|
5
|
+
},
|
|
6
|
+
},
|
|
7
|
+
groups: {},
|
|
8
|
+
users: {},
|
|
9
|
+
csv: {},
|
|
10
|
+
}))
|
|
11
|
+
|
|
12
|
+
import { db } from "@budibase/pro"
|
|
13
|
+
import { searchUsers } from "../groups"
|
|
14
|
+
|
|
15
|
+
const createCtx = (pageSize: string): Parameters<typeof searchUsers>[0] =>
|
|
16
|
+
({
|
|
17
|
+
request: {
|
|
18
|
+
query: {
|
|
19
|
+
pageSize,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
params: {
|
|
23
|
+
groupId: "group_1",
|
|
24
|
+
},
|
|
25
|
+
body: undefined,
|
|
26
|
+
}) as unknown as Parameters<typeof searchUsers>[0]
|
|
27
|
+
|
|
28
|
+
describe("Global groups controller", () => {
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
jest.clearAllMocks()
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it("coerces pageSize query param to a number before computing limit", async () => {
|
|
34
|
+
const getGroupUsers = db.groups.getGroupUsers as jest.Mock
|
|
35
|
+
getGroupUsers.mockResolvedValue(
|
|
36
|
+
Array.from({ length: 6 }).map((_, i) => ({
|
|
37
|
+
_id: `user_${i}`,
|
|
38
|
+
email: `user_${i}@example.com`,
|
|
39
|
+
}))
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
const ctx = createCtx("5")
|
|
43
|
+
|
|
44
|
+
await searchUsers(ctx)
|
|
45
|
+
|
|
46
|
+
expect(getGroupUsers).toHaveBeenCalledWith("group_1", {
|
|
47
|
+
limit: 6,
|
|
48
|
+
emailSearch: undefined,
|
|
49
|
+
bookmark: undefined,
|
|
50
|
+
})
|
|
51
|
+
expect(ctx.body).toEqual({
|
|
52
|
+
users: [
|
|
53
|
+
{ _id: "user_0", email: "user_0@example.com" },
|
|
54
|
+
{ _id: "user_1", email: "user_1@example.com" },
|
|
55
|
+
{ _id: "user_2", email: "user_2@example.com" },
|
|
56
|
+
{ _id: "user_3", email: "user_3@example.com" },
|
|
57
|
+
{ _id: "user_4", email: "user_4@example.com" },
|
|
58
|
+
],
|
|
59
|
+
bookmark: "user_5",
|
|
60
|
+
hasNextPage: true,
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it("falls back to the default page size for invalid query values", async () => {
|
|
65
|
+
const getGroupUsers = db.groups.getGroupUsers as jest.Mock
|
|
66
|
+
getGroupUsers.mockResolvedValue(
|
|
67
|
+
Array.from({ length: 11 }).map((_, i) => ({
|
|
68
|
+
_id: `user_${i}`,
|
|
69
|
+
email: `user_${i}@example.com`,
|
|
70
|
+
}))
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
const ctx = createCtx("not-a-number")
|
|
74
|
+
|
|
75
|
+
await searchUsers(ctx)
|
|
76
|
+
|
|
77
|
+
expect(getGroupUsers).toHaveBeenCalledWith("group_1", {
|
|
78
|
+
limit: 11,
|
|
79
|
+
emailSearch: undefined,
|
|
80
|
+
bookmark: undefined,
|
|
81
|
+
})
|
|
82
|
+
expect(ctx.body.users).toHaveLength(10)
|
|
83
|
+
})
|
|
84
|
+
})
|