2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00

Updated Integration model to use generateSlug (#10009)

no-issue

This ensures that slugs are stripped of illegal characters, and that we
do not create duplicates.
This commit is contained in:
Fabien O'Carroll 2018-10-16 12:25:54 +07:00 committed by GitHub
parent 9fd9186557
commit 3a70cdb2b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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);
},