mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05: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
5 changed files with 25 additions and 9 deletions
|
@ -16,7 +16,8 @@ const allowedIncludes = [
|
||||||
'sentiment',
|
'sentiment',
|
||||||
'count.positive_feedback',
|
'count.positive_feedback',
|
||||||
'count.negative_feedback',
|
'count.negative_feedback',
|
||||||
'post_revisions'
|
'post_revisions',
|
||||||
|
'post_revisions.author'
|
||||||
];
|
];
|
||||||
const unsafeAttrs = ['status', 'authors', 'visibility'];
|
const unsafeAttrs = ['status', 'authors', 'visibility'];
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ function defaultRelations(frame) {
|
||||||
return false;
|
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) {
|
function setDefaultOrder(frame) {
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
const ghostBookshelf = require('./base');
|
const ghostBookshelf = require('./base');
|
||||||
|
const _ = require('lodash');
|
||||||
|
|
||||||
const PostRevision = ghostBookshelf.Model.extend({
|
const PostRevision = ghostBookshelf.Model.extend({
|
||||||
tableName: 'post_revisions'
|
tableName: 'post_revisions',
|
||||||
}, {
|
|
||||||
|
relationships: ['author'],
|
||||||
|
|
||||||
|
author() {
|
||||||
|
return this.belongsTo('User', 'author_id');
|
||||||
|
},
|
||||||
|
|
||||||
permittedOptions(methodName) {
|
permittedOptions(methodName) {
|
||||||
let options = ghostBookshelf.Model.permittedOptions.call(this, methodName);
|
let options = ghostBookshelf.Model.permittedOptions.call(this, methodName);
|
||||||
const validOptions = {
|
const validOptions = {
|
||||||
|
@ -16,6 +23,14 @@ const PostRevision = ghostBookshelf.Model.extend({
|
||||||
return options;
|
return options;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
defaultRelations: function defaultRelations(methodName, options) {
|
||||||
|
if (['edit', 'add', 'destroy'].indexOf(methodName) !== -1) {
|
||||||
|
options.withRelated = _.union(['author'], options.withRelated || []);
|
||||||
|
}
|
||||||
|
|
||||||
|
return options;
|
||||||
|
},
|
||||||
|
|
||||||
orderDefaultRaw() {
|
orderDefaultRaw() {
|
||||||
return 'created_at_ts DESC';
|
return 'created_at_ts DESC';
|
||||||
},
|
},
|
||||||
|
@ -23,9 +38,9 @@ const PostRevision = ghostBookshelf.Model.extend({
|
||||||
toJSON(unfilteredOptions) {
|
toJSON(unfilteredOptions) {
|
||||||
const options = PostRevision.filterOptions(unfilteredOptions, 'toJSON');
|
const options = PostRevision.filterOptions(unfilteredOptions, 'toJSON');
|
||||||
const attrs = ghostBookshelf.Model.prototype.toJSON.call(this, options);
|
const attrs = ghostBookshelf.Model.prototype.toJSON.call(this, options);
|
||||||
|
|
||||||
// CASE: only for internal accuracy
|
// CASE: only for internal accuracy
|
||||||
delete attrs.created_at_ts;
|
delete attrs.created_at_ts;
|
||||||
|
delete attrs.author_id;
|
||||||
return attrs;
|
return attrs;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1193,7 +1193,7 @@ Post = ghostBookshelf.Model.extend({
|
||||||
*/
|
*/
|
||||||
defaultRelations: function defaultRelations(methodName, options) {
|
defaultRelations: function defaultRelations(methodName, options) {
|
||||||
if (['edit', 'add', 'destroy'].indexOf(methodName) !== -1) {
|
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');
|
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 {
|
Object {
|
||||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
"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",
|
"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-type": "application/json; charset=utf-8",
|
||||||
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
|
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
|
||||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
"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 {
|
Object {
|
||||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
"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",
|
"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-type": "application/json; charset=utf-8",
|
||||||
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
|
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
|
||||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
"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 {
|
Object {
|
||||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
"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",
|
"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-type": "application/json; charset=utf-8",
|
||||||
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
|
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
|
||||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||||
|
|
Loading…
Add table
Reference in a new issue