@budibase/worker 1.2.5 → 1.2.8

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.2.5",
4
+ "version": "1.2.8",
5
5
  "description": "Budibase background service",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -35,10 +35,10 @@
35
35
  "author": "Budibase",
36
36
  "license": "GPL-3.0",
37
37
  "dependencies": {
38
- "@budibase/backend-core": "^1.2.5",
39
- "@budibase/pro": "1.2.4",
40
- "@budibase/string-templates": "^1.2.5",
41
- "@budibase/types": "^1.2.5",
38
+ "@budibase/backend-core": "^1.2.8",
39
+ "@budibase/pro": "1.2.7",
40
+ "@budibase/string-templates": "^1.2.8",
41
+ "@budibase/types": "^1.2.8",
42
42
  "@koa/router": "8.0.8",
43
43
  "@sentry/node": "6.17.7",
44
44
  "@techpass/passport-openidconnect": "0.3.2",
@@ -101,5 +101,5 @@
101
101
  "./scripts/jestSetup.js"
102
102
  ]
103
103
  },
104
- "gitHead": "fe1a52ca497fd3440484bab2e91eaad54096f0ce"
104
+ "gitHead": "b3cfc815328c54aeaf0a79c35e88aa7925108520"
105
105
  }
@@ -214,13 +214,13 @@ export const invite = async (ctx: any) => {
214
214
  }
215
215
 
216
216
  export const inviteMultiple = async (ctx: any) => {
217
- let { emails, userInfo } = ctx.request.body
217
+ let users = ctx.request.body
218
218
  let existing = false
219
219
  let existingEmail
220
- for (let email of emails) {
221
- if (await usersCore.getGlobalUserByEmail(email)) {
220
+ for (let user of users) {
221
+ if (await usersCore.getGlobalUserByEmail(user.email)) {
222
222
  existing = true
223
- existingEmail = email
223
+ existingEmail = user.email
224
224
  break
225
225
  }
226
226
  }
@@ -228,17 +228,18 @@ export const inviteMultiple = async (ctx: any) => {
228
228
  if (existing) {
229
229
  ctx.throw(400, `${existingEmail} already exists`)
230
230
  }
231
- if (!userInfo) {
232
- userInfo = {}
233
- }
234
- userInfo.tenantId = tenancy.getTenantId()
235
- const opts: any = {
236
- subject: "{{ company }} platform invitation",
237
- info: userInfo,
238
- }
239
231
 
240
- for (let i = 0; i < emails.length; i++) {
241
- await sendEmail(emails[i], EmailTemplatePurpose.INVITATION, opts)
232
+ for (let i = 0; i < users.length; i++) {
233
+ let userInfo = users[i].userInfo
234
+ if (!userInfo) {
235
+ userInfo = {}
236
+ }
237
+ userInfo.tenantId = tenancy.getTenantId()
238
+ const opts: any = {
239
+ subject: "{{ company }} platform invitation",
240
+ info: userInfo,
241
+ }
242
+ await sendEmail(users[i].email, EmailTemplatePurpose.INVITATION, opts)
242
243
  }
243
244
 
244
245
  ctx.body = {
@@ -32,10 +32,12 @@ function buildInviteValidation() {
32
32
 
33
33
  function buildInviteMultipleValidation() {
34
34
  // prettier-ignore
35
- return joiValidator.body(Joi.object({
36
- emails: Joi.array().required(),
37
- userInfo: Joi.object().optional(),
38
- }).required())
35
+ return joiValidator.body(Joi.array().required().items(
36
+ Joi.object({
37
+ email: Joi.string(),
38
+ userInfo: Joi.object().optional(),
39
+ })
40
+ ))
39
41
  }
40
42
 
41
43
  function buildInviteAcceptValidation() {
@@ -79,7 +81,7 @@ router
79
81
  controller.invite
80
82
  )
81
83
  .post(
82
- "/api/global/users/inviteMultiple",
84
+ "/api/global/users/multi/invite",
83
85
  adminOnly,
84
86
  buildInviteMultipleValidation(),
85
87
  controller.inviteMultiple
@@ -101,7 +101,7 @@ interface SaveUserOpts {
101
101
  bulkCreate?: boolean
102
102
  }
103
103
 
104
- export const buildUser = async (
104
+ const buildUser = async (
105
105
  user: any,
106
106
  opts: SaveUserOpts = {
107
107
  hashPassword: true,
@@ -195,6 +195,11 @@ export const save = async (
195
195
  dbUser
196
196
  )
197
197
 
198
+ // make sure we set the _id field for a new user
199
+ if (!_id) {
200
+ _id = builtUser._id
201
+ }
202
+
198
203
  try {
199
204
  const putOpts = {
200
205
  password: builtUser.password,
@@ -220,7 +225,7 @@ export const save = async (
220
225
  await addTenant(tenantId, _id, email)
221
226
  await cache.user.invalidateUser(response.id)
222
227
  // let server know to sync user
223
- await apps.syncUserInApps(builtUser._id)
228
+ await apps.syncUserInApps(_id)
224
229
 
225
230
  return {
226
231
  _id: response.id,
@@ -305,6 +310,9 @@ export const bulkCreate = async (
305
310
 
306
311
  // Post processing of bulk added users, i.e events and cache operations
307
312
  for (const user of usersToBulkSave) {
313
+ // TODO: Refactor to bulk insert users into the info db
314
+ // instead of relying on looping tenant creation
315
+ await addTenant(tenantId, user._id, user.email)
308
316
  await eventHelpers.handleSaveEvents(user, null)
309
317
  await apps.syncUserInApps(user._id)
310
318
  }