mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 09:52:06 +03:00
7f29bbff8a
refs 17feb14e4a
- The original commit adding this intended to add transactions, following the pattern of always forcing a transaction when we use bookshelf-relations
- (We use bookshelf-relations here because integrations have api-keys and webhooks associated wtih them and we upsert as one)
- These add and edit methods were inadvertently added to the wrong argument object/section of bookshelf (really fucking easily done, one day we will fix bookshelf so its easier to work with)
- Bottom line: these methods have never been called
- I tried moving them to the right section, but this created test failures throughout our acceptance tests:
- Error: Transaction query already complete, run with DEBUG=knex:tx for more info
- This is likely because we need to account for integrations being used as part of the auth step in the before part of tests
- In terms of yak-shaving, fixing these tests is one step too far right now. I think not having this code here at all is a better state than having it look like it works when it doesn't
74 lines
2.1 KiB
JavaScript
74 lines
2.1 KiB
JavaScript
const ghostBookshelf = require('./base');
|
|
|
|
const Integration = ghostBookshelf.Model.extend({
|
|
tableName: 'integrations',
|
|
|
|
relationships: ['api_keys', 'webhooks'],
|
|
|
|
relationshipBelongsTo: {
|
|
api_keys: 'api_keys',
|
|
webhooks: 'webhooks'
|
|
},
|
|
|
|
defaults() {
|
|
return {
|
|
type: 'custom'
|
|
};
|
|
},
|
|
|
|
emitChange: function emitChange(event, options) {
|
|
const eventToTrigger = 'integration' + '.' + event;
|
|
ghostBookshelf.Model.prototype.emitChange.bind(this)(this, eventToTrigger, options);
|
|
},
|
|
|
|
onSaving(integration, attrs, options) {
|
|
ghostBookshelf.Model.prototype.onSaving.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(Integration, this.get('slug') || this.get('name'),
|
|
{transacting: options.transacting})
|
|
.then((slug) => {
|
|
this.set({slug});
|
|
});
|
|
}
|
|
},
|
|
|
|
onCreated: function onCreated(model, response, options) {
|
|
ghostBookshelf.Model.prototype.onCreated.apply(this, arguments);
|
|
|
|
model.emitChange('added', options);
|
|
},
|
|
|
|
permittedAttributes(...args) {
|
|
return ghostBookshelf.Model.prototype.permittedAttributes.apply(this, args).concat(this.relationships);
|
|
},
|
|
|
|
api_keys: function apiKeys() {
|
|
return this.hasMany('ApiKey', 'integration_id');
|
|
},
|
|
|
|
webhooks: function webhooks() {
|
|
return this.hasMany('Webhook', 'integration_id');
|
|
}
|
|
}, {
|
|
permittedOptions(methodName) {
|
|
let options = ghostBookshelf.Model.permittedOptions.call(this, methodName);
|
|
|
|
if (methodName === 'findOne') {
|
|
options = options.concat(['filter']);
|
|
}
|
|
|
|
return options;
|
|
}
|
|
});
|
|
|
|
const Integrations = ghostBookshelf.Collection.extend({
|
|
model: Integration
|
|
});
|
|
|
|
module.exports = {
|
|
Integration: ghostBookshelf.model('Integration', Integration),
|
|
Integrations: ghostBookshelf.collection('Integrations', Integrations)
|
|
};
|