@budibase/worker 2.2.3 → 2.2.4-alpha.0
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 +1291 -1238
- package/coverage/coverage-final.json +81 -77
- 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 +154 -211
- 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 +73 -49
- 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 +37 -22
- package/coverage/lcov-report/src/index.html +15 -15
- package/coverage/lcov-report/src/index.ts.html +40 -43
- 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 +148 -97
- package/coverage/lcov-report/src/tests/TestConfiguration.ts.html +104 -80
- 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/groups.ts.html +163 -0
- package/coverage/lcov-report/src/tests/api/index.html +71 -11
- package/coverage/lcov-report/src/tests/api/index.ts.html +61 -28
- package/coverage/lcov-report/src/tests/api/license.ts.html +136 -0
- 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/roles.ts.html +181 -0
- 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/templates.ts.html +175 -0
- 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.js.html → email.ts.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 +1949 -1779
- package/jest.config.ts +2 -0
- package/package.json +8 -7
- package/src/api/controllers/global/configs.ts +111 -130
- package/src/api/controllers/global/users.ts +1 -1
- package/src/api/routes/global/license.ts +1 -1
- package/src/api/routes/global/tests/groups.spec.ts +58 -0
- package/src/api/routes/global/tests/license.spec.ts +0 -2
- package/src/api/routes/global/tests/roles.spec.ts +66 -5
- package/src/api/routes/global/tests/templates.spec.ts +89 -9
- package/src/api/routes/global/tests/users.spec.ts +2 -2
- package/src/constants/index.ts +13 -5
- package/src/environment.ts +5 -0
- package/src/index.ts +1 -2
- package/src/sdk/users/users.ts +18 -1
- package/src/tests/TestConfiguration.ts +9 -1
- package/src/tests/api/groups.ts +26 -0
- package/src/tests/api/index.ts +12 -1
- package/src/tests/api/license.ts +17 -0
- package/src/tests/api/roles.ts +32 -0
- package/src/tests/api/templates.ts +30 -0
- package/src/tests/jestSetup.ts +3 -1
- package/src/tests/mocks/{email.js → email.ts} +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 +0 -1
package/jest.config.ts
CHANGED
|
@@ -19,6 +19,8 @@ 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"
|
|
22
24
|
config.moduleNameMapper["@budibase/pro"] =
|
|
23
25
|
"<rootDir>/../../../budibase-pro/packages/pro/src"
|
|
24
26
|
}
|
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.
|
|
4
|
+
"version": "2.2.4-alpha.0",
|
|
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": "
|
|
40
|
-
"@budibase/pro": "2.2.
|
|
41
|
-
"@budibase/string-templates": "
|
|
42
|
-
"@budibase/types": "
|
|
39
|
+
"@budibase/backend-core": "2.2.4-alpha.0",
|
|
40
|
+
"@budibase/pro": "2.2.3",
|
|
41
|
+
"@budibase/string-templates": "2.2.4-alpha.0",
|
|
42
|
+
"@budibase/types": "2.2.4-alpha.0",
|
|
43
43
|
"@koa/router": "8.0.8",
|
|
44
44
|
"@sentry/node": "6.17.7",
|
|
45
45
|
"@techpass/passport-openidconnect": "0.3.2",
|
|
@@ -73,10 +73,11 @@
|
|
|
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.8",
|
|
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",
|
|
80
81
|
"@types/uuid": "8.3.4",
|
|
81
82
|
"@typescript-eslint/parser": "5.45.0",
|
|
82
83
|
"copyfiles": "2.4.1",
|
|
@@ -94,5 +95,5 @@
|
|
|
94
95
|
"typescript": "4.7.3",
|
|
95
96
|
"update-dotenv": "1.1.1"
|
|
96
97
|
},
|
|
97
|
-
"gitHead": "
|
|
98
|
+
"gitHead": "e4f14f013c9627ba5c97aed22a30b697dc9bbcb9"
|
|
98
99
|
}
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
objectStore,
|
|
8
8
|
tenancy,
|
|
9
9
|
db as dbCore,
|
|
10
|
+
env as coreEnv,
|
|
10
11
|
} from "@budibase/backend-core"
|
|
11
12
|
import { checkAnyUserExists } from "../../../utilities/users"
|
|
12
13
|
import {
|
|
@@ -17,127 +18,106 @@ import {
|
|
|
17
18
|
GoogleConfig,
|
|
18
19
|
OIDCConfig,
|
|
19
20
|
SettingsConfig,
|
|
20
|
-
|
|
21
|
+
isGoogleConfig,
|
|
22
|
+
isOIDCConfig,
|
|
23
|
+
isSettingsConfig,
|
|
24
|
+
isSMTPConfig,
|
|
25
|
+
Ctx,
|
|
26
|
+
UserCtx,
|
|
21
27
|
} from "@budibase/types"
|
|
22
28
|
|
|
23
29
|
const getEventFns = async (db: Database, config: ConfigDoc) => {
|
|
24
30
|
const fns = []
|
|
25
|
-
const type = config.type
|
|
26
31
|
|
|
27
32
|
let existing
|
|
28
33
|
if (config._id) {
|
|
29
34
|
existing = await db.get(config._id)
|
|
30
35
|
}
|
|
31
36
|
|
|
32
|
-
const ssoType = type as SSOType
|
|
33
37
|
if (!existing) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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))
|
|
38
44
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
fns.push(() => events.auth.SSOActivated(ssoType))
|
|
44
|
-
}
|
|
45
|
-
break
|
|
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))
|
|
46
49
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
break
|
|
50
|
+
} else if (isSettingsConfig(config)) {
|
|
51
|
+
// company
|
|
52
|
+
const company = config.config.company
|
|
53
|
+
if (company && company !== "Budibase") {
|
|
54
|
+
fns.push(events.org.nameUpdated)
|
|
54
55
|
}
|
|
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
|
-
}
|
|
62
56
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
57
|
+
// logo
|
|
58
|
+
const logoUrl = config.config.logoUrl
|
|
59
|
+
if (logoUrl) {
|
|
60
|
+
fns.push(events.org.logoUpdated)
|
|
61
|
+
}
|
|
68
62
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
break
|
|
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)
|
|
79
71
|
}
|
|
80
72
|
}
|
|
81
73
|
} else {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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))
|
|
86
82
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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))
|
|
96
95
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
|
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)
|
|
112
102
|
}
|
|
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
|
-
}
|
|
121
103
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
+
}
|
|
128
110
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
break
|
|
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)
|
|
141
121
|
}
|
|
142
122
|
}
|
|
143
123
|
}
|
|
@@ -145,7 +125,7 @@ const getEventFns = async (db: Database, config: ConfigDoc) => {
|
|
|
145
125
|
return fns
|
|
146
126
|
}
|
|
147
127
|
|
|
148
|
-
export async function save(ctx:
|
|
128
|
+
export async function save(ctx: UserCtx) {
|
|
149
129
|
const db = tenancy.getGlobalDB()
|
|
150
130
|
const { type, workspace, user, config } = ctx.request.body
|
|
151
131
|
let eventFns = await getEventFns(db, ctx.request.body)
|
|
@@ -187,7 +167,7 @@ export async function save(ctx: BBContext) {
|
|
|
187
167
|
}
|
|
188
168
|
}
|
|
189
169
|
|
|
190
|
-
export async function fetch(ctx:
|
|
170
|
+
export async function fetch(ctx: UserCtx) {
|
|
191
171
|
const db = tenancy.getGlobalDB()
|
|
192
172
|
const response = await db.allDocs(
|
|
193
173
|
dbCore.getConfigParams(
|
|
@@ -204,7 +184,7 @@ export async function fetch(ctx: BBContext) {
|
|
|
204
184
|
* Gets the most granular config for a particular configuration type.
|
|
205
185
|
* The hierarchy is type -> workspace -> user.
|
|
206
186
|
*/
|
|
207
|
-
export async function find(ctx:
|
|
187
|
+
export async function find(ctx: UserCtx) {
|
|
208
188
|
const db = tenancy.getGlobalDB()
|
|
209
189
|
|
|
210
190
|
const { userId, workspaceId } = ctx.query
|
|
@@ -237,18 +217,18 @@ export async function find(ctx: BBContext) {
|
|
|
237
217
|
}
|
|
238
218
|
}
|
|
239
219
|
|
|
240
|
-
export async function publicOidc(ctx:
|
|
220
|
+
export async function publicOidc(ctx: Ctx) {
|
|
241
221
|
const db = tenancy.getGlobalDB()
|
|
242
222
|
try {
|
|
243
223
|
// Find the config with the most granular scope based on context
|
|
244
|
-
const oidcConfig = await dbCore.getScopedFullConfig(db, {
|
|
224
|
+
const oidcConfig: OIDCConfig = await dbCore.getScopedFullConfig(db, {
|
|
245
225
|
type: ConfigType.OIDC,
|
|
246
226
|
})
|
|
247
227
|
|
|
248
228
|
if (!oidcConfig) {
|
|
249
229
|
ctx.body = {}
|
|
250
230
|
} else {
|
|
251
|
-
ctx.body = oidcConfig.config.configs.map(
|
|
231
|
+
ctx.body = oidcConfig.config.configs.map(config => ({
|
|
252
232
|
logo: config.logo,
|
|
253
233
|
name: config.name,
|
|
254
234
|
uuid: config.uuid,
|
|
@@ -259,7 +239,7 @@ export async function publicOidc(ctx: BBContext) {
|
|
|
259
239
|
}
|
|
260
240
|
}
|
|
261
241
|
|
|
262
|
-
export async function publicSettings(ctx:
|
|
242
|
+
export async function publicSettings(ctx: Ctx) {
|
|
263
243
|
const db = tenancy.getGlobalDB()
|
|
264
244
|
|
|
265
245
|
try {
|
|
@@ -285,6 +265,16 @@ export async function publicSettings(ctx: BBContext) {
|
|
|
285
265
|
config = publicConfig
|
|
286
266
|
}
|
|
287
267
|
|
|
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
|
+
|
|
288
278
|
// google button flag
|
|
289
279
|
if (googleConfig && googleConfig.config) {
|
|
290
280
|
// activated by default for configs pre-activated flag
|
|
@@ -311,28 +301,17 @@ export async function publicSettings(ctx: BBContext) {
|
|
|
311
301
|
}
|
|
312
302
|
}
|
|
313
303
|
|
|
314
|
-
export async function upload(ctx:
|
|
315
|
-
if (ctx.request.files == null || ctx.request.files.file
|
|
304
|
+
export async function upload(ctx: UserCtx) {
|
|
305
|
+
if (ctx.request.files == null || Array.isArray(ctx.request.files.file)) {
|
|
316
306
|
ctx.throw(400, "One file must be uploaded.")
|
|
317
307
|
}
|
|
318
308
|
const file = ctx.request.files.file
|
|
319
309
|
const { type, name } = ctx.params
|
|
320
310
|
|
|
321
|
-
let bucket
|
|
322
|
-
|
|
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
|
-
}
|
|
311
|
+
let bucket = coreEnv.GLOBAL_BUCKET_NAME
|
|
312
|
+
const key = objectStore.getGlobalFileS3Key(type, name)
|
|
334
313
|
|
|
335
|
-
await objectStore.upload({
|
|
314
|
+
const result = await objectStore.upload({
|
|
336
315
|
bucket,
|
|
337
316
|
filename: key,
|
|
338
317
|
path: file.path,
|
|
@@ -349,24 +328,26 @@ export async function upload(ctx: BBContext) {
|
|
|
349
328
|
config: {},
|
|
350
329
|
}
|
|
351
330
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
331
|
+
|
|
332
|
+
// save the Etag for cache bursting
|
|
333
|
+
const etag = result.ETag
|
|
334
|
+
if (etag) {
|
|
335
|
+
cfgStructure.config[`${name}Etag`] = etag.replace(/"/g, "")
|
|
357
336
|
}
|
|
358
337
|
|
|
359
|
-
|
|
360
|
-
|
|
338
|
+
// save the file key
|
|
339
|
+
cfgStructure.config[`${name}`] = key
|
|
340
|
+
|
|
341
|
+
// write back to db
|
|
361
342
|
await db.put(cfgStructure)
|
|
362
343
|
|
|
363
344
|
ctx.body = {
|
|
364
345
|
message: "File has been uploaded and url stored to config.",
|
|
365
|
-
url,
|
|
346
|
+
url: objectStore.getGlobalFileUrl(type, name, etag),
|
|
366
347
|
}
|
|
367
348
|
}
|
|
368
349
|
|
|
369
|
-
export async function destroy(ctx:
|
|
350
|
+
export async function destroy(ctx: UserCtx) {
|
|
370
351
|
const db = tenancy.getGlobalDB()
|
|
371
352
|
const { id, rev } = ctx.params
|
|
372
353
|
try {
|
|
@@ -378,7 +359,7 @@ export async function destroy(ctx: BBContext) {
|
|
|
378
359
|
}
|
|
379
360
|
}
|
|
380
361
|
|
|
381
|
-
export async function configChecklist(ctx:
|
|
362
|
+
export async function configChecklist(ctx: Ctx) {
|
|
382
363
|
const db = tenancy.getGlobalDB()
|
|
383
364
|
const tenantId = tenancy.getTenantId()
|
|
384
365
|
|
|
@@ -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 sdk.users.getPlatformUser(id)
|
|
182
182
|
if (user) {
|
|
183
183
|
ctx.body = user
|
|
184
184
|
} else {
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { events } from "@budibase/backend-core"
|
|
2
|
+
import { structures, TestConfiguration, mocks } from "../../../../tests"
|
|
3
|
+
|
|
4
|
+
describe("/api/global/groups", () => {
|
|
5
|
+
const config = new TestConfiguration()
|
|
6
|
+
|
|
7
|
+
beforeAll(async () => {
|
|
8
|
+
await config.beforeAll()
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
afterAll(async () => {
|
|
12
|
+
await config.afterAll()
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
beforeEach(async () => {
|
|
16
|
+
mocks.licenses.useGroups()
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
describe("create", () => {
|
|
20
|
+
it("should be able to create a new group", async () => {
|
|
21
|
+
const group = structures.groups.UserGroup()
|
|
22
|
+
await config.api.groups.saveGroup(group)
|
|
23
|
+
expect(events.group.created).toBeCalledTimes(1)
|
|
24
|
+
expect(events.group.updated).not.toBeCalled()
|
|
25
|
+
expect(events.group.permissionsEdited).not.toBeCalled()
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
describe("update", () => {
|
|
30
|
+
it("should be able to update a basic group", async () => {
|
|
31
|
+
const group = structures.groups.UserGroup()
|
|
32
|
+
let oldGroup = await config.api.groups.saveGroup(group)
|
|
33
|
+
|
|
34
|
+
let updatedGroup = {
|
|
35
|
+
...oldGroup.body,
|
|
36
|
+
...group,
|
|
37
|
+
name: "New Name",
|
|
38
|
+
}
|
|
39
|
+
await config.api.groups.saveGroup(updatedGroup)
|
|
40
|
+
|
|
41
|
+
expect(events.group.updated).toBeCalledTimes(1)
|
|
42
|
+
expect(events.group.permissionsEdited).not.toBeCalled()
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
describe("destroy", () => {
|
|
46
|
+
it("should be able to delete a basic group", async () => {
|
|
47
|
+
const group = structures.groups.UserGroup()
|
|
48
|
+
let oldGroup = await config.api.groups.saveGroup(group)
|
|
49
|
+
await config.api.groups.deleteGroup(
|
|
50
|
+
oldGroup.body._id,
|
|
51
|
+
oldGroup.body._rev
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
expect(events.group.deleted).toBeCalledTimes(1)
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
})
|
|
@@ -1,11 +1,47 @@
|
|
|
1
|
-
import { TestConfiguration } from "../../../../tests"
|
|
1
|
+
import { structures, TestConfiguration } from "../../../../tests"
|
|
2
|
+
import { context, db, permissions, roles } from "@budibase/backend-core"
|
|
3
|
+
import { Mock } from "jest-mock"
|
|
2
4
|
|
|
3
|
-
|
|
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
|
+
}
|
|
4
32
|
|
|
5
33
|
describe("/api/global/roles", () => {
|
|
6
34
|
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
|
+
)
|
|
7
40
|
|
|
8
41
|
beforeAll(async () => {
|
|
42
|
+
console.debug(role)
|
|
43
|
+
appDb.put(role)
|
|
44
|
+
await addAppMetadata()
|
|
9
45
|
await config.beforeAll()
|
|
10
46
|
})
|
|
11
47
|
|
|
@@ -18,10 +54,35 @@ describe("/api/global/roles", () => {
|
|
|
18
54
|
})
|
|
19
55
|
|
|
20
56
|
describe("GET /api/global/roles", () => {
|
|
21
|
-
it("retrieves 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
|
+
})
|
|
22
65
|
})
|
|
23
66
|
|
|
24
|
-
describe("GET
|
|
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
|
+
})
|
|
25
74
|
|
|
26
|
-
describe("DELETE /api/global/roles/:appId", () => {
|
|
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
|
+
})
|
|
27
88
|
})
|