0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-08 02:52:39 -05:00

🐛 Fixed missing authors in webhook payload

closes https://github.com/TryGhost/Toolbox/issues/340
closes https://github.com/TryGhost/Ghost/issues/13451

- Webhook subscribers were receiving post request payloads without `authors` and `primary_author` properties.
- The behavior was due to missing "originalOptions" property that is needed to correctly serialize the model to json on the model layer.
- A more holistic approach would be to pass the options somehow along with the model with the event. This would require a deeper rework though
This commit is contained in:
Naz 2022-06-03 17:35:26 +08:00 committed by naz
parent 7d85a434b2
commit ba061d86e8
3 changed files with 71 additions and 1 deletions

View file

@ -13,9 +13,14 @@ module.exports = (event, model) => {
ops.push(() => {
let frame = {options: {previous: false, context: {user: true}}};
// NOTE: below options are lost in the during event processing, a more holistic approach would be
// to pass them somehow along with the model
if (['posts', 'pages'].includes(docName)) {
frame.options.formats = ['mobiledoc', 'html', 'plaintext'];
frame.options.withRelated = ['tags', 'authors'];
model._originalOptions = {
withRelated: ['tags', 'authors']
};
}
return apiShared

View file

@ -4,6 +4,30 @@ exports[`post.* events post.added even is triggered 1: [body] 1`] = `
Object {
"post": Object {
"current": Object {
"authors": Array [
Object {
"accessibility": null,
"bio": "bio",
"cover_image": null,
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
"email": "jbloggs@example.com",
"facebook": null,
"id": "1",
"last_seen": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
"location": "location",
"meta_description": null,
"meta_title": null,
"name": "Joe Bloggs",
"profile_image": "https://example.com/super_photo.jpg",
"slug": "joe-bloggs",
"status": "active",
"tour": null,
"twitter": null,
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
"url": "http://127.0.0.1:2369/author/joe-bloggs/",
"website": null,
},
],
"canonical_url": null,
"codeinjection_foot": null,
"codeinjection_head": null,
@ -82,6 +106,39 @@ exports[`post.* events post.published even is triggered 1: [body] 1`] = `
Object {
"post": Object {
"current": Object {
"authors": Array [
Object {
"accessibility": null,
"bio": "bio",
"cover_image": null,
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
"email": "jbloggs@example.com",
"facebook": null,
"id": "1",
"last_seen": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
"location": "location",
"meta_description": null,
"meta_title": null,
"name": "Joe Bloggs",
"profile_image": "https://example.com/super_photo.jpg",
"roles": Array [
Object {
"created_at": "2022-06-03T09:31:02.000Z",
"description": "Blog Owner",
"id": "6299d4d6cf0c0f6aabf10096",
"name": "Owner",
"updated_at": "2022-06-03T09:31:02.000Z",
},
],
"slug": "joe-bloggs",
"status": "active",
"tour": null,
"twitter": null,
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
"url": "http://127.0.0.1:2369/author/joe-bloggs/",
"website": null,
},
],
"canonical_url": null,
"codeinjection_foot": null,
"codeinjection_head": null,

View file

@ -7,6 +7,12 @@ const tierSnapshot = {
updated_at: anyISODateTime
};
const authorSnapshot = {
last_seen: anyISODateTime,
created_at: anyISODateTime,
updated_at: anyISODateTime
};
const buildPostSnapshotWithTiers = ({published, tiersCount}) => {
return {
id: anyObjectId,
@ -18,7 +24,9 @@ const buildPostSnapshotWithTiers = ({published, tiersCount}) => {
// @TODO: hack here! it's due to https://github.com/TryGhost/Toolbox/issues/341
// this matcher should be removed once the issue is solved
url: stringMatching(/http:\/\/127.0.0.1:2369\/\w+\//),
tiers: new Array(tiersCount).fill(tierSnapshot)
tiers: new Array(tiersCount).fill(tierSnapshot),
primary_author: authorSnapshot,
authors: new Array(1).fill(authorSnapshot)
};
};