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
|
|
|
|
*/
|
|
|
|
|
2020-04-21 05:04:34 +05:00
|
|
|
module.exports = {
|
|
|
|
inputs: {
|
|
|
|
record: {
|
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
2024-06-12 00:51:36 +02:00
|
|
|
project: {
|
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
2021-06-24 01:05:22 +05:00
|
|
|
board: {
|
2020-04-23 03:02:53 +05:00
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
2024-06-12 00:51:36 +02:00
|
|
|
list: {
|
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
2021-06-24 01:05:22 +05:00
|
|
|
card: {
|
2020-04-21 05:04:34 +05:00
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
2024-06-12 00:51:36 +02:00
|
|
|
actorUser: {
|
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
2020-04-21 05:04:34 +05:00
|
|
|
request: {
|
|
|
|
type: 'ref',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
async fn(inputs) {
|
2025-07-08 00:22:24 +02:00
|
|
|
const webhooks = await Webhook.qm.getAll();
|
|
|
|
|
2020-04-23 03:02:53 +05:00
|
|
|
if (inputs.record.id === inputs.card.coverAttachmentId) {
|
2021-06-24 01:05:22 +05:00
|
|
|
await sails.helpers.cards.updateOne.with({
|
2025-07-04 22:04:11 +02:00
|
|
|
webhooks,
|
2020-04-23 03:02:53 +05:00
|
|
|
record: inputs.card,
|
|
|
|
values: {
|
|
|
|
coverAttachmentId: null,
|
|
|
|
},
|
2024-06-12 00:51:36 +02:00
|
|
|
project: inputs.project,
|
|
|
|
board: inputs.board,
|
|
|
|
list: inputs.list,
|
|
|
|
actorUser: inputs.actorUser,
|
2020-04-23 03:02:53 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
const { attachment, fileReference } = await Attachment.qm.deleteOne(inputs.record.id, {
|
|
|
|
isFile: inputs.record.type === Attachment.Types.FILE,
|
|
|
|
});
|
2020-04-21 05:04:34 +05:00
|
|
|
|
|
|
|
if (attachment) {
|
2025-05-10 02:09:06 +02:00
|
|
|
if (fileReference) {
|
|
|
|
sails.helpers.attachments.removeUnreferencedFiles(fileReference);
|
2020-04-21 05:04:34 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
sails.sockets.broadcast(
|
|
|
|
`board:${inputs.board.id}`,
|
|
|
|
'attachmentDelete',
|
|
|
|
{
|
2025-05-10 02:09:06 +02:00
|
|
|
item: sails.helpers.attachments.presentOne(attachment),
|
2020-04-21 05:04:34 +05:00
|
|
|
},
|
|
|
|
inputs.request,
|
|
|
|
);
|
2024-06-06 20:22:14 +02:00
|
|
|
|
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.ATTACHMENT_DELETE,
|
2025-05-10 02:09:06 +02:00
|
|
|
buildData: () => ({
|
|
|
|
item: sails.helpers.attachments.presentOne(attachment),
|
2024-06-12 00:51:36 +02:00
|
|
|
included: {
|
|
|
|
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,
|
2024-06-06 20:22:14 +02:00
|
|
|
});
|
2020-04-21 05:04:34 +05:00
|
|
|
}
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
return attachment;
|
2020-04-21 05:04:34 +05:00
|
|
|
},
|
|
|
|
};
|