Files
wekan/client/lib/notificationTray.js
T
Lauri Ojansivu ab785acd1e Choose what notifications contain, and group and schedule them, for e-mail, the tray and webhooks.
One delivery model (models/lib/notificationDelivery.js) for every channel -
e-mail, the notification tray and outgoing webhooks - set in the
Notifications popup at Admin Panel, board and Member Settings scope, and in
each one-way webhook's form:

- Content. Webhooks: the text on or off, and which property groups are sent
  (standard, ids, names, links, actor, people, details), with checklist,
  list, swimlane and board names, before/after values, the card description
  and links added as opt-in groups. E-mail and tray: the classic sentence or
  a clear layout - the board as a link first, the actor and card in bold -
  and which parts are shown.
- Grouping: one message per event, per card, per board, or all together.
- Scheduling: immediately, every 5 minutes to 24 hours, or once a day, with
  optional quiet hours, in the time zone of whoever set it.

The most specific explicit setting wins: member, then board, then Admin
Panel for e-mail and tray; the webhook, then its board, then Admin Panel for
webhooks. A member can only leave their own name out of outgoing webhooks.
The built-in defaults keep today's behaviour. Grouped and scheduled webhooks
and e-mail go through durable queues that survive restarts; queued webhooks
use the SSRF guard and log a blocked address in Admin Panel - Problems.
Values of admin-only custom fields now reach only board admins in e-mail and
tray, and never a webhook.

The new strings are in English in every locale, pending Transifex.

Thanks to HaKePlan, Meeques and xet7 !

Fixes #3695,
Fixes #5171.
2026-10-10 15:28:26 +03:00

105 lines
4.5 KiB
JavaScript

import { ReactiveVar } from 'meteor/reactive-var';
import { ReactiveCache } from '/imports/reactiveCache';
import { TAPi18n } from '/imports/i18n';
const {
channelOf,
redactForRecipient,
renderNotificationItem,
resolveChannelSettings,
} = require('/models/lib/notificationDelivery');
// #5171: the tray (notification drawer) side of the shared notification
// delivery model (models/lib/notificationDelivery.js).
// schedule - an entry stamped with `showAt` (server/notifications/
// trayQueue.js) appears when that time comes;
// grouping - entries of one card/board collapse into one drawer row;
// content - the clearly arranged layout shows only the chosen parts.
// Everything here reads data the drawer's publications already sent to this
// member, so it can show nothing the member could not see in WeKan.
const minute = new ReactiveVar(Date.now());
let ticking = false;
function startTicking() {
if (ticking) return;
ticking = true;
Meteor.setInterval(() => minute.set(Date.now()), 60000);
}
// The current time, re-run every minute so a scheduled entry appears.
export function trayNow() {
startTicking();
return minute.get();
}
export function trayEntryVisible(entry, now = trayNow()) {
return !entry || typeof entry.showAt !== 'number' || entry.showAt <= now;
}
// One board's tray settings for the current member.
export function trayDeliveryFor(boardId) {
const user = ReactiveCache.getCurrentUser();
const setting = ReactiveCache.getCurrentSetting();
const board = boardId ? ReactiveCache.getBoard(boardId) : null;
return resolveChannelSettings('tray', [
['member', channelOf(user && user.profile && user.profile.notificationDelivery, 'tray')],
['board', channelOf(board && board.notificationDelivery, 'tray')],
['admin', channelOf(setting && setting.notificationDelivery, 'tray')],
]);
}
function title(doc) {
return doc && typeof doc.title === 'string' ? doc.title : '';
}
// The activity's values, as the e-mail builds them on the server.
function activityParams(activity) {
const user = ReactiveCache.getCurrentUser();
const board = activity.board && activity.board();
const card = activity.card && activity.card();
const actor = activity.user && activity.user();
const member = activity.member && activity.member();
const customField = activity.customField && activity.customField();
const params = {
user: actor ? (actor.profile && actor.profile.fullname) || actor.username || '' : '',
board: title(board),
oldBoard: title(activity.oldBoard && activity.oldBoard()),
list: title(activity.list && activity.list()),
oldList: title(activity.oldList && activity.oldList()),
swimlane: title(activity.swimlane && activity.swimlane()),
oldSwimlane: title(activity.oldSwimlane && activity.oldSwimlane()),
card: title(card),
cardId: activity.cardId,
member: member ? (member.profile && member.profile.fullname) || member.username || '' : '',
checklist: title(activity.checklist && activity.checklist()),
checklistItem: title(activity.checklistItem && activity.checklistItem()),
customField: customField ? customField.name || '' : '',
comment: activity.commentId && activity.commentDisplayText ? activity.commentDisplayText() : '',
customFieldValue: activity.value,
customFieldAdminOnly: !!(customField && customField.adminOnly === true),
timeValue: activity.timeValue,
timeOldValue: activity.timeOldValue,
};
if (board && typeof board.absoluteUrl === 'function') params.boardUrl = board.absoluteUrl();
if (card && typeof card.absoluteUrl === 'function') params.cardUrl = card.absoluteUrl(board);
params.url = params.cardUrl || params.boardUrl;
const isBoardAdmin = !!(board && user && typeof board.hasAdmin === 'function' && board.hasAdmin(user._id));
return redactForRecipient(params, { isBoardAdmin });
}
// The escaped HTML of one entry in the clearly arranged layout, or '' for the
// classic activity line.
export function trayClearItemHtml(activity) {
if (!activity || !activity.activityType) return '';
const delivery = trayDeliveryFor(activity.boardId);
if (delivery.layout !== 'clear') return '';
const description = `act-${activity.activityType}`;
// An activity with no sentence of its own keeps the classic line.
if (TAPi18n.__(description) === description) return '';
return renderNotificationItem({
description,
params: activityParams(activity),
parts: delivery.parts,
translate: (key, values) => TAPi18n.__(key, values),
}).html;
}