mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
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.
79 lines
3.0 KiB
JavaScript
79 lines
3.0 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const root = path.join(__dirname, '..');
|
|
const read = relative => fs.readFileSync(path.join(root, relative), 'utf8');
|
|
const english = JSON.parse(read('imports/i18n/data/en.i18n.json'));
|
|
const french = JSON.parse(read('imports/i18n/data/fr.i18n.json'));
|
|
const notification = read('server/notifications/email.js');
|
|
const localization = read('server/lib/emailLocalization.js');
|
|
const tap = read('imports/i18n/tap.js');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) {
|
|
fn();
|
|
passed += 1;
|
|
console.log(' ok -', name);
|
|
}
|
|
|
|
test('#5438 representative notification prose exists in French', () => {
|
|
assert.strictEqual(english['activity-added'], 'added %s to %s');
|
|
assert.strictEqual(french['activity-added'], 'a ajouté %s à %s');
|
|
assert.notStrictEqual(french['activity-added'], english['activity-added']);
|
|
assert.deepStrictEqual(
|
|
french['activity-added'].match(/%s/g),
|
|
english['activity-added'].match(/%s/g),
|
|
);
|
|
});
|
|
|
|
test('#5438 notification preparation loads the recipient language first', () => {
|
|
const load = notification.indexOf(
|
|
'await TAPi18n.ensureLanguageLoaded(lan)',
|
|
);
|
|
const language = notification.indexOf('const lan = user.getLanguage()');
|
|
const subject = notification.indexOf(
|
|
'formatActivityNotificationTitle(',
|
|
);
|
|
const body = notification.indexOf(
|
|
'TAPi18n.__(description, quoteParams, lan)',
|
|
);
|
|
assert.ok(language >= 0 && language < load && load < subject && subject < body);
|
|
});
|
|
|
|
test('the durable email keeps the recipient language selected when rendered', () => {
|
|
// #5171: the job is built, then the delivery fields are added to it.
|
|
assert.match(notification, /const job = \{ userId,[\s\S]*?language: lan[\s\S]*?return job;/);
|
|
assert.match(notification, /if \(job\) await emailOutbox.enqueue\(job\)/);
|
|
const worker = read('server/lib/emailOutbox.js');
|
|
assert.match(worker, /language: first.language/);
|
|
});
|
|
|
|
test('the shared email sender also loads before translating', () => {
|
|
const load = localization.indexOf('await TAPi18n.ensureLanguageLoaded(lang)');
|
|
const translate = localization.indexOf(
|
|
'TAPi18n.__(options.subject, options.params || {}, lang)',
|
|
);
|
|
assert.ok(load >= 0 && load < translate);
|
|
});
|
|
|
|
test('negative: unsupported or already-loaded languages do not load again', () => {
|
|
assert.match(tap, /if \(!language \|\| !this\.i18n\) return/);
|
|
assert.match(tap, /const key = this\.resolveTag\(language\)/);
|
|
assert.match(tap, /if \(!key\) return/);
|
|
assert.match(
|
|
tap,
|
|
/if \(this\.i18n\.hasResourceBundle\(this\.toI18nCode\(key\), DEFAULT_NAMESPACE\)\) return/,
|
|
);
|
|
});
|
|
|
|
test('negative: notification translation does not use the server default', () => {
|
|
assert.doesNotMatch(notification, /TAPi18n\.getLanguage\(\)/);
|
|
assert.doesNotMatch(notification, /TAPi18n\.__\(title, params\)(?!,)/);
|
|
assert.doesNotMatch(notification, /TAPi18n\.__\(description, quoteParams\)(?!,)/);
|
|
});
|
|
|
|
console.log(`\nnotificationEmailLanguage: all ${passed} tests passed`);
|