diff --git a/server/api/helpers/actions/update-one.js b/server/api/helpers/actions/update-one.js index 7835fa746..1d886ac5b 100644 --- a/server/api/helpers/actions/update-one.js +++ b/server/api/helpers/actions/update-one.js @@ -59,6 +59,9 @@ module.exports = { cards: [inputs.card], }, }, + prevData: { + item: inputs.record, + }, user: inputs.actorUser, }); } diff --git a/server/api/helpers/attachments/update-one.js b/server/api/helpers/attachments/update-one.js index 49660206d..a16b53fb0 100644 --- a/server/api/helpers/attachments/update-one.js +++ b/server/api/helpers/attachments/update-one.js @@ -59,6 +59,9 @@ module.exports = { cards: [inputs.card], }, }, + prevData: { + item: inputs.record, + }, user: inputs.actorUser, }); } diff --git a/server/api/helpers/board-memberships/update-one.js b/server/api/helpers/board-memberships/update-one.js index 639489078..28c23a89b 100644 --- a/server/api/helpers/board-memberships/update-one.js +++ b/server/api/helpers/board-memberships/update-one.js @@ -62,6 +62,9 @@ module.exports = { boards: [inputs.board], }, }, + prevData: { + item: inputs.record, + }, user: inputs.actorUser, }); } diff --git a/server/api/helpers/boards/update-one.js b/server/api/helpers/boards/update-one.js index e20324ddb..374484255 100644 --- a/server/api/helpers/boards/update-one.js +++ b/server/api/helpers/boards/update-one.js @@ -100,6 +100,9 @@ module.exports = { projects: [inputs.project], }, }, + prevData: { + item: inputs.record, + }, user: inputs.actorUser, }); } diff --git a/server/api/helpers/cards/update-one.js b/server/api/helpers/cards/update-one.js index 9be5c5764..f83f42ad6 100644 --- a/server/api/helpers/cards/update-one.js +++ b/server/api/helpers/cards/update-one.js @@ -264,6 +264,9 @@ module.exports = { lists: [list], }, }, + prevData: { + item: inputs.record, + }, user: inputs.actorUser, }); diff --git a/server/api/helpers/labels/update-one.js b/server/api/helpers/labels/update-one.js index 01efcdbd2..a27b9806d 100644 --- a/server/api/helpers/labels/update-one.js +++ b/server/api/helpers/labels/update-one.js @@ -91,6 +91,9 @@ module.exports = { boards: [inputs.board], }, }, + prevData: { + item: inputs.record, + }, user: inputs.actorUser, }); } diff --git a/server/api/helpers/lists/update-one.js b/server/api/helpers/lists/update-one.js index 0335b9eed..6fb751082 100644 --- a/server/api/helpers/lists/update-one.js +++ b/server/api/helpers/lists/update-one.js @@ -91,6 +91,9 @@ module.exports = { boards: [inputs.board], }, }, + prevData: { + item: inputs.record, + }, user: inputs.actorUser, }); } diff --git a/server/api/helpers/notifications/update-many.js b/server/api/helpers/notifications/update-many.js index 7775919d5..5f5f86727 100644 --- a/server/api/helpers/notifications/update-many.js +++ b/server/api/helpers/notifications/update-many.js @@ -48,6 +48,7 @@ module.exports = { inputs.request, ); + // TODO: with prevData? sails.helpers.utils.sendWebhooks.with({ event: 'notificationUpdate', data: { diff --git a/server/api/helpers/projects/update-one.js b/server/api/helpers/projects/update-one.js index f9e11eec4..db3e94187 100644 --- a/server/api/helpers/projects/update-one.js +++ b/server/api/helpers/projects/update-one.js @@ -118,6 +118,9 @@ module.exports = { data: { item: project, }, + prevData: { + item: inputs.record, + }, user: inputs.actorUser, }); } diff --git a/server/api/helpers/tasks/update-one.js b/server/api/helpers/tasks/update-one.js index 94c1d4b7d..7008d139a 100644 --- a/server/api/helpers/tasks/update-one.js +++ b/server/api/helpers/tasks/update-one.js @@ -101,6 +101,9 @@ module.exports = { cards: [inputs.card], }, }, + prevData: { + item: inputs.record, + }, user: inputs.actorUser, }); } diff --git a/server/api/helpers/users/update-one.js b/server/api/helpers/users/update-one.js index 325807b2f..05f025f7a 100644 --- a/server/api/helpers/users/update-one.js +++ b/server/api/helpers/users/update-one.js @@ -159,6 +159,9 @@ module.exports = { data: { item: user, }, + prevData: { + item: inputs.record, + }, user: inputs.actorUser, }); } diff --git a/server/api/helpers/utils/send-webhooks.js b/server/api/helpers/utils/send-webhooks.js index 0458a875c..87db95cdd 100644 --- a/server/api/helpers/utils/send-webhooks.js +++ b/server/api/helpers/utils/send-webhooks.js @@ -97,10 +97,11 @@ const jsonifyData = (data) => { * @param {*} webhook - Webhook configuration. * @param {string} event - The event (see {@link EVENT_TYPES}). * @param {Data} data - The data object containing event data and optionally included data. + * @param {Data} [prevData] - The data object containing previous state of data (optional). * @param {ref} user - User object associated with the event. * @returns {Promise<void>} */ -async function sendWebhook(webhook, event, data, user) { +async function sendWebhook(webhook, event, data, prevData, user) { const headers = { 'Content-Type': 'application/json', 'User-Agent': `planka (+${sails.config.custom.baseUrl})`, @@ -113,6 +114,7 @@ async function sendWebhook(webhook, event, data, user) { const body = JSON.stringify({ event, data: jsonifyData(data), + prevData: prevData && jsonifyData(prevData), user: sails.helpers.utils.jsonifyRecord(user), }); @@ -148,6 +150,9 @@ module.exports = { type: 'ref', required: true, }, + prevData: { + type: 'ref', + }, user: { type: 'ref', required: true, @@ -172,7 +177,7 @@ module.exports = { return; } - sendWebhook(webhook, inputs.event, inputs.data, inputs.user); + sendWebhook(webhook, inputs.event, inputs.data, inputs.prevData, inputs.user); }); }, };