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
This commit is contained in:
Sag 2023-08-30 10:56:21 +02:00 committed by GitHub
parent 89e9e4a2b8
commit f1cd6432a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 78 additions and 7 deletions

View File

@ -70,7 +70,8 @@ const EDITABLE_SETTINGS = [
'pintura_js_url', 'pintura_js_url',
'pintura_css_url', 'pintura_css_url',
'donations_currency', 'donations_currency',
'donations_suggested_amount' 'donations_suggested_amount',
'recommendations_enabled'
]; ];
module.exports = { module.exports = {

View File

@ -0,0 +1,8 @@
const {addSetting} = require('../../utils');
module.exports = addSetting({
key: 'recommendations_enabled',
value: 'false',
type: 'boolean',
group: 'recommendations'
});

View File

@ -565,5 +565,15 @@
}, },
"type": "number" "type": "number"
} }
},
"recommendations": {
"recommendations_enabled": {
"defaultValue": "false",
"validations": {
"isEmpty": false,
"isIn": [["true", "false"]]
},
"type": "boolean"
}
} }
} }

View File

@ -39,5 +39,6 @@ module.exports = {
portal_plans: 'portal_plans', portal_plans: 'portal_plans',
portal_name: 'portal_name', portal_name: 'portal_name',
portal_button: 'portal_button', portal_button: 'portal_button',
comments_enabled: 'comments_enabled' comments_enabled: 'comments_enabled',
recommendations_enabled: 'recommendations_enabled'
}; };

View File

@ -312,6 +312,10 @@ Object {
"key": "donations_suggested_amount", "key": "donations_suggested_amount",
"value": "0", "value": "0",
}, },
Object {
"key": "recommendations_enabled",
"value": false,
},
Object { Object {
"key": "members_enabled", "key": "members_enabled",
"value": true, "value": true,
@ -714,6 +718,10 @@ Object {
"key": "donations_suggested_amount", "key": "donations_suggested_amount",
"value": "0", "value": "0",
}, },
Object {
"key": "recommendations_enabled",
"value": false,
},
Object { Object {
"key": "members_enabled", "key": "members_enabled",
"value": true, "value": true,
@ -742,7 +750,7 @@ exports[`Settings API Edit Can edit a setting 2: [headers] 1`] = `
Object { Object {
"access-control-allow-origin": "http://127.0.0.1:2369", "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", "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-type": "application/json; charset=utf-8",
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/, "content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
@ -1064,6 +1072,10 @@ Object {
"key": "donations_suggested_amount", "key": "donations_suggested_amount",
"value": "0", "value": "0",
}, },
Object {
"key": "recommendations_enabled",
"value": false,
},
Object { Object {
"key": "members_enabled", "key": "members_enabled",
"value": true, "value": true,
@ -1413,6 +1425,10 @@ Object {
"key": "donations_suggested_amount", "key": "donations_suggested_amount",
"value": "0", "value": "0",
}, },
Object {
"key": "recommendations_enabled",
"value": false,
},
Object { Object {
"key": "members_enabled", "key": "members_enabled",
"value": true, "value": true,
@ -1767,6 +1783,10 @@ Object {
"key": "donations_suggested_amount", "key": "donations_suggested_amount",
"value": "0", "value": "0",
}, },
Object {
"key": "recommendations_enabled",
"value": false,
},
Object { Object {
"key": "members_enabled", "key": "members_enabled",
"value": true, "value": true,
@ -2209,6 +2229,10 @@ Object {
"key": "donations_suggested_amount", "key": "donations_suggested_amount",
"value": "0", "value": "0",
}, },
Object {
"key": "recommendations_enabled",
"value": false,
},
Object { Object {
"key": "members_enabled", "key": "members_enabled",
"value": true, "value": true,
@ -2623,6 +2647,10 @@ Object {
"key": "donations_suggested_amount", "key": "donations_suggested_amount",
"value": "0", "value": "0",
}, },
Object {
"key": "recommendations_enabled",
"value": false,
},
Object { Object {
"key": "members_enabled", "key": "members_enabled",
"value": true, "value": true,

View File

@ -8,7 +8,7 @@ const {stringMatching, anyEtag, anyUuid, anyContentLength, anyContentVersion} =
const models = require('../../../core/server/models'); const models = require('../../../core/server/models');
const {anyErrorId} = matchers; const {anyErrorId} = matchers;
const CURRENT_SETTINGS_COUNT = 82; const CURRENT_SETTINGS_COUNT = 83;
const settingsMatcher = {}; const settingsMatcher = {};

View File

@ -57,6 +57,7 @@ Object {
], ],
"portal_signup_checkbox_required": false, "portal_signup_checkbox_required": false,
"portal_signup_terms_html": null, "portal_signup_terms_html": null,
"recommendations_enabled": false,
"secondary_navigation": Array [ "secondary_navigation": Array [
Object { Object {
"label": "Data & privacy", "label": "Data & privacy",

View File

@ -1391,6 +1391,7 @@ Object {
], ],
"portal_signup_checkbox_required": false, "portal_signup_checkbox_required": false,
"portal_signup_terms_html": null, "portal_signup_terms_html": null,
"recommendations_enabled": false,
"secondary_navigation": Array [ "secondary_navigation": Array [
Object { Object {
"label": "Data & privacy", "label": "Data & privacy",
@ -1487,6 +1488,7 @@ Object {
], ],
"portal_signup_checkbox_required": false, "portal_signup_checkbox_required": false,
"portal_signup_terms_html": null, "portal_signup_terms_html": null,
"recommendations_enabled": false,
"secondary_navigation": Array [ "secondary_navigation": Array [
Object { Object {
"label": "Data & privacy", "label": "Data & privacy",

View File

@ -5,7 +5,7 @@ const db = require('../../../core/server/data/db');
// Stuff we are testing // Stuff we are testing
const models = require('../../../core/server/models'); const models = require('../../../core/server/models');
const SETTINGS_LENGTH = 92; const SETTINGS_LENGTH = 93;
describe('Settings Model', function () { describe('Settings Model', function () {
before(models.init); before(models.init);

View File

@ -236,7 +236,7 @@ describe('Exporter', function () {
// NOTE: if default settings changed either modify the settings keys blocklist or increase allowedKeysLength // 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 ;) // 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); totalKeysLength.should.eql(SETTING_KEYS_BLOCKLIST.length + allowedKeysLength);
}); });
}); });

View File

@ -37,7 +37,7 @@ describe('DB version integrity', function () {
// Only these variables should need updating // Only these variables should need updating
const currentSchemaHash = '5674764ca6518961a9b2917e7d8e2ea9'; const currentSchemaHash = '5674764ca6518961a9b2917e7d8e2ea9';
const currentFixturesHash = '31865c37aacfec9b8f16c1354b36a7de'; const currentFixturesHash = '31865c37aacfec9b8f16c1354b36a7de';
const currentSettingsHash = 'dd0e318627ded65e41f188fb5bdf5b74'; const currentSettingsHash = '3a7ca0aa6a06cba47e3e898aef7029c2';
const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01'; const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';
// If this test is failing, then it is likely a change has been made that requires a DB version bump, // If this test is failing, then it is likely a change has been made that requires a DB version bump,

View File

@ -540,5 +540,15 @@
}, },
"type": "number" "type": "number"
} }
},
"recommendations": {
"recommendations_enabled": {
"defaultValue": "false",
"validations": {
"isEmpty": false,
"isIn": [["true", "false"]]
},
"type": "boolean"
}
} }
} }

View File

@ -573,5 +573,15 @@
}, },
"type": "number" "type": "number"
} }
},
"recommendations": {
"recommendations_enabled": {
"defaultValue": "false",
"validations": {
"isEmpty": false,
"isIn": [["true", "false"]]
},
"type": "boolean"
}
} }
} }