From 8bc4d00fe63298063c44fbd0c7733e2b7d0793be Mon Sep 17 00:00:00 2001 From: Naz Date: Tue, 27 Jul 2021 14:07:11 +0400 Subject: [PATCH] Added email unfreeze for verified email config refs https://github.com/TryGhost/Team/issues/912 - When instance has "verified" email configuration it should remove email freeze and disallow future feezes --- core/boot.js | 6 ++++-- core/server/services/settings/index.js | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/core/boot.js b/core/boot.js index 7d0b0d4cb6..4625adddfc 100644 --- a/core/boot.js +++ b/core/boot.js @@ -62,8 +62,9 @@ async function initDatabase({config, logging}) { * (There's more to do to make this true) * @param {object} options * @param {object} options.ghostServer + * @param {object} options.config */ -async function initCore({ghostServer}) { +async function initCore({ghostServer, config}) { debug('Begin: initCore'); // URL Utils is a bit slow, put it here so the timing is visible separate from models @@ -81,6 +82,7 @@ async function initCore({ghostServer}) { debug('Begin: settings'); const settings = require('./server/services/settings'); await settings.init(); + await settings.syncEmailSettings(config.get('hostSettings:emailVerification:verified')); debug('End: settings'); // The URLService is a core part of Ghost, which depends on models. It needs moving from the frontend to make this clear. @@ -323,7 +325,7 @@ async function bootGhost() { // Step 4 - Load Ghost with all its services debug('Begin: Load Ghost Services & Apps'); - await initCore({ghostServer}); + await initCore({ghostServer, config}); await initFrontend(); const ghostApp = await initExpressApps(); await initDynamicRouting(); diff --git a/core/server/services/settings/index.js b/core/server/services/settings/index.js index 074325b9df..ec6bfe2a26 100644 --- a/core/server/services/settings/index.js +++ b/core/server/services/settings/index.js @@ -56,6 +56,22 @@ module.exports = { } }, + /** + * Handles email setting synchronization when email has been verified per instance + * + * @param {boolean} configValue current email verification value from local config + */ + async syncEmailSettings(configValue) { + const isEmailDisabled = SettingsCache.get('email_verification_required'); + + if (configValue === true && isEmailDisabled) { + return await models.Settings.edit([{ + key: 'email_verification_required', + value: false + }], {context: {internal: true}}); + } + }, + obfuscatedSetting, isSecretSetting, hideValueIfSecret