mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 20:03:12 +03:00
Added author details to post_revisions in posts endpoint (#16674)
no issue - added full author object to the post_revisions array on the /posts endpoint - to be used in the post history modal to display who authored each revision
This commit is contained in:
parent
b227fda4cf
commit
f95012066a
@ -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'];
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
});
|
||||
|
@ -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');
|
||||
|
@ -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 \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
|
Loading…
Reference in New Issue
Block a user