fix: add new props to existing auth strategies (#6250)
This commit is contained in:
parent
b5b1913396
commit
5acc7e752e
@ -92,6 +92,7 @@ module.exports = class Authentication extends Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const strategy of dbStrategies) {
|
for (const strategy of dbStrategies) {
|
||||||
|
let newProps = false
|
||||||
const strategyDef = _.find(WIKI.data.authentication, ['key', strategy.strategyKey])
|
const strategyDef = _.find(WIKI.data.authentication, ['key', strategy.strategyKey])
|
||||||
if (!strategyDef) {
|
if (!strategyDef) {
|
||||||
await WIKI.models.authentication.query().delete().where('key', strategy.key)
|
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) => {
|
strategy.config = _.transform(strategyDef.props, (result, value, key) => {
|
||||||
if (!_.has(result, key)) {
|
if (!_.has(result, key)) {
|
||||||
_.set(result, key, value.default)
|
_.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
|
return result
|
||||||
}, strategy.config)
|
}, strategy.config)
|
||||||
@ -111,6 +114,12 @@ module.exports = class Authentication extends Model {
|
|||||||
displayName: strategyDef.title
|
displayName: strategyDef.title
|
||||||
}).where('key', strategy.key)
|
}).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 ]`)
|
WIKI.logger.info(`Loaded ${WIKI.data.authentication.length} authentication strategies: [ OK ]`)
|
||||||
|
Loading…
Reference in New Issue
Block a user