2025-05-10 02:09:06 +02:00
|
|
|
/*!
|
|
|
|
|
* Copyright (c) 2024 PLANKA Software GmbH
|
|
|
|
|
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
|
|
|
|
*/
|
|
|
|
|
|
2025-09-08 16:20:27 +02:00
|
|
|
/**
|
|
|
|
|
* @swagger
|
|
|
|
|
* /api/boards/{id}:
|
|
|
|
|
* get:
|
|
|
|
|
* summary: Get board details
|
|
|
|
|
* description: Retrieves comprehensive board information, including lists, cards, and other related data.
|
|
|
|
|
* tags:
|
|
|
|
|
* - Boards
|
|
|
|
|
* parameters:
|
|
|
|
|
* - name: id
|
|
|
|
|
* in: path
|
|
|
|
|
* required: true
|
|
|
|
|
* description: ID of the board to retrieve
|
|
|
|
|
* schema:
|
|
|
|
|
* type: string
|
|
|
|
|
* example: 1357158568008091264
|
|
|
|
|
* - name: subscribe
|
|
|
|
|
* in: query
|
|
|
|
|
* required: false
|
|
|
|
|
* description: Whether to subscribe to real-time updates for this board (only for socket connections)
|
|
|
|
|
* schema:
|
|
|
|
|
* type: boolean
|
|
|
|
|
* example: true
|
|
|
|
|
* responses:
|
|
|
|
|
* 200:
|
|
|
|
|
* description: Board details retrieved successfully
|
|
|
|
|
* content:
|
|
|
|
|
* application/json:
|
|
|
|
|
* schema:
|
|
|
|
|
* type: object
|
|
|
|
|
* required:
|
|
|
|
|
* - item
|
|
|
|
|
* - included
|
|
|
|
|
* properties:
|
|
|
|
|
* item:
|
|
|
|
|
* allOf:
|
|
|
|
|
* - $ref: '#/components/schemas/Board'
|
|
|
|
|
* - type: object
|
|
|
|
|
* properties:
|
|
|
|
|
* isSubscribed:
|
|
|
|
|
* type: boolean
|
|
|
|
|
* description: Whether the current user is subscribed to the board
|
|
|
|
|
* example: true
|
|
|
|
|
* included:
|
|
|
|
|
* type: object
|
|
|
|
|
* required:
|
|
|
|
|
* - users
|
|
|
|
|
* - projects
|
|
|
|
|
* - boardMemberships
|
|
|
|
|
* - labels
|
|
|
|
|
* - lists
|
|
|
|
|
* - cards
|
|
|
|
|
* - cardMemberships
|
|
|
|
|
* - cardLabels
|
|
|
|
|
* - taskLists
|
|
|
|
|
* - tasks
|
|
|
|
|
* - attachments
|
|
|
|
|
* - customFieldGroups
|
|
|
|
|
* - customFields
|
|
|
|
|
* - customFieldValues
|
|
|
|
|
* properties:
|
|
|
|
|
* users:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Related users
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/User'
|
|
|
|
|
* projects:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Parent project
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/Project'
|
|
|
|
|
* boardMemberships:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Related board memberships
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/BoardMembership'
|
|
|
|
|
* labels:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Related labels
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/Label'
|
|
|
|
|
* lists:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Related lists
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/List'
|
|
|
|
|
* cards:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Related cards
|
|
|
|
|
* items:
|
|
|
|
|
* allOf:
|
|
|
|
|
* - $ref: '#/components/schemas/Card'
|
|
|
|
|
* - type: object
|
|
|
|
|
* properties:
|
|
|
|
|
* isSubscribed:
|
|
|
|
|
* type: boolean
|
|
|
|
|
* description: Whether the current user is subscribed to the card
|
|
|
|
|
* example: true
|
|
|
|
|
* cardMemberships:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Related card-membership associations
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/CardMembership'
|
|
|
|
|
* cardLabels:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Related card-label associations
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/CardLabel'
|
|
|
|
|
* taskLists:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Related task lists
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/TaskList'
|
|
|
|
|
* tasks:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Related tasks
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/Task'
|
|
|
|
|
* attachments:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Related attachments
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/Attachment'
|
|
|
|
|
* customFieldGroups:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Related custom field groups
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/CustomFieldGroup'
|
|
|
|
|
* customFields:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Related custom fields
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/CustomField'
|
|
|
|
|
* customFieldValues:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Related custom field values
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/CustomFieldValue'
|
|
|
|
|
* 400:
|
|
|
|
|
* $ref: '#/components/responses/ValidationError'
|
|
|
|
|
* 401:
|
|
|
|
|
* $ref: '#/components/responses/Unauthorized'
|
|
|
|
|
* 404:
|
|
|
|
|
* $ref: '#/components/responses/NotFound'
|
|
|
|
|
*/
|
|
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
const { idInput } = require('../../../utils/inputs');
|
|
|
|
|
|
2019-08-31 04:07:25 +05:00
|
|
|
const Errors = {
|
|
|
|
|
BOARD_NOT_FOUND: {
|
2020-04-03 00:35:25 +05:00
|
|
|
boardNotFound: 'Board not found',
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
inputs: {
|
|
|
|
|
id: {
|
2025-05-10 02:09:06 +02:00
|
|
|
...idInput,
|
2019-11-05 18:01:42 +05:00
|
|
|
required: true,
|
|
|
|
|
},
|
2023-01-05 15:03:06 +01:00
|
|
|
subscribe: {
|
|
|
|
|
type: 'boolean',
|
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
exits: {
|
2020-04-03 00:35:25 +05:00
|
|
|
boardNotFound: {
|
2019-11-05 18:01:42 +05:00
|
|
|
responseType: 'notFound',
|
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
async fn(inputs) {
|
2019-08-31 04:07:25 +05:00
|
|
|
const { currentUser } = this.req;
|
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
const { board, project } = await sails.helpers.boards
|
2025-05-10 02:09:06 +02:00
|
|
|
.getPathToProjectById(inputs.id)
|
2020-04-03 00:35:25 +05:00
|
|
|
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
if (currentUser.role !== User.Roles.ADMIN || project.ownerProjectManagerId) {
|
2021-06-24 01:05:22 +05:00
|
|
|
const isProjectManager = await sails.helpers.users.isProjectManager(
|
|
|
|
|
currentUser.id,
|
|
|
|
|
project.id,
|
|
|
|
|
);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
if (!isProjectManager) {
|
2025-05-10 02:09:06 +02:00
|
|
|
const boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
|
|
|
|
|
board.id,
|
|
|
|
|
currentUser.id,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (!boardMembership) {
|
|
|
|
|
throw Errors.BOARD_NOT_FOUND; // Forbidden
|
|
|
|
|
}
|
2021-06-24 01:05:22 +05:00
|
|
|
}
|
2019-08-31 04:07:25 +05:00
|
|
|
}
|
|
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
board.isSubscribed = await sails.helpers.users.isBoardSubscriber(currentUser.id, board.id);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
const boardMemberships = await BoardMembership.qm.getByBoardId(board.id);
|
|
|
|
|
const labels = await Label.qm.getByBoardId(board.id);
|
|
|
|
|
const lists = await List.qm.getByBoardId(board.id);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
const finiteLists = lists.filter((list) => sails.helpers.lists.isFinite(list));
|
|
|
|
|
const finiteListIds = sails.helpers.utils.mapRecords(finiteLists);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
const cards = await Card.qm.getByListIds(finiteListIds);
|
2021-06-24 01:05:22 +05:00
|
|
|
const cardIds = sails.helpers.utils.mapRecords(cards);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
const userIds = _.union(
|
|
|
|
|
sails.helpers.utils.mapRecords(boardMemberships, 'userId'),
|
|
|
|
|
sails.helpers.utils.mapRecords(cards, 'creatorUserId', true, true),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const users = await User.qm.getByIds(userIds);
|
|
|
|
|
const cardMemberships = await CardMembership.qm.getByCardIds(cardIds);
|
|
|
|
|
const cardLabels = await CardLabel.qm.getByCardIds(cardIds);
|
2021-06-24 01:05:22 +05:00
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
const taskLists = await TaskList.qm.getByCardIds(cardIds);
|
|
|
|
|
const taskListIds = sails.helpers.utils.mapRecords(taskLists);
|
|
|
|
|
|
|
|
|
|
const tasks = await Task.qm.getByTaskListIds(taskListIds);
|
|
|
|
|
const attachments = await Attachment.qm.getByCardIds(cardIds);
|
|
|
|
|
|
|
|
|
|
const boardCustomFieldGroups = await CustomFieldGroup.qm.getByBoardId(board.id);
|
|
|
|
|
const cardCustomFieldGroups = await CustomFieldGroup.qm.getByCardIds(cardIds);
|
|
|
|
|
|
|
|
|
|
const customFieldGroups = [...boardCustomFieldGroups, ...cardCustomFieldGroups];
|
|
|
|
|
const customFieldGroupIds = sails.helpers.utils.mapRecords(customFieldGroups);
|
|
|
|
|
|
|
|
|
|
const customFields = await CustomField.qm.getByCustomFieldGroupIds(customFieldGroupIds);
|
|
|
|
|
const customFieldValues = await CustomFieldValue.qm.getByCardIds(cardIds);
|
|
|
|
|
|
|
|
|
|
const cardSubscriptions = await CardSubscription.qm.getByCardIdsAndUserId(
|
|
|
|
|
cardIds,
|
|
|
|
|
currentUser.id,
|
|
|
|
|
);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
|
|
|
|
const isSubscribedByCardId = cardSubscriptions.reduce(
|
|
|
|
|
(result, cardSubscription) => ({
|
|
|
|
|
...result,
|
2019-11-05 18:01:42 +05:00
|
|
|
[cardSubscription.cardId]: true,
|
2019-08-31 04:07:25 +05:00
|
|
|
}),
|
2019-11-05 18:01:42 +05:00
|
|
|
{},
|
2019-08-31 04:07:25 +05:00
|
|
|
);
|
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
cards.forEach((card) => {
|
2022-12-26 21:10:50 +01:00
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
|
card.isSubscribed = isSubscribedByCardId[card.id] || false;
|
2021-06-24 01:05:22 +05:00
|
|
|
});
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2023-01-05 15:03:06 +01:00
|
|
|
if (inputs.subscribe && this.req.isSocket) {
|
|
|
|
|
sails.sockets.join(this.req, `board:${board.id}`);
|
2022-06-24 11:59:04 +02:00
|
|
|
}
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
return {
|
2019-08-31 04:07:25 +05:00
|
|
|
item: board,
|
|
|
|
|
included: {
|
2021-06-24 01:05:22 +05:00
|
|
|
boardMemberships,
|
2019-08-31 04:07:25 +05:00
|
|
|
labels,
|
2020-08-04 01:32:46 +05:00
|
|
|
lists,
|
2019-08-31 04:07:25 +05:00
|
|
|
cards,
|
|
|
|
|
cardMemberships,
|
|
|
|
|
cardLabels,
|
2025-05-10 02:09:06 +02:00
|
|
|
taskLists,
|
2019-11-05 18:01:42 +05:00
|
|
|
tasks,
|
2025-05-10 02:09:06 +02:00
|
|
|
customFieldGroups,
|
|
|
|
|
customFields,
|
|
|
|
|
customFieldValues,
|
|
|
|
|
users: sails.helpers.users.presentMany(users, currentUser),
|
2021-06-24 01:05:22 +05:00
|
|
|
projects: [project],
|
2025-05-10 02:09:06 +02:00
|
|
|
attachments: sails.helpers.attachments.presentMany(attachments),
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2021-06-24 01:05:22 +05:00
|
|
|
};
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|