From 25fdde6d219096132f0e8304abca034e52b92879 Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Thu, 15 Jul 2021 16:50:57 +0100 Subject: [PATCH] Default public config.config when missing --- .../src/api/controllers/admin/configs.js | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/packages/worker/src/api/controllers/admin/configs.js b/packages/worker/src/api/controllers/admin/configs.js index 5e7575498a..fe7c97f1e9 100644 --- a/packages/worker/src/api/controllers/admin/configs.js +++ b/packages/worker/src/api/controllers/admin/configs.js @@ -125,7 +125,7 @@ exports.publicOidc = async function (ctx) { exports.publicSettings = async function (ctx) { const db = new CouchDB(GLOBAL_DB) - let config = {} + try { // Find the config with the most granular scope based on context const publicConfig = await getScopedFullConfig(db, { @@ -140,20 +140,19 @@ exports.publicSettings = async function (ctx) { type: Configs.OIDC, }) - // Slightly complex logic here to deal with the fact that - // oidc / google might be enabled but org name etc (publicConfig) might not - if (publicConfig && !!googleConfig && !!oidcConfig) { - ctx.body = publicConfig - } else if (!publicConfig && !!googleConfig && !!oidcConfig) { - ctx.body = {} - } else { - if (publicConfig) { - config.config = publicConfig.config + let config = {} + if (!publicConfig) { + config = { + config: {}, } - config.config.oidc = !!oidcConfig - config.config.google = !!googleConfig - ctx.body = config + } else { + config = publicConfig } + + config.config.oidc = !!oidcConfig + config.config.google = !!googleConfig + + ctx.body = config } catch (err) { ctx.throw(err.status, err) }