1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-08-10 07:55:27 +02:00

feat: send emails on COMMENT_CARD notifications

This commit is contained in:
Edouard Richard 2024-03-17 12:08:33 +01:00
parent b4e01d7256
commit 007c45e3c7
4 changed files with 74 additions and 0 deletions

View file

@ -35,6 +35,14 @@ SECRET_KEY=notsecretkey
# OIDC_IGNORE_ROLES=true
# OIDC_ENFORCED=true
# Email Notifications (https://nodemailer.com/smtp/)
SMTP_HOST=
SMTP_USER=
SMTP_PASSWORD=
SMTP_PORT=587
SMTP_SECURE=
SMTP_FROM="Demo Demo" <demo@demo.demo>
## Do not edit this
TZ=UTC

View file

@ -1,3 +1,18 @@
const nodemailer = require('nodemailer');
const emailTransporter =
process.env.SMTP_HOST &&
nodemailer.createTransport({
pool: true,
host: process.env.SMTP_HOST,
port: process.env.SMTP_PORT,
secure: process.env.SMTP_SECURE === 'true',
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASSWORD,
},
});
const valuesValidator = (value) => {
if (!_.isPlainObject(value)) {
return false;
@ -14,6 +29,38 @@ const valuesValidator = (value) => {
return true;
};
async function sendEmailNotification({ notification, action }) {
const actionUser = await sails.helpers.users.getOne(action.userId);
const actionCard = await Card.findOne(action.cardId);
const notificationUser = await sails.helpers.users.getOne(notification.userId);
const actionBoard = await Board.findOne(actionCard.boardId);
let email;
switch (action.type) {
case Action.Types.COMMENT_CARD:
email = {
subject: `${actionUser.name} commented the card ${actionCard.name} on ${actionBoard.name}`,
html: `<p>${actionUser.name} commented the card ${actionCard.name} on ${actionBoard.name}</p><p>${action.data.text}</p>`,
};
break;
default:
break;
}
if (!email) {
return;
}
emailTransporter.sendMail(
{ from: process.env.SMTP_FROM, to: notificationUser.email, ...email },
(error, info) => {
if (error) {
sails.log.error(error);
} else {
sails.log.info('Email sent: %s', info.messageId);
}
},
);
}
module.exports = {
inputs: {
values: {
@ -36,6 +83,10 @@ module.exports = {
cardId: values.action.cardId,
}).fetch();
if (emailTransporter) {
sendEmailNotification({ notification, action: values.action });
}
sails.sockets.broadcast(`user:${notification.userId}`, 'notificationCreate', {
item: notification,
});

View file

@ -15,6 +15,7 @@
"lodash": "^4.17.21",
"moment": "^2.29.4",
"move-file": "^2.1.0",
"nodemailer": "^6.9.12",
"openid-client": "^5.6.1",
"rimraf": "^5.0.5",
"sails": "^1.5.7",
@ -5257,6 +5258,14 @@
}
}
},
"node_modules/nodemailer": {
"version": "6.9.12",
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.9.12.tgz",
"integrity": "sha512-pnLo7g37Br3jXbF0bl5DekBJihm2q+3bB3l2o/B060sWmb5l+VqeScAQCBqaQ+5ezRZFzW5SciZNGdRDEbq89w==",
"engines": {
"node": ">=6.0.0"
}
},
"node_modules/nodemon": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.0.1.tgz",
@ -12852,6 +12861,11 @@
"whatwg-url": "^5.0.0"
}
},
"nodemailer": {
"version": "6.9.12",
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.9.12.tgz",
"integrity": "sha512-pnLo7g37Br3jXbF0bl5DekBJihm2q+3bB3l2o/B060sWmb5l+VqeScAQCBqaQ+5ezRZFzW5SciZNGdRDEbq89w=="
},
"nodemon": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.0.1.tgz",

View file

@ -36,6 +36,7 @@
"lodash": "^4.17.21",
"moment": "^2.29.4",
"move-file": "^2.1.0",
"nodemailer": "^6.9.12",
"openid-client": "^5.6.1",
"rimraf": "^5.0.5",
"sails": "^1.5.7",