mirror of
https://github.com/plankanban/planka.git
synced 2026-08-29 02:31:29 +08:00
fix: Prevent sending notifications to deactivated users
This commit is contained in:
@@ -296,57 +296,60 @@ module.exports = {
|
||||
});
|
||||
|
||||
const notificationsByUserId = _.groupBy(notifications, 'userId');
|
||||
const userIds = Object.keys(notificationsByUserId);
|
||||
|
||||
const notificationServices = await NotificationService.qm.getByUserIds(userIds);
|
||||
const { transporter } = await sails.helpers.utils.makeSmtpTransporter();
|
||||
const notifiableUsers = await User.qm.getByIds(Object.keys(notificationsByUserId), {
|
||||
withDeactivated: false,
|
||||
});
|
||||
|
||||
if (notificationServices.length > 0 || transporter) {
|
||||
const users = await User.qm.getByIds(userIds);
|
||||
const userById = _.keyBy(users, 'id');
|
||||
if (notifiableUsers.length > 0) {
|
||||
const notifiableUserIds = sails.helpers.utils.mapRecords(notifiableUsers);
|
||||
|
||||
const notificationServicesByUserId = _.groupBy(notificationServices, 'userId');
|
||||
const notificationServices = await NotificationService.qm.getByUserIds(notifiableUserIds);
|
||||
const { transporter } = await sails.helpers.utils.makeSmtpTransporter();
|
||||
|
||||
Object.keys(notificationsByUserId).forEach(async (userId) => {
|
||||
const notifiableUser = userById[userId];
|
||||
const t = sails.helpers.utils.makeTranslator(notifiableUser.language);
|
||||
if (notificationServices.length > 0 || transporter) {
|
||||
const notificationServicesByUserId = _.groupBy(notificationServices, 'userId');
|
||||
|
||||
const emails = notificationsByUserId[userId].flatMap((notification) => {
|
||||
const values = valuesById[notification.id];
|
||||
notifiableUsers.forEach(async (notifiableUser) => {
|
||||
const t = sails.helpers.utils.makeTranslator(notifiableUser.language);
|
||||
|
||||
if (notificationServicesByUserId[userId]) {
|
||||
const services = notificationServicesByUserId[userId].map((notificationService) =>
|
||||
_.pick(notificationService, ['url', 'format']),
|
||||
);
|
||||
const emails = notificationsByUserId[notifiableUser.id].flatMap((notification) => {
|
||||
const values = valuesById[notification.id];
|
||||
|
||||
buildAndSendNotifications(
|
||||
services,
|
||||
inputs.board,
|
||||
values.card,
|
||||
notification,
|
||||
values.creatorUser,
|
||||
t,
|
||||
);
|
||||
if (notificationServicesByUserId[notifiableUser.id]) {
|
||||
const services = notificationServicesByUserId[notifiableUser.id].map(
|
||||
(notificationService) => _.pick(notificationService, ['url', 'format']),
|
||||
);
|
||||
|
||||
buildAndSendNotifications(
|
||||
services,
|
||||
inputs.board,
|
||||
values.card,
|
||||
notification,
|
||||
values.creatorUser,
|
||||
t,
|
||||
);
|
||||
}
|
||||
|
||||
if (transporter) {
|
||||
return buildEmail(
|
||||
inputs.board,
|
||||
values.card,
|
||||
notification,
|
||||
values.creatorUser,
|
||||
notifiableUser,
|
||||
t,
|
||||
);
|
||||
}
|
||||
|
||||
return [];
|
||||
});
|
||||
|
||||
if (emails.length > 0) {
|
||||
sendEmails(transporter, emails);
|
||||
}
|
||||
|
||||
if (transporter) {
|
||||
return buildEmail(
|
||||
inputs.board,
|
||||
values.card,
|
||||
notification,
|
||||
values.creatorUser,
|
||||
notifiableUser,
|
||||
t,
|
||||
);
|
||||
}
|
||||
|
||||
return [];
|
||||
});
|
||||
|
||||
if (emails.length > 0) {
|
||||
sendEmails(transporter, emails);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return notifications;
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,17 @@ const createOne = async (values) => {
|
||||
return User.create({ ...values }).fetch();
|
||||
};
|
||||
|
||||
const getByIds = (ids) => defaultFind(ids);
|
||||
const getByIds = (ids, { withDeactivated = true } = {}) => {
|
||||
const criteria = {
|
||||
id: ids,
|
||||
};
|
||||
|
||||
if (!withDeactivated) {
|
||||
criteria.isDeactivated = false;
|
||||
}
|
||||
|
||||
return defaultFind(criteria);
|
||||
};
|
||||
|
||||
const getAll = ({ roleOrRoles } = {}) =>
|
||||
defaultFind({
|
||||
|
||||
Reference in New Issue
Block a user