1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-24 15:49:46 +02:00

feat: Add notification when user is added to card

This commit is contained in:
Maksim Eltyshev 2025-05-17 01:50:40 +02:00
parent f43785c3d0
commit f6568ce41b
14 changed files with 169 additions and 39 deletions

View file

@ -143,55 +143,76 @@ module.exports = {
});
if (action.type !== Action.Types.CREATE_CARD) {
const cardSubscriptionUserIds = await sails.helpers.cards.getSubscriptionUserIds(
action.cardId,
action.userId,
);
const boardSubscriptionUserIds = await sails.helpers.boards.getSubscriptionUserIds(
inputs.board.id,
action.userId,
);
const notifiableUserIds = _.union(cardSubscriptionUserIds, boardSubscriptionUserIds);
await Promise.all(
notifiableUserIds.map((userId) =>
sails.helpers.notifications.createOne.with({
if (action.type === Action.Types.ADD_MEMBER_TO_CARD) {
if (values.user !== action.data.user.id) {
await sails.helpers.notifications.createOne.with({
values: {
userId,
action,
type: action.type,
data: {
...action.data,
card: _.pick(values.card, ['name']),
},
userId: action.data.user.id,
creatorUser: values.user,
card: values.card,
},
project: inputs.project,
board: inputs.board,
list: inputs.list,
}),
),
);
}
});
}
} else {
const cardSubscriptionUserIds = await sails.helpers.cards.getSubscriptionUserIds(
action.cardId,
action.userId,
);
const notificationServices = await NotificationService.qm.getByBoardId(inputs.board.id);
const boardSubscriptionUserIds = await sails.helpers.boards.getSubscriptionUserIds(
inputs.board.id,
action.userId,
);
if (notificationServices.length > 0) {
const services = notificationServices.map((notificationService) =>
_.pick(notificationService, ['url', 'format']),
);
const notifiableUserIds = _.union(cardSubscriptionUserIds, boardSubscriptionUserIds);
buildAndSendNotifications(
services,
inputs.board,
values.card,
action,
values.user,
sails.helpers.utils.makeTranslator(),
);
await Promise.all(
notifiableUserIds.map((userId) =>
sails.helpers.notifications.createOne.with({
values: {
userId,
action,
type: action.type,
data: {
...action.data,
card: _.pick(values.card, ['name']),
},
creatorUser: values.user,
card: values.card,
},
project: inputs.project,
board: inputs.board,
list: inputs.list,
}),
),
);
const notificationServices = await NotificationService.qm.getByBoardId(inputs.board.id);
if (notificationServices.length > 0) {
const services = notificationServices.map((notificationService) =>
_.pick(notificationService, ['url', 'format']),
);
buildAndSendNotifications(
services,
inputs.board,
values.card,
action,
values.user,
sails.helpers.utils.makeTranslator(),
);
}
}
}
return action;

View file

@ -37,15 +37,12 @@ module.exports = {
async fn(inputs) {
const { values } = inputs;
if (values.user) {
values.userId = values.user.id;
}
let cardMembership;
try {
cardMembership = await CardMembership.qm.createOne({
...values,
cardId: values.card.id,
userId: values.user.id,
});
} catch (error) {
if (error.code === 'E_UNIQUE') {
@ -69,6 +66,7 @@ module.exports = {
buildData: () => ({
item: cardMembership,
included: {
users: [values.user],
projects: [inputs.project],
boards: [inputs.board],
lists: [inputs.list],
@ -107,6 +105,20 @@ module.exports = {
// TODO: send webhooks
}
await sails.helpers.actions.createOne.with({
values: {
type: Action.Types.ADD_MEMBER_TO_CARD,
data: {
user: _.pick(values.user, ['id', 'name']),
},
user: inputs.actorUser,
card: values.card,
},
project: inputs.project,
board: inputs.board,
list: inputs.list,
});
return cardMembership;
},
};

View file

@ -12,6 +12,8 @@ const buildTitle = (notification, t) => {
return t('Card Moved');
case Notification.Types.COMMENT_CARD:
return t('New Comment');
case Notification.Types.ADD_MEMBER_TO_CARD:
return t('You Were Added to Card');
default:
return null;
}
@ -77,6 +79,22 @@ const buildBodyByFormat = (board, card, notification, actorUser, t) => {
)}:\n\n<i>${escapeHtml(commentText)}</i>`,
};
}
case Notification.Types.ADD_MEMBER_TO_CARD:
return {
text: t('%s added you to %s on %s', actorUser.name, card.name, board.name),
markdown: t(
'%s added you to %s on %s',
escapeMarkdown(actorUser.name),
markdownCardLink,
escapeMarkdown(board.name),
),
html: t(
'%s added you to %s on %s',
escapeHtml(actorUser.name),
htmlCardLink,
escapeHtml(board.name),
),
};
default:
return null;
}
@ -120,6 +138,15 @@ const buildAndSendEmail = async (board, card, notification, actorUser, notifiabl
boardLink,
)}</p><p>${escapeHtml(notification.data.text)}</p>`;
break;
case Notification.Types.ADD_MEMBER_TO_CARD:
html = `<p>${t(
'%s added you to %s on %s',
escapeHtml(actorUser.name),
cardLink,
boardLink,
)}</p>`;
break;
default:
return;