mirror of
https://github.com/plankanban/planka.git
synced 2025-07-18 12:49:43 +02:00
69 lines
1.4 KiB
JavaScript
Executable file
69 lines
1.4 KiB
JavaScript
Executable file
const Errors = {
|
|
NOT_ENOUGH_RIGHTS: {
|
|
notEnoughRights: 'Not enough rights',
|
|
},
|
|
ATTACHMENT_NOT_FOUND: {
|
|
attachmentNotFound: 'Attachment not found',
|
|
},
|
|
};
|
|
|
|
module.exports = {
|
|
inputs: {
|
|
id: {
|
|
type: 'string',
|
|
regex: /^[0-9]+$/,
|
|
required: true,
|
|
},
|
|
},
|
|
|
|
exits: {
|
|
notEnoughRights: {
|
|
responseType: 'forbidden',
|
|
},
|
|
attachmentNotFound: {
|
|
responseType: 'notFound',
|
|
},
|
|
},
|
|
|
|
async fn(inputs) {
|
|
const { currentUser } = this.req;
|
|
|
|
const path = await sails.helpers.attachments
|
|
.getProjectPath(inputs.id)
|
|
.intercept('pathNotFound', () => Errors.ATTACHMENT_NOT_FOUND);
|
|
|
|
let { attachment } = path;
|
|
const { card, list, board, project } = path;
|
|
|
|
const boardMembership = await BoardMembership.findOne({
|
|
boardId: board.id,
|
|
userId: currentUser.id,
|
|
});
|
|
|
|
if (!boardMembership) {
|
|
throw Errors.ATTACHMENT_NOT_FOUND; // Forbidden
|
|
}
|
|
|
|
if (boardMembership.role !== BoardMembership.Roles.EDITOR) {
|
|
throw Errors.NOT_ENOUGH_RIGHTS;
|
|
}
|
|
|
|
attachment = await sails.helpers.attachments.deleteOne.with({
|
|
project,
|
|
board,
|
|
list,
|
|
card,
|
|
record: attachment,
|
|
actorUser: currentUser,
|
|
request: this.req,
|
|
});
|
|
|
|
if (!attachment) {
|
|
throw Errors.ATTACHMENT_NOT_FOUND;
|
|
}
|
|
|
|
return {
|
|
item: attachment,
|
|
};
|
|
},
|
|
};
|