mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Added support for locale key in Admin Settings API
refs https://github.com/TryGhost/Team/issues/509 - Allows to update and read 'locale' key along with the deprecated 'lang' - In Ghost v5 the 'lang' key will be dropped and the migration in settings table will clean up the key name to match the one exposed through the APIs
This commit is contained in:
parent
7a11a9b3c4
commit
9995ae3616
3 changed files with 92 additions and 0 deletions
|
@ -86,6 +86,10 @@ module.exports = {
|
||||||
if (frame.options.key === 'default_locale') {
|
if (frame.options.key === 'default_locale') {
|
||||||
frame.options.key = 'lang';
|
frame.options.key = 'lang';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (frame.options.key === 'locale') {
|
||||||
|
frame.options.key = 'lang';
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
edit(apiConfig, frame) {
|
edit(apiConfig, frame) {
|
||||||
|
@ -151,6 +155,10 @@ module.exports = {
|
||||||
setting.key = 'lang';
|
setting.key = 'lang';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (setting.key === 'locale') {
|
||||||
|
setting.key = 'lang';
|
||||||
|
}
|
||||||
|
|
||||||
if (['cover_image', 'icon', 'logo', 'portal_button_icon'].includes(setting.key)) {
|
if (['cover_image', 'icon', 'logo', 'portal_button_icon'].includes(setting.key)) {
|
||||||
setting = url.forSetting(setting);
|
setting = url.forSetting(setting);
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,6 +93,9 @@ module.exports.forSettings = (attrs, frame) => {
|
||||||
} else if (setting.key === 'default_locale') {
|
} else if (setting.key === 'default_locale') {
|
||||||
const target = _.find(attrs, {key: 'lang'});
|
const target = _.find(attrs, {key: 'lang'});
|
||||||
target.key = 'default_locale';
|
target.key = 'default_locale';
|
||||||
|
} else if (setting.key === 'locale') {
|
||||||
|
const target = _.find(attrs, {key: 'lang'});
|
||||||
|
target.key = 'locale';
|
||||||
} else if (setting.key === 'slack') {
|
} else if (setting.key === 'slack') {
|
||||||
const slackURL = _.cloneDeep(_.find(attrs, {key: 'slack_url'}));
|
const slackURL = _.cloneDeep(_.find(attrs, {key: 'slack_url'}));
|
||||||
const slackUsername = _.cloneDeep(_.find(attrs, {key: 'slack_username'}));
|
const slackUsername = _.cloneDeep(_.find(attrs, {key: 'slack_username'}));
|
||||||
|
@ -120,6 +123,7 @@ module.exports.forSettings = (attrs, frame) => {
|
||||||
const lang = _.cloneDeep(_.find(attrs, {key: 'lang'}));
|
const lang = _.cloneDeep(_.find(attrs, {key: 'lang'}));
|
||||||
const slackURL = _.cloneDeep(_.find(attrs, {key: 'slack_url'}));
|
const slackURL = _.cloneDeep(_.find(attrs, {key: 'slack_url'}));
|
||||||
const slackUsername = _.cloneDeep(_.find(attrs, {key: 'slack_username'}));
|
const slackUsername = _.cloneDeep(_.find(attrs, {key: 'slack_username'}));
|
||||||
|
const locale = _.cloneDeep(_.find(attrs, {key: 'lang'}));
|
||||||
|
|
||||||
if (ghostHead) {
|
if (ghostHead) {
|
||||||
ghostHead.key = 'ghost_head';
|
ghostHead.key = 'ghost_head';
|
||||||
|
@ -151,5 +155,10 @@ module.exports.forSettings = (attrs, frame) => {
|
||||||
|
|
||||||
attrs.push(slack);
|
attrs.push(slack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (locale) {
|
||||||
|
locale.key = 'locale';
|
||||||
|
attrs.push(locale);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,6 +15,7 @@ const defaultSettingsKeyTypes = [
|
||||||
{key: 'cover_image', type: 'blog'},
|
{key: 'cover_image', type: 'blog'},
|
||||||
{key: 'icon', type: 'blog'},
|
{key: 'icon', type: 'blog'},
|
||||||
{key: 'lang', type: 'blog'},
|
{key: 'lang', type: 'blog'},
|
||||||
|
{key: 'locale', type: 'blog'},
|
||||||
{key: 'timezone', type: 'blog'},
|
{key: 'timezone', type: 'blog'},
|
||||||
{key: 'codeinjection_head', type: 'blog'},
|
{key: 'codeinjection_head', type: 'blog'},
|
||||||
{key: 'codeinjection_foot', type: 'blog'},
|
{key: 'codeinjection_foot', type: 'blog'},
|
||||||
|
@ -328,6 +329,80 @@ describe('Settings API (canary)', function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Can edit deprecated lang setting', function () {
|
||||||
|
return request.get(localUtils.API.getApiQuery('settings/lang/'))
|
||||||
|
.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: 'lang', 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('lang');
|
||||||
|
jsonResponse.settings[0].value.should.eql('ua');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
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('locale');
|
||||||
|
jsonResponse.settings[0].value.should.eql('ge');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('Can read timezone', function (done) {
|
it('Can read timezone', function (done) {
|
||||||
request.get(localUtils.API.getApiQuery('settings/timezone/'))
|
request.get(localUtils.API.getApiQuery('settings/timezone/'))
|
||||||
.set('Origin', config.get('url'))
|
.set('Origin', config.get('url'))
|
||||||
|
|
Loading…
Add table
Reference in a new issue