From f68936900c877a72b7c208a5ce1b4557b752c9de Mon Sep 17 00:00:00 2001 From: Ronald Langeveld Date: Fri, 21 Apr 2023 15:17:25 +0100 Subject: [PATCH] Added post status saving (#16702) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit no issue ### 🤖 Generated by Copilot at ebd1973 This pull request adds support for storing and tracking the status of posts in revisions. It introduces a new `post_status` column and property in the `post` and `PostRevision` models, and updates the `PostRevisions.formatInput` method to handle it. --- ghost/core/core/server/models/post.js | 8 +++++--- .../test/e2e-api/admin/__snapshots__/posts.test.js.snap | 6 +++--- ghost/post-revisions/lib/post-revisions.js | 5 ++++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/ghost/core/core/server/models/post.js b/ghost/core/core/server/models/post.js index 1c7f560664..08b55f1bb1 100644 --- a/ghost/core/core/server/models/post.js +++ b/ghost/core/core/server/models/post.js @@ -913,7 +913,7 @@ Post = ghostBookshelf.Model.extend({ const revisionModels = await ghostBookshelf.model('PostRevision') .findAll(Object.assign({ filter: `post_id:${model.id}`, - columns: ['id', 'lexical', 'created_at', 'author_id', 'title', 'reason'] + columns: ['id', 'lexical', 'created_at', 'author_id', 'title', 'reason', 'post_status'] }, _.pick(options, 'transacting'))); const revisions = revisionModels.toJSON(); @@ -923,7 +923,8 @@ Post = ghostBookshelf.Model.extend({ html: model.previous('html'), author_id: model.previous('updated_by'), feature_image: model.previous('feature_image'), - title: model.previous('title') + title: model.previous('title'), + post_status: model.previous('status') }; const current = { id: model.id, @@ -931,7 +932,8 @@ Post = ghostBookshelf.Model.extend({ html: model.get('html'), author_id: authorId, feature_image: model.get('feature_image'), - title: model.get('title') + title: model.get('title'), + post_status: model.get('status') }; // This can be refactored once we have the status stored in each revision diff --git a/ghost/core/test/e2e-api/admin/__snapshots__/posts.test.js.snap b/ghost/core/test/e2e-api/admin/__snapshots__/posts.test.js.snap index 713a0c2f2b..9b720807d8 100644 --- a/ghost/core/test/e2e-api/admin/__snapshots__/posts.test.js.snap +++ b/ghost/core/test/e2e-api/admin/__snapshots__/posts.test.js.snap @@ -831,7 +831,7 @@ exports[`Posts API Create Can create a post with lexical 2: [headers] 1`] = ` Object { "access-control-allow-origin": "http://127.0.0.1:2369", "cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0", - "content-length": "5309", + "content-length": "5312", "content-type": "application/json; charset=utf-8", "content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/, "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, @@ -1261,7 +1261,7 @@ exports[`Posts API Update Can update a post with lexical 2: [headers] 1`] = ` Object { "access-control-allow-origin": "http://127.0.0.1:2369", "cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0", - "content-length": "5246", + "content-length": "5249", "content-type": "application/json; charset=utf-8", "content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/, "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, @@ -1371,7 +1371,7 @@ exports[`Posts API Update Can update a post with lexical 4: [headers] 1`] = ` Object { "access-control-allow-origin": "http://127.0.0.1:2369", "cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0", - "content-length": "6511", + "content-length": "6517", "content-type": "application/json; charset=utf-8", "content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/, "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, diff --git a/ghost/post-revisions/lib/post-revisions.js b/ghost/post-revisions/lib/post-revisions.js index 19ba29c15b..5f35f7f053 100644 --- a/ghost/post-revisions/lib/post-revisions.js +++ b/ghost/post-revisions/lib/post-revisions.js @@ -7,6 +7,7 @@ * @property {string} feature_image * @property {string} title * @property {string} reason + * @property {string} post_status */ /** @@ -18,6 +19,7 @@ * @property {string} feature_image * @property {string} title * @property {string} reason + * @property {string} post_status */ class PostRevisions { @@ -104,7 +106,8 @@ class PostRevisions { created_at_ts: Date.now() - offset, author_id: input.author_id, feature_image: input.feature_image, - title: input.title + title: input.title, + post_status: input.post_status }; }