mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
d15f1f8961
Further changes to the data model to ensure created_by, author_id and updated_by are all set to user 1 Updated settings such that the default type is always 'general', and changed the types in the fixtures to be slightly more useful Added additional assertions to tests to cover more assumptions about data
50 lines
No EOL
1.5 KiB
JavaScript
50 lines
No EOL
1.5 KiB
JavaScript
(function () {
|
|
"use strict";
|
|
|
|
var Settings,
|
|
GhostBookshelf = require('./base'),
|
|
uuid = require('node-uuid'),
|
|
_ = require('underscore'),
|
|
errors = require('../errorHandling'),
|
|
when = require('when');
|
|
|
|
// Each setting is saved as a separate row in the database,
|
|
// but the overlying API treats them as a single key:value mapping
|
|
Settings = GhostBookshelf.Model.extend({
|
|
tableName: 'settings',
|
|
hasTimestamps: true,
|
|
defaults: function () {
|
|
return {
|
|
uuid: uuid.v4(),
|
|
type: 'general'
|
|
};
|
|
}
|
|
}, {
|
|
read: function (_key) {
|
|
// Allow for just passing the key instead of attributes
|
|
if (!_.isObject(_key)) {
|
|
_key = { key: _key };
|
|
}
|
|
return GhostBookshelf.Model.read.call(this, _key);
|
|
},
|
|
|
|
edit: function (_data) {
|
|
var settings = this;
|
|
if (!Array.isArray(_data)) {
|
|
_data = [_data];
|
|
}
|
|
return when.map(_data, function (item) {
|
|
// Accept an array of models as input
|
|
if (item.toJSON) { item = item.toJSON(); }
|
|
return settings.forge({ key: item.key }).fetch().then(function (setting) {
|
|
return setting.set('value', item.value).save();
|
|
}, errors.logAndThrowError);
|
|
});
|
|
}
|
|
});
|
|
|
|
module.exports = {
|
|
Settings: Settings
|
|
};
|
|
|
|
}()); |