@budibase/worker 1.2.3 → 1.2.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": "1.2.3",
4
+ "version": "1.2.6",
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.3",
39
- "@budibase/pro": "1.2.2",
40
- "@budibase/string-templates": "^1.2.3",
41
- "@budibase/types": "^1.2.3",
38
+ "@budibase/backend-core": "^1.2.6",
39
+ "@budibase/pro": "1.2.5",
40
+ "@budibase/string-templates": "^1.2.6",
41
+ "@budibase/types": "^1.2.6",
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": "1a58e53794ecb7c6655be29b82f85bac333ce04d"
104
+ "gitHead": "7aa3a20ecc0f6d0f4617c6e703bf4f6f1998071e"
105
105
  }
@@ -3,17 +3,18 @@ import { checkInviteCode } from "../../../utilities/redis"
3
3
  import { sendEmail } from "../../../utilities/email"
4
4
  import { users } from "../../../sdk"
5
5
  import env from "../../../environment"
6
- import { User, CloudAccount } from "@budibase/types"
6
+ import { CloudAccount, User } from "@budibase/types"
7
7
  import {
8
- events,
9
- errors,
10
8
  accounts,
11
- users as usersCore,
12
- tenancy,
13
9
  cache,
10
+ errors,
11
+ events,
12
+ tenancy,
13
+ users as usersCore,
14
14
  } from "@budibase/backend-core"
15
15
  import { checkAnyUserExists } from "../../../utilities/users"
16
16
  import { groups as groupUtils } from "@budibase/pro"
17
+
17
18
  const MAX_USERS_UPLOAD_LIMIT = 1000
18
19
 
19
20
  export const save = async (ctx: any) => {
@@ -117,8 +118,7 @@ export const adminUser = async (ctx: any) => {
117
118
  export const countByApp = async (ctx: any) => {
118
119
  const appId = ctx.params.appId
119
120
  try {
120
- const response = await users.countUsersByApp(appId)
121
- ctx.body = response
121
+ ctx.body = await users.countUsersByApp(appId)
122
122
  } catch (err: any) {
123
123
  ctx.throw(err.status || 400, err)
124
124
  }
@@ -126,6 +126,9 @@ export const countByApp = async (ctx: any) => {
126
126
 
127
127
  export const destroy = async (ctx: any) => {
128
128
  const id = ctx.params.id
129
+ if (id === ctx.user._id) {
130
+ ctx.throw(400, "Unable to delete self.")
131
+ }
129
132
 
130
133
  await users.destroy(id, ctx.user)
131
134
 
@@ -136,6 +139,10 @@ export const destroy = async (ctx: any) => {
136
139
 
137
140
  export const bulkDelete = async (ctx: any) => {
138
141
  const { userIds } = ctx.request.body
142
+ if (userIds?.indexOf(ctx.user._id) !== -1) {
143
+ ctx.throw(400, "Unable to delete self.")
144
+ }
145
+
139
146
  try {
140
147
  let usersResponse = await users.bulkDelete(userIds)
141
148
 
@@ -207,13 +214,13 @@ export const invite = async (ctx: any) => {
207
214
  }
208
215
 
209
216
  export const inviteMultiple = async (ctx: any) => {
210
- let { emails, userInfo } = ctx.request.body
217
+ let users = ctx.request.body
211
218
  let existing = false
212
219
  let existingEmail
213
- for (let email of emails) {
214
- if (await usersCore.getGlobalUserByEmail(email)) {
220
+ for (let user of users) {
221
+ if (await usersCore.getGlobalUserByEmail(user.email)) {
215
222
  existing = true
216
- existingEmail = email
223
+ existingEmail = user.email
217
224
  break
218
225
  }
219
226
  }
@@ -221,17 +228,18 @@ export const inviteMultiple = async (ctx: any) => {
221
228
  if (existing) {
222
229
  ctx.throw(400, `${existingEmail} already exists`)
223
230
  }
224
- if (!userInfo) {
225
- userInfo = {}
226
- }
227
- userInfo.tenantId = tenancy.getTenantId()
228
- const opts: any = {
229
- subject: "{{ company }} platform invitation",
230
- info: userInfo,
231
- }
232
231
 
233
- for (let i = 0; i < emails.length; i++) {
234
- 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)
235
243
  }
236
244
 
237
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() {
@@ -64,7 +66,7 @@ router
64
66
  .post("/api/global/users/search", builderOrAdmin, controller.search)
65
67
  .delete("/api/global/users/:id", adminOnly, controller.destroy)
66
68
  .post("/api/global/users/bulkDelete", adminOnly, controller.bulkDelete)
67
- .get("/api/global/users/count/:appId", adminOnly, controller.countByApp)
69
+ .get("/api/global/users/count/:appId", builderOrAdmin, controller.countByApp)
68
70
  .get("/api/global/roles/:appId")
69
71
  .post(
70
72
  "/api/global/users/invite",
@@ -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