@budibase/worker 2.2.12-alpha.2 → 2.2.12

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.
Files changed (134) hide show
  1. package/coverage/clover.xml +1238 -1291
  2. package/coverage/coverage-final.json +77 -81
  3. package/coverage/lcov-report/index.html +73 -73
  4. package/coverage/lcov-report/src/api/controllers/global/auth.ts.html +26 -26
  5. package/coverage/lcov-report/src/api/controllers/global/configs.ts.html +212 -155
  6. package/coverage/lcov-report/src/api/controllers/global/email.ts.html +4 -4
  7. package/coverage/lcov-report/src/api/controllers/global/index.html +39 -39
  8. package/coverage/lcov-report/src/api/controllers/global/license.ts.html +7 -7
  9. package/coverage/lcov-report/src/api/controllers/global/roles.ts.html +76 -76
  10. package/coverage/lcov-report/src/api/controllers/global/self.ts.html +14 -14
  11. package/coverage/lcov-report/src/api/controllers/global/templates.ts.html +53 -53
  12. package/coverage/lcov-report/src/api/controllers/global/users.ts.html +27 -27
  13. package/coverage/lcov-report/src/api/controllers/global/workspaces.ts.html +6 -6
  14. package/coverage/lcov-report/src/api/controllers/system/accounts.ts.html +4 -4
  15. package/coverage/lcov-report/src/api/controllers/system/environment.ts.html +3 -3
  16. package/coverage/lcov-report/src/api/controllers/system/index.html +1 -1
  17. package/coverage/lcov-report/src/api/controllers/system/migrations.ts.html +4 -4
  18. package/coverage/lcov-report/src/api/controllers/system/restore.ts.html +4 -4
  19. package/coverage/lcov-report/src/api/controllers/system/status.ts.html +4 -4
  20. package/coverage/lcov-report/src/api/controllers/system/tenants.ts.html +5 -5
  21. package/coverage/lcov-report/src/api/index.html +1 -1
  22. package/coverage/lcov-report/src/api/index.ts.html +23 -23
  23. package/coverage/lcov-report/src/api/routes/global/auth.ts.html +11 -11
  24. package/coverage/lcov-report/src/api/routes/global/configs.ts.html +16 -16
  25. package/coverage/lcov-report/src/api/routes/global/email.ts.html +10 -10
  26. package/coverage/lcov-report/src/api/routes/global/index.html +1 -1
  27. package/coverage/lcov-report/src/api/routes/global/license.ts.html +7 -7
  28. package/coverage/lcov-report/src/api/routes/global/roles.ts.html +7 -7
  29. package/coverage/lcov-report/src/api/routes/global/self.ts.html +8 -8
  30. package/coverage/lcov-report/src/api/routes/global/templates.ts.html +11 -11
  31. package/coverage/lcov-report/src/api/routes/global/users.ts.html +16 -16
  32. package/coverage/lcov-report/src/api/routes/global/workspaces.ts.html +9 -9
  33. package/coverage/lcov-report/src/api/routes/index.html +1 -1
  34. package/coverage/lcov-report/src/api/routes/index.ts.html +19 -19
  35. package/coverage/lcov-report/src/api/routes/system/accounts.ts.html +7 -7
  36. package/coverage/lcov-report/src/api/routes/system/environment.ts.html +6 -6
  37. package/coverage/lcov-report/src/api/routes/system/index.html +1 -1
  38. package/coverage/lcov-report/src/api/routes/system/migrations.ts.html +7 -7
  39. package/coverage/lcov-report/src/api/routes/system/restore.ts.html +6 -6
  40. package/coverage/lcov-report/src/api/routes/system/status.ts.html +6 -6
  41. package/coverage/lcov-report/src/api/routes/system/tenants.ts.html +7 -7
  42. package/coverage/lcov-report/src/api/routes/validation/index.html +1 -1
  43. package/coverage/lcov-report/src/api/routes/validation/index.ts.html +2 -2
  44. package/coverage/lcov-report/src/api/routes/validation/users.ts.html +13 -13
  45. package/coverage/lcov-report/src/constants/index.html +9 -9
  46. package/coverage/lcov-report/src/constants/index.ts.html +49 -73
  47. package/coverage/lcov-report/src/constants/templates/index.html +19 -19
  48. package/coverage/lcov-report/src/constants/templates/index.ts.html +39 -39
  49. package/coverage/lcov-report/src/db/index.html +1 -1
  50. package/coverage/lcov-report/src/db/index.ts.html +8 -8
  51. package/coverage/lcov-report/src/environment.ts.html +22 -37
  52. package/coverage/lcov-report/src/index.html +15 -15
  53. package/coverage/lcov-report/src/index.ts.html +43 -40
  54. package/coverage/lcov-report/src/middleware/cloudRestricted.ts.html +4 -4
  55. package/coverage/lcov-report/src/middleware/index.html +1 -1
  56. package/coverage/lcov-report/src/migrations/functions/globalInfoSyncUsers.ts.html +3 -3
  57. package/coverage/lcov-report/src/migrations/functions/index.html +1 -1
  58. package/coverage/lcov-report/src/migrations/index.html +1 -1
  59. package/coverage/lcov-report/src/migrations/index.ts.html +17 -17
  60. package/coverage/lcov-report/src/sdk/accounts/accounts.ts.html +6 -6
  61. package/coverage/lcov-report/src/sdk/accounts/index.html +1 -1
  62. package/coverage/lcov-report/src/sdk/accounts/index.ts.html +2 -2
  63. package/coverage/lcov-report/src/sdk/index.html +1 -1
  64. package/coverage/lcov-report/src/sdk/index.ts.html +4 -4
  65. package/coverage/lcov-report/src/sdk/users/events.ts.html +46 -46
  66. package/coverage/lcov-report/src/sdk/users/index.html +15 -15
  67. package/coverage/lcov-report/src/sdk/users/index.ts.html +2 -2
  68. package/coverage/lcov-report/src/sdk/users/users.ts.html +97 -148
  69. package/coverage/lcov-report/src/tests/TestConfiguration.ts.html +80 -104
  70. package/coverage/lcov-report/src/tests/api/accounts.ts.html +6 -6
  71. package/coverage/lcov-report/src/tests/api/auth.ts.html +7 -7
  72. package/coverage/lcov-report/src/tests/api/base.ts.html +4 -4
  73. package/coverage/lcov-report/src/tests/api/configs.ts.html +8 -8
  74. package/coverage/lcov-report/src/tests/api/email.ts.html +5 -5
  75. package/coverage/lcov-report/src/tests/api/environment.ts.html +5 -5
  76. package/coverage/lcov-report/src/tests/api/index.html +11 -71
  77. package/coverage/lcov-report/src/tests/api/index.ts.html +28 -61
  78. package/coverage/lcov-report/src/tests/api/migrations.ts.html +6 -6
  79. package/coverage/lcov-report/src/tests/api/restore.ts.html +5 -5
  80. package/coverage/lcov-report/src/tests/api/self.ts.html +6 -6
  81. package/coverage/lcov-report/src/tests/api/status.ts.html +5 -5
  82. package/coverage/lcov-report/src/tests/api/tenants.ts.html +5 -5
  83. package/coverage/lcov-report/src/tests/api/users.ts.html +16 -16
  84. package/coverage/lcov-report/src/tests/controllers.ts.html +6 -6
  85. package/coverage/lcov-report/src/tests/index.html +10 -10
  86. package/coverage/lcov-report/src/tests/index.ts.html +9 -9
  87. package/coverage/lcov-report/src/tests/mocks/{email.ts.html → email.js.html} +5 -5
  88. package/coverage/lcov-report/src/tests/mocks/index.html +2 -2
  89. package/coverage/lcov-report/src/tests/mocks/index.ts.html +7 -7
  90. package/coverage/lcov-report/src/tests/structures/configs.ts.html +10 -10
  91. package/coverage/lcov-report/src/tests/structures/groups.ts.html +15 -15
  92. package/coverage/lcov-report/src/tests/structures/index.html +16 -16
  93. package/coverage/lcov-report/src/tests/structures/index.ts.html +11 -11
  94. package/coverage/lcov-report/src/tests/structures/users.ts.html +11 -11
  95. package/coverage/lcov-report/src/utilities/appService.ts.html +10 -10
  96. package/coverage/lcov-report/src/utilities/email.ts.html +15 -15
  97. package/coverage/lcov-report/src/utilities/fileSystem.ts.html +4 -4
  98. package/coverage/lcov-report/src/utilities/index.html +1 -1
  99. package/coverage/lcov-report/src/utilities/index.ts.html +2 -2
  100. package/coverage/lcov-report/src/utilities/redis.ts.html +12 -12
  101. package/coverage/lcov-report/src/utilities/templates.ts.html +6 -6
  102. package/coverage/lcov-report/src/utilities/users.ts.html +3 -3
  103. package/coverage/lcov.info +1779 -1949
  104. package/jest.config.ts +0 -2
  105. package/package.json +7 -8
  106. package/src/api/controllers/global/configs.ts +131 -112
  107. package/src/api/controllers/global/users.ts +1 -1
  108. package/src/api/routes/global/license.ts +1 -1
  109. package/src/api/routes/global/tests/license.spec.ts +2 -0
  110. package/src/api/routes/global/tests/roles.spec.ts +5 -66
  111. package/src/api/routes/global/tests/templates.spec.ts +9 -89
  112. package/src/api/routes/global/tests/users.spec.ts +2 -2
  113. package/src/constants/index.ts +5 -13
  114. package/src/environment.ts +0 -5
  115. package/src/index.ts +2 -1
  116. package/src/sdk/users/users.ts +1 -18
  117. package/src/tests/TestConfiguration.ts +1 -9
  118. package/src/tests/api/index.ts +1 -12
  119. package/src/tests/jestSetup.ts +1 -3
  120. package/src/tests/mocks/{email.ts → email.js} +1 -1
  121. package/src/tests/mocks/index.ts +3 -3
  122. package/src/tests/structures/configs.ts +2 -2
  123. package/src/tests/structures/groups.ts +1 -1
  124. package/src/tests/structures/users.ts +1 -1
  125. package/tsconfig.json +1 -0
  126. package/coverage/lcov-report/src/tests/api/groups.ts.html +0 -163
  127. package/coverage/lcov-report/src/tests/api/license.ts.html +0 -136
  128. package/coverage/lcov-report/src/tests/api/roles.ts.html +0 -181
  129. package/coverage/lcov-report/src/tests/api/templates.ts.html +0 -175
  130. package/src/api/routes/global/tests/groups.spec.ts +0 -58
  131. package/src/tests/api/groups.ts +0 -26
  132. package/src/tests/api/license.ts +0 -17
  133. package/src/tests/api/roles.ts +0 -32
  134. package/src/tests/api/templates.ts +0 -30
package/jest.config.ts CHANGED
@@ -19,8 +19,6 @@ if (!process.env.CI) {
19
19
  }
20
20
  // add pro sources if they exist
21
21
  if (fs.existsSync("../../../budibase-pro")) {
22
- config.moduleNameMapper["@budibase/pro/(.*)"] =
23
- "<rootDir>/../../../budibase-pro/packages/pro/$1"
24
22
  config.moduleNameMapper["@budibase/pro"] =
25
23
  "<rootDir>/../../../budibase-pro/packages/pro/src"
26
24
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/worker",
3
3
  "email": "hi@budibase.com",
4
- "version": "2.2.12-alpha.2",
4
+ "version": "2.2.12",
5
5
  "description": "Budibase background service",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -36,10 +36,10 @@
36
36
  "author": "Budibase",
37
37
  "license": "GPL-3.0",
38
38
  "dependencies": {
39
- "@budibase/backend-core": "2.2.12-alpha.2",
40
- "@budibase/pro": "2.2.12-alpha.1",
41
- "@budibase/string-templates": "2.2.12-alpha.2",
42
- "@budibase/types": "2.2.12-alpha.2",
39
+ "@budibase/backend-core": "^2.2.12",
40
+ "@budibase/pro": "2.2.11",
41
+ "@budibase/string-templates": "^2.2.12",
42
+ "@budibase/types": "^2.2.12",
43
43
  "@koa/router": "8.0.8",
44
44
  "@sentry/node": "6.17.7",
45
45
  "@techpass/passport-openidconnect": "0.3.2",
@@ -73,11 +73,10 @@
73
73
  "@types/jest": "26.0.23",
74
74
  "@types/jsonwebtoken": "8.5.1",
75
75
  "@types/koa": "2.13.4",
76
- "@types/koa__router": "8.0.8",
76
+ "@types/koa__router": "8.0.11",
77
77
  "@types/node": "14.18.20",
78
78
  "@types/node-fetch": "2.6.1",
79
79
  "@types/pouchdb": "6.4.0",
80
- "@types/server-destroy": "1.0.1",
81
80
  "@types/uuid": "8.3.4",
82
81
  "@typescript-eslint/parser": "5.45.0",
83
82
  "copyfiles": "2.4.1",
@@ -95,5 +94,5 @@
95
94
  "typescript": "4.7.3",
96
95
  "update-dotenv": "1.1.1"
97
96
  },
98
- "gitHead": "f33fe0fc19b1a8566d7c1262bb329fbecdaa9586"
97
+ "gitHead": "01d4b731bff015e11bcb691dce007ab1c95d36c0"
99
98
  }
@@ -7,7 +7,6 @@ import {
7
7
  objectStore,
8
8
  tenancy,
9
9
  db as dbCore,
10
- env as coreEnv,
11
10
  } from "@budibase/backend-core"
12
11
  import { checkAnyUserExists } from "../../../utilities/users"
13
12
  import {
@@ -18,106 +17,127 @@ import {
18
17
  GoogleConfig,
19
18
  OIDCConfig,
20
19
  SettingsConfig,
21
- isGoogleConfig,
22
- isOIDCConfig,
23
- isSettingsConfig,
24
- isSMTPConfig,
25
- Ctx,
26
- UserCtx,
20
+ BBContext,
27
21
  } from "@budibase/types"
28
22
 
29
23
  const getEventFns = async (db: Database, config: ConfigDoc) => {
30
24
  const fns = []
25
+ const type = config.type
31
26
 
32
27
  let existing
33
28
  if (config._id) {
34
29
  existing = await db.get(config._id)
35
30
  }
36
31
 
32
+ const ssoType = type as SSOType
37
33
  if (!existing) {
38
- if (isSMTPConfig(config)) {
39
- fns.push(events.email.SMTPCreated)
40
- } else if (isGoogleConfig(config)) {
41
- fns.push(() => events.auth.SSOCreated(ConfigType.GOOGLE))
42
- if (config.config.activated) {
43
- fns.push(() => events.auth.SSOActivated(ConfigType.GOOGLE))
34
+ switch (config.type) {
35
+ case ConfigType.SMTP: {
36
+ fns.push(events.email.SMTPCreated)
37
+ break
44
38
  }
45
- } else if (isOIDCConfig(config)) {
46
- fns.push(() => events.auth.SSOCreated(ConfigType.OIDC))
47
- if (config.config.configs[0].activated) {
48
- fns.push(() => events.auth.SSOActivated(ConfigType.OIDC))
39
+ case ConfigType.GOOGLE: {
40
+ const googleCfg = config as GoogleConfig
41
+ fns.push(() => events.auth.SSOCreated(ssoType))
42
+ if (googleCfg.config.activated) {
43
+ fns.push(() => events.auth.SSOActivated(ssoType))
44
+ }
45
+ break
49
46
  }
50
- } else if (isSettingsConfig(config)) {
51
- // company
52
- const company = config.config.company
53
- if (company && company !== "Budibase") {
54
- fns.push(events.org.nameUpdated)
47
+ case ConfigType.OIDC: {
48
+ const oidcCfg = config as OIDCConfig
49
+ fns.push(() => events.auth.SSOCreated(ssoType))
50
+ if (oidcCfg.config.configs[0].activated) {
51
+ fns.push(() => events.auth.SSOActivated(ssoType))
52
+ }
53
+ break
55
54
  }
55
+ case ConfigType.SETTINGS: {
56
+ // company
57
+ const settingsCfg = config as SettingsConfig
58
+ const company = settingsCfg.config.company
59
+ if (company && company !== "Budibase") {
60
+ fns.push(events.org.nameUpdated)
61
+ }
56
62
 
57
- // logo
58
- const logoUrl = config.config.logoUrl
59
- if (logoUrl) {
60
- fns.push(events.org.logoUpdated)
61
- }
63
+ // logo
64
+ const logoUrl = settingsCfg.config.logoUrl
65
+ if (logoUrl) {
66
+ fns.push(events.org.logoUpdated)
67
+ }
62
68
 
63
- // platform url
64
- const platformUrl = config.config.platformUrl
65
- if (
66
- platformUrl &&
67
- platformUrl !== "http://localhost:10000" &&
68
- env.SELF_HOSTED
69
- ) {
70
- fns.push(events.org.platformURLUpdated)
69
+ // platform url
70
+ const platformUrl = settingsCfg.config.platformUrl
71
+ if (
72
+ platformUrl &&
73
+ platformUrl !== "http://localhost:10000" &&
74
+ env.SELF_HOSTED
75
+ ) {
76
+ fns.push(events.org.platformURLUpdated)
77
+ }
78
+ break
71
79
  }
72
80
  }
73
81
  } else {
74
- if (isSMTPConfig(config)) {
75
- fns.push(events.email.SMTPUpdated)
76
- } else if (isGoogleConfig(config)) {
77
- fns.push(() => events.auth.SSOUpdated(ConfigType.GOOGLE))
78
- if (!existing.config.activated && config.config.activated) {
79
- fns.push(() => events.auth.SSOActivated(ConfigType.GOOGLE))
80
- } else if (existing.config.activated && !config.config.activated) {
81
- fns.push(() => events.auth.SSODeactivated(ConfigType.GOOGLE))
82
+ switch (config.type) {
83
+ case ConfigType.SMTP: {
84
+ fns.push(events.email.SMTPUpdated)
85
+ break
82
86
  }
83
- } else if (isOIDCConfig(config)) {
84
- fns.push(() => events.auth.SSOUpdated(ConfigType.OIDC))
85
- if (
86
- !existing.config.configs[0].activated &&
87
- config.config.configs[0].activated
88
- ) {
89
- fns.push(() => events.auth.SSOActivated(ConfigType.OIDC))
90
- } else if (
91
- existing.config.configs[0].activated &&
92
- !config.config.configs[0].activated
93
- ) {
94
- fns.push(() => events.auth.SSODeactivated(ConfigType.OIDC))
87
+ case ConfigType.GOOGLE: {
88
+ const googleCfg = config as GoogleConfig
89
+ fns.push(() => events.auth.SSOUpdated(ssoType))
90
+ if (!existing.config.activated && googleCfg.config.activated) {
91
+ fns.push(() => events.auth.SSOActivated(ssoType))
92
+ } else if (existing.config.activated && !googleCfg.config.activated) {
93
+ fns.push(() => events.auth.SSODeactivated(ssoType))
94
+ }
95
+ break
95
96
  }
96
- } else if (isSettingsConfig(config)) {
97
- // company
98
- const existingCompany = existing.config.company
99
- const company = config.config.company
100
- if (company && company !== "Budibase" && existingCompany !== company) {
101
- fns.push(events.org.nameUpdated)
97
+ case ConfigType.OIDC: {
98
+ const oidcCfg = config as OIDCConfig
99
+ fns.push(() => events.auth.SSOUpdated(ssoType))
100
+ if (
101
+ !existing.config.configs[0].activated &&
102
+ oidcCfg.config.configs[0].activated
103
+ ) {
104
+ fns.push(() => events.auth.SSOActivated(ssoType))
105
+ } else if (
106
+ existing.config.configs[0].activated &&
107
+ !oidcCfg.config.configs[0].activated
108
+ ) {
109
+ fns.push(() => events.auth.SSODeactivated(ssoType))
110
+ }
111
+ break
102
112
  }
113
+ case ConfigType.SETTINGS: {
114
+ // company
115
+ const settingsCfg = config as SettingsConfig
116
+ const existingCompany = existing.config.company
117
+ const company = settingsCfg.config.company
118
+ if (company && company !== "Budibase" && existingCompany !== company) {
119
+ fns.push(events.org.nameUpdated)
120
+ }
103
121
 
104
- // logo
105
- const existingLogoUrl = existing.config.logoUrl
106
- const logoUrl = config.config.logoUrl
107
- if (logoUrl && existingLogoUrl !== logoUrl) {
108
- fns.push(events.org.logoUpdated)
109
- }
122
+ // logo
123
+ const existingLogoUrl = existing.config.logoUrl
124
+ const logoUrl = settingsCfg.config.logoUrl
125
+ if (logoUrl && existingLogoUrl !== logoUrl) {
126
+ fns.push(events.org.logoUpdated)
127
+ }
110
128
 
111
- // platform url
112
- const existingPlatformUrl = existing.config.platformUrl
113
- const platformUrl = config.config.platformUrl
114
- if (
115
- platformUrl &&
116
- platformUrl !== "http://localhost:10000" &&
117
- existingPlatformUrl !== platformUrl &&
118
- env.SELF_HOSTED
119
- ) {
120
- fns.push(events.org.platformURLUpdated)
129
+ // platform url
130
+ const existingPlatformUrl = existing.config.platformUrl
131
+ const platformUrl = settingsCfg.config.platformUrl
132
+ if (
133
+ platformUrl &&
134
+ platformUrl !== "http://localhost:10000" &&
135
+ existingPlatformUrl !== platformUrl &&
136
+ env.SELF_HOSTED
137
+ ) {
138
+ fns.push(events.org.platformURLUpdated)
139
+ }
140
+ break
121
141
  }
122
142
  }
123
143
  }
@@ -125,7 +145,7 @@ const getEventFns = async (db: Database, config: ConfigDoc) => {
125
145
  return fns
126
146
  }
127
147
 
128
- export async function save(ctx: UserCtx) {
148
+ export async function save(ctx: BBContext) {
129
149
  const db = tenancy.getGlobalDB()
130
150
  const { type, workspace, user, config } = ctx.request.body
131
151
  let eventFns = await getEventFns(db, ctx.request.body)
@@ -167,7 +187,7 @@ export async function save(ctx: UserCtx) {
167
187
  }
168
188
  }
169
189
 
170
- export async function fetch(ctx: UserCtx) {
190
+ export async function fetch(ctx: BBContext) {
171
191
  const db = tenancy.getGlobalDB()
172
192
  const response = await db.allDocs(
173
193
  dbCore.getConfigParams(
@@ -184,7 +204,7 @@ export async function fetch(ctx: UserCtx) {
184
204
  * Gets the most granular config for a particular configuration type.
185
205
  * The hierarchy is type -> workspace -> user.
186
206
  */
187
- export async function find(ctx: UserCtx) {
207
+ export async function find(ctx: BBContext) {
188
208
  const db = tenancy.getGlobalDB()
189
209
 
190
210
  const { userId, workspaceId } = ctx.query
@@ -217,18 +237,18 @@ export async function find(ctx: UserCtx) {
217
237
  }
218
238
  }
219
239
 
220
- export async function publicOidc(ctx: Ctx) {
240
+ export async function publicOidc(ctx: BBContext) {
221
241
  const db = tenancy.getGlobalDB()
222
242
  try {
223
243
  // Find the config with the most granular scope based on context
224
- const oidcConfig: OIDCConfig = await dbCore.getScopedFullConfig(db, {
244
+ const oidcConfig = await dbCore.getScopedFullConfig(db, {
225
245
  type: ConfigType.OIDC,
226
246
  })
227
247
 
228
248
  if (!oidcConfig) {
229
249
  ctx.body = {}
230
250
  } else {
231
- ctx.body = oidcConfig.config.configs.map(config => ({
251
+ ctx.body = oidcConfig.config.configs.map((config: any) => ({
232
252
  logo: config.logo,
233
253
  name: config.name,
234
254
  uuid: config.uuid,
@@ -239,7 +259,7 @@ export async function publicOidc(ctx: Ctx) {
239
259
  }
240
260
  }
241
261
 
242
- export async function publicSettings(ctx: Ctx) {
262
+ export async function publicSettings(ctx: BBContext) {
243
263
  const db = tenancy.getGlobalDB()
244
264
 
245
265
  try {
@@ -265,16 +285,6 @@ export async function publicSettings(ctx: Ctx) {
265
285
  config = publicConfig
266
286
  }
267
287
 
268
- // enrich the logo url
269
- // empty url means deleted
270
- if (config.config.logoUrl !== "") {
271
- config.config.logoUrl = objectStore.getGlobalFileUrl(
272
- "settings",
273
- "logoUrl",
274
- config.config.logoUrlEtag
275
- )
276
- }
277
-
278
288
  // google button flag
279
289
  if (googleConfig && googleConfig.config) {
280
290
  // activated by default for configs pre-activated flag
@@ -301,17 +311,28 @@ export async function publicSettings(ctx: Ctx) {
301
311
  }
302
312
  }
303
313
 
304
- export async function upload(ctx: UserCtx) {
305
- if (ctx.request.files == null || Array.isArray(ctx.request.files.file)) {
314
+ export async function upload(ctx: BBContext) {
315
+ if (ctx.request.files == null || ctx.request.files.file.length > 1) {
306
316
  ctx.throw(400, "One file must be uploaded.")
307
317
  }
308
- const file = ctx.request.files.file as any
318
+ const file = ctx.request.files.file
309
319
  const { type, name } = ctx.params
310
320
 
311
- let bucket = coreEnv.GLOBAL_BUCKET_NAME
312
- const key = objectStore.getGlobalFileS3Key(type, name)
321
+ let bucket
322
+ if (env.SELF_HOSTED) {
323
+ bucket = objectStore.ObjectStoreBuckets.GLOBAL
324
+ } else {
325
+ bucket = objectStore.ObjectStoreBuckets.GLOBAL_CLOUD
326
+ }
327
+
328
+ let key
329
+ if (env.MULTI_TENANCY) {
330
+ key = `${tenancy.getTenantId()}/${type}/${name}`
331
+ } else {
332
+ key = `${type}/${name}`
333
+ }
313
334
 
314
- const result = await objectStore.upload({
335
+ await objectStore.upload({
315
336
  bucket,
316
337
  filename: key,
317
338
  path: file.path,
@@ -328,26 +349,24 @@ export async function upload(ctx: UserCtx) {
328
349
  config: {},
329
350
  }
330
351
  }
331
-
332
- // save the Etag for cache bursting
333
- const etag = result.ETag
334
- if (etag) {
335
- cfgStructure.config[`${name}Etag`] = etag.replace(/"/g, "")
352
+ let url
353
+ if (env.SELF_HOSTED) {
354
+ url = `/${bucket}/${key}`
355
+ } else {
356
+ url = `${env.CDN_URL}/${key}`
336
357
  }
337
358
 
338
- // save the file key
339
- cfgStructure.config[`${name}`] = key
340
-
341
- // write back to db
359
+ cfgStructure.config[`${name}`] = url
360
+ // write back to db with url updated
342
361
  await db.put(cfgStructure)
343
362
 
344
363
  ctx.body = {
345
364
  message: "File has been uploaded and url stored to config.",
346
- url: objectStore.getGlobalFileUrl(type, name, etag),
365
+ url,
347
366
  }
348
367
  }
349
368
 
350
- export async function destroy(ctx: UserCtx) {
369
+ export async function destroy(ctx: BBContext) {
351
370
  const db = tenancy.getGlobalDB()
352
371
  const { id, rev } = ctx.params
353
372
  try {
@@ -359,7 +378,7 @@ export async function destroy(ctx: UserCtx) {
359
378
  }
360
379
  }
361
380
 
362
- export async function configChecklist(ctx: Ctx) {
381
+ export async function configChecklist(ctx: BBContext) {
363
382
  const db = tenancy.getGlobalDB()
364
383
  const tenantId = tenancy.getTenantId()
365
384
 
@@ -178,7 +178,7 @@ export const find = async (ctx: any) => {
178
178
 
179
179
  export const tenantUserLookup = async (ctx: any) => {
180
180
  const id = ctx.params.id
181
- const user = await sdk.users.getPlatformUser(id)
181
+ const user = await tenancy.getTenantUser(id)
182
182
  if (user) {
183
183
  ctx.body = user
184
184
  } else {
@@ -10,4 +10,4 @@ router
10
10
  .delete("/api/global/license/info", controller.deleteInfo)
11
11
  .get("/api/global/license/usage", controller.getQuotaUsage)
12
12
 
13
- export default router
13
+ export = router
@@ -1,5 +1,7 @@
1
1
  import { TestConfiguration } from "../../../../tests"
2
2
 
3
+ // TODO
4
+
3
5
  describe("/api/global/license", () => {
4
6
  const config = new TestConfiguration()
5
7
 
@@ -1,47 +1,11 @@
1
- import { structures, TestConfiguration } from "../../../../tests"
2
- import { context, db, permissions, roles } from "@budibase/backend-core"
3
- import { Mock } from "jest-mock"
1
+ import { TestConfiguration } from "../../../../tests"
4
2
 
5
- jest.mock("@budibase/backend-core", () => {
6
- const core = jest.requireActual("@budibase/backend-core")
7
- return {
8
- ...core,
9
- db: {
10
- ...core.db,
11
- },
12
- context: {
13
- ...core.context,
14
- getAppDB: jest.fn(),
15
- },
16
- }
17
- })
18
-
19
- const appDb = db.getDB("app_test")
20
- const mockAppDB = context.getAppDB as Mock
21
- mockAppDB.mockReturnValue(appDb)
22
-
23
- async function addAppMetadata() {
24
- await appDb.put({
25
- _id: "app_metadata",
26
- appId: "app_test",
27
- name: "New App",
28
- version: "version",
29
- url: "url",
30
- })
31
- }
3
+ // TODO
32
4
 
33
5
  describe("/api/global/roles", () => {
34
6
  const config = new TestConfiguration()
35
- const role = new roles.Role(
36
- db.generateRoleID("newRole"),
37
- roles.BUILTIN_ROLE_IDS.BASIC,
38
- permissions.BuiltinPermissionID.READ_ONLY
39
- )
40
7
 
41
8
  beforeAll(async () => {
42
- console.debug(role)
43
- appDb.put(role)
44
- await addAppMetadata()
45
9
  await config.beforeAll()
46
10
  })
47
11
 
@@ -54,35 +18,10 @@ describe("/api/global/roles", () => {
54
18
  })
55
19
 
56
20
  describe("GET /api/global/roles", () => {
57
- it("retrieves roles", async () => {
58
- const res = await config.api.roles.get()
59
- expect(res.body).toBeDefined()
60
- expect(res.body["app_test"].roles.length).toEqual(5)
61
- expect(res.body["app_test"].roles.map((r: any) => r._id)).toContain(
62
- role._id
63
- )
64
- })
21
+ it("retrieves roles", () => {})
65
22
  })
66
23
 
67
- describe("GET api/global/roles/:appId", () => {
68
- it("finds a role by appId", async () => {
69
- const res = await config.api.roles.find("app_test")
70
- expect(res.body).toBeDefined()
71
- expect(res.body.name).toEqual("New App")
72
- })
73
- })
24
+ describe("GET /api/global/roles/:appId", () => {})
74
25
 
75
- describe("DELETE /api/global/roles/:appId", () => {
76
- it("removes an app role", async () => {
77
- let user = structures.users.user()
78
- user.roles = {
79
- app_test: "role1",
80
- }
81
- const userResponse = await config.createUser(user)
82
- const res = await config.api.roles.remove("app_test")
83
- const updatedUser = await config.api.users.getUser(userResponse._id!)
84
- expect(updatedUser.body.roles).not.toHaveProperty("app_test")
85
- expect(res.body.message).toEqual("App role removed from all users")
86
- })
87
- })
26
+ describe("DELETE /api/global/roles/:appId", () => {})
88
27
  })
@@ -1,17 +1,4 @@
1
- import {
2
- addBaseTemplates,
3
- EmailTemplates,
4
- getTemplates,
5
- } from "../../../../constants/templates"
6
- import {
7
- EmailTemplatePurpose,
8
- TemplateMetadata,
9
- TemplateMetadataNames,
10
- TemplateType,
11
- } from "../../../../constants"
12
1
  import { TestConfiguration } from "../../../../tests"
13
- import { join } from "path"
14
- import { readStaticFile } from "../../../../../src/utilities/fileSystem"
15
2
 
16
3
  // TODO
17
4
 
@@ -31,85 +18,18 @@ describe("/api/global/template", () => {
31
18
  })
32
19
 
33
20
  describe("GET /api/global/template/definitions", () => {
34
- describe("retrieves definitions", () => {
35
- it("checks description definitions", async () => {
36
- let result = await config.api.templates.definitions()
21
+ it("retrieves definitions", () => {})
22
+ })
37
23
 
38
- expect(result.body.info[EmailTemplatePurpose.BASE].description).toEqual(
39
- TemplateMetadata[TemplateType.EMAIL][0].description
40
- )
41
- expect(
42
- result.body.info[EmailTemplatePurpose.PASSWORD_RECOVERY].description
43
- ).toEqual(TemplateMetadata[TemplateType.EMAIL][1].description)
44
- expect(
45
- result.body.info[EmailTemplatePurpose.WELCOME].description
46
- ).toEqual(TemplateMetadata[TemplateType.EMAIL][2].description)
47
- expect(
48
- result.body.info[EmailTemplatePurpose.INVITATION].description
49
- ).toEqual(TemplateMetadata[TemplateType.EMAIL][3].description)
50
- expect(
51
- result.body.info[EmailTemplatePurpose.CUSTOM].description
52
- ).toEqual(TemplateMetadata[TemplateType.EMAIL][4].description)
53
- })
24
+ describe("POST /api/global/template", () => {})
54
25
 
55
- it("checks description bindings", async () => {
56
- let result = await config.api.templates.definitions()
26
+ describe("GET /api/global/template", () => {})
57
27
 
58
- expect(result.body.bindings[EmailTemplatePurpose.BASE]).toEqual(
59
- TemplateMetadata[TemplateType.EMAIL][0].bindings
60
- )
61
- expect(
62
- result.body.bindings[EmailTemplatePurpose.PASSWORD_RECOVERY]
63
- ).toEqual(TemplateMetadata[TemplateType.EMAIL][1].bindings)
64
- expect(result.body.bindings[EmailTemplatePurpose.WELCOME]).toEqual(
65
- TemplateMetadata[TemplateType.EMAIL][2].bindings
66
- )
67
- expect(result.body.bindings[EmailTemplatePurpose.INVITATION]).toEqual(
68
- TemplateMetadata[TemplateType.EMAIL][3].bindings
69
- )
70
- expect(result.body.bindings[EmailTemplatePurpose.CUSTOM]).toEqual(
71
- TemplateMetadata[TemplateType.EMAIL][4].bindings
72
- )
73
- })
74
- })
75
- })
28
+ describe("GET /api/global/template/:type", () => {})
76
29
 
77
- describe("POST /api/global/template", () => {
78
- it("adds a new template", async () => {
79
- let purpose = "base"
80
- let contents = "Test contents"
81
- let updatedTemplate = {
82
- contents: contents,
83
- purpose: purpose,
84
- type: "email",
85
- }
86
- await config.api.templates.saveTemplate(updatedTemplate)
87
- let res = await config.api.templates.getTemplate()
88
- let newTemplate = res.body.find((t: any) => (t.purpose = purpose))
89
- expect(newTemplate.contents).toEqual(contents)
90
- })
91
- })
30
+ describe("GET /api/global/template/:ownerId", () => {})
92
31
 
93
- describe("GET /api/global/template", () => {
94
- it("fetches templates", async () => {
95
- let res = await config.api.templates.getTemplate()
96
- expect(
97
- res.body.find((t: any) => t.purpose === EmailTemplatePurpose.BASE)
98
- ).toBeDefined()
99
- expect(
100
- res.body.find((t: any) => t.purpose === EmailTemplatePurpose.CUSTOM)
101
- ).toBeDefined()
102
- expect(
103
- res.body.find((t: any) => t.purpose === EmailTemplatePurpose.INVITATION)
104
- ).toBeDefined()
105
- expect(
106
- res.body.find(
107
- (t: any) => t.purpose === EmailTemplatePurpose.PASSWORD_RECOVERY
108
- )
109
- ).toBeDefined()
110
- expect(
111
- res.body.find((t: any) => t.purpose === EmailTemplatePurpose.WELCOME)
112
- ).toBeDefined()
113
- })
114
- })
32
+ describe("GET /api/global/template/:id", () => {})
33
+
34
+ describe("DELETE /api/global/template/:id/:rev", () => {})
115
35
  })
@@ -116,7 +116,7 @@ describe("/api/global/users", () => {
116
116
 
117
117
  it("should ignore users existing in other tenants", async () => {
118
118
  const user = await config.createUser()
119
- jest.clearAllMocks()
119
+ jest.resetAllMocks()
120
120
 
121
121
  await tenancy.doInTenant(TENANT_1, async () => {
122
122
  const response = await config.api.users.bulkCreateUsers([user])
@@ -229,7 +229,7 @@ describe("/api/global/users", () => {
229
229
 
230
230
  it("should not be able to create user that exists in other tenant", async () => {
231
231
  const user = await config.createUser()
232
- jest.clearAllMocks()
232
+ jest.resetAllMocks()
233
233
 
234
234
  await tenancy.doInTenant(TENANT_1, async () => {
235
235
  delete user._id