diff --git a/ghost/core/core/server/api/endpoints/posts.js b/ghost/core/core/server/api/endpoints/posts.js index 24b5b8c553..59dcffa231 100644 --- a/ghost/core/core/server/api/endpoints/posts.js +++ b/ghost/core/core/server/api/endpoints/posts.js @@ -16,7 +16,8 @@ const allowedIncludes = [ 'sentiment', 'count.positive_feedback', 'count.negative_feedback', - 'post_revisions' + 'post_revisions', + 'post_revisions.author' ]; const unsafeAttrs = ['status', 'authors', 'visibility']; diff --git a/ghost/core/core/server/api/endpoints/utils/serializers/input/posts.js b/ghost/core/core/server/api/endpoints/utils/serializers/input/posts.js index 3c5dd77f85..8898c349fd 100644 --- a/ghost/core/core/server/api/endpoints/utils/serializers/input/posts.js +++ b/ghost/core/core/server/api/endpoints/utils/serializers/input/posts.js @@ -41,7 +41,7 @@ function defaultRelations(frame) { return false; } - frame.options.withRelated = ['tags', 'authors', 'authors.roles', 'email', 'tiers', 'newsletter', 'count.clicks', 'post_revisions']; + frame.options.withRelated = ['tags', 'authors', 'authors.roles', 'email', 'tiers', 'newsletter', 'count.clicks', 'post_revisions', 'post_revisions.author']; } function setDefaultOrder(frame) { diff --git a/ghost/core/core/server/models/post-revision.js b/ghost/core/core/server/models/post-revision.js index b9c9c305ec..9d5b6bb299 100644 --- a/ghost/core/core/server/models/post-revision.js +++ b/ghost/core/core/server/models/post-revision.js @@ -1,8 +1,15 @@ const ghostBookshelf = require('./base'); +const _ = require('lodash'); const PostRevision = ghostBookshelf.Model.extend({ - tableName: 'post_revisions' -}, { + tableName: 'post_revisions', + + relationships: ['author'], + + author() { + return this.belongsTo('User', 'author_id'); + }, + permittedOptions(methodName) { let options = ghostBookshelf.Model.permittedOptions.call(this, methodName); const validOptions = { @@ -16,6 +23,14 @@ const PostRevision = ghostBookshelf.Model.extend({ return options; }, + defaultRelations: function defaultRelations(methodName, options) { + if (['edit', 'add', 'destroy'].indexOf(methodName) !== -1) { + options.withRelated = _.union(['author'], options.withRelated || []); + } + + return options; + }, + orderDefaultRaw() { return 'created_at_ts DESC'; }, @@ -23,9 +38,9 @@ const PostRevision = ghostBookshelf.Model.extend({ toJSON(unfilteredOptions) { const options = PostRevision.filterOptions(unfilteredOptions, 'toJSON'); const attrs = ghostBookshelf.Model.prototype.toJSON.call(this, options); - // CASE: only for internal accuracy delete attrs.created_at_ts; + delete attrs.author_id; return attrs; } }); diff --git a/ghost/core/core/server/models/post.js b/ghost/core/core/server/models/post.js index 69a66ff991..6af0f4e01b 100644 --- a/ghost/core/core/server/models/post.js +++ b/ghost/core/core/server/models/post.js @@ -1193,7 +1193,7 @@ Post = ghostBookshelf.Model.extend({ */ defaultRelations: function defaultRelations(methodName, options) { if (['edit', 'add', 'destroy'].indexOf(methodName) !== -1) { - options.withRelated = _.union(['authors', 'tags', 'post_revisions'], options.withRelated || []); + options.withRelated = _.union(['authors', 'tags', 'post_revisions', 'post_revisions.author'], options.withRelated || []); } const META_ATTRIBUTES = _.without(ghostBookshelf.model('PostsMeta').prototype.permittedAttributes(), 'id', 'post_id'); 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 cbd9127b5a..d252b8bf01 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": "4574", + "content-length": "5241", "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": "4511", + "content-length": "5178", "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": "5044", + "content-length": "6378", "content-type": "application/json; charset=utf-8", "content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/, "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,