diff --git a/core/client/app/routes/settings/general.js b/core/client/app/routes/settings/general.js index 7c563ec5fd5c..2d1246314d60 100644 --- a/core/client/app/routes/settings/general.js +++ b/core/client/app/routes/settings/general.js @@ -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'); }); }, diff --git a/core/server/data/default-settings.json b/core/server/data/default-settings.json index 99ed0cd6fbcf..dc7e991e137b 100644 --- a/core/server/data/default-settings.json +++ b/core/server/data/default-settings.json @@ -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": "" + } } } diff --git a/core/server/data/fixtures/index.js b/core/server/data/fixtures/index.js index f66177656e25..feb803dd7429 100644 --- a/core/server/data/fixtures/index.js +++ b/core/server/data/fixtures/index.js @@ -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'); diff --git a/core/server/data/migration/index.js b/core/server/data/migration/index.js index 93c7124749ee..0e08b622ef9e 100644 --- a/core/server/data/migration/index.js +++ b/core/server/data/migration/index.js @@ -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); }); }; diff --git a/core/server/data/schema.js b/core/server/data/schema.js index ae2f904804f7..9b3c8c5cdc65 100644 --- a/core/server/data/schema.js +++ b/core/server/data/schema.js @@ -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}, diff --git a/core/server/models/settings.js b/core/server/models/settings.js index 26c79e47913e..f068f1306da9 100644 --- a/core/server/models/settings.js +++ b/core/server/models/settings.js @@ -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));