Skip to content

Commit

Permalink
fix: Include previous data state in webhook
Browse files Browse the repository at this point in the history
Closes #809
  • Loading branch information
meltyshev committed Oct 30, 2024
1 parent 38bc4cb commit f75b023
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 2 deletions.
3 changes: 3 additions & 0 deletions server/api/helpers/actions/update-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ module.exports = {
cards: [inputs.card],
},
},
prevData: {
item: inputs.record,
},
user: inputs.actorUser,
});
}
Expand Down
3 changes: 3 additions & 0 deletions server/api/helpers/attachments/update-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ module.exports = {
cards: [inputs.card],
},
},
prevData: {
item: inputs.record,
},
user: inputs.actorUser,
});
}
Expand Down
3 changes: 3 additions & 0 deletions server/api/helpers/board-memberships/update-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ module.exports = {
boards: [inputs.board],
},
},
prevData: {
item: inputs.record,
},
user: inputs.actorUser,
});
}
Expand Down
3 changes: 3 additions & 0 deletions server/api/helpers/boards/update-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ module.exports = {
projects: [inputs.project],
},
},
prevData: {
item: inputs.record,
},
user: inputs.actorUser,
});
}
Expand Down
3 changes: 3 additions & 0 deletions server/api/helpers/cards/update-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ module.exports = {
lists: [list],
},
},
prevData: {
item: inputs.record,
},
user: inputs.actorUser,
});

Expand Down
3 changes: 3 additions & 0 deletions server/api/helpers/labels/update-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ module.exports = {
boards: [inputs.board],
},
},
prevData: {
item: inputs.record,
},
user: inputs.actorUser,
});
}
Expand Down
3 changes: 3 additions & 0 deletions server/api/helpers/lists/update-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ module.exports = {
boards: [inputs.board],
},
},
prevData: {
item: inputs.record,
},
user: inputs.actorUser,
});
}
Expand Down
1 change: 1 addition & 0 deletions server/api/helpers/notifications/update-many.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module.exports = {
inputs.request,
);

// TODO: with prevData?
sails.helpers.utils.sendWebhooks.with({
event: 'notificationUpdate',
data: {
Expand Down
3 changes: 3 additions & 0 deletions server/api/helpers/projects/update-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ module.exports = {
data: {
item: project,
},
prevData: {
item: inputs.record,
},
user: inputs.actorUser,
});
}
Expand Down
3 changes: 3 additions & 0 deletions server/api/helpers/tasks/update-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ module.exports = {
cards: [inputs.card],
},
},
prevData: {
item: inputs.record,
},
user: inputs.actorUser,
});
}
Expand Down
3 changes: 3 additions & 0 deletions server/api/helpers/users/update-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ module.exports = {
data: {
item: user,
},
prevData: {
item: inputs.record,
},
user: inputs.actorUser,
});
}
Expand Down
9 changes: 7 additions & 2 deletions server/api/helpers/utils/send-webhooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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})`,
Expand All @@ -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),
});

Expand Down Expand Up @@ -148,6 +150,9 @@ module.exports = {
type: 'ref',
required: true,
},
prevData: {
type: 'ref',
},
user: {
type: 'ref',
required: true,
Expand All @@ -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);
});
},
};

0 comments on commit f75b023

Please sign in to comment.