@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.
- package/coverage/clover.xml +1238 -1291
- package/coverage/coverage-final.json +77 -81
- package/coverage/lcov-report/index.html +73 -73
- package/coverage/lcov-report/src/api/controllers/global/auth.ts.html +26 -26
- package/coverage/lcov-report/src/api/controllers/global/configs.ts.html +212 -155
- package/coverage/lcov-report/src/api/controllers/global/email.ts.html +4 -4
- package/coverage/lcov-report/src/api/controllers/global/index.html +39 -39
- package/coverage/lcov-report/src/api/controllers/global/license.ts.html +7 -7
- package/coverage/lcov-report/src/api/controllers/global/roles.ts.html +76 -76
- package/coverage/lcov-report/src/api/controllers/global/self.ts.html +14 -14
- package/coverage/lcov-report/src/api/controllers/global/templates.ts.html +53 -53
- package/coverage/lcov-report/src/api/controllers/global/users.ts.html +27 -27
- package/coverage/lcov-report/src/api/controllers/global/workspaces.ts.html +6 -6
- package/coverage/lcov-report/src/api/controllers/system/accounts.ts.html +4 -4
- package/coverage/lcov-report/src/api/controllers/system/environment.ts.html +3 -3
- package/coverage/lcov-report/src/api/controllers/system/index.html +1 -1
- package/coverage/lcov-report/src/api/controllers/system/migrations.ts.html +4 -4
- package/coverage/lcov-report/src/api/controllers/system/restore.ts.html +4 -4
- package/coverage/lcov-report/src/api/controllers/system/status.ts.html +4 -4
- package/coverage/lcov-report/src/api/controllers/system/tenants.ts.html +5 -5
- package/coverage/lcov-report/src/api/index.html +1 -1
- package/coverage/lcov-report/src/api/index.ts.html +23 -23
- package/coverage/lcov-report/src/api/routes/global/auth.ts.html +11 -11
- package/coverage/lcov-report/src/api/routes/global/configs.ts.html +16 -16
- package/coverage/lcov-report/src/api/routes/global/email.ts.html +10 -10
- package/coverage/lcov-report/src/api/routes/global/index.html +1 -1
- package/coverage/lcov-report/src/api/routes/global/license.ts.html +7 -7
- package/coverage/lcov-report/src/api/routes/global/roles.ts.html +7 -7
- package/coverage/lcov-report/src/api/routes/global/self.ts.html +8 -8
- package/coverage/lcov-report/src/api/routes/global/templates.ts.html +11 -11
- package/coverage/lcov-report/src/api/routes/global/users.ts.html +16 -16
- package/coverage/lcov-report/src/api/routes/global/workspaces.ts.html +9 -9
- package/coverage/lcov-report/src/api/routes/index.html +1 -1
- package/coverage/lcov-report/src/api/routes/index.ts.html +19 -19
- package/coverage/lcov-report/src/api/routes/system/accounts.ts.html +7 -7
- package/coverage/lcov-report/src/api/routes/system/environment.ts.html +6 -6
- package/coverage/lcov-report/src/api/routes/system/index.html +1 -1
- package/coverage/lcov-report/src/api/routes/system/migrations.ts.html +7 -7
- package/coverage/lcov-report/src/api/routes/system/restore.ts.html +6 -6
- package/coverage/lcov-report/src/api/routes/system/status.ts.html +6 -6
- package/coverage/lcov-report/src/api/routes/system/tenants.ts.html +7 -7
- package/coverage/lcov-report/src/api/routes/validation/index.html +1 -1
- package/coverage/lcov-report/src/api/routes/validation/index.ts.html +2 -2
- package/coverage/lcov-report/src/api/routes/validation/users.ts.html +13 -13
- package/coverage/lcov-report/src/constants/index.html +9 -9
- package/coverage/lcov-report/src/constants/index.ts.html +49 -73
- package/coverage/lcov-report/src/constants/templates/index.html +19 -19
- package/coverage/lcov-report/src/constants/templates/index.ts.html +39 -39
- package/coverage/lcov-report/src/db/index.html +1 -1
- package/coverage/lcov-report/src/db/index.ts.html +8 -8
- package/coverage/lcov-report/src/environment.ts.html +22 -37
- package/coverage/lcov-report/src/index.html +15 -15
- package/coverage/lcov-report/src/index.ts.html +43 -40
- package/coverage/lcov-report/src/middleware/cloudRestricted.ts.html +4 -4
- package/coverage/lcov-report/src/middleware/index.html +1 -1
- package/coverage/lcov-report/src/migrations/functions/globalInfoSyncUsers.ts.html +3 -3
- 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 +17 -17
- package/coverage/lcov-report/src/sdk/accounts/accounts.ts.html +6 -6
- package/coverage/lcov-report/src/sdk/accounts/index.html +1 -1
- package/coverage/lcov-report/src/sdk/accounts/index.ts.html +2 -2
- package/coverage/lcov-report/src/sdk/index.html +1 -1
- package/coverage/lcov-report/src/sdk/index.ts.html +4 -4
- package/coverage/lcov-report/src/sdk/users/events.ts.html +46 -46
- package/coverage/lcov-report/src/sdk/users/index.html +15 -15
- package/coverage/lcov-report/src/sdk/users/index.ts.html +2 -2
- package/coverage/lcov-report/src/sdk/users/users.ts.html +97 -148
- package/coverage/lcov-report/src/tests/TestConfiguration.ts.html +80 -104
- package/coverage/lcov-report/src/tests/api/accounts.ts.html +6 -6
- package/coverage/lcov-report/src/tests/api/auth.ts.html +7 -7
- package/coverage/lcov-report/src/tests/api/base.ts.html +4 -4
- package/coverage/lcov-report/src/tests/api/configs.ts.html +8 -8
- package/coverage/lcov-report/src/tests/api/email.ts.html +5 -5
- package/coverage/lcov-report/src/tests/api/environment.ts.html +5 -5
- package/coverage/lcov-report/src/tests/api/index.html +11 -71
- package/coverage/lcov-report/src/tests/api/index.ts.html +28 -61
- package/coverage/lcov-report/src/tests/api/migrations.ts.html +6 -6
- package/coverage/lcov-report/src/tests/api/restore.ts.html +5 -5
- package/coverage/lcov-report/src/tests/api/self.ts.html +6 -6
- package/coverage/lcov-report/src/tests/api/status.ts.html +5 -5
- package/coverage/lcov-report/src/tests/api/tenants.ts.html +5 -5
- package/coverage/lcov-report/src/tests/api/users.ts.html +16 -16
- package/coverage/lcov-report/src/tests/controllers.ts.html +6 -6
- package/coverage/lcov-report/src/tests/index.html +10 -10
- package/coverage/lcov-report/src/tests/index.ts.html +9 -9
- package/coverage/lcov-report/src/tests/mocks/{email.ts.html → email.js.html} +5 -5
- package/coverage/lcov-report/src/tests/mocks/index.html +2 -2
- package/coverage/lcov-report/src/tests/mocks/index.ts.html +7 -7
- package/coverage/lcov-report/src/tests/structures/configs.ts.html +10 -10
- package/coverage/lcov-report/src/tests/structures/groups.ts.html +15 -15
- package/coverage/lcov-report/src/tests/structures/index.html +16 -16
- package/coverage/lcov-report/src/tests/structures/index.ts.html +11 -11
- package/coverage/lcov-report/src/tests/structures/users.ts.html +11 -11
- package/coverage/lcov-report/src/utilities/appService.ts.html +10 -10
- package/coverage/lcov-report/src/utilities/email.ts.html +15 -15
- package/coverage/lcov-report/src/utilities/fileSystem.ts.html +4 -4
- package/coverage/lcov-report/src/utilities/index.html +1 -1
- package/coverage/lcov-report/src/utilities/index.ts.html +2 -2
- package/coverage/lcov-report/src/utilities/redis.ts.html +12 -12
- package/coverage/lcov-report/src/utilities/templates.ts.html +6 -6
- package/coverage/lcov-report/src/utilities/users.ts.html +3 -3
- package/coverage/lcov.info +1779 -1949
- package/jest.config.ts +0 -2
- package/package.json +7 -8
- package/src/api/controllers/global/configs.ts +131 -112
- package/src/api/controllers/global/users.ts +1 -1
- package/src/api/routes/global/license.ts +1 -1
- package/src/api/routes/global/tests/license.spec.ts +2 -0
- package/src/api/routes/global/tests/roles.spec.ts +5 -66
- package/src/api/routes/global/tests/templates.spec.ts +9 -89
- package/src/api/routes/global/tests/users.spec.ts +2 -2
- package/src/constants/index.ts +5 -13
- package/src/environment.ts +0 -5
- package/src/index.ts +2 -1
- package/src/sdk/users/users.ts +1 -18
- package/src/tests/TestConfiguration.ts +1 -9
- package/src/tests/api/index.ts +1 -12
- package/src/tests/jestSetup.ts +1 -3
- package/src/tests/mocks/{email.ts → email.js} +1 -1
- package/src/tests/mocks/index.ts +3 -3
- package/src/tests/structures/configs.ts +2 -2
- package/src/tests/structures/groups.ts +1 -1
- package/src/tests/structures/users.ts +1 -1
- package/tsconfig.json +1 -0
- package/coverage/lcov-report/src/tests/api/groups.ts.html +0 -163
- package/coverage/lcov-report/src/tests/api/license.ts.html +0 -136
- package/coverage/lcov-report/src/tests/api/roles.ts.html +0 -181
- package/coverage/lcov-report/src/tests/api/templates.ts.html +0 -175
- package/src/api/routes/global/tests/groups.spec.ts +0 -58
- package/src/tests/api/groups.ts +0 -26
- package/src/tests/api/license.ts +0 -17
- package/src/tests/api/roles.ts +0 -32
- 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
|
|
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
|
|
40
|
-
"@budibase/pro": "2.2.
|
|
41
|
-
"@budibase/string-templates": "2.2.12
|
|
42
|
-
"@budibase/types": "2.2.12
|
|
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.
|
|
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": "
|
|
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
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
63
|
+
// logo
|
|
64
|
+
const logoUrl = settingsCfg.config.logoUrl
|
|
65
|
+
if (logoUrl) {
|
|
66
|
+
fns.push(events.org.logoUpdated)
|
|
67
|
+
}
|
|
62
68
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
!existing.config.
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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
|
|
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:
|
|
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:
|
|
305
|
-
if (ctx.request.files == null ||
|
|
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
|
|
318
|
+
const file = ctx.request.files.file
|
|
309
319
|
const { type, name } = ctx.params
|
|
310
320
|
|
|
311
|
-
let bucket
|
|
312
|
-
|
|
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
|
-
|
|
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
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
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
|
-
|
|
339
|
-
|
|
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
|
|
365
|
+
url,
|
|
347
366
|
}
|
|
348
367
|
}
|
|
349
368
|
|
|
350
|
-
export async function destroy(ctx:
|
|
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:
|
|
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
|
|
181
|
+
const user = await tenancy.getTenantUser(id)
|
|
182
182
|
if (user) {
|
|
183
183
|
ctx.body = user
|
|
184
184
|
} else {
|
|
@@ -1,47 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { context, db, permissions, roles } from "@budibase/backend-core"
|
|
3
|
-
import { Mock } from "jest-mock"
|
|
1
|
+
import { TestConfiguration } from "../../../../tests"
|
|
4
2
|
|
|
5
|
-
|
|
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",
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
let result = await config.api.templates.definitions()
|
|
21
|
+
it("retrieves definitions", () => {})
|
|
22
|
+
})
|
|
37
23
|
|
|
38
|
-
|
|
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
|
-
|
|
56
|
-
let result = await config.api.templates.definitions()
|
|
26
|
+
describe("GET /api/global/template", () => {})
|
|
57
27
|
|
|
58
|
-
|
|
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("
|
|
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
|
-
|
|
95
|
-
|
|
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.
|
|
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.
|
|
232
|
+
jest.resetAllMocks()
|
|
233
233
|
|
|
234
234
|
await tenancy.doInTenant(TENANT_1, async () => {
|
|
235
235
|
delete user._id
|