From f1cd6432a8768d8179e0eb3373c60a7c70cae76e Mon Sep 17 00:00:00 2001 From: Sag Date: Wed, 30 Aug 2023 10:56:21 +0200 Subject: [PATCH] Added new setting to enable Recommendations (#17856) closes https://github.com/TryGhost/Product/issues/3772 - Recommendations are disabled by default and will get enabled when a first recommendation is added. The "recommendations_enabled" setting will be not shown explicitly in Admin, it will rather be set implicitly based on whether there is at least one recommendation - The "recommendations_enabled" setting belongs to a new setting group called "recommendations" Tech Spec: https://www.notion.so/ghost/Recommentions-Tech-Spec-598f09e4109f4eef8d9e32db7245a90c?pvs=4 --- .../utils/serializers/input/settings.js | 3 +- ...04-add-recommendations-enabled-settings.js | 8 +++++ .../default-settings/default-settings.json | 10 +++++++ .../core/core/shared/settings-cache/public.js | 3 +- .../admin/__snapshots__/settings.test.js.snap | 30 ++++++++++++++++++- .../core/test/e2e-api/admin/settings.test.js | 2 +- .../__snapshots__/settings.test.js.snap | 1 + .../shared/__snapshots__/version.test.js.snap | 2 ++ .../regression/models/model_settings.test.js | 2 +- .../unit/server/data/exporter/index.test.js | 2 +- .../unit/server/data/schema/integrity.test.js | 2 +- .../fixtures/default-settings-browser.json | 10 +++++++ .../test/utils/fixtures/default-settings.json | 10 +++++++ 13 files changed, 78 insertions(+), 7 deletions(-) create mode 100644 ghost/core/core/server/data/migrations/versions/5.61/2023-08-30-07-37-04-add-recommendations-enabled-settings.js diff --git a/ghost/core/core/server/api/endpoints/utils/serializers/input/settings.js b/ghost/core/core/server/api/endpoints/utils/serializers/input/settings.js index 7cffdbe36a..c1de8ce2eb 100644 --- a/ghost/core/core/server/api/endpoints/utils/serializers/input/settings.js +++ b/ghost/core/core/server/api/endpoints/utils/serializers/input/settings.js @@ -70,7 +70,8 @@ const EDITABLE_SETTINGS = [ 'pintura_js_url', 'pintura_css_url', 'donations_currency', - 'donations_suggested_amount' + 'donations_suggested_amount', + 'recommendations_enabled' ]; module.exports = { diff --git a/ghost/core/core/server/data/migrations/versions/5.61/2023-08-30-07-37-04-add-recommendations-enabled-settings.js b/ghost/core/core/server/data/migrations/versions/5.61/2023-08-30-07-37-04-add-recommendations-enabled-settings.js new file mode 100644 index 0000000000..1d6686b30a --- /dev/null +++ b/ghost/core/core/server/data/migrations/versions/5.61/2023-08-30-07-37-04-add-recommendations-enabled-settings.js @@ -0,0 +1,8 @@ +const {addSetting} = require('../../utils'); + +module.exports = addSetting({ + key: 'recommendations_enabled', + value: 'false', + type: 'boolean', + group: 'recommendations' +}); diff --git a/ghost/core/core/server/data/schema/default-settings/default-settings.json b/ghost/core/core/server/data/schema/default-settings/default-settings.json index 5a79fde169..5826d4a749 100644 --- a/ghost/core/core/server/data/schema/default-settings/default-settings.json +++ b/ghost/core/core/server/data/schema/default-settings/default-settings.json @@ -565,5 +565,15 @@ }, "type": "number" } + }, + "recommendations": { + "recommendations_enabled": { + "defaultValue": "false", + "validations": { + "isEmpty": false, + "isIn": [["true", "false"]] + }, + "type": "boolean" + } } } diff --git a/ghost/core/core/shared/settings-cache/public.js b/ghost/core/core/shared/settings-cache/public.js index 2098bb4ac9..31dee51aa0 100644 --- a/ghost/core/core/shared/settings-cache/public.js +++ b/ghost/core/core/shared/settings-cache/public.js @@ -39,5 +39,6 @@ module.exports = { portal_plans: 'portal_plans', portal_name: 'portal_name', portal_button: 'portal_button', - comments_enabled: 'comments_enabled' + comments_enabled: 'comments_enabled', + recommendations_enabled: 'recommendations_enabled' }; diff --git a/ghost/core/test/e2e-api/admin/__snapshots__/settings.test.js.snap b/ghost/core/test/e2e-api/admin/__snapshots__/settings.test.js.snap index 10e8fa5fa2..cdc530a746 100644 --- a/ghost/core/test/e2e-api/admin/__snapshots__/settings.test.js.snap +++ b/ghost/core/test/e2e-api/admin/__snapshots__/settings.test.js.snap @@ -312,6 +312,10 @@ Object { "key": "donations_suggested_amount", "value": "0", }, + Object { + "key": "recommendations_enabled", + "value": false, + }, Object { "key": "members_enabled", "value": true, @@ -714,6 +718,10 @@ Object { "key": "donations_suggested_amount", "value": "0", }, + Object { + "key": "recommendations_enabled", + "value": false, + }, Object { "key": "members_enabled", "value": true, @@ -742,7 +750,7 @@ exports[`Settings API Edit Can edit a setting 2: [headers] 1`] = ` Object { "access-control-allow-origin": "http://127.0.0.1:2369", "cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0", - "content-length": "4145", + "content-length": "4193", "content-type": "application/json; charset=utf-8", "content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/, "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, @@ -1064,6 +1072,10 @@ Object { "key": "donations_suggested_amount", "value": "0", }, + Object { + "key": "recommendations_enabled", + "value": false, + }, Object { "key": "members_enabled", "value": true, @@ -1413,6 +1425,10 @@ Object { "key": "donations_suggested_amount", "value": "0", }, + Object { + "key": "recommendations_enabled", + "value": false, + }, Object { "key": "members_enabled", "value": true, @@ -1767,6 +1783,10 @@ Object { "key": "donations_suggested_amount", "value": "0", }, + Object { + "key": "recommendations_enabled", + "value": false, + }, Object { "key": "members_enabled", "value": true, @@ -2209,6 +2229,10 @@ Object { "key": "donations_suggested_amount", "value": "0", }, + Object { + "key": "recommendations_enabled", + "value": false, + }, Object { "key": "members_enabled", "value": true, @@ -2623,6 +2647,10 @@ Object { "key": "donations_suggested_amount", "value": "0", }, + Object { + "key": "recommendations_enabled", + "value": false, + }, Object { "key": "members_enabled", "value": true, diff --git a/ghost/core/test/e2e-api/admin/settings.test.js b/ghost/core/test/e2e-api/admin/settings.test.js index 1bcb2e135a..3d568af2be 100644 --- a/ghost/core/test/e2e-api/admin/settings.test.js +++ b/ghost/core/test/e2e-api/admin/settings.test.js @@ -8,7 +8,7 @@ const {stringMatching, anyEtag, anyUuid, anyContentLength, anyContentVersion} = const models = require('../../../core/server/models'); const {anyErrorId} = matchers; -const CURRENT_SETTINGS_COUNT = 82; +const CURRENT_SETTINGS_COUNT = 83; const settingsMatcher = {}; diff --git a/ghost/core/test/e2e-api/content/__snapshots__/settings.test.js.snap b/ghost/core/test/e2e-api/content/__snapshots__/settings.test.js.snap index 6a14321368..4ce1767887 100644 --- a/ghost/core/test/e2e-api/content/__snapshots__/settings.test.js.snap +++ b/ghost/core/test/e2e-api/content/__snapshots__/settings.test.js.snap @@ -57,6 +57,7 @@ Object { ], "portal_signup_checkbox_required": false, "portal_signup_terms_html": null, + "recommendations_enabled": false, "secondary_navigation": Array [ Object { "label": "Data & privacy", diff --git a/ghost/core/test/e2e-api/shared/__snapshots__/version.test.js.snap b/ghost/core/test/e2e-api/shared/__snapshots__/version.test.js.snap index b4acfca7d9..0cba8154ba 100644 --- a/ghost/core/test/e2e-api/shared/__snapshots__/version.test.js.snap +++ b/ghost/core/test/e2e-api/shared/__snapshots__/version.test.js.snap @@ -1391,6 +1391,7 @@ Object { ], "portal_signup_checkbox_required": false, "portal_signup_terms_html": null, + "recommendations_enabled": false, "secondary_navigation": Array [ Object { "label": "Data & privacy", @@ -1487,6 +1488,7 @@ Object { ], "portal_signup_checkbox_required": false, "portal_signup_terms_html": null, + "recommendations_enabled": false, "secondary_navigation": Array [ Object { "label": "Data & privacy", diff --git a/ghost/core/test/regression/models/model_settings.test.js b/ghost/core/test/regression/models/model_settings.test.js index a3f930466b..737f3d5d31 100644 --- a/ghost/core/test/regression/models/model_settings.test.js +++ b/ghost/core/test/regression/models/model_settings.test.js @@ -5,7 +5,7 @@ const db = require('../../../core/server/data/db'); // Stuff we are testing const models = require('../../../core/server/models'); -const SETTINGS_LENGTH = 92; +const SETTINGS_LENGTH = 93; describe('Settings Model', function () { before(models.init); diff --git a/ghost/core/test/unit/server/data/exporter/index.test.js b/ghost/core/test/unit/server/data/exporter/index.test.js index cb3c2e3995..f90001c994 100644 --- a/ghost/core/test/unit/server/data/exporter/index.test.js +++ b/ghost/core/test/unit/server/data/exporter/index.test.js @@ -236,7 +236,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 = 84; + const allowedKeysLength = 85; totalKeysLength.should.eql(SETTING_KEYS_BLOCKLIST.length + allowedKeysLength); }); }); diff --git a/ghost/core/test/unit/server/data/schema/integrity.test.js b/ghost/core/test/unit/server/data/schema/integrity.test.js index 316345aec3..c02891ca2b 100644 --- a/ghost/core/test/unit/server/data/schema/integrity.test.js +++ b/ghost/core/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 = '5674764ca6518961a9b2917e7d8e2ea9'; const currentFixturesHash = '31865c37aacfec9b8f16c1354b36a7de'; - const currentSettingsHash = 'dd0e318627ded65e41f188fb5bdf5b74'; + const currentSettingsHash = '3a7ca0aa6a06cba47e3e898aef7029c2'; 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/ghost/core/test/utils/fixtures/default-settings-browser.json b/ghost/core/test/utils/fixtures/default-settings-browser.json index f2d453ff5c..f2a0b422a7 100644 --- a/ghost/core/test/utils/fixtures/default-settings-browser.json +++ b/ghost/core/test/utils/fixtures/default-settings-browser.json @@ -540,5 +540,15 @@ }, "type": "number" } + }, + "recommendations": { + "recommendations_enabled": { + "defaultValue": "false", + "validations": { + "isEmpty": false, + "isIn": [["true", "false"]] + }, + "type": "boolean" + } } } diff --git a/ghost/core/test/utils/fixtures/default-settings.json b/ghost/core/test/utils/fixtures/default-settings.json index ff2e899ce8..ada45f5339 100644 --- a/ghost/core/test/utils/fixtures/default-settings.json +++ b/ghost/core/test/utils/fixtures/default-settings.json @@ -573,5 +573,15 @@ }, "type": "number" } + }, + "recommendations": { + "recommendations_enabled": { + "defaultValue": "false", + "validations": { + "isEmpty": false, + "isIn": [["true", "false"]] + }, + "type": "boolean" + } } }