From 323074f106374245b6b5f6c71058122f9e08546d Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Thu, 24 Jun 2021 09:58:35 +0100 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20error=20when=20delet?= =?UTF-8?q?ing=20non-existent=20snippet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes https://github.com/TryGhost/Team/issues/809 - Bookshelf won't throw a `NotFoundError` unless `require=true` in the options - this is present in most other API endpoints, so it's just simply missing from the snippet one - without this, Ghost will crash with a 500 saying `Cannot read property 'destroy' of null` - this commit adds `require=true` to the destroy options for both the canary + v3 endpoints --- core/server/api/canary/snippets.js | 2 ++ core/server/api/v3/snippets.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/core/server/api/canary/snippets.js b/core/server/api/canary/snippets.js index 71ffa9b8b4..3e8bb0d0a1 100644 --- a/core/server/api/canary/snippets.js +++ b/core/server/api/canary/snippets.js @@ -97,6 +97,8 @@ module.exports = { }, permissions: true, query(frame) { + frame.options.require = true; + return models.Snippet.destroy(frame.options) .then(() => null) .catch(models.Snippet.NotFoundError, () => { diff --git a/core/server/api/v3/snippets.js b/core/server/api/v3/snippets.js index 71ffa9b8b4..3e8bb0d0a1 100644 --- a/core/server/api/v3/snippets.js +++ b/core/server/api/v3/snippets.js @@ -97,6 +97,8 @@ module.exports = { }, permissions: true, query(frame) { + frame.options.require = true; + return models.Snippet.destroy(frame.options) .then(() => null) .catch(models.Snippet.NotFoundError, () => { From ce68b2e4a91d93ced2b2ce40578b4bb06ad1ded0 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Thu, 24 Jun 2021 10:17:40 +0100 Subject: [PATCH 2/4] Reverted `destroy` function of CRUD plugin to chained promises refs https://github.com/TryGhost/Team/issues/808 - see referenced issue for context, but turning this function into async-await seems to have broken error handling when deleting things that don't exist - i'm really not sure why - but my running theory is that it's something to do with Bluebird Promises vs native Promises - this should keep the same functionality until I can investigate what is going on --- core/server/models/base/plugins/crud.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/server/models/base/plugins/crud.js b/core/server/models/base/plugins/crud.js index 60a5b69d3c..ec813537fa 100644 --- a/core/server/models/base/plugins/crud.js +++ b/core/server/models/base/plugins/crud.js @@ -198,7 +198,7 @@ module.exports = function (Bookshelf) { * @param {Object} [unfilteredOptions] * @return {Promise} Empty Model */ - destroy: async function destroy(unfilteredOptions) { + destroy: function destroy(unfilteredOptions) { const options = this.filterOptions(unfilteredOptions, 'destroy'); if (!options.destroyBy) { @@ -208,8 +208,11 @@ module.exports = function (Bookshelf) { } // Fetch the object before destroying it, so that the changed data is available to events - const obj = await this.forge(options.destroyBy).fetch(options); - return obj.destroy(options); + return this.forge(options.destroyBy) + .fetch(options) + .then(function then(obj) { + return obj.destroy(options); + }); }, // When loading an instance, subclasses can specify default to fetch From a91a790d0ddb4e4260c5a99a03f913262bac835c Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Thu, 24 Jun 2021 11:19:09 +0100 Subject: [PATCH 3/4] Updated Ghost-Admin to v4.8.1 --- core/client | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/client b/core/client index a2517f3190..4c4fcdad48 160000 --- a/core/client +++ b/core/client @@ -1 +1 @@ -Subproject commit a2517f3190e9ee77ef0e7fef5372fae43356c002 +Subproject commit 4c4fcdad486670e9202f8ca22f77c4333c3bb3ec From 13adff145c7c9f2b817a610fc204768b9ea844c9 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Thu, 24 Jun 2021 11:19:09 +0100 Subject: [PATCH 4/4] v4.8.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5c39322f21..88f0ee9fed 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ghost", - "version": "4.8.0", + "version": "4.8.1", "description": "The professional publishing platform", "author": "Ghost Foundation", "homepage": "https://ghost.org",