2025-05-10 02:09:06 +02:00
|
|
|
/*!
|
|
|
|
* Copyright (c) 2024 PLANKA Software GmbH
|
|
|
|
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
|
|
|
*/
|
|
|
|
|
2019-08-31 04:07:25 +05:00
|
|
|
module.exports = {
|
|
|
|
inputs: {
|
|
|
|
record: {
|
|
|
|
type: 'ref',
|
2019-11-05 18:01:42 +05:00
|
|
|
required: true,
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
2025-05-17 22:24:37 +02:00
|
|
|
user: {
|
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
2024-06-12 00:51:36 +02:00
|
|
|
project: {
|
2024-06-06 20:22:14 +02:00
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
board: {
|
|
|
|
type: 'ref',
|
2019-11-05 18:01:42 +05:00
|
|
|
required: true,
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
2024-06-12 00:51:36 +02:00
|
|
|
list: {
|
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
card: {
|
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
actorUser: {
|
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
request: {
|
2019-11-05 18:01:42 +05:00
|
|
|
type: 'ref',
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
async fn(inputs) {
|
2025-05-10 02:09:06 +02:00
|
|
|
const cardMembership = await CardMembership.qm.deleteOne(inputs.record.id);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
|
|
|
if (cardMembership) {
|
|
|
|
sails.sockets.broadcast(
|
|
|
|
`board:${inputs.board.id}`,
|
|
|
|
'cardMembershipDelete',
|
|
|
|
{
|
2019-11-05 18:01:42 +05:00
|
|
|
item: cardMembership,
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
2019-11-05 18:01:42 +05:00
|
|
|
inputs.request,
|
2019-08-31 04:07:25 +05:00
|
|
|
);
|
|
|
|
|
2025-07-04 22:04:11 +02:00
|
|
|
const webhooks = await Webhook.qm.getAll();
|
|
|
|
|
2024-06-12 00:51:36 +02:00
|
|
|
sails.helpers.utils.sendWebhooks.with({
|
2025-07-04 22:04:11 +02:00
|
|
|
webhooks,
|
|
|
|
event: Webhook.Events.CARD_MEMBERSHIP_DELETE,
|
2025-05-10 02:09:06 +02:00
|
|
|
buildData: () => ({
|
2024-06-12 00:51:36 +02:00
|
|
|
item: cardMembership,
|
|
|
|
included: {
|
2025-05-17 22:24:37 +02:00
|
|
|
users: [inputs.user],
|
2024-06-12 00:51:36 +02:00
|
|
|
projects: [inputs.project],
|
|
|
|
boards: [inputs.board],
|
|
|
|
lists: [inputs.list],
|
|
|
|
cards: [inputs.card],
|
|
|
|
},
|
2025-05-10 02:09:06 +02:00
|
|
|
}),
|
2024-06-12 00:51:36 +02:00
|
|
|
user: inputs.actorUser,
|
|
|
|
});
|
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
const cardSubscription = await CardSubscription.qm.deleteOne({
|
2019-08-31 04:07:25 +05:00
|
|
|
cardId: cardMembership.cardId,
|
|
|
|
userId: cardMembership.userId,
|
2019-11-05 18:01:42 +05:00
|
|
|
isPermanent: false,
|
2019-08-31 04:07:25 +05:00
|
|
|
});
|
|
|
|
|
|
|
|
if (cardSubscription) {
|
|
|
|
sails.sockets.broadcast(`user:${cardMembership.userId}`, 'cardUpdate', {
|
|
|
|
item: {
|
|
|
|
id: cardMembership.cardId,
|
2019-11-05 18:01:42 +05:00
|
|
|
isSubscribed: false,
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
});
|
2024-06-12 00:51:36 +02:00
|
|
|
}
|
2025-05-17 22:24:37 +02:00
|
|
|
|
|
|
|
await sails.helpers.actions.createOne.with({
|
2025-07-04 22:04:11 +02:00
|
|
|
webhooks,
|
2025-05-17 22:24:37 +02:00
|
|
|
values: {
|
|
|
|
type: Action.Types.REMOVE_MEMBER_FROM_CARD,
|
|
|
|
data: {
|
|
|
|
user: _.pick(inputs.user, ['id', 'name']),
|
2025-05-22 23:14:46 +02:00
|
|
|
card: _.pick(inputs.card, ['name']),
|
2025-05-17 22:24:37 +02:00
|
|
|
},
|
|
|
|
user: inputs.actorUser,
|
|
|
|
card: inputs.card,
|
|
|
|
},
|
|
|
|
project: inputs.project,
|
|
|
|
board: inputs.board,
|
|
|
|
list: inputs.list,
|
|
|
|
});
|
2019-08-31 04:07:25 +05:00
|
|
|
}
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
return cardMembership;
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|