fix: Prevent sending notifications to deactivated users

This commit is contained in:
Maksim Eltyshev
2026-01-23 17:20:12 +01:00
parent b2c4c530c6
commit 6ec0bafecb
3 changed files with 89 additions and 71 deletions
+33 -28
View File
@@ -277,38 +277,43 @@ module.exports = {
user: values.creatorUser,
});
const notificationServices = await NotificationService.qm.getByUserId(notification.userId);
const { transporter } = await sails.helpers.utils.makeSmtpTransporter();
const notifiableUser = await User.qm.getOneById(notification.userId, {
withDeactivated: false,
});
if (notificationServices.length > 0 || transporter) {
const notifiableUser = await User.qm.getOneById(notification.userId);
const t = sails.helpers.utils.makeTranslator(notifiableUser.language);
if (notifiableUser) {
const notificationServices = await NotificationService.qm.getByUserId(notification.userId);
const { transporter } = await sails.helpers.utils.makeSmtpTransporter();
if (notificationServices.length > 0) {
const services = notificationServices.map((notificationService) =>
_.pick(notificationService, ['url', 'format']),
);
if (notificationServices.length > 0 || transporter) {
const t = sails.helpers.utils.makeTranslator(notifiableUser.language);
buildAndSendNotifications(
services,
inputs.board,
values.card,
notification,
values.creatorUser,
t,
);
}
if (notificationServices.length > 0) {
const services = notificationServices.map((notificationService) =>
_.pick(notificationService, ['url', 'format']),
);
if (transporter) {
buildAndSendEmail(
transporter,
inputs.board,
values.card,
notification,
values.creatorUser,
notifiableUser,
t,
);
buildAndSendNotifications(
services,
inputs.board,
values.card,
notification,
values.creatorUser,
t,
);
}
if (transporter) {
buildAndSendEmail(
transporter,
inputs.board,
values.card,
notification,
values.creatorUser,
notifiableUser,
t,
);
}
}
}