From 1ecb837981e966af9549234f138d89824e478620 Mon Sep 17 00:00:00 2001 From: Naz Date: Thu, 21 Apr 2022 10:48:21 +0800 Subject: [PATCH] Added `version_notifications` key to settings table refs https://github.com/TryGhost/Toolbox/issues/292 - When version missmatch handling is done in Ghost we need to store the 'Accept-Version' header values that have been already processed in the past (to avoid sending notifications about the same mismatch multiple times) - The `version_notifications` will be storing an array with handled versions like so: `['v3.44', 'v4.23', 'v4.39']`. - The emailing logic and processing is slightly similar to how "notification" key is handled, that's why I've placed the definition of this new key close by. --- ...02-55-add-notifications-key-entry-to-settings-table.js | 8 ++++++++ .../data/schema/default-settings/default-settings.json | 4 ++++ test/integration/settings/settings.test.js | 1 + test/regression/models/model_settings.test.js | 4 ++-- test/unit/server/data/exporter/index.test.js | 2 +- test/unit/server/data/schema/integrity.test.js | 2 +- test/utils/fixtures/default-settings.json | 4 ++++ 7 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 core/server/data/migrations/versions/4.45/2022-04-21-02-55-add-notifications-key-entry-to-settings-table.js diff --git a/core/server/data/migrations/versions/4.45/2022-04-21-02-55-add-notifications-key-entry-to-settings-table.js b/core/server/data/migrations/versions/4.45/2022-04-21-02-55-add-notifications-key-entry-to-settings-table.js new file mode 100644 index 0000000000..2b02920db6 --- /dev/null +++ b/core/server/data/migrations/versions/4.45/2022-04-21-02-55-add-notifications-key-entry-to-settings-table.js @@ -0,0 +1,8 @@ +const {addSetting} = require('../../utils.js'); + +module.exports = addSetting({ + key: 'version_notifications', + value: '[]', + type: 'array', + group: 'core' +}); diff --git a/core/server/data/schema/default-settings/default-settings.json b/core/server/data/schema/default-settings/default-settings.json index 824f6ea19e..7167613ff5 100644 --- a/core/server/data/schema/default-settings/default-settings.json +++ b/core/server/data/schema/default-settings/default-settings.json @@ -16,6 +16,10 @@ "defaultValue": "[]", "type": "array" }, + "version_notifications": { + "defaultValue": "[]", + "type": "array" + }, "session_secret": { "defaultValue": null, "type": "string" diff --git a/test/integration/settings/settings.test.js b/test/integration/settings/settings.test.js index 3e662d53f3..748bc0fdce 100644 --- a/test/integration/settings/settings.test.js +++ b/test/integration/settings/settings.test.js @@ -19,6 +19,7 @@ describe('Settings', function () { 'routes_hash', 'next_update_check', 'notifications', + 'version_notifications', 'session_secret', 'theme_session_secret', 'ghost_public_key', diff --git a/test/regression/models/model_settings.test.js b/test/regression/models/model_settings.test.js index a93294d1b5..bca7a1baf2 100644 --- a/test/regression/models/model_settings.test.js +++ b/test/regression/models/model_settings.test.js @@ -17,7 +17,7 @@ describe('Settings Model', function () { await models.Settings.populateDefaults(); const settingsPopulated = await models.Settings.findAll(); - settingsPopulated.length.should.equal(95); + settingsPopulated.length.should.equal(96); }); it('doesn\'t overwrite any existing settings', async function () { @@ -42,7 +42,7 @@ describe('Settings Model', function () { await models.Settings.populateDefaults(); const settingsPopulated = await models.Settings.findAll(); - settingsPopulated.length.should.equal(95); + settingsPopulated.length.should.equal(96); const titleSetting = settingsPopulated.models.find(s => s.get('key') === 'title'); titleSetting.get('value').should.equal('Testing Defaults'); diff --git a/test/unit/server/data/exporter/index.test.js b/test/unit/server/data/exporter/index.test.js index 5637ee20dc..444a835a56 100644 --- a/test/unit/server/data/exporter/index.test.js +++ b/test/unit/server/data/exporter/index.test.js @@ -198,7 +198,7 @@ describe('Exporter', function () { // NOTE: if default settings changed either modify the settings keys blocklist or increase allowedKeysLength // This is a reminder to think about the importer/exporter scenarios ;) - const allowedKeysLength = 85; + const allowedKeysLength = 86; totalKeysLength.should.eql(SETTING_KEYS_BLOCKLIST.length + allowedKeysLength); }); }); diff --git a/test/unit/server/data/schema/integrity.test.js b/test/unit/server/data/schema/integrity.test.js index c800827a63..1d5354fe38 100644 --- a/test/unit/server/data/schema/integrity.test.js +++ b/test/unit/server/data/schema/integrity.test.js @@ -37,7 +37,7 @@ describe('DB version integrity', function () { // Only these variables should need updating const currentSchemaHash = 'ae71340a8c89f6580b2eb06101f003b4'; const currentFixturesHash = '2fe576bcde3428c3063c05b2f2c37367'; - const currentSettingsHash = '71fa38d0c805c18ceebe0fda80886230'; + const currentSettingsHash = 'ffd899a82b0ad2886e92d8244bcbca6a'; const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01'; // If this test is failing, then it is likely a change has been made that requires a DB version bump, diff --git a/test/utils/fixtures/default-settings.json b/test/utils/fixtures/default-settings.json index cce7f0520c..9d73839b87 100644 --- a/test/utils/fixtures/default-settings.json +++ b/test/utils/fixtures/default-settings.json @@ -16,6 +16,10 @@ "defaultValue": "[]", "type": "array" }, + "version_notifications": { + "defaultValue": "[]", + "type": "array" + }, "session_secret": { "defaultValue": null, "type": "string"