@budibase/worker 1.0.185 → 1.0.186

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.0.185",
4
+ "version": "1.0.186",
5
5
  "description": "Budibase background service",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -32,9 +32,9 @@
32
32
  "author": "Budibase",
33
33
  "license": "GPL-3.0",
34
34
  "dependencies": {
35
- "@budibase/backend-core": "^1.0.185",
36
- "@budibase/pro": "1.0.184",
37
- "@budibase/string-templates": "^1.0.185",
35
+ "@budibase/backend-core": "^1.0.186",
36
+ "@budibase/pro": "1.0.185",
37
+ "@budibase/string-templates": "^1.0.186",
38
38
  "@koa/router": "^8.0.0",
39
39
  "@sentry/node": "6.17.7",
40
40
  "@techpass/passport-openidconnect": "^0.3.0",
@@ -90,5 +90,5 @@
90
90
  "./scripts/jestSetup.js"
91
91
  ]
92
92
  },
93
- "gitHead": "9bdb67f67219b1227e4878c4a8751f0548f3ec7d"
93
+ "gitHead": "4ecd3e9454ffd139a893e3d92af3dc0a3b736b07"
94
94
  }
@@ -12,6 +12,7 @@ const {
12
12
  getTenantId,
13
13
  getTenantUser,
14
14
  doesTenantExist,
15
+ doInTenant,
15
16
  } = require("@budibase/backend-core/tenancy")
16
17
  const { removeUserFromInfoDB } = require("@budibase/backend-core/deprovision")
17
18
  const { errors } = require("@budibase/backend-core")
@@ -41,70 +42,73 @@ const parseBooleanParam = (param: any) => {
41
42
 
42
43
  export const adminUser = async (ctx: any) => {
43
44
  const { email, password, tenantId } = ctx.request.body
45
+ await doInTenant(tenantId, async () => {
46
+ // account portal sends a pre-hashed password - honour param to prevent double hashing
47
+ const hashPassword = parseBooleanParam(ctx.request.query.hashPassword)
48
+ // account portal sends no password for SSO users
49
+ const requirePassword = parseBooleanParam(ctx.request.query.requirePassword)
50
+
51
+ if (await doesTenantExist(tenantId)) {
52
+ ctx.throw(403, "Organisation already exists.")
53
+ }
44
54
 
45
- // account portal sends a pre-hashed password - honour param to prevent double hashing
46
- const hashPassword = parseBooleanParam(ctx.request.query.hashPassword)
47
- // account portal sends no password for SSO users
48
- const requirePassword = parseBooleanParam(ctx.request.query.requirePassword)
49
-
50
- if (await doesTenantExist(tenantId)) {
51
- ctx.throw(403, "Organisation already exists.")
52
- }
53
-
54
- const response = await doWithGlobalDB(tenantId, async (db: any) => {
55
- const response = await db.allDocs(
56
- getGlobalUserParams(null, {
57
- include_docs: true,
58
- })
59
- )
60
- // write usage quotas for cloud
61
- if (!env.SELF_HOSTED) {
62
- // could be a scenario where it exists, make sure its clean
63
- try {
64
- const usageQuota = await db.get(StaticDatabases.GLOBAL.docs.usageQuota)
65
- if (usageQuota) {
66
- await db.remove(usageQuota._id, usageQuota._rev)
55
+ const response = await doWithGlobalDB(tenantId, async (db: any) => {
56
+ const response = await db.allDocs(
57
+ getGlobalUserParams(null, {
58
+ include_docs: true,
59
+ })
60
+ )
61
+ // write usage quotas for cloud
62
+ if (!env.SELF_HOSTED) {
63
+ // could be a scenario where it exists, make sure its clean
64
+ try {
65
+ const usageQuota = await db.get(
66
+ StaticDatabases.GLOBAL.docs.usageQuota
67
+ )
68
+ if (usageQuota) {
69
+ await db.remove(usageQuota._id, usageQuota._rev)
70
+ }
71
+ } catch (err) {
72
+ // don't worry about errors
67
73
  }
68
- } catch (err) {
69
- // don't worry about errors
74
+ await db.put(quotas.generateNewQuotaUsage())
70
75
  }
71
- await db.put(quotas.generateNewQuotaUsage())
76
+ return response
77
+ })
78
+
79
+ if (response.rows.some((row: any) => row.doc.admin)) {
80
+ ctx.throw(
81
+ 403,
82
+ "You cannot initialise once an global user has been created."
83
+ )
72
84
  }
73
- return response
74
- })
75
85
 
76
- if (response.rows.some((row: any) => row.doc.admin)) {
77
- ctx.throw(
78
- 403,
79
- "You cannot initialise once an global user has been created."
80
- )
81
- }
82
-
83
- const user = {
84
- email: email,
85
- password: password,
86
- createdAt: Date.now(),
87
- roles: {},
88
- builder: {
89
- global: true,
90
- },
91
- admin: {
92
- global: true,
93
- },
94
- tenantId,
95
- }
96
- try {
97
- const finalUser = await users.save(
98
- user,
86
+ const user = {
87
+ email: email,
88
+ password: password,
89
+ createdAt: Date.now(),
90
+ roles: {},
91
+ builder: {
92
+ global: true,
93
+ },
94
+ admin: {
95
+ global: true,
96
+ },
99
97
  tenantId,
100
- hashPassword,
101
- requirePassword
102
- )
103
- await bustCache(CacheKeys.CHECKLIST)
104
- ctx.body = finalUser
105
- } catch (err: any) {
106
- ctx.throw(err.status || 400, err)
107
- }
98
+ }
99
+ try {
100
+ const finalUser = await users.save(
101
+ user,
102
+ tenantId,
103
+ hashPassword,
104
+ requirePassword
105
+ )
106
+ await bustCache(CacheKeys.CHECKLIST)
107
+ ctx.body = finalUser
108
+ } catch (err: any) {
109
+ ctx.throw(err.status || 400, err)
110
+ }
111
+ })
108
112
  }
109
113
 
110
114
  export const destroy = async (ctx: any) => {