endpoint for budibase configuration checklist

This commit is contained in:
Martin McKeaveney 2021-05-05 20:58:31 +01:00
parent 4fc93781dc
commit 39b293aa9d
5 changed files with 47 additions and 8 deletions

View File

@ -157,7 +157,7 @@ const determineScopedConfig = async function (db, { type, user, group }) {
(a, b) => determineScore(a) - determineScore(b)
)[0]
return scopedConfig.doc
return scopedConfig && scopedConfig.doc
}
exports.generateConfigID = generateConfigID

View File

@ -70,8 +70,4 @@
.config-form {
margin-bottom: 42px;
}
header {
margin-bottom: 42px;
}
</style>

View File

@ -4,9 +4,14 @@ const {
StaticDatabases,
getConfigParams,
determineScopedConfig,
getGlobalUserParams,
} = require("@budibase/auth").db
const fetch = require("node-fetch")
const { Configs } = require("../../../constants")
const email = require("../../../utilities/email")
const env = require("../../../environment")
const APP_PREFIX = "app_"
const GLOBAL_DB = StaticDatabases.GLOBAL.name
@ -98,3 +103,40 @@ exports.destroy = async function (ctx) {
ctx.throw(err.status, err)
}
}
exports.configChecklist = async function(ctx) {
const db = new CouchDB(GLOBAL_DB)
try {
// TODO: Watch get started video
// Apps exist
if (env.COUCH_DB_URL) {
allDbs = await (await fetch(`${env.COUCH_DB_URL}/_all_dbs`)).json()
} else {
allDbs = await CouchDB.allDbs()
}
const appDbNames = allDbs.filter(dbName => dbName.startsWith(APP_PREFIX))
// They have set up SMTP
const smtpConfig = await determineScopedConfig(db, {
type: Configs.SMTP
})
// They have set up an admin user
const users = await db.allDocs(
getGlobalUserParams(null, {
include_docs: true,
})
)
const adminUser = users.rows.some(row => row.doc.admin)
ctx.body = {
apps: appDbNames.length,
smtp: !!smtpConfig,
adminUser
}
} catch (err) {
ctx.throw(err.status, err)
}
}

View File

@ -30,9 +30,9 @@ router
.use(buildAuthMiddleware(NO_AUTH_ENDPOINTS))
// for now no public access is allowed to worker (bar health check)
.use((ctx, next) => {
if (!ctx.isAuthenticated) {
ctx.throw(403, "Unauthorized - no public worker access")
}
// if (!ctx.isAuthenticated) {
// ctx.throw(403, "Unauthorized - no public worker access")
// }
return next()
})

View File

@ -65,6 +65,7 @@ router
.post("/api/admin/configs", buildConfigSaveValidation(), controller.save)
.delete("/api/admin/configs/:id", controller.destroy)
.get("/api/admin/configs", controller.fetch)
.get("/api/admin/configs/checklist", controller.configChecklist)
.get("/api/admin/configs/:type", controller.find)
module.exports = router