@budibase/worker 2.1.39 → 2.1.40-alpha.1
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/__mocks__/aws-sdk.ts +15 -0
- package/__mocks__/oauth.ts +57 -0
- package/coverage/clover.xml +2153 -0
- package/coverage/coverage-final.json +78 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +431 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov-report/src/api/controllers/global/auth.ts.html +925 -0
- package/coverage/lcov-report/src/api/controllers/global/configs.ts.html +1405 -0
- package/coverage/lcov-report/src/api/controllers/global/email.ts.html +196 -0
- package/coverage/lcov-report/src/api/controllers/global/index.html +236 -0
- package/coverage/lcov-report/src/api/controllers/global/license.ts.html +187 -0
- package/coverage/lcov-report/src/api/controllers/global/roles.ts.html +283 -0
- package/coverage/lcov-report/src/api/controllers/global/self.ts.html +577 -0
- package/coverage/lcov-report/src/api/controllers/global/templates.ts.html +316 -0
- package/coverage/lcov-report/src/api/controllers/global/users.ts.html +796 -0
- package/coverage/lcov-report/src/api/controllers/global/workspaces.ts.html +244 -0
- package/coverage/lcov-report/src/api/controllers/system/accounts.ts.html +148 -0
- package/coverage/lcov-report/src/api/controllers/system/environment.ts.html +124 -0
- package/coverage/lcov-report/src/api/controllers/system/index.html +191 -0
- package/coverage/lcov-report/src/api/controllers/system/migrations.ts.html +124 -0
- package/coverage/lcov-report/src/api/controllers/system/restore.ts.html +124 -0
- package/coverage/lcov-report/src/api/controllers/system/status.ts.html +133 -0
- package/coverage/lcov-report/src/api/controllers/system/tenants.ts.html +154 -0
- package/coverage/lcov-report/src/api/index.html +116 -0
- package/coverage/lcov-report/src/api/index.ts.html +583 -0
- package/coverage/lcov-report/src/api/routes/global/auth.ts.html +349 -0
- package/coverage/lcov-report/src/api/routes/global/configs.ts.html +457 -0
- package/coverage/lcov-report/src/api/routes/global/email.ts.html +193 -0
- package/coverage/lcov-report/src/api/routes/global/index.html +236 -0
- package/coverage/lcov-report/src/api/routes/global/license.ts.html +124 -0
- package/coverage/lcov-report/src/api/routes/global/roles.ts.html +133 -0
- package/coverage/lcov-report/src/api/routes/global/self.ts.html +139 -0
- package/coverage/lcov-report/src/api/routes/global/templates.ts.html +196 -0
- package/coverage/lcov-report/src/api/routes/global/users.ts.html +409 -0
- package/coverage/lcov-report/src/api/routes/global/workspaces.ts.html +196 -0
- package/coverage/lcov-report/src/api/routes/index.html +116 -0
- package/coverage/lcov-report/src/api/routes/index.ts.html +196 -0
- package/coverage/lcov-report/src/api/routes/system/accounts.ts.html +142 -0
- package/coverage/lcov-report/src/api/routes/system/environment.ts.html +109 -0
- package/coverage/lcov-report/src/api/routes/system/index.html +191 -0
- package/coverage/lcov-report/src/api/routes/system/migrations.ts.html +142 -0
- package/coverage/lcov-report/src/api/routes/system/restore.ts.html +109 -0
- package/coverage/lcov-report/src/api/routes/system/status.ts.html +109 -0
- package/coverage/lcov-report/src/api/routes/system/tenants.ts.html +124 -0
- package/coverage/lcov-report/src/api/routes/validation/index.html +131 -0
- package/coverage/lcov-report/src/api/routes/validation/index.ts.html +88 -0
- package/coverage/lcov-report/src/api/routes/validation/users.ts.html +235 -0
- package/coverage/lcov-report/src/constants/index.html +116 -0
- package/coverage/lcov-report/src/constants/index.ts.html +613 -0
- package/coverage/lcov-report/src/constants/templates/index.html +116 -0
- package/coverage/lcov-report/src/constants/templates/index.ts.html +316 -0
- package/coverage/lcov-report/src/db/index.html +116 -0
- package/coverage/lcov-report/src/db/index.ts.html +115 -0
- package/coverage/lcov-report/src/environment.ts.html +373 -0
- package/coverage/lcov-report/src/index.html +131 -0
- package/coverage/lcov-report/src/index.ts.html +394 -0
- package/coverage/lcov-report/src/middleware/cloudRestricted.ts.html +139 -0
- package/coverage/lcov-report/src/middleware/index.html +116 -0
- package/coverage/lcov-report/src/migrations/functions/globalInfoSyncUsers.ts.html +145 -0
- package/coverage/lcov-report/src/migrations/functions/index.html +116 -0
- package/coverage/lcov-report/src/migrations/index.html +116 -0
- package/coverage/lcov-report/src/migrations/index.ts.html +271 -0
- package/coverage/lcov-report/src/sdk/accounts/accounts.ts.html +262 -0
- package/coverage/lcov-report/src/sdk/accounts/index.html +131 -0
- package/coverage/lcov-report/src/sdk/accounts/index.ts.html +88 -0
- package/coverage/lcov-report/src/sdk/index.html +116 -0
- package/coverage/lcov-report/src/sdk/index.ts.html +106 -0
- package/coverage/lcov-report/src/sdk/users/events.ts.html +577 -0
- package/coverage/lcov-report/src/sdk/users/index.html +146 -0
- package/coverage/lcov-report/src/sdk/users/index.ts.html +88 -0
- package/coverage/lcov-report/src/sdk/users/users.ts.html +1903 -0
- package/coverage/lcov-report/src/tests/TestConfiguration.ts.html +1051 -0
- package/coverage/lcov-report/src/tests/api/accounts.ts.html +160 -0
- package/coverage/lcov-report/src/tests/api/auth.ts.html +220 -0
- package/coverage/lcov-report/src/tests/api/base.ts.html +133 -0
- package/coverage/lcov-report/src/tests/api/configs.ts.html +226 -0
- package/coverage/lcov-report/src/tests/api/email.ts.html +148 -0
- package/coverage/lcov-report/src/tests/api/environment.ts.html +130 -0
- package/coverage/lcov-report/src/tests/api/index.html +296 -0
- package/coverage/lcov-report/src/tests/api/index.ts.html +205 -0
- package/coverage/lcov-report/src/tests/api/migrations.ts.html +151 -0
- package/coverage/lcov-report/src/tests/api/restore.ts.html +127 -0
- package/coverage/lcov-report/src/tests/api/self.ts.html +163 -0
- package/coverage/lcov-report/src/tests/api/status.ts.html +121 -0
- package/coverage/lcov-report/src/tests/api/tenants.ts.html +130 -0
- package/coverage/lcov-report/src/tests/api/users.ts.html +511 -0
- package/coverage/lcov-report/src/tests/controllers.ts.html +100 -0
- package/coverage/lcov-report/src/tests/index.html +146 -0
- package/coverage/lcov-report/src/tests/index.ts.html +139 -0
- package/coverage/lcov-report/src/tests/mocks/email.js.html +115 -0
- package/coverage/lcov-report/src/tests/mocks/index.html +131 -0
- package/coverage/lcov-report/src/tests/mocks/index.ts.html +106 -0
- package/coverage/lcov-report/src/tests/structures/configs.ts.html +313 -0
- package/coverage/lcov-report/src/tests/structures/groups.ts.html +118 -0
- package/coverage/lcov-report/src/tests/structures/index.html +161 -0
- package/coverage/lcov-report/src/tests/structures/index.ts.html +151 -0
- package/coverage/lcov-report/src/tests/structures/users.ts.html +196 -0
- package/coverage/lcov-report/src/utilities/appService.ts.html +181 -0
- package/coverage/lcov-report/src/utilities/email.ts.html +850 -0
- package/coverage/lcov-report/src/utilities/fileSystem.ts.html +100 -0
- package/coverage/lcov-report/src/utilities/index.html +206 -0
- package/coverage/lcov-report/src/utilities/index.ts.html +112 -0
- package/coverage/lcov-report/src/utilities/redis.ts.html +424 -0
- package/coverage/lcov-report/src/utilities/templates.ts.html +232 -0
- package/coverage/lcov-report/src/utilities/users.ts.html +133 -0
- package/coverage/lcov.info +3958 -0
- package/jest.config.ts +29 -0
- package/package.json +14 -24
- package/scripts/localdomain.js +33 -7
- package/src/api/controllers/global/auth.ts +51 -43
- package/src/api/controllers/global/{configs.js → configs.ts} +119 -114
- package/src/api/controllers/global/{email.js → email.ts} +6 -5
- package/src/api/controllers/global/roles.ts +66 -0
- package/src/api/controllers/global/self.ts +2 -2
- package/src/api/controllers/global/users.ts +4 -2
- package/src/api/controllers/global/{workspaces.js → workspaces.ts} +15 -18
- package/src/api/controllers/system/{environment.js → environment.ts} +3 -2
- package/src/api/controllers/system/restore.ts +1 -1
- package/src/api/controllers/system/{status.js → status.ts} +4 -3
- package/src/api/controllers/system/tenants.ts +8 -51
- package/src/api/index.ts +31 -8
- package/src/api/routes/global/{auth.js → auth.ts} +31 -48
- package/src/api/routes/global/{configs.js → configs.ts} +22 -23
- package/src/api/routes/global/{email.js → email.ts} +9 -10
- package/src/api/routes/global/license.ts +1 -1
- package/src/api/routes/global/roles.ts +16 -0
- package/src/api/routes/global/self.ts +2 -2
- package/src/api/routes/global/templates.ts +4 -4
- package/src/api/routes/global/tests/auth.spec.ts +134 -64
- package/src/api/routes/global/tests/configs.spec.ts +34 -35
- package/src/api/routes/global/tests/email.spec.ts +4 -3
- package/src/api/routes/global/tests/license.spec.ts +31 -0
- package/src/api/routes/global/tests/realEmail.spec.ts +2 -3
- package/src/api/routes/global/tests/roles.spec.ts +27 -0
- package/src/api/routes/global/tests/self.spec.ts +3 -4
- package/src/api/routes/global/tests/templates.spec.ts +35 -0
- package/src/api/routes/global/tests/users.spec.ts +51 -43
- package/src/api/routes/global/tests/workspaces.spec.ts +29 -0
- package/src/api/routes/global/{users.js → users.ts} +26 -24
- package/src/api/routes/global/{workspaces.js → workspaces.ts} +9 -10
- package/src/api/routes/index.ts +2 -1
- package/src/api/routes/system/accounts.ts +1 -1
- package/src/api/routes/system/environment.ts +8 -0
- package/src/api/routes/system/migrations.ts +1 -1
- package/src/api/routes/system/restore.ts +1 -1
- package/src/api/routes/system/status.ts +8 -0
- package/src/api/routes/system/tenants.ts +13 -0
- package/src/api/routes/system/tests/accounts.spec.ts +5 -6
- package/src/api/routes/system/tests/environment.spec.ts +29 -0
- package/src/api/routes/system/tests/migrations.spec.ts +63 -0
- package/src/api/routes/system/tests/restore.spec.ts +36 -0
- package/src/api/routes/system/tests/status.spec.ts +48 -0
- package/src/api/routes/system/tests/tenants.spec.ts +61 -0
- package/src/api/routes/validation/users.ts +3 -3
- package/src/constants/{index.js → index.ts} +57 -64
- package/src/constants/templates/{index.js → index.ts} +23 -19
- package/src/db/index.ts +10 -0
- package/src/environment.ts +8 -6
- package/src/index.ts +15 -16
- package/src/middleware/{cloudRestricted.js → cloudRestricted.ts} +5 -4
- package/src/middleware/tests/tenancy.spec.ts +73 -0
- package/src/tests/TestConfiguration.ts +99 -50
- package/src/tests/api/accounts.ts +5 -8
- package/src/tests/api/auth.ts +3 -6
- package/src/tests/api/base.ts +16 -0
- package/src/tests/api/configs.ts +15 -8
- package/src/tests/api/email.ts +3 -6
- package/src/tests/api/environment.ts +15 -0
- package/src/tests/api/index.ts +15 -0
- package/src/tests/api/migrations.ts +22 -0
- package/src/tests/api/restore.ts +14 -0
- package/src/tests/api/self.ts +11 -6
- package/src/tests/api/status.ts +12 -0
- package/src/tests/api/tenants.ts +15 -0
- package/src/tests/api/users.ts +38 -6
- package/src/tests/controllers.ts +5 -0
- package/src/tests/index.ts +5 -1
- package/{scripts/jestSetup.js → src/tests/jestSetup.ts} +12 -3
- package/src/tests/structures/{configs.js → configs.ts} +11 -11
- package/src/tests/structures/index.ts +5 -3
- package/src/tests/structures/users.ts +1 -0
- package/src/utilities/appService.ts +32 -0
- package/src/utilities/{email.js → email.ts} +78 -45
- package/src/utilities/fileSystem.ts +5 -0
- package/src/utilities/{index.js → index.ts} +1 -1
- package/src/utilities/{redis.js → redis.ts} +29 -24
- package/src/utilities/templates.ts +49 -0
- package/src/utilities/users.ts +16 -0
- package/tsconfig.build.json +2 -3
- package/tsconfig.json +3 -1
- package/src/api/controllers/global/roles.js +0 -68
- package/src/api/routes/global/roles.js +0 -12
- package/src/api/routes/system/environment.js +0 -8
- package/src/api/routes/system/status.js +0 -8
- package/src/api/routes/system/tenants.js +0 -12
- package/src/db/index.js +0 -11
- package/src/tests/controllers.js +0 -7
- package/src/tests/structures/accounts.ts +0 -24
- package/src/utilities/appService.js +0 -33
- package/src/utilities/fileSystem.js +0 -5
- package/src/utilities/templates.js +0 -49
- package/src/utilities/users.js +0 -17
package/tsconfig.json
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"paths": {
|
|
9
9
|
"@budibase/types": ["../types/src"],
|
|
10
10
|
"@budibase/backend-core": ["../backend-core/src"],
|
|
11
|
-
"@budibase/backend-core/*": ["../backend-core/*"]
|
|
11
|
+
"@budibase/backend-core/*": ["../backend-core/*"],
|
|
12
|
+
"@budibase/pro": ["../../../budibase-pro/packages/pro/src"]
|
|
12
13
|
}
|
|
13
14
|
},
|
|
14
15
|
"ts-node": {
|
|
@@ -17,6 +18,7 @@
|
|
|
17
18
|
"references": [
|
|
18
19
|
{ "path": "../types" },
|
|
19
20
|
{ "path": "../backend-core" },
|
|
21
|
+
{ "path": "../../../budibase-pro/packages/pro" }
|
|
20
22
|
],
|
|
21
23
|
"include": [
|
|
22
24
|
"src/**/*",
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
const { getAllRoles } = require("@budibase/backend-core/roles")
|
|
2
|
-
const {
|
|
3
|
-
getAllApps,
|
|
4
|
-
getProdAppID,
|
|
5
|
-
getDevAppID,
|
|
6
|
-
DocumentType,
|
|
7
|
-
} = require("@budibase/backend-core/db")
|
|
8
|
-
const { doInAppContext, getAppDB } = require("@budibase/backend-core/context")
|
|
9
|
-
const { user: userCache } = require("@budibase/backend-core/cache")
|
|
10
|
-
const { getGlobalDB } = require("@budibase/backend-core/tenancy")
|
|
11
|
-
const { allUsers } = require("../../../sdk/users")
|
|
12
|
-
|
|
13
|
-
exports.fetch = async ctx => {
|
|
14
|
-
const tenantId = ctx.user.tenantId
|
|
15
|
-
// always use the dev apps as they'll be most up to date (true)
|
|
16
|
-
const apps = await getAllApps({ tenantId, all: true })
|
|
17
|
-
const promises = []
|
|
18
|
-
for (let app of apps) {
|
|
19
|
-
// use dev app IDs
|
|
20
|
-
promises.push(getAllRoles(app.appId))
|
|
21
|
-
}
|
|
22
|
-
const roles = await Promise.all(promises)
|
|
23
|
-
const response = {}
|
|
24
|
-
for (let app of apps) {
|
|
25
|
-
const deployedAppId = getProdAppID(app.appId)
|
|
26
|
-
response[deployedAppId] = {
|
|
27
|
-
roles: roles.shift(),
|
|
28
|
-
name: app.name,
|
|
29
|
-
version: app.version,
|
|
30
|
-
url: app.url,
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
ctx.body = response
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
exports.find = async ctx => {
|
|
37
|
-
const appId = ctx.params.appId
|
|
38
|
-
await doInAppContext(getDevAppID(appId), async () => {
|
|
39
|
-
const db = getAppDB()
|
|
40
|
-
const app = await db.get(DocumentType.APP_METADATA)
|
|
41
|
-
ctx.body = {
|
|
42
|
-
roles: await getAllRoles(),
|
|
43
|
-
name: app.name,
|
|
44
|
-
version: app.version,
|
|
45
|
-
url: app.url,
|
|
46
|
-
}
|
|
47
|
-
})
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
exports.removeAppRole = async ctx => {
|
|
51
|
-
const { appId } = ctx.params
|
|
52
|
-
const db = getGlobalDB()
|
|
53
|
-
const users = await allUsers(ctx)
|
|
54
|
-
const bulk = []
|
|
55
|
-
const cacheInvalidations = []
|
|
56
|
-
for (let user of users) {
|
|
57
|
-
if (user.roles[appId]) {
|
|
58
|
-
cacheInvalidations.push(userCache.invalidateUser(user._id))
|
|
59
|
-
delete user.roles[appId]
|
|
60
|
-
bulk.push(user)
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
await db.bulkDocs(bulk)
|
|
64
|
-
await Promise.all(cacheInvalidations)
|
|
65
|
-
ctx.body = {
|
|
66
|
-
message: "App role removed from all users",
|
|
67
|
-
}
|
|
68
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const Router = require("@koa/router")
|
|
2
|
-
const controller = require("../../controllers/global/roles")
|
|
3
|
-
const { builderOrAdmin } = require("@budibase/backend-core/auth")
|
|
4
|
-
|
|
5
|
-
const router = new Router()
|
|
6
|
-
|
|
7
|
-
router
|
|
8
|
-
.get("/api/global/roles", builderOrAdmin, controller.fetch)
|
|
9
|
-
.get("/api/global/roles/:appId", builderOrAdmin, controller.find)
|
|
10
|
-
.delete("/api/global/roles/:appId", builderOrAdmin, controller.removeAppRole)
|
|
11
|
-
|
|
12
|
-
module.exports = router
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const Router = require("@koa/router")
|
|
2
|
-
const controller = require("../../controllers/system/tenants")
|
|
3
|
-
const { adminOnly } = require("@budibase/backend-core/auth")
|
|
4
|
-
|
|
5
|
-
const router = new Router()
|
|
6
|
-
|
|
7
|
-
router
|
|
8
|
-
.get("/api/system/tenants/:tenantId/exists", controller.exists)
|
|
9
|
-
.get("/api/system/tenants", adminOnly, controller.fetch)
|
|
10
|
-
.delete("/api/system/tenants/:tenantId", adminOnly, controller.delete)
|
|
11
|
-
|
|
12
|
-
module.exports = router
|
package/src/db/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const core = require("@budibase/backend-core")
|
|
2
|
-
const env = require("../environment")
|
|
3
|
-
|
|
4
|
-
exports.init = () => {
|
|
5
|
-
const dbConfig = {}
|
|
6
|
-
if (env.isTest() && !env.COUCH_DB_URL) {
|
|
7
|
-
dbConfig.inMemory = true
|
|
8
|
-
dbConfig.allDbs = true
|
|
9
|
-
}
|
|
10
|
-
core.init({ db: dbConfig })
|
|
11
|
-
}
|
package/src/tests/controllers.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
email: require("../api/controllers/global/email"),
|
|
3
|
-
workspaces: require("../api/controllers/global/workspaces"),
|
|
4
|
-
config: require("../api/controllers/global/configs"),
|
|
5
|
-
templates: require("../api/controllers/global/templates"),
|
|
6
|
-
users: require("../api/controllers/global/users"),
|
|
7
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Account, AuthType, Hosting, CloudAccount } from "@budibase/types"
|
|
2
|
-
import { v4 as uuid } from "uuid"
|
|
3
|
-
import { utils } from "@budibase/backend-core"
|
|
4
|
-
|
|
5
|
-
export const account = (): Account => {
|
|
6
|
-
return {
|
|
7
|
-
email: `${uuid()}@test.com`,
|
|
8
|
-
tenantId: utils.newid(),
|
|
9
|
-
hosting: Hosting.SELF,
|
|
10
|
-
authType: AuthType.SSO,
|
|
11
|
-
accountId: uuid(),
|
|
12
|
-
createdAt: Date.now(),
|
|
13
|
-
verified: true,
|
|
14
|
-
verificationSent: true,
|
|
15
|
-
tier: "FREE",
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const cloudAccount = (): CloudAccount => {
|
|
20
|
-
return {
|
|
21
|
-
...account(),
|
|
22
|
-
budibaseUserId: uuid(),
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
const fetch = require("node-fetch")
|
|
2
|
-
const { Headers } = require("@budibase/backend-core/constants")
|
|
3
|
-
const { getTenantId, isTenantIdSet } = require("@budibase/backend-core/tenancy")
|
|
4
|
-
const { checkSlashesInUrl } = require("../utilities")
|
|
5
|
-
const env = require("../environment")
|
|
6
|
-
|
|
7
|
-
async function makeAppRequest(url, method, body) {
|
|
8
|
-
if (env.isTest()) {
|
|
9
|
-
return
|
|
10
|
-
}
|
|
11
|
-
const request = { headers: {} }
|
|
12
|
-
request.headers[Headers.API_KEY] = env.INTERNAL_API_KEY
|
|
13
|
-
if (isTenantIdSet()) {
|
|
14
|
-
request.headers[Headers.TENANT_ID] = getTenantId()
|
|
15
|
-
}
|
|
16
|
-
if (body) {
|
|
17
|
-
request.headers["Content-Type"] = "application/json"
|
|
18
|
-
request.body = JSON.stringify(body)
|
|
19
|
-
}
|
|
20
|
-
request.method = method
|
|
21
|
-
return fetch(checkSlashesInUrl(env.APPS_URL + url), request)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
exports.syncUserInApps = async userId => {
|
|
25
|
-
const response = await makeAppRequest(
|
|
26
|
-
`/api/users/metadata/sync/${userId}`,
|
|
27
|
-
"POST",
|
|
28
|
-
{}
|
|
29
|
-
)
|
|
30
|
-
if (response && response.status !== 200) {
|
|
31
|
-
throw "Unable to sync user."
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
const { getScopedConfig } = require("@budibase/backend-core/db")
|
|
2
|
-
const {
|
|
3
|
-
Configs,
|
|
4
|
-
InternalTemplateBindings,
|
|
5
|
-
LOGO_URL,
|
|
6
|
-
EmailTemplatePurpose,
|
|
7
|
-
} = require("../constants")
|
|
8
|
-
const { checkSlashesInUrl } = require("./index")
|
|
9
|
-
const {
|
|
10
|
-
getGlobalDB,
|
|
11
|
-
addTenantToUrl,
|
|
12
|
-
} = require("@budibase/backend-core/tenancy")
|
|
13
|
-
const BASE_COMPANY = "Budibase"
|
|
14
|
-
|
|
15
|
-
exports.getSettingsTemplateContext = async (purpose, code = null) => {
|
|
16
|
-
const db = getGlobalDB()
|
|
17
|
-
// TODO: use more granular settings in the future if required
|
|
18
|
-
let settings = (await getScopedConfig(db, { type: Configs.SETTINGS })) || {}
|
|
19
|
-
const URL = settings.platformUrl
|
|
20
|
-
const context = {
|
|
21
|
-
[InternalTemplateBindings.LOGO_URL]:
|
|
22
|
-
checkSlashesInUrl(`${URL}/${settings.logoUrl}`) || LOGO_URL,
|
|
23
|
-
[InternalTemplateBindings.PLATFORM_URL]: URL,
|
|
24
|
-
[InternalTemplateBindings.COMPANY]: settings.company || BASE_COMPANY,
|
|
25
|
-
[InternalTemplateBindings.DOCS_URL]:
|
|
26
|
-
settings.docsUrl || "https://docs.budibase.com/",
|
|
27
|
-
[InternalTemplateBindings.LOGIN_URL]: checkSlashesInUrl(
|
|
28
|
-
addTenantToUrl(`${URL}/login`)
|
|
29
|
-
),
|
|
30
|
-
[InternalTemplateBindings.CURRENT_DATE]: new Date().toISOString(),
|
|
31
|
-
[InternalTemplateBindings.CURRENT_YEAR]: new Date().getFullYear(),
|
|
32
|
-
}
|
|
33
|
-
// attach purpose specific context
|
|
34
|
-
switch (purpose) {
|
|
35
|
-
case EmailTemplatePurpose.PASSWORD_RECOVERY:
|
|
36
|
-
context[InternalTemplateBindings.RESET_CODE] = code
|
|
37
|
-
context[InternalTemplateBindings.RESET_URL] = checkSlashesInUrl(
|
|
38
|
-
addTenantToUrl(`${URL}/builder/auth/reset?code=${code}`)
|
|
39
|
-
)
|
|
40
|
-
break
|
|
41
|
-
case EmailTemplatePurpose.INVITATION:
|
|
42
|
-
context[InternalTemplateBindings.INVITE_CODE] = code
|
|
43
|
-
context[InternalTemplateBindings.INVITE_URL] = checkSlashesInUrl(
|
|
44
|
-
addTenantToUrl(`${URL}/builder/invite?code=${code}`)
|
|
45
|
-
)
|
|
46
|
-
break
|
|
47
|
-
}
|
|
48
|
-
return context
|
|
49
|
-
}
|
package/src/utilities/users.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const { getGlobalDB } = require("@budibase/backend-core/tenancy")
|
|
2
|
-
const { getGlobalUserParams } = require("@budibase/backend-core/db")
|
|
3
|
-
|
|
4
|
-
exports.checkAnyUserExists = async () => {
|
|
5
|
-
try {
|
|
6
|
-
const db = getGlobalDB()
|
|
7
|
-
const users = await db.allDocs(
|
|
8
|
-
getGlobalUserParams(null, {
|
|
9
|
-
include_docs: true,
|
|
10
|
-
limit: 1,
|
|
11
|
-
})
|
|
12
|
-
)
|
|
13
|
-
return users && users.rows.length >= 1
|
|
14
|
-
} catch (err) {
|
|
15
|
-
throw new Error("Unable to retrieve user list")
|
|
16
|
-
}
|
|
17
|
-
}
|