diff --git a/core/server/models/integration.js b/core/server/models/integration.js index 4fc049d916..076eead567 100644 --- a/core/server/models/integration.js +++ b/core/server/models/integration.js @@ -9,6 +9,17 @@ const Integration = ghostBookshelf.Model.extend({ 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); },