From cf529111f6dd6e495b6cfd70fecae8b017c15b0f Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Wed, 6 Jul 2022 16:06:41 +0200 Subject: [PATCH] Updated comment API to only return top-level comments refs https://github.com/TryGhost/Team/issues/1664 - we will have a separate concept of returning replies --- core/server/models/comment.js | 5 +++++ .../__snapshots__/comments.test.js.snap | 20 ++----------------- .../e2e-api/members-comments/comments.test.js | 2 +- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/core/server/models/comment.js b/core/server/models/comment.js index 4fdc647f36..2a131ea561 100644 --- a/core/server/models/comment.js +++ b/core/server/models/comment.js @@ -48,7 +48,12 @@ const Comment = ghostBookshelf.Model.extend({ } model.emitChange('added', options); + }, + + enforcedFilters: function enforcedFilters() { + return 'parent_id:null'; } + }, { destroy: function destroy(unfilteredOptions) { let options = this.filterOptions(unfilteredOptions, 'destroy', {extraAllowedProperties: ['id']}); diff --git a/test/e2e-api/members-comments/__snapshots__/comments.test.js.snap b/test/e2e-api/members-comments/__snapshots__/comments.test.js.snap index a0e37be05b..8f6613e4c3 100644 --- a/test/e2e-api/members-comments/__snapshots__/comments.test.js.snap +++ b/test/e2e-api/members-comments/__snapshots__/comments.test.js.snap @@ -19,22 +19,6 @@ Object { }, "status": "published", }, - Object { - "created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/, - "edited_at": null, - "html": "

Really original

", - "id": StringMatching /\\[a-f0-9\\]\\{24\\}/, - "liked": Any, - "likes_count": Any, - "member": Object { - "avatar_image": null, - "bio": null, - "id": StringMatching /\\[a-f0-9\\]\\{24\\}/, - "name": null, - "uuid": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/, - }, - "status": "published", - }, Object { "created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/, "edited_at": null, @@ -59,7 +43,7 @@ Object { "page": 1, "pages": 1, "prev": null, - "total": 3, + "total": 2, }, }, } @@ -69,7 +53,7 @@ exports[`Comments API when authenticated Can browse all comments of a post 2: [h Object { "access-control-allow-origin": "*", "cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0", - "content-length": "1010", + "content-length": "704", "content-type": "application/json; charset=utf-8", "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, "vary": "Accept-Encoding", diff --git a/test/e2e-api/members-comments/comments.test.js b/test/e2e-api/members-comments/comments.test.js index 48196371da..e22923203f 100644 --- a/test/e2e-api/members-comments/comments.test.js +++ b/test/e2e-api/members-comments/comments.test.js @@ -69,7 +69,7 @@ describe('Comments API', function () { etag: anyEtag }) .matchBodySnapshot({ - comments: new Array(3).fill(commentMatcherWithMember) + comments: new Array(2).fill(commentMatcherWithMember) }); });