mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -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.
93 lines
6.0 KiB
JavaScript
93 lines
6.0 KiB
JavaScript
/* eslint-env mocha */
|
|
import assert from 'node:assert/strict';
|
|
import { Meteor } from 'meteor/meteor';
|
|
import { Random } from 'meteor/random';
|
|
import Boards from '/models/boards';
|
|
import Integrations from '/models/integrations';
|
|
import Settings from '/models/settings';
|
|
import '/server/methods/notificationDelivery';
|
|
|
|
// #3695 / #5171: setNotificationDelivery writes only validated values, and
|
|
// only for the level the caller may change.
|
|
describe('Notification delivery settings method', function () {
|
|
this.timeout(30000);
|
|
const call = (userId, ...args) => Meteor.server.method_handlers.setNotificationDelivery.apply({ userId }, args);
|
|
const refused = async (promise, error) => {
|
|
await assert.rejects(promise, err => err.error === error);
|
|
};
|
|
|
|
it('saves each level for the right caller and refuses everyone else', async function () {
|
|
if (!Meteor.isAppTest) this.skip();
|
|
const admin = Random.id(), boardAdmin = Random.id(), member = Random.id();
|
|
const boardId = Random.id(), hookId = Random.id(), globalId = Random.id();
|
|
const setting = await Settings.findOneAsync({});
|
|
const original = setting && setting.notificationDelivery;
|
|
try {
|
|
await Meteor.users.rawCollection().insertMany([
|
|
{ _id: admin, username: `a-${admin}`, isAdmin: true, profile: {} },
|
|
{ _id: boardAdmin, username: `b-${boardAdmin}`, profile: {} },
|
|
{ _id: member, username: `m-${member}`, profile: {} },
|
|
]);
|
|
await Boards.rawCollection().insertOne({ _id: boardId, title: 'Delivery board', permission: 'private',
|
|
members: [{ userId: boardAdmin, isActive: true, isAdmin: true }, { userId: member, isActive: true, isAdmin: false }] });
|
|
const base = { enabled: true, activities: ['all'], url: 'https://example.invalid/hook', type: 'outgoing-webhooks', createdAt: new Date(0) };
|
|
await Integrations.rawCollection().insertMany([
|
|
{ ...base, _id: hookId, boardId, userId: boardAdmin },
|
|
{ ...base, _id: globalId, boardId: Integrations.Const.GLOBAL_WEBHOOK_ID, userId: admin },
|
|
]);
|
|
|
|
// Board: its admin yes, a plain member no; every channel.
|
|
await call(boardAdmin, 'board', boardId, 'email', { layout: 'clear', grouping: 'board', parts: ['card', 'board'] });
|
|
await call(boardAdmin, 'board', boardId, 'webhook', { text: false, fields: ['names', 'ids'] });
|
|
const board = await Boards.findOneAsync(boardId);
|
|
assert.deepEqual(board.notificationDelivery.email, { layout: 'clear', parts: ['board', 'card'], grouping: 'board' });
|
|
assert.deepEqual(board.notificationDelivery.webhook, { text: false, fields: ['ids', 'names'] });
|
|
await refused(call(member, 'board', boardId, 'tray', { grouping: 'card' }), 'not-authorized');
|
|
|
|
// A board webhook: the board admin; a global webhook: instance admins only.
|
|
await call(boardAdmin, 'integration', hookId, 'webhook', { grouping: 'all', schedule: 'interval', intervalMinutes: 60 });
|
|
assert.equal((await Integrations.findOneAsync(hookId)).notificationDelivery.webhook.grouping, 'all');
|
|
await refused(call(member, 'integration', hookId, 'webhook', { text: false }), 'not-authorized');
|
|
await refused(call(boardAdmin, 'integration', globalId, 'webhook', { text: false }), 'not-authorized');
|
|
await refused(call(boardAdmin, 'integration', hookId, 'email', { layout: 'clear' }), 'invalid-channel');
|
|
await call(admin, 'integration', globalId, 'webhook', { text: false });
|
|
assert.deepEqual((await Integrations.findOneAsync(globalId)).notificationDelivery.webhook, { text: false });
|
|
await call(boardAdmin, 'integration', hookId, 'webhook', null);
|
|
assert.equal((await Integrations.findOneAsync(hookId)).notificationDelivery?.webhook, undefined);
|
|
|
|
// Admin Panel: instance admins only.
|
|
await refused(call(boardAdmin, 'admin', null, 'email', { grouping: 'none' }), 'not-authorized');
|
|
if (setting) {
|
|
await call(admin, 'admin', null, 'tray', { schedule: 'daily', dailyTime: '08:00', timezone: 'Europe/Helsinki' });
|
|
assert.equal((await Settings.findOneAsync(setting._id)).notificationDelivery.tray.dailyTime, '08:00');
|
|
}
|
|
|
|
// Member: only their own e-mail and tray, and only their identity for webhooks.
|
|
await call(member, 'member', null, 'email', { schedule: 'daily', dailyTime: '07:00', timezone: 'UTC' });
|
|
assert.equal((await Meteor.users.findOneAsync(member)).profile.notificationDelivery.email.dailyTime, '07:00');
|
|
await call(member, 'member', null, 'webhook', { hideIdentity: true });
|
|
assert.equal((await Meteor.users.findOneAsync(member)).profile.webhookHideIdentity, true);
|
|
await refused(call(member, 'member', null, 'webhook', { text: false }), 'invalid-notification-delivery');
|
|
await refused(call(member, 'member', boardAdmin, 'email', { grouping: 'none' }), 'not-authorized');
|
|
assert.equal((await Meteor.users.findOneAsync(boardAdmin)).profile.notificationDelivery, undefined);
|
|
|
|
// Invalid values are refused before anything is written.
|
|
for (const bad of [{ grouping: 'galaxy' }, { schedule: 'weekly' }, { dailyTime: '25:00' }, { token: 'x' }, { timezone: 'Mars/Base' }]) {
|
|
await refused(call(boardAdmin, 'board', boardId, 'email', bad), 'invalid-notification-delivery');
|
|
}
|
|
await refused(call(admin, 'nobody', null, 'email', {}), 'invalid-scope');
|
|
await refused(call(admin, 'admin', null, 'sms', {}), 'invalid-channel');
|
|
await refused(call(null, 'member', null, 'email', { grouping: 'none' }), 'not-authorized');
|
|
assert.equal((await Boards.findOneAsync(boardId)).notificationDelivery.email.grouping, 'board');
|
|
} finally {
|
|
await Meteor.users.rawCollection().deleteMany({ _id: { $in: [admin, boardAdmin, member] } });
|
|
await Boards.rawCollection().deleteOne({ _id: boardId });
|
|
await Integrations.rawCollection().deleteMany({ _id: { $in: [hookId, globalId] } });
|
|
if (setting) {
|
|
await Settings.rawCollection().updateOne({ _id: setting._id }, original
|
|
? { $set: { notificationDelivery: original } } : { $unset: { notificationDelivery: '' } });
|
|
}
|
|
}
|
|
});
|
|
});
|