mirror of
https://github.com/plankanban/planka.git
synced 2025-07-23 15:19: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
|
@ -19,7 +19,7 @@ module.exports = {
|
|||
},
|
||||
},
|
||||
|
||||
async fn(inputs, exits) {
|
||||
async fn(inputs) {
|
||||
// TODO: allow over HTTP without subscription
|
||||
if (!this.req.isSocket) {
|
||||
return this.res.badRequest();
|
||||
|
@ -27,35 +27,43 @@ module.exports = {
|
|||
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { board, project } = await sails.helpers
|
||||
.getBoardToProjectPath(inputs.id)
|
||||
const { board, project } = await sails.helpers.boards
|
||||
.getProjectPath(inputs.id)
|
||||
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND);
|
||||
|
||||
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
|
||||
project.id,
|
||||
currentUser.id,
|
||||
);
|
||||
const isBoardMember = await sails.helpers.users.isBoardMember(currentUser.id, board.id);
|
||||
|
||||
if (!isUserMemberForProject) {
|
||||
throw Errors.BOARD_NOT_FOUND; // Forbidden
|
||||
if (!isBoardMember) {
|
||||
const isProjectManager = await sails.helpers.users.isProjectManager(
|
||||
currentUser.id,
|
||||
project.id,
|
||||
);
|
||||
|
||||
if (!isProjectManager) {
|
||||
throw Errors.BOARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
}
|
||||
|
||||
const labels = await sails.helpers.getLabelsForBoard(board.id);
|
||||
const lists = await sails.helpers.getListsForBoard(board.id);
|
||||
const boardMemberships = await sails.helpers.boards.getBoardMemberships(board.id);
|
||||
|
||||
const cards = await sails.helpers.getCardsForBoard(board);
|
||||
const cardIds = sails.helpers.mapRecords(cards);
|
||||
const userIds = sails.helpers.utils.mapRecords(boardMemberships, 'userId');
|
||||
const users = await sails.helpers.users.getMany(userIds);
|
||||
|
||||
const cardSubscriptions = await sails.helpers.getSubscriptionsByUserForCard(
|
||||
cardIds,
|
||||
currentUser.id,
|
||||
);
|
||||
const labels = await sails.helpers.boards.getLabels(board.id);
|
||||
const lists = await sails.helpers.boards.getLists(board.id);
|
||||
|
||||
const cardMemberships = await sails.helpers.getMembershipsForCard(cardIds);
|
||||
const cardLabels = await sails.helpers.getCardLabelsForCard(cardIds);
|
||||
const cards = await sails.helpers.boards.getCards(board);
|
||||
const cardIds = sails.helpers.utils.mapRecords(cards);
|
||||
|
||||
const tasks = await sails.helpers.getTasksForCard(cardIds);
|
||||
const attachments = await sails.helpers.getAttachmentsForCard(cardIds);
|
||||
const cardSubscriptions = await sails.helpers.cardSubscriptions.getMany({
|
||||
cardId: cardIds,
|
||||
userId: currentUser.id,
|
||||
});
|
||||
|
||||
const cardMemberships = await sails.helpers.cards.getCardMemberships(cardIds);
|
||||
const cardLabels = await sails.helpers.cards.getCardLabels(cardIds);
|
||||
const tasks = await sails.helpers.cards.getTasks(cardIds);
|
||||
const attachments = await sails.helpers.cards.getAttachments(cardIds);
|
||||
|
||||
const isSubscribedByCardId = cardSubscriptions.reduce(
|
||||
(result, cardSubscription) => ({
|
||||
|
@ -65,16 +73,17 @@ module.exports = {
|
|||
{},
|
||||
);
|
||||
|
||||
cards.map((card) => ({
|
||||
...card,
|
||||
isSubscribed: isSubscribedByCardId[card.id] || false,
|
||||
}));
|
||||
cards.forEach((card) => {
|
||||
card.isSubscribed = isSubscribedByCardId[card.id] || false; // eslint-disable-line no-param-reassign
|
||||
});
|
||||
|
||||
sails.sockets.join(this.req, `board:${board.id}`); // TODO: only when subscription needed
|
||||
|
||||
return exits.success({
|
||||
return {
|
||||
item: board,
|
||||
included: {
|
||||
users,
|
||||
boardMemberships,
|
||||
labels,
|
||||
lists,
|
||||
cards,
|
||||
|
@ -82,7 +91,8 @@ module.exports = {
|
|||
cardLabels,
|
||||
tasks,
|
||||
attachments,
|
||||
projects: [project],
|
||||
},
|
||||
});
|
||||
};
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue