Removed active_timezone, default_locale & locale compat (#14788)

- These settings no longer exist, having been renamed to timezone and lang
- As of 5.0 we no longer need any kind of backwards compatibility outside of the importer
- We making breaking changes and cleaning up as many old code paths as possible 
- We have not really exposed the admin Settings API, meaning backwards compatibility was more for internal use
- We will be changing lang back to locale, but that's a separate issue and won't need backwards compatibility
This commit is contained in:
Hannah Wolfe 2022-05-11 16:22:25 +01:00 committed by GitHub
parent ae45579903
commit 196b8ad0da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 267 deletions

View File

@ -70,20 +70,6 @@ module.exports = {
}
},
read(apiConfig, frame) {
if (frame.options.key === 'active_timezone') {
frame.options.key = 'timezone';
}
if (frame.options.key === 'default_locale') {
frame.options.key = 'lang';
}
if (frame.options.key === 'locale') {
frame.options.key = 'lang';
}
},
edit(apiConfig, frame) {
// CASE: allow shorthand syntax where a single key and value are passed to edit instead of object and options
if (_.isString(frame.data)) {
@ -133,18 +119,6 @@ module.exports = {
setting.value = setting.value === 'true';
}
if (setting.key === 'active_timezone') {
setting.key = 'timezone';
}
if (setting.key === 'default_locale') {
setting.key = 'lang';
}
if (setting.key === 'locale') {
setting.key = 'lang';
}
if (setting.key === 'labs') {
const inputLabsValue = JSON.parse(setting.value);
const filteredLabsValue = {};

View File

@ -40,24 +40,6 @@ module.exports.forSettings = (attrs, frame) => {
if (_.isArray(attrs)) {
// CASE: read single setting
if (frame.original.params && frame.original.params.key) {
if (frame.original.params.key === 'active_timezone') {
attrs[0].key = 'active_timezone';
return;
}
if (frame.original.params.key === 'default_locale') {
attrs[0].key = 'default_locale';
return;
}
if (frame.original.params.key === 'timezone') {
return;
}
if (frame.original.params.key === 'lang') {
return;
}
if (frame.original.params.key === 'slack_url'
|| frame.original.params.key === 'slack_username') {
return;
@ -66,16 +48,7 @@ module.exports.forSettings = (attrs, frame) => {
// CASE: edit
if (frame.original.body && frame.original.body.settings) {
frame.original.body.settings.forEach((setting) => {
if (setting.key === 'active_timezone') {
const target = _.find(attrs, {key: 'timezone'});
target.key = 'active_timezone';
} else if (setting.key === 'default_locale') {
const target = _.find(attrs, {key: 'lang'});
target.key = 'default_locale';
} else if (setting.key === 'locale') {
const target = _.find(attrs, {key: 'lang'});
target.key = 'locale';
} else if (setting.key === 'slack') {
if (setting.key === 'slack') {
const slackURL = _.cloneDeep(_.find(attrs, {key: 'slack_url'}));
const slackUsername = _.cloneDeep(_.find(attrs, {key: 'slack_username'}));
@ -96,21 +69,8 @@ module.exports.forSettings = (attrs, frame) => {
}
// CASE: browse all settings, add extra keys and keep deprecated
const timezone = _.cloneDeep(_.find(attrs, {key: 'timezone'}));
const lang = _.cloneDeep(_.find(attrs, {key: 'lang'}));
const slackURL = _.cloneDeep(_.find(attrs, {key: 'slack_url'}));
const slackUsername = _.cloneDeep(_.find(attrs, {key: 'slack_username'}));
const locale = _.cloneDeep(_.find(attrs, {key: 'lang'}));
if (timezone) {
timezone.key = 'active_timezone';
attrs.push(timezone);
}
if (lang) {
lang.key = 'default_locale';
attrs.push(lang);
}
if (slackURL || slackUsername) {
const slack = slackURL || slackUsername;
@ -122,10 +82,5 @@ module.exports.forSettings = (attrs, frame) => {
attrs.push(slack);
}
if (locale) {
locale.key = 'locale';
attrs.push(locale);
}
}
};

View File

@ -1082,26 +1082,6 @@ Object {
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
"value": true,
},
Object {
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
"flags": null,
"group": "site",
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
"key": "active_timezone",
"type": "string",
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
"value": "Etc/UTC",
},
Object {
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
"flags": null,
"group": "site",
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
"key": "default_locale",
"type": "string",
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
"value": "en",
},
Object {
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
"flags": null,
@ -1112,16 +1092,6 @@ Object {
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
"value": "[{\\"url\\":\\"\\",\\"username\\":\\"Ghost\\"}]",
},
Object {
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
"flags": null,
"group": "site",
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
"key": "locale",
"type": "string",
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
"value": "en",
},
],
}
`;
@ -1130,7 +1100,7 @@ exports[`Settings API Can request all settings 1: [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": "18219",
"content-length": "18287",
"content-type": "application/json; charset=utf-8",
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
"vary": "Origin, Accept-Encoding",
@ -1142,7 +1112,7 @@ exports[`Settings API Can request all settings 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": "18867",
"content-length": "18287",
"content-type": "application/json; charset=utf-8",
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
"vary": "Origin, Accept-Encoding",

View File

@ -2,7 +2,7 @@ const assert = require('assert');
const {agentProvider, fixtureManager, mockManager, matchers} = require('../../utils/e2e-framework');
const {stringMatching, anyEtag, anyObjectId, anyISODateTime} = matchers;
const CURRENT_SETTINGS_COUNT = 89;
const CURRENT_SETTINGS_COUNT = 86;
const settingsMatcher = {
id: anyObjectId,

View File

@ -39,11 +39,6 @@ const defaultSettingsKeyTypes = [
type: 'string',
group: 'site'
},
{
key: 'locale',
type: 'string',
group: 'site'
},
{
key: 'timezone',
type: 'string',
@ -339,16 +334,6 @@ const defaultSettingsKeyTypes = [
type: 'array',
group: 'views'
},
{
key: 'active_timezone',
type: 'string',
group: 'site'
},
{
key: 'default_locale',
type: 'string',
group: 'site'
},
{
key: 'accent_color',
type: 'string',
@ -469,7 +454,6 @@ describe('Settings API (canary)', function () {
jsonResponse.settings.should.be.an.Object();
const settings = jsonResponse.settings;
should.equal(settings.length, (defaultSettingsKeyTypes.length + calculatedSettingsTypes.length));
for (const defaultSetting of defaultSettingsKeyTypes) {
should.exist(settings.find((setting) => {
return (setting.key === defaultSetting.key)
@ -478,6 +462,8 @@ describe('Settings API (canary)', function () {
}), `Expected to find a setting with key ${defaultSetting.key}, type ${defaultSetting.type}, and group ${defaultSetting.group}`);
}
should.equal(settings.length, (defaultSettingsKeyTypes.length + calculatedSettingsTypes.length));
const unsplash = settings.find(s => s.key === 'unsplash');
should.exist(unsplash);
unsplash.value.should.equal(true);
@ -693,69 +679,6 @@ describe('Settings API (canary)', function () {
jsonResponse.settings[0].value.should.match(jsonObjectRegex);
});
it('Can read deprecated default_locale', function (done) {
request.get(localUtils.API.getApiQuery('settings/default_locale/'))
.set('Origin', config.get('url'))
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)
.expect(200)
.end(function (err, res) {
if (err) {
return done(err);
}
should.not.exist(res.headers['x-cache-invalidate']);
const jsonResponse = res.body;
should.exist(jsonResponse);
should.exist(jsonResponse.settings);
jsonResponse.settings.length.should.eql(1);
testUtils.API.checkResponseValue(jsonResponse.settings[0], ['id', 'group', 'key', 'value', 'type', 'flags', 'created_at', 'updated_at']);
jsonResponse.settings[0].key.should.eql('default_locale');
done();
});
});
it('Can edit deprecated default_locale setting', function () {
return request.get(localUtils.API.getApiQuery('settings/default_locale/'))
.set('Origin', config.get('url'))
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)
.then(function (res) {
let jsonResponse = res.body;
const newValue = 'new value';
should.exist(jsonResponse);
should.exist(jsonResponse.settings);
jsonResponse.settings = [{key: 'default_locale', value: 'ua'}];
return jsonResponse;
})
.then((editedSetting) => {
return request.put(localUtils.API.getApiQuery('settings/'))
.set('Origin', config.get('url'))
.send(editedSetting)
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)
.expect(200)
.then(function (res) {
should.exist(res.headers['x-cache-invalidate']);
const jsonResponse = res.body;
should.exist(jsonResponse);
should.exist(jsonResponse.settings);
jsonResponse.settings.length.should.eql(1);
testUtils.API.checkResponseValue(jsonResponse.settings[0], ['id', 'group', 'key', 'value', 'type', 'flags', 'created_at', 'updated_at']);
jsonResponse.settings[0].key.should.eql('default_locale');
jsonResponse.settings[0].value.should.eql('ua');
});
});
});
it('Can edit deprecated lang setting', function () {
return request.get(localUtils.API.getApiQuery('settings/lang/'))
.set('Origin', config.get('url'))
@ -793,42 +716,43 @@ describe('Settings API (canary)', function () {
});
});
it('Can edit newly introduced locale setting', function () {
return request.get(localUtils.API.getApiQuery('settings/locale/'))
.set('Origin', config.get('url'))
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)
.then(function (res) {
let jsonResponse = res.body;
should.exist(jsonResponse);
should.exist(jsonResponse.settings);
jsonResponse.settings = [{key: 'locale', value: 'ge'}];
// @TODO: swap this test for the one above when renaming the setting is in place
// it('Can edit newly introduced locale setting', function () {
// return request.get(localUtils.API.getApiQuery('settings/locale/'))
// .set('Origin', config.get('url'))
// .set('Accept', 'application/json')
// .expect('Content-Type', /json/)
// .expect('Cache-Control', testUtils.cacheRules.private)
// .then(function (res) {
// let jsonResponse = res.body;
// should.exist(jsonResponse);
// should.exist(jsonResponse.settings);
// jsonResponse.settings = [{key: 'locale', value: 'ge'}];
return jsonResponse;
})
.then((editedSetting) => {
return request.put(localUtils.API.getApiQuery('settings/'))
.set('Origin', config.get('url'))
.send(editedSetting)
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)
.expect(200)
.then(function (res) {
should.exist(res.headers['x-cache-invalidate']);
const jsonResponse = res.body;
// return jsonResponse;
// })
// .then((editedSetting) => {
// return request.put(localUtils.API.getApiQuery('settings/'))
// .set('Origin', config.get('url'))
// .send(editedSetting)
// .expect('Content-Type', /json/)
// .expect('Cache-Control', testUtils.cacheRules.private)
// .expect(200)
// .then(function (res) {
// should.exist(res.headers['x-cache-invalidate']);
// const jsonResponse = res.body;
should.exist(jsonResponse);
should.exist(jsonResponse.settings);
// should.exist(jsonResponse);
// should.exist(jsonResponse.settings);
jsonResponse.settings.length.should.eql(1);
// jsonResponse.settings.length.should.eql(1);
testUtils.API.checkResponseValue(jsonResponse.settings[0], ['id', 'group', 'key', 'value', 'type', 'flags', 'created_at', 'updated_at']);
jsonResponse.settings[0].key.should.eql('locale');
jsonResponse.settings[0].value.should.eql('ge');
});
});
});
// testUtils.API.checkResponseValue(jsonResponse.settings[0], ['id', 'group', 'key', 'value', 'type', 'flags', 'created_at', 'updated_at']);
// jsonResponse.settings[0].key.should.eql('locale');
// jsonResponse.settings[0].value.should.eql('ge');
// });
// });
// });
it('Can read timezone', function (done) {
request.get(localUtils.API.getApiQuery('settings/timezone/'))
@ -855,56 +779,6 @@ describe('Settings API (canary)', function () {
});
});
it('Can read active_timezone', function (done) {
request.get(localUtils.API.getApiQuery('settings/active_timezone/'))
.set('Origin', config.get('url'))
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)
.expect(200)
.end(function (err, res) {
if (err) {
return done(err);
}
should.not.exist(res.headers['x-cache-invalidate']);
const jsonResponse = res.body;
should.exist(jsonResponse);
should.exist(jsonResponse.settings);
jsonResponse.settings.length.should.eql(1);
testUtils.API.checkResponseValue(jsonResponse.settings[0], ['id', 'group', 'key', 'value', 'type', 'flags', 'created_at', 'updated_at']);
jsonResponse.settings[0].key.should.eql('active_timezone');
done();
});
});
it('Can read deprecated active_timezone', function (done) {
request.get(localUtils.API.getApiQuery('settings/active_timezone/'))
.set('Origin', config.get('url'))
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)
.expect(200)
.end(function (err, res) {
if (err) {
return done(err);
}
should.not.exist(res.headers['x-cache-invalidate']);
const jsonResponse = res.body;
should.exist(jsonResponse);
should.exist(jsonResponse.settings);
jsonResponse.settings.length.should.eql(1);
testUtils.API.checkResponseValue(jsonResponse.settings[0], ['id', 'group', 'key', 'value', 'type', 'flags', 'created_at', 'updated_at']);
jsonResponse.settings[0].key.should.eql('active_timezone');
done();
});
});
it('Can read slack renamed&reformatted in v4', function (done) {
request.get(localUtils.API.getApiQuery('settings/slack/'))
.set('Origin', config.get('url'))

View File

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="{{lang}}">
<html lang="{{@site.locale}}">
<head>
{{ghost_head}}
</head>