0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00

Change type for private blog settings

refs #5614 and #5503

- update private blog type, including update to settings.edit
- switch order of populate settings & update fixtures + populate all settings

Private blog settings should not be returned by public endpoints
therefore they need a type which is not `blog` or `theme`.
`core` doesn't suit either, as those settings don't usually have UI
To resolve this, I created a new type `private` which can be used
for any setting which has a UI but should not be public data
This commit is contained in:
Hannah Wolfe 2015-08-24 12:43:26 +01:00
parent d215983d53
commit 114696f7e2
6 changed files with 51 additions and 18 deletions

View file

@ -15,7 +15,7 @@ export default AuthenticatedRoute.extend(styleBody, CurrentUserSettings, {
},
model: function () {
return this.store.find('setting', {type: 'blog,theme'}).then(function (records) {
return this.store.find('setting', {type: 'blog,theme,private'}).then(function (records) {
return records.get('firstObject');
});
},

View file

@ -66,12 +66,6 @@
},
"navigation": {
"defaultValue": "[{\"label\":\"Home\", \"url\":\"/\"}]"
},
"isPrivate": {
"defaultValue": "false"
},
"password": {
"defaultValue": ""
}
},
"theme": {
@ -86,5 +80,13 @@
"installedApps": {
"defaultValue": "[]"
}
},
"private": {
"isPrivate": {
"defaultValue": "false"
},
"password": {
"defaultValue": ""
}
}
}

View file

@ -37,7 +37,7 @@ logInfo = function logInfo(message) {
* Changes an admin user to have the owner role
* @returns {Promise|*}
*/
convertAdminToOwner = function () {
convertAdminToOwner = function convertAdminToOwner() {
var adminUser;
return models.User.findOne({role: 'Administrator'}).then(function (user) {
@ -56,7 +56,7 @@ convertAdminToOwner = function () {
* Creates the user fixture and gives it the owner role
* @returns {Promise|*}
*/
createOwner = function () {
createOwner = function createOwner() {
var user = fixtures.users[0];
return models.Role.findOne({name: 'Owner'}).then(function (ownerRole) {
@ -68,7 +68,7 @@ createOwner = function () {
});
};
populate = function () {
populate = function populate() {
var ops = [],
relations = [],
Post = models.Post,
@ -122,7 +122,7 @@ populate = function () {
* Note: At the moment this is pretty adhoc & untestable, in future it would be better to have a config based system.
* @returns {Promise|*}
*/
to003 = function () {
to003 = function to003() {
var ops = [],
upgradeOp,
Role = models.Role,
@ -161,7 +161,7 @@ to003 = function () {
* Update ghost_foot to include a CDN of jquery if the DB is migrating from
* @return {Promise}
*/
to004 = function () {
to004 = function to004() {
var value,
ops = [],
upgradeOp,
@ -199,6 +199,26 @@ to004 = function () {
});
ops.push(upgradeOp);
// change `type` for protected blog `isPrivate` setting
upgradeOp = models.Settings.findOne('isPrivate').then(function (setting) {
if (setting) {
logInfo('Update isPrivate setting');
return models.Settings.edit({key: 'isPrivate', type: 'private'}, options);
}
return Promise.resolve();
});
ops.push(upgradeOp);
// change `type` for protected blog `password` setting
upgradeOp = models.Settings.findOne('password').then(function (setting) {
if (setting) {
logInfo('Update password setting');
return models.Settings.edit({key: 'password', type: 'private'}, options);
}
return Promise.resolve();
});
ops.push(upgradeOp);
// Update ghost-admin client fixture
// ghost-admin should exist from 003 version
upgradeOp = models.Client.findOne({slug: fixtures.clients[0].slug}).then(function (client) {
@ -222,7 +242,7 @@ to004 = function () {
return Promise.all(ops);
};
update = function (fromVersion, toVersion) {
update = function update(fromVersion, toVersion) {
var ops = [];
logInfo('Updating fixtures');

View file

@ -33,7 +33,7 @@ logInfo = function logInfo(message) {
populateDefaultSettings = function populateDefaultSettings() {
// Initialise the default settings
logInfo('Populating default settings');
return models.Settings.populateDefault('databaseVersion').then(function () {
return models.Settings.populateDefaults().then(function () {
logInfo('Complete');
});
};
@ -178,9 +178,11 @@ migrateUp = function (fromVersion, toVersion) {
return sequence(migrateOps);
}
}).then(function () {
return fixtures.update(fromVersion, toVersion);
}).then(function () {
// Ensure all of the current default settings are created (these are fixtures, so should be inserted first)
return populateDefaultSettings();
}).then(function () {
// Finally, run any updates to the fixtures, including default settings
return fixtures.update(fromVersion, toVersion);
});
};

View file

@ -92,7 +92,7 @@ var db = {
uuid: {type: 'string', maxlength: 36, nullable: false, validations: {isUUID: true}},
key: {type: 'string', maxlength: 150, nullable: false, unique: true},
value: {type: 'text', maxlength: 65535, nullable: true},
type: {type: 'string', maxlength: 150, nullable: false, defaultTo: 'core', validations: {isIn: [['core', 'blog', 'theme', 'app', 'plugin']]}},
type: {type: 'string', maxlength: 150, nullable: false, defaultTo: 'core', validations: {isIn: [['core', 'blog', 'theme', 'app', 'plugin', 'private']]}},
created_at: {type: 'dateTime', nullable: false},
created_by: {type: 'integer', nullable: false},
updated_at: {type: 'dateTime', nullable: true},

View file

@ -125,8 +125,17 @@ Settings = ghostBookshelf.Model.extend({
item = self.filterData(item);
return Settings.forge({key: item.key}).fetch(options).then(function then(setting) {
var saveData = {};
if (setting) {
return setting.save({value: item.value}, options);
if (item.hasOwnProperty('value')) {
saveData.value = item.value;
}
// Internal context can overwrite type (for fixture migrations)
if (options.context.internal && item.hasOwnProperty('type')) {
saveData.type = item.type;
}
return setting.save(saveData, options);
}
return Promise.reject(new errors.NotFoundError('Unable to find setting to update: ' + item.key));