1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 05:09:43 +02:00
planka/server/api/controllers/actions/index-in-board.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 = {
2025-05-22 23:14:46 +02:00
BOARD_NOT_FOUND: {
boardNotFound: 'Board not found',
},
2019-08-31 04:07:25 +05:00
};
module.exports = {
inputs: {
2025-05-22 23:14:46 +02:00
boardId: {
...idInput,
required: true,
2019-08-31 04:07:25 +05:00
},
beforeId: idInput,
2019-08-31 04:07:25 +05:00
},
exits: {
2025-05-22 23:14:46 +02:00
boardNotFound: {
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;
2025-05-22 23:14:46 +02:00
const { board, project } = await sails.helpers.boards
.getPathToProjectById(inputs.boardId)
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND);
2019-08-31 04:07:25 +05:00
const boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
2025-05-22 23:14:46 +02:00
board.id,
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) {
2025-05-22 23:14:46 +02:00
throw Errors.BOARD_NOT_FOUND; // Forbidden
}
}
2019-08-31 04:07:25 +05:00
}
2025-05-22 23:14:46 +02:00
const actions = await Action.qm.getByBoardId(board.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
};