Files
wekan/models/lib/labelDisplayName.js
T
Lauri Ojansivu aad00cdba2 Fix #5442: outgoing webhooks now include the label name on add/remove label
Labels are embedded in the board document, not a separate collection, but the
Activities label() helper looked the label id up in the Cards collection and
always returned undefined. So the addedLabel/removedLabel webhook and
notification params never got a label value and the __label__ token in the
message text rendered as a bare, generic "label" with no name.

Resolve the label from the already-loaded board via getLabelById, and add a
pure labelDisplayName() helper (name -> color -> id fallback) so a nameless
label is shown by its color, matching the UI. Add a plain-Node unit test.
2026-07-09 02:14:07 +03:00

25 lines
1.0 KiB
JavaScript

'use strict';
// Pure helper: resolve a board label's human-readable display name for
// notification / outgoing-webhook text. Extracted so the fallback logic is
// unit-testable in plain Node without Meteor (mirrors
// models/lib/boardSortReorder.js and models/lib/cardSearch.js).
//
// #5442 (outgoing webhook on add/remove label did not include the label name):
// a WeKan label has an optional `name` and a `color`. In the UI a label with an
// empty name is shown by its color, so the webhook must do the same instead of
// emitting a bare, generic "label". Preference order: name, then color, then the
// label id, so the resolved text is never empty.
function labelDisplayName(label) {
if (!label) return '';
const name = typeof label.name === 'string' ? label.name.trim() : '';
if (name) return label.name;
const color = typeof label.color === 'string' ? label.color.trim() : '';
if (color) return label.color;
return typeof label._id === 'string' ? label._id : '';
}
module.exports = {
labelDisplayName,
};