mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-08 02:52:39 -05:00
Fixed serialized webhook payload for deleted resources
no issue - serializer did not kick in correctly
This commit is contained in:
parent
370f3bbcc0
commit
6c50dadb90
2 changed files with 21 additions and 13 deletions
|
@ -599,18 +599,20 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
|
|||
const options = ghostBookshelf.Model.filterOptions(unfilteredOptions, 'toJSON');
|
||||
options.omitPivot = true;
|
||||
|
||||
// CASE: get JSON of previous attrs
|
||||
if (options.previous) {
|
||||
const attrs = {};
|
||||
const relations = {};
|
||||
const clonedModel = _.cloneDeep(this);
|
||||
clonedModel.attributes = this._previousAttributes;
|
||||
|
||||
if (this._previousRelations) {
|
||||
_.each(Object.keys(this._previousRelations), (key) => {
|
||||
relations[key] = this._previousRelations[key].toJSON();
|
||||
if (this.relationships) {
|
||||
this.relationships.forEach((relation) => {
|
||||
if (this._previousRelations && this._previousRelations.hasOwnProperty(relation)) {
|
||||
clonedModel.related(relation).models = this._previousRelations[relation].models;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Object.assign(attrs, this._previousAttributes, relations);
|
||||
return attrs;
|
||||
return proto.toJSON.call(clonedModel, options);
|
||||
}
|
||||
|
||||
return proto.toJSON.call(this, options);
|
||||
|
|
|
@ -9,13 +9,14 @@ module.exports = (event, model) => {
|
|||
const ops = [];
|
||||
|
||||
if (Object.keys(model.attributes).length) {
|
||||
let frame = {options: {previous: false, context: {user: true}}};
|
||||
|
||||
if (['posts', 'pages'].includes(docName)) {
|
||||
frame.options.formats = ['mobiledoc', 'html', 'plaintext'];
|
||||
}
|
||||
|
||||
ops.push(() => {
|
||||
let frame = {options: {previous: false, context: {user: true}}};
|
||||
|
||||
if (['posts', 'pages'].includes(docName)) {
|
||||
frame.options.formats = ['mobiledoc', 'html', 'plaintext'];
|
||||
frame.options.withRelated = ['tags', 'authors'];
|
||||
}
|
||||
|
||||
return api.shared
|
||||
.serializers
|
||||
.handle
|
||||
|
@ -34,6 +35,11 @@ module.exports = (event, model) => {
|
|||
ops.push(() => {
|
||||
const frame = {options: {previous: true, context: {user: true}}};
|
||||
|
||||
if (['posts', 'pages'].includes(docName)) {
|
||||
frame.options.formats = ['mobiledoc', 'html', 'plaintext'];
|
||||
frame.options.withRelated = ['tags', 'authors'];
|
||||
}
|
||||
|
||||
return api.shared
|
||||
.serializers
|
||||
.handle
|
||||
|
|
Loading…
Add table
Reference in a new issue