@budibase/worker 2.1.22-alpha.6 → 2.1.22-alpha.7
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/coverage/clover.xml +326 -305
- package/coverage/coverage-final.json +13 -13
- package/coverage/lcov-report/index.html +34 -34
- package/coverage/lcov-report/src/api/controllers/global/auth.ts.html +50 -38
- package/coverage/lcov-report/src/api/controllers/global/configs.js.html +18 -18
- package/coverage/lcov-report/src/api/controllers/global/email.js.html +1 -1
- package/coverage/lcov-report/src/api/controllers/global/index.html +10 -10
- package/coverage/lcov-report/src/api/controllers/global/license.ts.html +1 -1
- package/coverage/lcov-report/src/api/controllers/global/roles.js.html +1 -1
- package/coverage/lcov-report/src/api/controllers/global/self.ts.html +3 -3
- package/coverage/lcov-report/src/api/controllers/global/templates.ts.html +1 -1
- package/coverage/lcov-report/src/api/controllers/global/users.ts.html +1 -1
- package/coverage/lcov-report/src/api/controllers/global/workspaces.js.html +1 -1
- package/coverage/lcov-report/src/api/controllers/system/accounts.ts.html +1 -1
- package/coverage/lcov-report/src/api/controllers/system/environment.ts.html +1 -1
- package/coverage/lcov-report/src/api/controllers/system/index.html +1 -1
- package/coverage/lcov-report/src/api/controllers/system/migrations.ts.html +1 -1
- package/coverage/lcov-report/src/api/controllers/system/restore.ts.html +1 -1
- package/coverage/lcov-report/src/api/controllers/system/status.ts.html +1 -1
- package/coverage/lcov-report/src/api/controllers/system/tenants.ts.html +1 -1
- package/coverage/lcov-report/src/api/index.html +1 -1
- package/coverage/lcov-report/src/api/index.ts.html +1 -1
- package/coverage/lcov-report/src/api/routes/global/auth.js.html +1 -1
- package/coverage/lcov-report/src/api/routes/global/configs.js.html +10 -10
- package/coverage/lcov-report/src/api/routes/global/email.js.html +1 -1
- package/coverage/lcov-report/src/api/routes/global/index.html +1 -1
- package/coverage/lcov-report/src/api/routes/global/license.ts.html +1 -1
- package/coverage/lcov-report/src/api/routes/global/roles.js.html +1 -1
- package/coverage/lcov-report/src/api/routes/global/self.ts.html +1 -1
- package/coverage/lcov-report/src/api/routes/global/templates.ts.html +3 -3
- package/coverage/lcov-report/src/api/routes/global/users.js.html +1 -1
- package/coverage/lcov-report/src/api/routes/global/workspaces.js.html +1 -1
- package/coverage/lcov-report/src/api/routes/index.html +1 -1
- package/coverage/lcov-report/src/api/routes/index.ts.html +1 -1
- package/coverage/lcov-report/src/api/routes/system/accounts.ts.html +1 -1
- package/coverage/lcov-report/src/api/routes/system/environment.ts.html +1 -1
- package/coverage/lcov-report/src/api/routes/system/index.html +1 -1
- package/coverage/lcov-report/src/api/routes/system/migrations.ts.html +1 -1
- package/coverage/lcov-report/src/api/routes/system/restore.ts.html +1 -1
- package/coverage/lcov-report/src/api/routes/system/status.ts.html +1 -1
- package/coverage/lcov-report/src/api/routes/system/tenants.ts.html +1 -1
- package/coverage/lcov-report/src/api/routes/validation/index.html +1 -1
- package/coverage/lcov-report/src/api/routes/validation/index.ts.html +1 -1
- package/coverage/lcov-report/src/api/routes/validation/users.ts.html +1 -1
- package/coverage/lcov-report/src/constants/index.html +10 -10
- package/coverage/lcov-report/src/constants/{index.js.html → index.ts.html} +92 -113
- package/coverage/lcov-report/src/constants/templates/index.html +1 -1
- package/coverage/lcov-report/src/constants/templates/index.js.html +3 -3
- package/coverage/lcov-report/src/db/index.html +1 -1
- package/coverage/lcov-report/src/db/index.ts.html +1 -1
- package/coverage/lcov-report/src/environment.ts.html +1 -1
- package/coverage/lcov-report/src/index.html +1 -1
- package/coverage/lcov-report/src/index.ts.html +1 -1
- package/coverage/lcov-report/src/middleware/cloudRestricted.js.html +3 -3
- package/coverage/lcov-report/src/middleware/index.html +1 -1
- package/coverage/lcov-report/src/migrations/functions/globalInfoSyncUsers.ts.html +1 -1
- package/coverage/lcov-report/src/migrations/functions/index.html +1 -1
- package/coverage/lcov-report/src/migrations/index.html +1 -1
- package/coverage/lcov-report/src/migrations/index.ts.html +1 -1
- package/coverage/lcov-report/src/sdk/accounts/accounts.ts.html +1 -1
- package/coverage/lcov-report/src/sdk/accounts/index.html +1 -1
- package/coverage/lcov-report/src/sdk/accounts/index.ts.html +1 -1
- package/coverage/lcov-report/src/sdk/index.html +1 -1
- package/coverage/lcov-report/src/sdk/index.ts.html +1 -1
- package/coverage/lcov-report/src/sdk/users/events.ts.html +1 -1
- package/coverage/lcov-report/src/sdk/users/index.html +1 -1
- package/coverage/lcov-report/src/sdk/users/index.ts.html +1 -1
- package/coverage/lcov-report/src/sdk/users/users.ts.html +1 -1
- package/coverage/lcov-report/src/tests/TestConfiguration.ts.html +31 -22
- package/coverage/lcov-report/src/tests/api/accounts.ts.html +1 -1
- package/coverage/lcov-report/src/tests/api/auth.ts.html +1 -1
- package/coverage/lcov-report/src/tests/api/base.ts.html +1 -1
- package/coverage/lcov-report/src/tests/api/configs.ts.html +1 -1
- package/coverage/lcov-report/src/tests/api/email.ts.html +1 -1
- package/coverage/lcov-report/src/tests/api/environment.ts.html +1 -1
- package/coverage/lcov-report/src/tests/api/index.html +1 -1
- package/coverage/lcov-report/src/tests/api/index.ts.html +1 -1
- package/coverage/lcov-report/src/tests/api/migrations.ts.html +1 -1
- package/coverage/lcov-report/src/tests/api/restore.ts.html +1 -1
- package/coverage/lcov-report/src/tests/api/self.ts.html +1 -1
- package/coverage/lcov-report/src/tests/api/status.ts.html +1 -1
- package/coverage/lcov-report/src/tests/api/tenants.ts.html +1 -1
- package/coverage/lcov-report/src/tests/api/users.ts.html +1 -1
- package/coverage/lcov-report/src/tests/controllers.js.html +1 -1
- package/coverage/lcov-report/src/tests/index.html +15 -15
- package/coverage/lcov-report/src/tests/index.ts.html +1 -1
- package/coverage/lcov-report/src/tests/mocks/email.js.html +1 -1
- package/coverage/lcov-report/src/tests/mocks/index.html +1 -1
- package/coverage/lcov-report/src/tests/mocks/index.ts.html +1 -1
- package/coverage/lcov-report/src/tests/structures/configs.js.html +7 -7
- package/coverage/lcov-report/src/tests/structures/groups.ts.html +1 -1
- package/coverage/lcov-report/src/tests/structures/index.html +1 -1
- package/coverage/lcov-report/src/tests/structures/index.ts.html +1 -1
- package/coverage/lcov-report/src/tests/structures/users.ts.html +1 -1
- package/coverage/lcov-report/src/utilities/appService.js.html +4 -4
- package/coverage/lcov-report/src/utilities/{email.js.html → email.ts.html} +160 -61
- package/coverage/lcov-report/src/utilities/fileSystem.js.html +1 -1
- package/coverage/lcov-report/src/utilities/index.html +23 -23
- package/coverage/lcov-report/src/utilities/index.js.html +1 -1
- package/coverage/lcov-report/src/utilities/{redis.js.html → redis.ts.html} +53 -38
- package/coverage/lcov-report/src/utilities/{templates.js.html → templates.ts.html} +38 -38
- package/coverage/lcov-report/src/utilities/users.js.html +1 -1
- package/coverage/lcov.info +593 -529
- package/jest.config.ts +1 -0
- package/package.json +6 -6
- package/src/api/controllers/global/auth.ts +34 -30
- package/src/api/controllers/global/configs.js +17 -17
- package/src/api/controllers/global/self.ts +2 -2
- package/src/api/routes/global/configs.js +9 -9
- package/src/api/routes/global/templates.ts +2 -2
- package/src/api/routes/global/tests/configs.spec.ts +29 -29
- package/src/constants/{index.js → index.ts} +57 -64
- package/src/constants/templates/index.js +2 -2
- package/src/middleware/cloudRestricted.js +2 -2
- package/src/middleware/tests/tenancy.spec.ts +7 -7
- package/src/tests/TestConfiguration.ts +15 -12
- package/src/tests/structures/configs.js +6 -6
- package/src/utilities/appService.js +3 -3
- package/src/utilities/{email.js → email.ts} +78 -45
- package/src/utilities/{redis.js → redis.ts} +29 -24
- package/src/utilities/templates.ts +49 -0
- package/tsconfig.build.json +3 -3
- package/src/utilities/templates.js +0 -49
package/jest.config.ts
CHANGED
|
@@ -15,6 +15,7 @@ if (!process.env.CI) {
|
|
|
15
15
|
"@budibase/backend-core/(.*)": "<rootDir>/../backend-core/$1",
|
|
16
16
|
"@budibase/backend-core": "<rootDir>/../backend-core/src",
|
|
17
17
|
"@budibase/types": "<rootDir>/../types/src",
|
|
18
|
+
"^axios.*$": "<rootDir>/node_modules/axios/lib/axios.js",
|
|
18
19
|
}
|
|
19
20
|
// add pro sources if they exist
|
|
20
21
|
if (fs.existsSync("../../../budibase-pro")) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/worker",
|
|
3
3
|
"email": "hi@budibase.com",
|
|
4
|
-
"version": "2.1.22-alpha.
|
|
4
|
+
"version": "2.1.22-alpha.7",
|
|
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.1.22-alpha.
|
|
40
|
-
"@budibase/pro": "2.1.22-alpha.
|
|
41
|
-
"@budibase/string-templates": "2.1.22-alpha.
|
|
42
|
-
"@budibase/types": "2.1.22-alpha.
|
|
39
|
+
"@budibase/backend-core": "2.1.22-alpha.7",
|
|
40
|
+
"@budibase/pro": "2.1.22-alpha.6",
|
|
41
|
+
"@budibase/string-templates": "2.1.22-alpha.7",
|
|
42
|
+
"@budibase/types": "2.1.22-alpha.7",
|
|
43
43
|
"@koa/router": "8.0.8",
|
|
44
44
|
"@sentry/node": "6.17.7",
|
|
45
45
|
"@techpass/passport-openidconnect": "0.3.2",
|
|
@@ -94,5 +94,5 @@
|
|
|
94
94
|
"typescript": "4.7.3",
|
|
95
95
|
"update-dotenv": "1.1.1"
|
|
96
96
|
},
|
|
97
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "c90a987eb1fd4c82429fc965f7389f0af6fb48ed"
|
|
98
98
|
}
|
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
import core from "@budibase/backend-core"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
events,
|
|
4
|
+
users as usersCore,
|
|
5
|
+
context,
|
|
6
|
+
tenancy,
|
|
7
|
+
} from "@budibase/backend-core"
|
|
8
|
+
import { Config, EmailTemplatePurpose } from "../../../constants"
|
|
9
|
+
import { sendEmail, isEmailConfigured } from "../../../utilities/email"
|
|
10
|
+
import { checkResetPasswordCode } from "../../../utilities/redis"
|
|
11
|
+
import env from "../../../environment"
|
|
11
12
|
import sdk from "../../../sdk"
|
|
12
13
|
import { User } from "@budibase/types"
|
|
14
|
+
const { setCookie, getCookie, clearCookie, hash, platformLogout } = core.utils
|
|
15
|
+
const { Cookie, Header } = core.constants
|
|
16
|
+
const { passport, ssoCallbackUrl, google, oidc } = core.auth
|
|
13
17
|
|
|
14
18
|
export const googleCallbackUrl = async (config: any) => {
|
|
15
|
-
return ssoCallbackUrl(getGlobalDB(), config, "google")
|
|
19
|
+
return ssoCallbackUrl(tenancy.getGlobalDB(), config, "google")
|
|
16
20
|
}
|
|
17
21
|
|
|
18
22
|
export const oidcCallbackUrl = async (config: any) => {
|
|
19
|
-
return ssoCallbackUrl(getGlobalDB(), config, "oidc")
|
|
23
|
+
return ssoCallbackUrl(tenancy.getGlobalDB(), config, "oidc")
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
async function authInternal(ctx: any, user: any, err = null, info = null) {
|
|
@@ -30,13 +34,13 @@ async function authInternal(ctx: any, user: any, err = null, info = null) {
|
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
// set a cookie for browser access
|
|
33
|
-
setCookie(ctx, user.token,
|
|
37
|
+
setCookie(ctx, user.token, Cookie.Auth, { sign: false })
|
|
34
38
|
// set the token in a header as well for APIs
|
|
35
|
-
ctx.set(
|
|
39
|
+
ctx.set(Header.TOKEN, user.token)
|
|
36
40
|
// get rid of any app cookies on login
|
|
37
41
|
// have to check test because this breaks cypress
|
|
38
42
|
if (!env.isTest()) {
|
|
39
|
-
clearCookie(ctx,
|
|
43
|
+
clearCookie(ctx, Cookie.CurrentApp)
|
|
40
44
|
}
|
|
41
45
|
}
|
|
42
46
|
|
|
@@ -55,15 +59,15 @@ export const authenticate = async (ctx: any, next: any) => {
|
|
|
55
59
|
|
|
56
60
|
export const setInitInfo = (ctx: any) => {
|
|
57
61
|
const initInfo = ctx.request.body
|
|
58
|
-
setCookie(ctx, initInfo,
|
|
62
|
+
setCookie(ctx, initInfo, Cookie.Init)
|
|
59
63
|
ctx.status = 200
|
|
60
64
|
}
|
|
61
65
|
|
|
62
66
|
export const getInitInfo = (ctx: any) => {
|
|
63
67
|
try {
|
|
64
|
-
ctx.body = getCookie(ctx,
|
|
68
|
+
ctx.body = getCookie(ctx, Cookie.Init) || {}
|
|
65
69
|
} catch (err) {
|
|
66
|
-
clearCookie(ctx,
|
|
70
|
+
clearCookie(ctx, Cookie.Init)
|
|
67
71
|
ctx.body = {}
|
|
68
72
|
}
|
|
69
73
|
}
|
|
@@ -106,7 +110,7 @@ export const resetUpdate = async (ctx: any) => {
|
|
|
106
110
|
const { resetCode, password } = ctx.request.body
|
|
107
111
|
try {
|
|
108
112
|
const { userId } = await checkResetPasswordCode(resetCode)
|
|
109
|
-
const db = getGlobalDB()
|
|
113
|
+
const db = tenancy.getGlobalDB()
|
|
110
114
|
const user = await db.get(userId)
|
|
111
115
|
user.password = await hash(password)
|
|
112
116
|
await db.put(user)
|
|
@@ -141,14 +145,14 @@ export const datasourcePreAuth = async (ctx: any, next: any) => {
|
|
|
141
145
|
appId: ctx.query.appId,
|
|
142
146
|
datasourceId: ctx.query.datasourceId,
|
|
143
147
|
},
|
|
144
|
-
|
|
148
|
+
Cookie.DatasourceAuth
|
|
145
149
|
)
|
|
146
150
|
|
|
147
151
|
return handler.preAuth(passport, ctx, next)
|
|
148
152
|
}
|
|
149
153
|
|
|
150
154
|
export const datasourceAuth = async (ctx: any, next: any) => {
|
|
151
|
-
const authStateCookie = getCookie(ctx,
|
|
155
|
+
const authStateCookie = getCookie(ctx, Cookie.DatasourceAuth)
|
|
152
156
|
const provider = authStateCookie.provider
|
|
153
157
|
const middleware = require(`@budibase/backend-core/middleware`)
|
|
154
158
|
const handler = middleware.datasource[provider]
|
|
@@ -160,10 +164,10 @@ export const datasourceAuth = async (ctx: any, next: any) => {
|
|
|
160
164
|
* On a successful login, you will be redirected to the googleAuth callback route.
|
|
161
165
|
*/
|
|
162
166
|
export const googlePreAuth = async (ctx: any, next: any) => {
|
|
163
|
-
const db = getGlobalDB()
|
|
167
|
+
const db = tenancy.getGlobalDB()
|
|
164
168
|
|
|
165
169
|
const config = await core.db.getScopedConfig(db, {
|
|
166
|
-
type:
|
|
170
|
+
type: Config.GOOGLE,
|
|
167
171
|
workspace: ctx.query.workspace,
|
|
168
172
|
})
|
|
169
173
|
let callbackUrl = await exports.googleCallbackUrl(config)
|
|
@@ -181,10 +185,10 @@ export const googlePreAuth = async (ctx: any, next: any) => {
|
|
|
181
185
|
}
|
|
182
186
|
|
|
183
187
|
export const googleAuth = async (ctx: any, next: any) => {
|
|
184
|
-
const db = getGlobalDB()
|
|
188
|
+
const db = tenancy.getGlobalDB()
|
|
185
189
|
|
|
186
190
|
const config = await core.db.getScopedConfig(db, {
|
|
187
|
-
type:
|
|
191
|
+
type: Config.GOOGLE,
|
|
188
192
|
workspace: ctx.query.workspace,
|
|
189
193
|
})
|
|
190
194
|
const callbackUrl = await exports.googleCallbackUrl(config)
|
|
@@ -208,9 +212,9 @@ export const googleAuth = async (ctx: any, next: any) => {
|
|
|
208
212
|
}
|
|
209
213
|
|
|
210
214
|
export const oidcStrategyFactory = async (ctx: any, configId: any) => {
|
|
211
|
-
const db = getGlobalDB()
|
|
215
|
+
const db = tenancy.getGlobalDB()
|
|
212
216
|
const config = await core.db.getScopedConfig(db, {
|
|
213
|
-
type:
|
|
217
|
+
type: Config.OIDC,
|
|
214
218
|
group: ctx.query.group,
|
|
215
219
|
})
|
|
216
220
|
|
|
@@ -233,11 +237,11 @@ export const oidcPreAuth = async (ctx: any, next: any) => {
|
|
|
233
237
|
const { configId } = ctx.params
|
|
234
238
|
const strategy = await oidcStrategyFactory(ctx, configId)
|
|
235
239
|
|
|
236
|
-
setCookie(ctx, configId,
|
|
240
|
+
setCookie(ctx, configId, Cookie.OIDC_CONFIG)
|
|
237
241
|
|
|
238
|
-
const db = getGlobalDB()
|
|
242
|
+
const db = tenancy.getGlobalDB()
|
|
239
243
|
const config = await core.db.getScopedConfig(db, {
|
|
240
|
-
type:
|
|
244
|
+
type: Config.OIDC,
|
|
241
245
|
group: ctx.query.group,
|
|
242
246
|
})
|
|
243
247
|
|
|
@@ -255,7 +259,7 @@ export const oidcPreAuth = async (ctx: any, next: any) => {
|
|
|
255
259
|
}
|
|
256
260
|
|
|
257
261
|
export const oidcAuth = async (ctx: any, next: any) => {
|
|
258
|
-
const configId = getCookie(ctx,
|
|
262
|
+
const configId = getCookie(ctx, Cookie.OIDC_CONFIG)
|
|
259
263
|
const strategy = await oidcStrategyFactory(ctx, configId)
|
|
260
264
|
|
|
261
265
|
return passport.authenticate(
|
|
@@ -4,7 +4,7 @@ const {
|
|
|
4
4
|
getScopedFullConfig,
|
|
5
5
|
getAllApps,
|
|
6
6
|
} = require("@budibase/backend-core/db")
|
|
7
|
-
const {
|
|
7
|
+
const { Config } = require("../../../constants")
|
|
8
8
|
const email = require("../../../utilities/email")
|
|
9
9
|
const {
|
|
10
10
|
upload,
|
|
@@ -33,25 +33,25 @@ const getEventFns = async (db, config) => {
|
|
|
33
33
|
|
|
34
34
|
if (!existing) {
|
|
35
35
|
switch (config.type) {
|
|
36
|
-
case
|
|
36
|
+
case Config.SMTP: {
|
|
37
37
|
fns.push(events.email.SMTPCreated)
|
|
38
38
|
break
|
|
39
39
|
}
|
|
40
|
-
case
|
|
40
|
+
case Config.GOOGLE: {
|
|
41
41
|
fns.push(() => events.auth.SSOCreated(type))
|
|
42
42
|
if (config.config.activated) {
|
|
43
43
|
fns.push(() => events.auth.SSOActivated(type))
|
|
44
44
|
}
|
|
45
45
|
break
|
|
46
46
|
}
|
|
47
|
-
case
|
|
47
|
+
case Config.OIDC: {
|
|
48
48
|
fns.push(() => events.auth.SSOCreated(type))
|
|
49
49
|
if (config.config.configs[0].activated) {
|
|
50
50
|
fns.push(() => events.auth.SSOActivated(type))
|
|
51
51
|
}
|
|
52
52
|
break
|
|
53
53
|
}
|
|
54
|
-
case
|
|
54
|
+
case Config.SETTINGS: {
|
|
55
55
|
// company
|
|
56
56
|
const company = config.config.company
|
|
57
57
|
if (company && company !== "Budibase") {
|
|
@@ -78,11 +78,11 @@ const getEventFns = async (db, config) => {
|
|
|
78
78
|
}
|
|
79
79
|
} else {
|
|
80
80
|
switch (config.type) {
|
|
81
|
-
case
|
|
81
|
+
case Config.SMTP: {
|
|
82
82
|
fns.push(events.email.SMTPUpdated)
|
|
83
83
|
break
|
|
84
84
|
}
|
|
85
|
-
case
|
|
85
|
+
case Config.GOOGLE: {
|
|
86
86
|
fns.push(() => events.auth.SSOUpdated(type))
|
|
87
87
|
if (!existing.config.activated && config.config.activated) {
|
|
88
88
|
fns.push(() => events.auth.SSOActivated(type))
|
|
@@ -91,7 +91,7 @@ const getEventFns = async (db, config) => {
|
|
|
91
91
|
}
|
|
92
92
|
break
|
|
93
93
|
}
|
|
94
|
-
case
|
|
94
|
+
case Config.OIDC: {
|
|
95
95
|
fns.push(() => events.auth.SSOUpdated(type))
|
|
96
96
|
if (
|
|
97
97
|
!existing.config.configs[0].activated &&
|
|
@@ -106,7 +106,7 @@ const getEventFns = async (db, config) => {
|
|
|
106
106
|
}
|
|
107
107
|
break
|
|
108
108
|
}
|
|
109
|
-
case
|
|
109
|
+
case Config.SETTINGS: {
|
|
110
110
|
// company
|
|
111
111
|
const existingCompany = existing.config.company
|
|
112
112
|
const company = config.config.company
|
|
@@ -155,7 +155,7 @@ exports.save = async function (ctx) {
|
|
|
155
155
|
try {
|
|
156
156
|
// verify the configuration
|
|
157
157
|
switch (type) {
|
|
158
|
-
case
|
|
158
|
+
case Config.SMTP:
|
|
159
159
|
await email.verifyConfig(config)
|
|
160
160
|
break
|
|
161
161
|
}
|
|
@@ -237,7 +237,7 @@ exports.publicOidc = async function (ctx) {
|
|
|
237
237
|
try {
|
|
238
238
|
// Find the config with the most granular scope based on context
|
|
239
239
|
const oidcConfig = await getScopedFullConfig(db, {
|
|
240
|
-
type:
|
|
240
|
+
type: Config.OIDC,
|
|
241
241
|
})
|
|
242
242
|
|
|
243
243
|
if (!oidcConfig) {
|
|
@@ -260,15 +260,15 @@ exports.publicSettings = async function (ctx) {
|
|
|
260
260
|
try {
|
|
261
261
|
// Find the config with the most granular scope based on context
|
|
262
262
|
const publicConfig = await getScopedFullConfig(db, {
|
|
263
|
-
type:
|
|
263
|
+
type: Config.SETTINGS,
|
|
264
264
|
})
|
|
265
265
|
|
|
266
266
|
const googleConfig = await getScopedFullConfig(db, {
|
|
267
|
-
type:
|
|
267
|
+
type: Config.GOOGLE,
|
|
268
268
|
})
|
|
269
269
|
|
|
270
270
|
const oidcConfig = await getScopedFullConfig(db, {
|
|
271
|
-
type:
|
|
271
|
+
type: Config.OIDC,
|
|
272
272
|
})
|
|
273
273
|
|
|
274
274
|
let config
|
|
@@ -390,17 +390,17 @@ exports.configChecklist = async function (ctx) {
|
|
|
390
390
|
|
|
391
391
|
// They have set up SMTP
|
|
392
392
|
const smtpConfig = await getScopedFullConfig(db, {
|
|
393
|
-
type:
|
|
393
|
+
type: Config.SMTP,
|
|
394
394
|
})
|
|
395
395
|
|
|
396
396
|
// They have set up Google Auth
|
|
397
397
|
const googleConfig = await getScopedFullConfig(db, {
|
|
398
|
-
type:
|
|
398
|
+
type: Config.GOOGLE,
|
|
399
399
|
})
|
|
400
400
|
|
|
401
401
|
// They have set up OIDC
|
|
402
402
|
const oidcConfig = await getScopedFullConfig(db, {
|
|
403
|
-
type:
|
|
403
|
+
type: Config.OIDC,
|
|
404
404
|
})
|
|
405
405
|
|
|
406
406
|
// They have set up an global user
|
|
@@ -73,12 +73,12 @@ export async function fetchAPIKey(ctx: any) {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
const checkCurrentApp = (ctx: any) => {
|
|
76
|
-
const appCookie = getCookie(ctx, constants.
|
|
76
|
+
const appCookie = getCookie(ctx, constants.Cookie.CurrentApp)
|
|
77
77
|
if (appCookie && !tenancy.isUserInAppTenant(appCookie.appId)) {
|
|
78
78
|
// there is a currentapp cookie from another tenant
|
|
79
79
|
// remove the cookie as this is incompatible with the builder
|
|
80
80
|
// due to builder and admin permissions being removed
|
|
81
|
-
clearCookie(ctx, constants.
|
|
81
|
+
clearCookie(ctx, constants.Cookie.CurrentApp)
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
|
|
@@ -3,7 +3,7 @@ const controller = require("../../controllers/global/configs")
|
|
|
3
3
|
const { joiValidator } = require("@budibase/backend-core/auth")
|
|
4
4
|
const { adminOnly } = require("@budibase/backend-core/auth")
|
|
5
5
|
const Joi = require("joi")
|
|
6
|
-
const {
|
|
6
|
+
const { Config } = require("../../../constants")
|
|
7
7
|
|
|
8
8
|
const router = new Router()
|
|
9
9
|
|
|
@@ -65,17 +65,17 @@ function buildConfigSaveValidation() {
|
|
|
65
65
|
_id: Joi.string().optional(),
|
|
66
66
|
_rev: Joi.string().optional(),
|
|
67
67
|
workspace: Joi.string().optional(),
|
|
68
|
-
type: Joi.string().valid(...Object.values(
|
|
68
|
+
type: Joi.string().valid(...Object.values(Config)).required(),
|
|
69
69
|
createdAt: Joi.string().optional(),
|
|
70
70
|
updatedAt: Joi.string().optional(),
|
|
71
71
|
config: Joi.alternatives()
|
|
72
72
|
.conditional("type", {
|
|
73
73
|
switch: [
|
|
74
|
-
{ is:
|
|
75
|
-
{ is:
|
|
76
|
-
{ is:
|
|
77
|
-
{ is:
|
|
78
|
-
{ is:
|
|
74
|
+
{ is: Config.SMTP, then: smtpValidation() },
|
|
75
|
+
{ is: Config.SETTINGS, then: settingValidation() },
|
|
76
|
+
{ is: Config.ACCOUNT, then: Joi.object().unknown(true) },
|
|
77
|
+
{ is: Config.GOOGLE, then: googleValidation() },
|
|
78
|
+
{ is: Config.OIDC, then: oidcValidation() }
|
|
79
79
|
],
|
|
80
80
|
}),
|
|
81
81
|
}).required().unknown(true),
|
|
@@ -85,7 +85,7 @@ function buildConfigSaveValidation() {
|
|
|
85
85
|
function buildUploadValidation() {
|
|
86
86
|
// prettier-ignore
|
|
87
87
|
return joiValidator.params(Joi.object({
|
|
88
|
-
type: Joi.string().valid(...Object.values(
|
|
88
|
+
type: Joi.string().valid(...Object.values(Config)).required(),
|
|
89
89
|
name: Joi.string().required(),
|
|
90
90
|
}).required().unknown(true))
|
|
91
91
|
}
|
|
@@ -93,7 +93,7 @@ function buildUploadValidation() {
|
|
|
93
93
|
function buildConfigGetValidation() {
|
|
94
94
|
// prettier-ignore
|
|
95
95
|
return joiValidator.params(Joi.object({
|
|
96
|
-
type: Joi.string().valid(...Object.values(
|
|
96
|
+
type: Joi.string().valid(...Object.values(Config)).required()
|
|
97
97
|
}).required().unknown(true))
|
|
98
98
|
}
|
|
99
99
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Router from "@koa/router"
|
|
2
2
|
import * as controller from "../../controllers/global/templates"
|
|
3
|
-
import { TemplatePurpose,
|
|
3
|
+
import { TemplatePurpose, TemplateType } from "../../../constants"
|
|
4
4
|
import { auth as authCore } from "@budibase/backend-core"
|
|
5
5
|
import Joi from "joi"
|
|
6
6
|
const { adminOnly, joiValidator } = authCore
|
|
@@ -16,7 +16,7 @@ function buildTemplateSaveValidation() {
|
|
|
16
16
|
name: Joi.string().allow(null, ""),
|
|
17
17
|
contents: Joi.string().required(),
|
|
18
18
|
purpose: Joi.string().required().valid(...Object.values(TemplatePurpose)),
|
|
19
|
-
type: Joi.string().required().valid(...Object.values(
|
|
19
|
+
type: Joi.string().required().valid(...Object.values(TemplateType)),
|
|
20
20
|
}).required().unknown(true).optional())
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
jest.mock("nodemailer")
|
|
3
3
|
import { TestConfiguration, structures, mocks } from "../../../../tests"
|
|
4
4
|
mocks.email.mock()
|
|
5
|
-
import {
|
|
5
|
+
import { Config, events } from "@budibase/backend-core"
|
|
6
6
|
|
|
7
7
|
describe("configs", () => {
|
|
8
8
|
const config = new TestConfiguration()
|
|
@@ -49,20 +49,20 @@ describe("configs", () => {
|
|
|
49
49
|
it("should create activated google config", async () => {
|
|
50
50
|
await saveGoogleConfig()
|
|
51
51
|
expect(events.auth.SSOCreated).toBeCalledTimes(1)
|
|
52
|
-
expect(events.auth.SSOCreated).toBeCalledWith(
|
|
52
|
+
expect(events.auth.SSOCreated).toBeCalledWith(Config.GOOGLE)
|
|
53
53
|
expect(events.auth.SSODeactivated).not.toBeCalled()
|
|
54
54
|
expect(events.auth.SSOActivated).toBeCalledTimes(1)
|
|
55
|
-
expect(events.auth.SSOActivated).toBeCalledWith(
|
|
56
|
-
await config.deleteConfig(
|
|
55
|
+
expect(events.auth.SSOActivated).toBeCalledWith(Config.GOOGLE)
|
|
56
|
+
await config.deleteConfig(Config.GOOGLE)
|
|
57
57
|
})
|
|
58
58
|
|
|
59
59
|
it("should create deactivated google config", async () => {
|
|
60
60
|
await saveGoogleConfig({ activated: false })
|
|
61
61
|
expect(events.auth.SSOCreated).toBeCalledTimes(1)
|
|
62
|
-
expect(events.auth.SSOCreated).toBeCalledWith(
|
|
62
|
+
expect(events.auth.SSOCreated).toBeCalledWith(Config.GOOGLE)
|
|
63
63
|
expect(events.auth.SSOActivated).not.toBeCalled()
|
|
64
64
|
expect(events.auth.SSODeactivated).not.toBeCalled()
|
|
65
|
-
await config.deleteConfig(
|
|
65
|
+
await config.deleteConfig(Config.GOOGLE)
|
|
66
66
|
})
|
|
67
67
|
})
|
|
68
68
|
|
|
@@ -76,11 +76,11 @@ describe("configs", () => {
|
|
|
76
76
|
googleConf._rev
|
|
77
77
|
)
|
|
78
78
|
expect(events.auth.SSOUpdated).toBeCalledTimes(1)
|
|
79
|
-
expect(events.auth.SSOUpdated).toBeCalledWith(
|
|
79
|
+
expect(events.auth.SSOUpdated).toBeCalledWith(Config.GOOGLE)
|
|
80
80
|
expect(events.auth.SSOActivated).not.toBeCalled()
|
|
81
81
|
expect(events.auth.SSODeactivated).toBeCalledTimes(1)
|
|
82
|
-
expect(events.auth.SSODeactivated).toBeCalledWith(
|
|
83
|
-
await config.deleteConfig(
|
|
82
|
+
expect(events.auth.SSODeactivated).toBeCalledWith(Config.GOOGLE)
|
|
83
|
+
await config.deleteConfig(Config.GOOGLE)
|
|
84
84
|
})
|
|
85
85
|
|
|
86
86
|
it("should update google config to activated", async () => {
|
|
@@ -92,11 +92,11 @@ describe("configs", () => {
|
|
|
92
92
|
googleConf._rev
|
|
93
93
|
)
|
|
94
94
|
expect(events.auth.SSOUpdated).toBeCalledTimes(1)
|
|
95
|
-
expect(events.auth.SSOUpdated).toBeCalledWith(
|
|
95
|
+
expect(events.auth.SSOUpdated).toBeCalledWith(Config.GOOGLE)
|
|
96
96
|
expect(events.auth.SSODeactivated).not.toBeCalled()
|
|
97
97
|
expect(events.auth.SSOActivated).toBeCalledTimes(1)
|
|
98
|
-
expect(events.auth.SSOActivated).toBeCalledWith(
|
|
99
|
-
await config.deleteConfig(
|
|
98
|
+
expect(events.auth.SSOActivated).toBeCalledWith(Config.GOOGLE)
|
|
99
|
+
await config.deleteConfig(Config.GOOGLE)
|
|
100
100
|
})
|
|
101
101
|
})
|
|
102
102
|
})
|
|
@@ -115,20 +115,20 @@ describe("configs", () => {
|
|
|
115
115
|
it("should create activated OIDC config", async () => {
|
|
116
116
|
await saveOIDCConfig()
|
|
117
117
|
expect(events.auth.SSOCreated).toBeCalledTimes(1)
|
|
118
|
-
expect(events.auth.SSOCreated).toBeCalledWith(
|
|
118
|
+
expect(events.auth.SSOCreated).toBeCalledWith(Config.OIDC)
|
|
119
119
|
expect(events.auth.SSODeactivated).not.toBeCalled()
|
|
120
120
|
expect(events.auth.SSOActivated).toBeCalledTimes(1)
|
|
121
|
-
expect(events.auth.SSOActivated).toBeCalledWith(
|
|
122
|
-
await config.deleteConfig(
|
|
121
|
+
expect(events.auth.SSOActivated).toBeCalledWith(Config.OIDC)
|
|
122
|
+
await config.deleteConfig(Config.OIDC)
|
|
123
123
|
})
|
|
124
124
|
|
|
125
125
|
it("should create deactivated OIDC config", async () => {
|
|
126
126
|
await saveOIDCConfig({ activated: false })
|
|
127
127
|
expect(events.auth.SSOCreated).toBeCalledTimes(1)
|
|
128
|
-
expect(events.auth.SSOCreated).toBeCalledWith(
|
|
128
|
+
expect(events.auth.SSOCreated).toBeCalledWith(Config.OIDC)
|
|
129
129
|
expect(events.auth.SSOActivated).not.toBeCalled()
|
|
130
130
|
expect(events.auth.SSODeactivated).not.toBeCalled()
|
|
131
|
-
await config.deleteConfig(
|
|
131
|
+
await config.deleteConfig(Config.OIDC)
|
|
132
132
|
})
|
|
133
133
|
})
|
|
134
134
|
|
|
@@ -142,11 +142,11 @@ describe("configs", () => {
|
|
|
142
142
|
oidcConf._rev
|
|
143
143
|
)
|
|
144
144
|
expect(events.auth.SSOUpdated).toBeCalledTimes(1)
|
|
145
|
-
expect(events.auth.SSOUpdated).toBeCalledWith(
|
|
145
|
+
expect(events.auth.SSOUpdated).toBeCalledWith(Config.OIDC)
|
|
146
146
|
expect(events.auth.SSOActivated).not.toBeCalled()
|
|
147
147
|
expect(events.auth.SSODeactivated).toBeCalledTimes(1)
|
|
148
|
-
expect(events.auth.SSODeactivated).toBeCalledWith(
|
|
149
|
-
await config.deleteConfig(
|
|
148
|
+
expect(events.auth.SSODeactivated).toBeCalledWith(Config.OIDC)
|
|
149
|
+
await config.deleteConfig(Config.OIDC)
|
|
150
150
|
})
|
|
151
151
|
|
|
152
152
|
it("should update OIDC config to activated", async () => {
|
|
@@ -158,11 +158,11 @@ describe("configs", () => {
|
|
|
158
158
|
oidcConf._rev
|
|
159
159
|
)
|
|
160
160
|
expect(events.auth.SSOUpdated).toBeCalledTimes(1)
|
|
161
|
-
expect(events.auth.SSOUpdated).toBeCalledWith(
|
|
161
|
+
expect(events.auth.SSOUpdated).toBeCalledWith(Config.OIDC)
|
|
162
162
|
expect(events.auth.SSODeactivated).not.toBeCalled()
|
|
163
163
|
expect(events.auth.SSOActivated).toBeCalledTimes(1)
|
|
164
|
-
expect(events.auth.SSOActivated).toBeCalledWith(
|
|
165
|
-
await config.deleteConfig(
|
|
164
|
+
expect(events.auth.SSOActivated).toBeCalledWith(Config.OIDC)
|
|
165
|
+
await config.deleteConfig(Config.OIDC)
|
|
166
166
|
})
|
|
167
167
|
})
|
|
168
168
|
})
|
|
@@ -179,11 +179,11 @@ describe("configs", () => {
|
|
|
179
179
|
|
|
180
180
|
describe("create", () => {
|
|
181
181
|
it("should create SMTP config", async () => {
|
|
182
|
-
await config.deleteConfig(
|
|
182
|
+
await config.deleteConfig(Config.SMTP)
|
|
183
183
|
await saveSMTPConfig()
|
|
184
184
|
expect(events.email.SMTPUpdated).not.toBeCalled()
|
|
185
185
|
expect(events.email.SMTPCreated).toBeCalledTimes(1)
|
|
186
|
-
await config.deleteConfig(
|
|
186
|
+
await config.deleteConfig(Config.SMTP)
|
|
187
187
|
})
|
|
188
188
|
})
|
|
189
189
|
|
|
@@ -194,7 +194,7 @@ describe("configs", () => {
|
|
|
194
194
|
await saveSMTPConfig(smtpConf.config, smtpConf._id, smtpConf._rev)
|
|
195
195
|
expect(events.email.SMTPCreated).not.toBeCalled()
|
|
196
196
|
expect(events.email.SMTPUpdated).toBeCalledTimes(1)
|
|
197
|
-
await config.deleteConfig(
|
|
197
|
+
await config.deleteConfig(Config.SMTP)
|
|
198
198
|
})
|
|
199
199
|
})
|
|
200
200
|
})
|
|
@@ -211,7 +211,7 @@ describe("configs", () => {
|
|
|
211
211
|
|
|
212
212
|
describe("create", () => {
|
|
213
213
|
it("should create settings config with default settings", async () => {
|
|
214
|
-
await config.deleteConfig(
|
|
214
|
+
await config.deleteConfig(Config.SETTINGS)
|
|
215
215
|
|
|
216
216
|
await saveSettingsConfig()
|
|
217
217
|
|
|
@@ -222,7 +222,7 @@ describe("configs", () => {
|
|
|
222
222
|
|
|
223
223
|
it("should create settings config with non-default settings", async () => {
|
|
224
224
|
config.modeSelf()
|
|
225
|
-
await config.deleteConfig(
|
|
225
|
+
await config.deleteConfig(Config.SETTINGS)
|
|
226
226
|
const conf = {
|
|
227
227
|
company: "acme",
|
|
228
228
|
logoUrl: "http://example.com",
|
|
@@ -241,7 +241,7 @@ describe("configs", () => {
|
|
|
241
241
|
describe("update", () => {
|
|
242
242
|
it("should update settings config", async () => {
|
|
243
243
|
config.modeSelf()
|
|
244
|
-
await config.deleteConfig(
|
|
244
|
+
await config.deleteConfig(Config.SETTINGS)
|
|
245
245
|
const settingsConfig = await saveSettingsConfig()
|
|
246
246
|
settingsConfig.config.company = "acme"
|
|
247
247
|
settingsConfig.config.logoUrl = "http://example.com"
|