mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 09:52:06 +03:00
c638863cb9
* Extended webhooks schema/model and connected with integrations refs #9942 - Updated webhooks schema with new columns - name, integration_id, secret, last_triggered_at, api_version - Updated webhooks and integration model to map relationships - Updated schema hash - Updated test utils to exclude new webhooks columns for response comparison * Added migration script for new webhooks columns refs #9942 - Added migration script in 2.3 to add new columns to webhooks * Updated schema hash * Updated maxLength for api_version in schema * Removed concurrency value from migration script * Added defaults for webhooks model * Added status field to webhooks for last trigger status * Updated schema hash * Fixed tests with status field * Removed concurrency value in migration script * Cleanup * Updated schema with new fields - last_triggered_status, last_triggered_error
45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
JavaScript
const ghostBookshelf = require('./base');
|
|
|
|
const Integration = ghostBookshelf.Model.extend({
|
|
tableName: 'integrations',
|
|
|
|
relationships: ['api_keys', 'webhooks'],
|
|
|
|
relationshipBelongsTo: {
|
|
api_keys: 'api_keys',
|
|
webhooks: 'webhooks'
|
|
},
|
|
|
|
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');
|
|
},
|
|
|
|
webhooks: function webhooks() {
|
|
return this.hasMany('Webhook', 'integration_id');
|
|
}
|
|
});
|
|
|
|
const Integrations = ghostBookshelf.Collection.extend({
|
|
model: Integration
|
|
});
|
|
|
|
module.exports = {
|
|
Integration: ghostBookshelf.model('Integration', Integration),
|
|
Integrations: ghostBookshelf.collection('Integrations', Integrations)
|
|
};
|