@budibase/worker 1.3.17 → 1.3.19-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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/worker",
3
3
  "email": "hi@budibase.com",
4
- "version": "1.3.17",
4
+ "version": "1.3.19-alpha.0",
5
5
  "description": "Budibase background service",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -23,6 +23,7 @@
23
23
  "dev:stack:init": "node ./scripts/dev/manage.js init",
24
24
  "dev:builder": "npm run dev:stack:init && nodemon",
25
25
  "test": "jest --runInBand",
26
+ "test:watch": "jest --watch",
26
27
  "env:multi:enable": "node scripts/multiTenancy.js enable",
27
28
  "env:multi:disable": "node scripts/multiTenancy.js disable",
28
29
  "env:selfhost:enable": "node scripts/selfhost.js enable",
@@ -35,10 +36,10 @@
35
36
  "author": "Budibase",
36
37
  "license": "GPL-3.0",
37
38
  "dependencies": {
38
- "@budibase/backend-core": "^1.3.17",
39
- "@budibase/pro": "1.3.16",
40
- "@budibase/string-templates": "^1.3.17",
41
- "@budibase/types": "^1.3.17",
39
+ "@budibase/backend-core": "1.3.19-alpha.0",
40
+ "@budibase/pro": "1.3.18",
41
+ "@budibase/string-templates": "1.3.19-alpha.0",
42
+ "@budibase/types": "1.3.19-alpha.0",
42
43
  "@koa/router": "8.0.8",
43
44
  "@sentry/node": "6.17.7",
44
45
  "@techpass/passport-openidconnect": "0.3.2",
@@ -103,5 +104,5 @@
103
104
  "./scripts/jestSetup.js"
104
105
  ]
105
106
  },
106
- "gitHead": "01d7c9d994aa66a1d08ab71acc9e6c8eab825a47"
107
+ "gitHead": "04749bf93a17516f8f71d44b49995b2d50b080bb"
107
108
  }
@@ -242,6 +242,26 @@ describe("/api/global/users", () => {
242
242
  expect(response.body.message).toBe(`Unavailable`)
243
243
  expect(events.user.created).toBeCalledTimes(0)
244
244
  })
245
+
246
+ it("should not be able to create a user with the same email and different casing", async () => {
247
+ const user = structures.users.user()
248
+ await api.users.saveUser(user)
249
+
250
+ user.email = user.email.toUpperCase()
251
+ await api.users.saveUser(user, 400)
252
+
253
+ expect(events.user.created).toBeCalledTimes(1)
254
+ })
255
+
256
+ it("should not be able to bulk create a user with the same email and different casing", async () => {
257
+ const user = structures.users.user()
258
+ await api.users.saveUser(user)
259
+
260
+ user.email = user.email.toUpperCase()
261
+ await api.users.bulkCreateUsers([user])
262
+
263
+ expect(events.user.created).toBeCalledTimes(1)
264
+ })
245
265
  })
246
266
 
247
267
  describe("update", () => {
@@ -278,39 +278,61 @@ export const addTenant = async (
278
278
  }
279
279
 
280
280
  const getExistingTenantUsers = async (emails: string[]): Promise<User[]> => {
281
- return dbUtils.queryGlobalView(ViewName.USER_BY_EMAIL, {
282
- keys: emails,
281
+ const lcEmails = emails.map(email => email.toLowerCase())
282
+ const params = {
283
+ keys: lcEmails,
283
284
  include_docs: true,
285
+ }
286
+
287
+ const opts = {
284
288
  arrayResponse: true,
285
- })
289
+ }
290
+
291
+ return dbUtils.queryGlobalView(
292
+ ViewName.USER_BY_EMAIL,
293
+ params,
294
+ undefined,
295
+ opts
296
+ ) as Promise<User[]>
286
297
  }
287
298
 
288
299
  const getExistingPlatformUsers = async (
289
300
  emails: string[]
290
301
  ): Promise<PlatformUserByEmail[]> => {
291
- return dbUtils.doWithDB(
292
- StaticDatabases.PLATFORM_INFO.name,
293
- async (infoDb: any) => {
294
- const response: AllDocsResponse<PlatformUserByEmail> =
295
- await infoDb.allDocs({
296
- keys: emails,
297
- include_docs: true,
298
- })
299
- return response.rows
300
- .filter(row => row.doc && (row.error !== "not_found") !== null)
301
- .map((row: any) => row.doc)
302
- }
303
- )
302
+ const lcEmails = emails.map(email => email.toLowerCase())
303
+ const params = {
304
+ keys: lcEmails,
305
+ include_docs: true,
306
+ }
307
+
308
+ const opts = {
309
+ arrayResponse: true,
310
+ }
311
+ return dbUtils.queryPlatformView(
312
+ ViewName.PLATFORM_USERS_LOWERCASE,
313
+ params,
314
+ opts
315
+ ) as Promise<PlatformUserByEmail[]>
304
316
  }
305
317
 
306
318
  const getExistingAccounts = async (
307
319
  emails: string[]
308
320
  ): Promise<AccountMetadata[]> => {
309
- return dbUtils.queryPlatformView(ViewName.ACCOUNT_BY_EMAIL, {
310
- keys: emails,
321
+ const lcEmails = emails.map(email => email.toLowerCase())
322
+ const params = {
323
+ keys: lcEmails,
311
324
  include_docs: true,
325
+ }
326
+
327
+ const opts = {
312
328
  arrayResponse: true,
313
- })
329
+ }
330
+
331
+ return dbUtils.queryPlatformView(
332
+ ViewName.ACCOUNT_BY_EMAIL,
333
+ params,
334
+ opts
335
+ ) as Promise<AccountMetadata[]>
314
336
  }
315
337
 
316
338
  /**
@@ -332,7 +354,7 @@ const searchExistingEmails = async (emails: string[]) => {
332
354
  const existingAccounts = await getExistingAccounts(emails)
333
355
  matchedEmails.push(...existingAccounts.map(account => account.email))
334
356
 
335
- return [...new Set(matchedEmails)]
357
+ return [...new Set(matchedEmails.map(email => email.toLowerCase()))]
336
358
  }
337
359
 
338
360
  export const bulkCreate = async (
@@ -351,8 +373,10 @@ export const bulkCreate = async (
351
373
 
352
374
  for (const newUser of newUsersRequested) {
353
375
  if (
354
- newUsers.find((x: any) => x.email === newUser.email) ||
355
- existingEmails.includes(newUser.email)
376
+ newUsers.find(
377
+ (x: User) => x.email.toLowerCase() === newUser.email.toLowerCase()
378
+ ) ||
379
+ existingEmails.includes(newUser.email.toLowerCase())
356
380
  ) {
357
381
  unsuccessful.push({
358
382
  email: newUser.email,