Files
wekan/tests/notificationIndicator.test.cjs
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

37 lines
1.8 KiB
JavaScript

'use strict';
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const source = fs.readFileSync(path.join(__dirname, '../client/components/notifications/notifications.js'), 'utf8');
const start = source.indexOf('Template.notifications.helpers(');
const end = source.indexOf('Template.notifications.events(', start);
let helpers;
let user;
vm.runInNewContext(source.slice(start, end), {
Template: { notifications: { helpers(value) { helpers = value; } } },
ReactiveCache: { getCurrentUser: () => user },
// #5171: client/lib/notificationTray.js - an entry scheduled for later
// (showAt) is not counted until its time.
trayEntryVisible: entry => !entry || typeof entry.showAt !== 'number' || entry.showAt <= Date.now(),
});
user = {
profile: { notifications: [{ activity: 'not-yet-subscribed', read: null }] },
notifications() { throw new Error('The closed drawer has no activity details'); },
};
assert.equal(helpers.unreadNotifications(), 1);
user.profile.notifications.push({ activity: 'already-read', read: new Date() });
assert.equal(helpers.unreadNotifications(), 1);
user.profile.notifications[0].read = new Date();
assert.equal(helpers.unreadNotifications(), 0);
user = { profile: { notifications: [{ activity: 'later', read: null, showAt: Date.now() + 3600000 }] } };
assert.equal(helpers.unreadNotifications(), 0, 'scheduled for later: not counted yet');
user.profile.notifications[0].showAt = Date.now() - 1000;
assert.equal(helpers.unreadNotifications(), 1, 'its time has come');
for (user of [null, {}, { profile: {} }, { profile: { notifications: [] } }]) {
assert.equal(helpers.unreadNotifications(), 0);
}
console.log(' ok - the bell counts unread records without drawer data and ignores read or missing notifications');