mirror of
https://github.com/plankanban/planka.git
synced 2025-07-25 08:09:44 +02:00
feat: SMTP integration and email notifications (#631)
This commit is contained in:
parent
803e14c9e1
commit
ca4d6761cd
14 changed files with 188 additions and 4 deletions
|
@ -21,6 +21,10 @@ module.exports = {
|
|||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
board: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
|
@ -56,6 +60,9 @@ module.exports = {
|
|||
userId,
|
||||
action,
|
||||
},
|
||||
user: values.user,
|
||||
board: inputs.board,
|
||||
card: values.card,
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
|
|
@ -25,6 +25,10 @@ module.exports = {
|
|||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
board: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
|
@ -104,6 +108,7 @@ module.exports = {
|
|||
},
|
||||
user: values.creatorUser,
|
||||
},
|
||||
board: inputs.board,
|
||||
});
|
||||
|
||||
return card;
|
||||
|
|
|
@ -232,6 +232,7 @@ module.exports = {
|
|||
toList: _.pick(values.list, ['id', 'name']),
|
||||
},
|
||||
},
|
||||
board: inputs.board,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,40 @@ const valuesValidator = (value) => {
|
|||
return true;
|
||||
};
|
||||
|
||||
// TODO: use templates (views) to build html
|
||||
const buildAndSendEmail = async (user, board, card, action, notifiableUser) => {
|
||||
let emailData;
|
||||
switch (action.type) {
|
||||
case Action.Types.MOVE_CARD:
|
||||
emailData = {
|
||||
subject: `${user.name} moved ${card.name} from ${action.data.fromList.name} to ${action.data.toList.name} on ${board.name}`,
|
||||
html:
|
||||
`<p>${user.name} moved ` +
|
||||
`<a href="${process.env.BASE_URL}/cards/${card.id}">${card.name}</a> ` +
|
||||
`from ${action.data.fromList.name} to ${action.data.toList.name} ` +
|
||||
`on <a href="${process.env.BASE_URL}/boards/${board.id}">${board.name}</a></p>`,
|
||||
};
|
||||
break;
|
||||
case Action.Types.COMMENT_CARD:
|
||||
emailData = {
|
||||
subject: `${user.name} left a new comment to ${card.name} on ${board.name}`,
|
||||
html:
|
||||
`<p>${user.name} left a new comment to ` +
|
||||
`<a href="${process.env.BASE_URL}/cards/${card.id}">${card.name}</a> ` +
|
||||
`on <a href="${process.env.BASE_URL}/boards/${board.id}">${board.name}</a></p>` +
|
||||
`<p>${action.data.text}</p>`,
|
||||
};
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
await sails.helpers.utils.sendEmail.with({
|
||||
...emailData,
|
||||
to: notifiableUser.email,
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
values: {
|
||||
|
@ -21,6 +55,18 @@ module.exports = {
|
|||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
user: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
board: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
card: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
|
@ -40,6 +86,17 @@ module.exports = {
|
|||
item: notification,
|
||||
});
|
||||
|
||||
if (sails.hooks.smtp.isActive()) {
|
||||
let notifiableUser;
|
||||
if (values.user) {
|
||||
notifiableUser = values.user;
|
||||
} else {
|
||||
notifiableUser = await sails.helpers.users.getOne(notification.userId);
|
||||
}
|
||||
|
||||
buildAndSendEmail(inputs.user, inputs.board, inputs.card, values.action, notifiableUser);
|
||||
}
|
||||
|
||||
return notification;
|
||||
},
|
||||
};
|
||||
|
|
31
server/api/helpers/utils/send-email.js
Normal file
31
server/api/helpers/utils/send-email.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
to: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
},
|
||||
subject: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
},
|
||||
html: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const transporter = sails.hooks.smtp.getTransporter(); // TODO: check if active?
|
||||
|
||||
try {
|
||||
const info = await transporter.sendMail({
|
||||
...inputs,
|
||||
from: sails.config.custom.smtpFrom,
|
||||
});
|
||||
|
||||
sails.log.info('Email sent: %s', info.messageId);
|
||||
} catch (error) {
|
||||
sails.log.error(error);
|
||||
}
|
||||
},
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue