1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-20 05:39:43 +02:00
planka/server/api/controllers/actions/index-in-card.js

69 lines
1.5 KiB
JavaScript
Raw Normal View History

/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
const { idInput } = require('../../../utils/inputs');
2019-08-31 04:07:25 +05:00
const Errors = {
CARD_NOT_FOUND: {
2020-04-03 00:35:25 +05:00
cardNotFound: 'Card not found',
},
2019-08-31 04:07:25 +05:00
};
module.exports = {
inputs: {
cardId: {
...idInput,
required: true,
2019-08-31 04:07:25 +05:00
},
beforeId: idInput,
2019-08-31 04:07:25 +05:00
},
exits: {
2020-04-03 00:35:25 +05:00
cardNotFound: {
responseType: 'notFound',
},
2019-08-31 04:07:25 +05:00
},
async fn(inputs) {
2019-08-31 04:07:25 +05:00
const { currentUser } = this.req;
const { card, project } = await sails.helpers.cards
.getPathToProjectById(inputs.cardId)
2020-04-03 00:35:25 +05:00
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
2019-08-31 04:07:25 +05:00
const boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
card.boardId,
currentUser.id,
);
2019-08-31 04:07:25 +05:00
if (!boardMembership) {
if (currentUser.role !== User.Roles.ADMIN || project.ownerProjectManagerId) {
const isProjectManager = await sails.helpers.users.isProjectManager(
currentUser.id,
project.id,
);
if (!isProjectManager) {
throw Errors.CARD_NOT_FOUND; // Forbidden
}
}
2019-08-31 04:07:25 +05:00
}
const actions = await Action.qm.getByCardId(card.id, {
beforeId: inputs.beforeId,
});
2019-08-31 04:07:25 +05:00
const userIds = sails.helpers.utils.mapRecords(actions, 'userId', true, true);
const users = await User.qm.getByIds(userIds);
2019-08-31 04:07:25 +05:00
return {
2019-08-31 04:07:25 +05:00
items: actions,
included: {
users: sails.helpers.users.presentMany(users, currentUser),
},
};
},
2019-08-31 04:07:25 +05:00
};