Files
wekan/models/lib/notificationSettings.js
T
Lauri Ojansivu bde66a5c7d Add a 3-tier Notification Settings popup (Member/Board/Admin).
Admin Panel / People, Board Settings and Member Settings each gain a
"Notification Settings" menu entry, right below Email in Admin Panel /
People. All three open the same reusable notificationSettingsPopup
template, letting notifications (tray/in-app and email, the two services
Notifications.notify already dispatches to) be turned on or off with the
same precedence the theme override already uses: Admin Panel default,
then Board override, then the member's own override.

models/lib/notificationSettings.js is a small pure module with the
resolution function (resolveNotificationSetting) and the notification-type
catalog; server/notifications/profile.js and server/notifications/email.js
now resolve the decision before adding to the tray or buffering an email,
so a disabled service is genuinely skipped rather than only hidden in the
UI. Settings.notifyDefaultTray/Email hold the admin default,
Board.notifyOverrideTray/Email the board override, and
profile.notifyOverrideTray/Email the member override; each is optional/
nullable so "unset" always falls through to the next level.
2026-09-10 21:00:20 +03:00

61 lines
2.1 KiB
JavaScript

// 3-tier Notification Settings resolution.
//
// Precedence (highest wins), mirroring the theme-override pattern used
// elsewhere in WeKan (admin default -> board override -> member override):
// 1) Member Settings override (profile.notifyOverride.<service>)
// 2) Board Settings override (board.notifyOverride.<service>)
// 3) Admin Panel default (Settings.notifyDefault<Service>)
// 4) hardcoded fallback (true) — matches the current behavior when
// nothing has ever been configured anywhere.
//
// A tri-state value is represented as `true` / `false` / `undefined` (or
// `null`, treated the same as `undefined`) at each level: only an explicit
// boolean counts as an override, an unset level falls through to the next.
//
// This module is intentionally pure (no Meteor/Mongo imports) so it can be
// unit-tested with plain Node and reused identically on the client and the
// server.
// The current notification-type catalog. Kept in sync with the services
// registered via Notifications.subscribe() in server/notifications/*.js:
// 'profile' == the in-app notification tray, 'email' == outgoing email
// notifications.
const NOTIFICATION_SERVICES = {
tray: 'profile',
email: 'email',
};
const HARDCODED_FALLBACK = true;
function normalize(value) {
return value === true || value === false ? value : undefined;
}
// resolveNotificationSetting(service, { adminDefault, boardOverride, memberOverride })
// -> Boolean
//
// `service` is one of the NOTIFICATION_SERVICES keys ('tray', 'email'), used
// only for documentation/validation purposes here — the three override
// values are already resolved to this service by the caller.
function resolveNotificationSetting(
service,
{ adminDefault, boardOverride, memberOverride } = {},
) {
const member = normalize(memberOverride);
if (member !== undefined) return member;
const board = normalize(boardOverride);
if (board !== undefined) return board;
const admin = normalize(adminDefault);
if (admin !== undefined) return admin;
return HARDCODED_FALLBACK;
}
module.exports = {
NOTIFICATION_SERVICES,
HARDCODED_FALLBACK,
resolveNotificationSetting,
};