mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-05 18:34:39 +03:00
87cda81c84
closes #2653 - enforce strict whitelists for model methods - create a class method that reports a model method's valid options - create a class method that filters a model's valid attributes from data - create a class method that filters valid options from a model method's options hash
42 lines
1.0 KiB
JavaScript
42 lines
1.0 KiB
JavaScript
var ghostBookshelf = require('./base'),
|
|
|
|
Session,
|
|
Sessions;
|
|
|
|
Session = ghostBookshelf.Model.extend({
|
|
|
|
tableName: 'sessions',
|
|
|
|
// override for base function since we don't have
|
|
// a created_by field for sessions
|
|
creating: function (newObj, attr, options) {
|
|
/*jshint unused:false*/
|
|
},
|
|
|
|
// override for base function since we don't have
|
|
// a updated_by field for sessions
|
|
saving: function (newObj, attr, options) {
|
|
/*jshint unused:false*/
|
|
// Remove any properties which don't belong on the model
|
|
this.attributes = this.pick(this.permittedAttributes());
|
|
},
|
|
|
|
}, {
|
|
destroyAll: function (options) {
|
|
options = this.filterOptions(options, 'destroyAll');
|
|
return ghostBookshelf.Collection.forge([], {model: this}).fetch()
|
|
.then(function (collection) {
|
|
collection.invokeThen('destroy', options);
|
|
});
|
|
}
|
|
});
|
|
|
|
Sessions = ghostBookshelf.Collection.extend({
|
|
model: Session
|
|
});
|
|
|
|
module.exports = {
|
|
Session: Session,
|
|
Sessions: Sessions
|
|
};
|