From 5acc7e752e836fbe771e829e3e7218d8438e3256 Mon Sep 17 00:00:00 2001 From: Charlotte County Public Schools <119430841+icsinfo@users.noreply.github.com> Date: Fri, 17 Mar 2023 17:27:31 -0400 Subject: [PATCH] fix: add new props to existing auth strategies (#6250) --- server/models/authentication.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/server/models/authentication.js b/server/models/authentication.js index 8d6ac9e3..eeab4db6 100644 --- a/server/models/authentication.js +++ b/server/models/authentication.js @@ -92,6 +92,7 @@ module.exports = class Authentication extends Model { } for (const strategy of dbStrategies) { + let newProps = false const strategyDef = _.find(WIKI.data.authentication, ['key', strategy.strategyKey]) if (!strategyDef) { await WIKI.models.authentication.query().delete().where('key', strategy.key) @@ -101,6 +102,8 @@ module.exports = class Authentication extends Model { strategy.config = _.transform(strategyDef.props, (result, value, key) => { if (!_.has(result, key)) { _.set(result, key, value.default) + // we have some new properties added to an existing auth strategy to write to the database + newProps = true } return result }, strategy.config) @@ -111,6 +114,12 @@ module.exports = class Authentication extends Model { displayName: strategyDef.title }).where('key', strategy.key) } + // write existing auth model to database with new properties and defaults + if (newProps) { + await WIKI.models.authentication.query().patch({ + config: strategy.config + }).where('key', strategy.key) + } } WIKI.logger.info(`Loaded ${WIKI.data.authentication.length} authentication strategies: [ OK ]`)