mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 09:52:06 +03:00
3a70cdb2b6
no-issue This ensures that slugs are stripped of illegal characters, and that we do not create duplicates.
40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
const ghostBookshelf = require('./base');
|
|
|
|
const Integration = ghostBookshelf.Model.extend({
|
|
tableName: 'integrations',
|
|
|
|
relationships: ['api_keys'],
|
|
|
|
relationshipBelongsTo: {
|
|
api_keys: 'api_keys'
|
|
},
|
|
|
|
onSaving(newIntegration, attr, options) {
|
|
if (this.hasChanged('slug') || !this.get('slug')) {
|
|
// Pass the new slug through the generator to strip illegal characters, detect duplicates
|
|
return ghostBookshelf.Model.generateSlug(Integration, this.get('slug') || this.get('name'),
|
|
{transacting: options.transacting})
|
|
.then((slug) => {
|
|
this.set({slug});
|
|
});
|
|
}
|
|
},
|
|
|
|
permittedAttributes(...args) {
|
|
return ghostBookshelf.Model.prototype.permittedAttributes.apply(this, args).concat(this.relationships);
|
|
},
|
|
|
|
api_keys: function apiKeys() {
|
|
return this.hasMany('ApiKey', 'integration_id');
|
|
}
|
|
});
|
|
|
|
const Integrations = ghostBookshelf.Collection.extend({
|
|
model: Integration
|
|
});
|
|
|
|
module.exports = {
|
|
Integration: ghostBookshelf.model('Integration', Integration),
|
|
Integrations: ghostBookshelf.collection('Integrations', Integrations)
|
|
};
|