From 283698f8c5cb3448229b8c5144ef5d39a75f2844 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Tue, 13 Jul 2021 21:46:50 +0100 Subject: [PATCH] Fix config form saving bugs --- .../builder/portal/manage/auth/index.svelte | 25 ++++++++++++++----- .../src/api/controllers/admin/configs.js | 2 +- .../worker/src/api/routes/admin/configs.js | 4 +-- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/packages/builder/src/pages/builder/portal/manage/auth/index.svelte b/packages/builder/src/pages/builder/portal/manage/auth/index.svelte index cd6ce10393..70c833cd7d 100644 --- a/packages/builder/src/pages/builder/portal/manage/auth/index.svelte +++ b/packages/builder/src/pages/builder/portal/manage/auth/index.svelte @@ -64,8 +64,20 @@ let fileinput let image + let google let oidc + const providers = { google, oidc } + + // Create a flag so that it will only try to save completed forms + $: googleComplete = + providers.google?.config.clientID && + providers.google?.config.clientSecret && + providers.google?.config.callbackURL + $: oidcComplete = + providers.oidc?.config.configs[0].configUrl && + providers.oidc?.config.configs[0].clientID && + providers.oidc?.config.configs[0].clientSecret async function uploadLogo(file) { let data = new FormData() @@ -85,20 +97,21 @@ iconDropdownOptions.unshift({ label: fileName, value: fileName }) } - const providers = { google, oidc } - async function save(docs) { // only if the user has provided an image, upload it. image && uploadLogo(image) let calls = [] docs.forEach(element => { - //Add a UUID here so each config is distinguishable when it arrives at the login page. - if (element.type === "oidc") { + if (element.type === ConfigTypes.OIDC) { + //Add a UUID here so each config is distinguishable when it arrives at the login page. element.config.configs.forEach(config => { - config.uuid = uuid() + !config.uuid && (config.uuid = uuid()) }) + oidcComplete && calls.push(api.post(`/api/admin/configs`, element)) + } + if (element.type === ConfigTypes.Google) { + googleComplete && calls.push(api.post(`/api/admin/configs`, element)) } - calls.push(api.post(`/api/admin/configs`, element)) }) Promise.all(calls) .then(responses => { diff --git a/packages/worker/src/api/controllers/admin/configs.js b/packages/worker/src/api/controllers/admin/configs.js index 27b6c7f238..802141310b 100644 --- a/packages/worker/src/api/controllers/admin/configs.js +++ b/packages/worker/src/api/controllers/admin/configs.js @@ -226,7 +226,7 @@ exports.configChecklist = async function (ctx) { apps: appDbNames.length, smtp: !!smtpConfig, adminUser, - sso: !!googleConfig || !!oidcConfig + sso: !!googleConfig || !!oidcConfig, } } catch (err) { ctx.throw(err.status, err) diff --git a/packages/worker/src/api/routes/admin/configs.js b/packages/worker/src/api/routes/admin/configs.js index fd7764316b..66be9dd13b 100644 --- a/packages/worker/src/api/routes/admin/configs.js +++ b/packages/worker/src/api/routes/admin/configs.js @@ -49,8 +49,8 @@ function oidcValidation() { clientID: Joi.string().required(), clientSecret: Joi.string().required(), configUrl: Joi.string().required(), - logo: Joi.string().optional(), - name: Joi.string().optional(), + logo: Joi.string().allow("", null), + name: Joi.string().allow("", null), uuid: Joi.string().required(), }) ).required(true)