2014-02-12 07:40:39 +04:00
|
|
|
var ghostBookshelf = require('./base'),
|
|
|
|
App,
|
|
|
|
Apps;
|
|
|
|
|
|
|
|
App = ghostBookshelf.Model.extend({
|
|
|
|
tableName: 'apps',
|
|
|
|
|
2014-06-24 21:59:45 +04:00
|
|
|
saving: function (newPage, attr, options) {
|
2015-05-01 00:14:19 +03:00
|
|
|
/*jshint unused:false*/
|
2014-06-24 21:59:45 +04:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
ghostBookshelf.Model.prototype.saving.apply(this, arguments);
|
|
|
|
|
|
|
|
if (this.hasChanged('slug') || !this.get('slug')) {
|
|
|
|
// Pass the new slug through the generator to strip illegal characters, detect duplicates
|
|
|
|
return ghostBookshelf.Model.generateSlug(App, this.get('slug') || this.get('name'),
|
|
|
|
{transacting: options.transacting})
|
|
|
|
.then(function (slug) {
|
|
|
|
self.set({slug: slug});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-02-12 07:40:39 +04:00
|
|
|
permissions: function () {
|
2014-07-13 15:17:18 +04:00
|
|
|
return this.belongsToMany('Permission', 'permissions_apps');
|
2014-02-25 00:28:18 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
settings: function () {
|
2014-07-13 15:17:18 +04:00
|
|
|
return this.belongsToMany('AppSetting', 'app_settings');
|
2014-02-12 07:40:39 +04:00
|
|
|
}
|
2014-05-06 05:45:08 +04:00
|
|
|
}, {
|
|
|
|
/**
|
|
|
|
* Returns an array of keys permitted in a method's `options` hash, depending on the current method.
|
|
|
|
* @param {String} methodName The name of the method to check valid options for.
|
|
|
|
* @return {Array} Keys allowed in the `options` hash of the model's method.
|
|
|
|
*/
|
|
|
|
permittedOptions: function (methodName) {
|
|
|
|
var options = ghostBookshelf.Model.permittedOptions(),
|
|
|
|
|
|
|
|
// whitelists for the `options` hash argument on methods, by method name.
|
|
|
|
// these are the only options that can be passed to Bookshelf / Knex.
|
|
|
|
validOptions = {
|
|
|
|
findOne: ['withRelated']
|
|
|
|
};
|
|
|
|
|
|
|
|
if (validOptions[methodName]) {
|
|
|
|
options = options.concat(validOptions[methodName]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return options;
|
|
|
|
}
|
2014-02-12 07:40:39 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
Apps = ghostBookshelf.Collection.extend({
|
|
|
|
model: App
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = {
|
2014-07-13 15:17:18 +04:00
|
|
|
App: ghostBookshelf.model('App', App),
|
|
|
|
Apps: ghostBookshelf.collection('Apps', Apps)
|
2014-02-12 07:40:39 +04:00
|
|
|
};
|