mirror of
https://github.com/plankanban/planka.git
synced 2025-07-22 22:59:44 +02:00
Project managers, board members, auto-update after reconnection, refactoring
This commit is contained in:
parent
d6cb1f6683
commit
b39119ace4
478 changed files with 21226 additions and 19495 deletions
65
server/api/controllers/projects/show.js
Normal file
65
server/api/controllers/projects/show.js
Normal file
|
@ -0,0 +1,65 @@
|
|||
const Errors = {
|
||||
PROJECT_NOT_FOUND: {
|
||||
projectNotFound: 'Project not found',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'string',
|
||||
regex: /^[0-9]+$/,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
projectNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const project = await Project.findOne(inputs.id);
|
||||
|
||||
if (!project) {
|
||||
throw Errors.PROJECT_NOT_FOUND;
|
||||
}
|
||||
|
||||
let boards = await sails.helpers.projects.getBoards(project.id);
|
||||
let boardIds = sails.helpers.utils.mapRecords(boards);
|
||||
|
||||
const boardMemberships = await sails.helpers.boardMemberships.getMany({
|
||||
boardId: boardIds,
|
||||
userId: currentUser.id,
|
||||
});
|
||||
|
||||
const isProjectManager = await sails.helpers.users.isProjectManager(currentUser.id, project.id);
|
||||
|
||||
if (!isProjectManager) {
|
||||
if (boardMemberships.length === 0) {
|
||||
throw Errors.PROJECT_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
boardIds = sails.helpers.utils.mapRecords(boardMemberships, 'boardId');
|
||||
boards = boards.filter((board) => boardIds.includes(board.id));
|
||||
}
|
||||
|
||||
const projectManagers = await sails.helpers.projects.getProjectManagers(project.id);
|
||||
|
||||
const userIds = sails.helpers.utils.mapRecords(projectManagers, 'userId');
|
||||
const users = await sails.helpers.users.getMany(userIds);
|
||||
|
||||
return {
|
||||
item: project,
|
||||
included: {
|
||||
users,
|
||||
projectManagers,
|
||||
boards,
|
||||
boardMemberships,
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue