mirror of
https://github.com/wekan/wekan.git
synced 2026-11-07 11:02:33 -05:00
A webhook whose activity list names act-editCard now receives that event for card title and description edits, with a `field` parameter saying which one changed. A webhook on `all` or on the per-field events keeps receiving act-a-changedTitle / act-a-changedDescription as before, and every webhook still gets one delivery per edit, so no receiver sees the same edit twice. Ordinary dispatch and stored Sync webhook plans make the same per-webhook choice. The English event text is pending Transifex. Thanks to Rishats and xet7 ! Fixes #4912.
50 lines
2.0 KiB
JavaScript
50 lines
2.0 KiB
JavaScript
'use strict';
|
|
// #4912: the consolidated `act-editCard` webhook event.
|
|
//
|
|
// Card text edits already reach webhooks as one event per field
|
|
// (`act-a-changedTitle`, `act-a-changedDescription`). `act-editCard` is an
|
|
// OPT-IN alternative to those, decided on 2026-10-02: a webhook receives it
|
|
// only when its own activity list names `act-editCard` explicitly. A webhook
|
|
// subscribed to `all` or to the per-field events keeps receiving exactly what
|
|
// it received before, and every webhook still gets ONE delivery per activity,
|
|
// so a receiver never sees the same edit twice.
|
|
const EDIT_CARD_EVENT = 'act-editCard';
|
|
// Which per-field events count as an edit of the card, and the field each one
|
|
// reports in the `field` parameter.
|
|
const EDIT_CARD_FIELDS = Object.freeze({
|
|
'act-a-changedTitle': 'title',
|
|
'act-a-changedDescription': 'description',
|
|
});
|
|
|
|
function isEditCardSource(description) {
|
|
return Object.hasOwn(EDIT_CARD_FIELDS, description);
|
|
}
|
|
|
|
// The activity names to select webhooks by for one activity description.
|
|
function webhookActivitySelection(description) {
|
|
return isEditCardSource(description) ? [description, 'all', EDIT_CARD_EVENT] : [description, 'all'];
|
|
}
|
|
|
|
// The event one webhook receives for one activity. A webhook that also names
|
|
// the per-field event or `all` asked for that event, so it keeps it.
|
|
function webhookDescriptionFor(integration, description) {
|
|
const activities = Array.isArray(integration?.activities) ? integration.activities : [];
|
|
if (!isEditCardSource(description) || !activities.includes(EDIT_CARD_EVENT) ||
|
|
activities.includes(description) || activities.includes('all')) return description;
|
|
return EDIT_CARD_EVENT;
|
|
}
|
|
|
|
function webhookParamsFor(params, description, deliveredDescription) {
|
|
if (deliveredDescription !== EDIT_CARD_EVENT) return params;
|
|
return { ...params, field: EDIT_CARD_FIELDS[description] };
|
|
}
|
|
|
|
module.exports = {
|
|
EDIT_CARD_EVENT,
|
|
EDIT_CARD_FIELDS,
|
|
isEditCardSource,
|
|
webhookActivitySelection,
|
|
webhookDescriptionFor,
|
|
webhookParamsFor,
|
|
};
|