import Planka upstream
This commit is contained in:
+221
@@ -0,0 +1,221 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /lists/{listId}/cards:
|
||||
* post:
|
||||
* summary: Create card
|
||||
* description: Creates a card within a list. Requires board editor permissions.
|
||||
* tags:
|
||||
* - Cards
|
||||
* operationId: createCard
|
||||
* parameters:
|
||||
* - name: listId
|
||||
* in: path
|
||||
* required: true
|
||||
* description: ID of the list to create the card in
|
||||
* schema:
|
||||
* type: string
|
||||
* example: "1357158568008091264"
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - type
|
||||
* - name
|
||||
* properties:
|
||||
* type:
|
||||
* type: string
|
||||
* enum: [project, story]
|
||||
* description: Type of the card
|
||||
* example: project
|
||||
* position:
|
||||
* type: number
|
||||
* minimum: 0
|
||||
* nullable: true
|
||||
* description: Position of the card within the list
|
||||
* example: 65536
|
||||
* name:
|
||||
* type: string
|
||||
* maxLength: 1024
|
||||
* description: Name/title of the card
|
||||
* example: Implement user authentication
|
||||
* description:
|
||||
* type: string
|
||||
* maxLength: 1048576
|
||||
* nullable: true
|
||||
* description: Detailed description of the card
|
||||
* example: Add JWT-based authentication system...
|
||||
* dueDate:
|
||||
* type: string
|
||||
* format: date-time
|
||||
* description: Due date for the card
|
||||
* example: 2024-01-01T00:00:00.000Z
|
||||
* isDueCompleted:
|
||||
* type: boolean
|
||||
* nullable: true
|
||||
* description: Whether the due date is completed
|
||||
* example: false
|
||||
* stopwatch:
|
||||
* type: object
|
||||
* required:
|
||||
* - startedAt
|
||||
* - total
|
||||
* nullable: true
|
||||
* description: Stopwatch data for time tracking
|
||||
* properties:
|
||||
* startedAt:
|
||||
* type: string
|
||||
* format: date-time
|
||||
* description: When the stopwatch was started
|
||||
* example: 2024-01-01T00:00:00.000Z
|
||||
* total:
|
||||
* type: number
|
||||
* description: Total time in seconds
|
||||
* example: 3600
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Card created successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - item
|
||||
* properties:
|
||||
* item:
|
||||
* $ref: '#/components/schemas/Card'
|
||||
* 400:
|
||||
* $ref: '#/components/responses/ValidationError'
|
||||
* 401:
|
||||
* $ref: '#/components/responses/Unauthorized'
|
||||
* 403:
|
||||
* $ref: '#/components/responses/Forbidden'
|
||||
* 404:
|
||||
* $ref: '#/components/responses/NotFound'
|
||||
* 422:
|
||||
* $ref: '#/components/responses/UnprocessableEntity'
|
||||
*/
|
||||
|
||||
const { isDueDate, isStopwatch } = require('../../../utils/validators');
|
||||
const { idInput } = require('../../../utils/inputs');
|
||||
|
||||
const Errors = {
|
||||
NOT_ENOUGH_RIGHTS: {
|
||||
notEnoughRights: 'Not enough rights',
|
||||
},
|
||||
LIST_NOT_FOUND: {
|
||||
listNotFound: 'List not found',
|
||||
},
|
||||
POSITION_MUST_BE_PRESENT: {
|
||||
positionMustBePresent: 'Position must be present',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
listId: {
|
||||
...idInput,
|
||||
required: true,
|
||||
},
|
||||
type: {
|
||||
type: 'string',
|
||||
isIn: Object.values(Card.Types),
|
||||
required: true,
|
||||
},
|
||||
position: {
|
||||
type: 'number',
|
||||
min: 0,
|
||||
allowNull: true,
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
maxLength: 1024,
|
||||
required: true,
|
||||
},
|
||||
description: {
|
||||
type: 'string',
|
||||
isNotEmptyString: true,
|
||||
maxLength: 1048576,
|
||||
allowNull: true,
|
||||
},
|
||||
dueDate: {
|
||||
type: 'string',
|
||||
custom: isDueDate,
|
||||
},
|
||||
isDueCompleted: {
|
||||
type: 'boolean',
|
||||
allowNull: true,
|
||||
},
|
||||
stopwatch: {
|
||||
type: 'json',
|
||||
custom: isStopwatch,
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
notEnoughRights: {
|
||||
responseType: 'forbidden',
|
||||
},
|
||||
listNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
positionMustBePresent: {
|
||||
responseType: 'unprocessableEntity',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { list, board, project } = await sails.helpers.lists
|
||||
.getPathToProjectById(inputs.listId)
|
||||
.intercept('pathNotFound', () => Errors.LIST_NOT_FOUND);
|
||||
|
||||
const boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
|
||||
board.id,
|
||||
currentUser.id,
|
||||
);
|
||||
|
||||
if (!boardMembership) {
|
||||
throw Errors.LIST_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
if (boardMembership.role !== BoardMembership.Roles.EDITOR) {
|
||||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, [
|
||||
'type',
|
||||
'position',
|
||||
'name',
|
||||
'description',
|
||||
'dueDate',
|
||||
'isDueCompleted',
|
||||
'stopwatch',
|
||||
]);
|
||||
|
||||
const card = await sails.helpers.cards.createOne
|
||||
.with({
|
||||
project,
|
||||
values: {
|
||||
...values,
|
||||
board,
|
||||
list,
|
||||
creatorUser: currentUser,
|
||||
},
|
||||
request: this.req,
|
||||
})
|
||||
.intercept('positionMustBeInValues', () => Errors.POSITION_MUST_BE_PRESENT);
|
||||
|
||||
return {
|
||||
item: card,
|
||||
};
|
||||
},
|
||||
};
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /cards/{id}:
|
||||
* delete:
|
||||
* summary: Delete card
|
||||
* description: Deletes a card and all its contents (tasks, attachments, etc.). Requires board editor permissions.
|
||||
* tags:
|
||||
* - Cards
|
||||
* operationId: deleteCard
|
||||
* parameters:
|
||||
* - name: id
|
||||
* in: path
|
||||
* required: true
|
||||
* description: ID of the card to delete
|
||||
* schema:
|
||||
* type: string
|
||||
* example: "1357158568008091264"
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Card deleted successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - item
|
||||
* properties:
|
||||
* item:
|
||||
* $ref: '#/components/schemas/Card'
|
||||
* 400:
|
||||
* $ref: '#/components/responses/ValidationError'
|
||||
* 401:
|
||||
* $ref: '#/components/responses/Unauthorized'
|
||||
* 403:
|
||||
* $ref: '#/components/responses/Forbidden'
|
||||
* 404:
|
||||
* $ref: '#/components/responses/NotFound'
|
||||
*/
|
||||
|
||||
const { idInput } = require('../../../utils/inputs');
|
||||
|
||||
const Errors = {
|
||||
NOT_ENOUGH_RIGHTS: {
|
||||
notEnoughRights: 'Not enough rights',
|
||||
},
|
||||
CARD_NOT_FOUND: {
|
||||
cardNotFound: 'Card not found',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
...idInput,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
notEnoughRights: {
|
||||
responseType: 'forbidden',
|
||||
},
|
||||
cardNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const pathToProject = await sails.helpers.cards
|
||||
.getPathToProjectById(inputs.id)
|
||||
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
|
||||
|
||||
let { card } = pathToProject;
|
||||
const { list, board, project } = pathToProject;
|
||||
|
||||
const boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
|
||||
board.id,
|
||||
currentUser.id,
|
||||
);
|
||||
|
||||
if (!boardMembership) {
|
||||
throw Errors.CARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
if (boardMembership.role !== BoardMembership.Roles.EDITOR) {
|
||||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
}
|
||||
|
||||
card = await sails.helpers.cards.deleteOne.with({
|
||||
project,
|
||||
board,
|
||||
list,
|
||||
record: card,
|
||||
actorUser: currentUser,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
if (!card) {
|
||||
throw Errors.CARD_NOT_FOUND;
|
||||
}
|
||||
|
||||
return {
|
||||
item: card,
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,296 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /cards/{id}/duplicate:
|
||||
* post:
|
||||
* summary: Duplicate card
|
||||
* description: Creates a duplicate of a card with all its contents (tasks, attachments, etc.). Requires board editor permissions.
|
||||
* tags:
|
||||
* - Cards
|
||||
* operationId: duplicateCard
|
||||
* parameters:
|
||||
* - name: id
|
||||
* in: path
|
||||
* required: true
|
||||
* description: ID of the card to duplicate
|
||||
* schema:
|
||||
* type: string
|
||||
* example: "1357158568008091264"
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* boardId:
|
||||
* type: string
|
||||
* description: ID of the board to duplicate the card to
|
||||
* example: "1357158568008091265"
|
||||
* listId:
|
||||
* type: string
|
||||
* description: ID of the list to duplicate the card to
|
||||
* example: "1357158568008091266"
|
||||
* position:
|
||||
* type: number
|
||||
* minimum: 0
|
||||
* nullable: true
|
||||
* description: Position for the duplicated card within the list
|
||||
* example: 65536
|
||||
* name:
|
||||
* type: string
|
||||
* maxLength: 1024
|
||||
* nullable: true
|
||||
* description: Name/title for the duplicated card
|
||||
* example: Implement user authentication (copy)
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Card duplicated successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - item
|
||||
* - included
|
||||
* properties:
|
||||
* item:
|
||||
* $ref: '#/components/schemas/Card'
|
||||
* included:
|
||||
* type: object
|
||||
* required:
|
||||
* - cardMemberships
|
||||
* - cardLabels
|
||||
* - taskLists
|
||||
* - tasks
|
||||
* - attachments
|
||||
* - customFieldGroups
|
||||
* - customFields
|
||||
* - customFieldValues
|
||||
* properties:
|
||||
* 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'
|
||||
* 403:
|
||||
* $ref: '#/components/responses/Forbidden'
|
||||
* 404:
|
||||
* $ref: '#/components/responses/NotFound'
|
||||
* 422:
|
||||
* $ref: '#/components/responses/UnprocessableEntity'
|
||||
*/
|
||||
|
||||
const { idInput } = require('../../../utils/inputs');
|
||||
|
||||
const Errors = {
|
||||
NOT_ENOUGH_RIGHTS: {
|
||||
notEnoughRights: 'Not enough rights',
|
||||
},
|
||||
CARD_NOT_FOUND: {
|
||||
cardNotFound: 'Card not found',
|
||||
},
|
||||
BOARD_NOT_FOUND: {
|
||||
boardNotFound: 'Board not found',
|
||||
},
|
||||
LIST_NOT_FOUND: {
|
||||
listNotFound: 'List not found',
|
||||
},
|
||||
LIST_MUST_BE_PRESENT: {
|
||||
listMustBePresent: 'List must be present',
|
||||
},
|
||||
POSITION_MUST_BE_PRESENT: {
|
||||
positionMustBePresent: 'Position must be present',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
...idInput,
|
||||
required: true,
|
||||
},
|
||||
boardId: idInput,
|
||||
listId: idInput,
|
||||
position: {
|
||||
type: 'number',
|
||||
min: 0,
|
||||
allowNull: true,
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
maxLength: 1024,
|
||||
allowNull: true,
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
notEnoughRights: {
|
||||
responseType: 'forbidden',
|
||||
},
|
||||
cardNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
boardNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
listNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
listMustBePresent: {
|
||||
responseType: 'unprocessableEntity',
|
||||
},
|
||||
positionMustBePresent: {
|
||||
responseType: 'unprocessableEntity',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { card, list, board, project } = await sails.helpers.cards
|
||||
.getPathToProjectById(inputs.id)
|
||||
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
|
||||
|
||||
const isProjectManager = await sails.helpers.users.isProjectManager(currentUser.id, project.id);
|
||||
|
||||
let boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
|
||||
board.id,
|
||||
currentUser.id,
|
||||
);
|
||||
|
||||
if (!isProjectManager) {
|
||||
if (!boardMembership) {
|
||||
throw Errors.CARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
if (boardMembership.role !== BoardMembership.Roles.EDITOR) {
|
||||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
}
|
||||
}
|
||||
|
||||
let nextProject;
|
||||
let nextBoard;
|
||||
|
||||
if (!_.isUndefined(inputs.boardId)) {
|
||||
({ board: nextBoard, project: nextProject } = await sails.helpers.boards
|
||||
.getPathToProjectById(inputs.boardId)
|
||||
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND));
|
||||
|
||||
boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
|
||||
nextBoard.id,
|
||||
currentUser.id,
|
||||
);
|
||||
|
||||
if (!boardMembership) {
|
||||
throw Errors.BOARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
}
|
||||
|
||||
if (!boardMembership) {
|
||||
throw Errors.LIST_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
if (boardMembership.role !== BoardMembership.Roles.EDITOR) {
|
||||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
}
|
||||
|
||||
let nextList;
|
||||
if (!_.isUndefined(inputs.listId)) {
|
||||
nextList = await List.qm.getOneById(inputs.listId, {
|
||||
boardId: (nextBoard || board).id,
|
||||
});
|
||||
|
||||
if (!nextList) {
|
||||
throw Errors.LIST_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, ['position', 'name']);
|
||||
|
||||
const {
|
||||
card: nextCard,
|
||||
cardMemberships,
|
||||
cardLabels,
|
||||
taskLists,
|
||||
tasks,
|
||||
attachments,
|
||||
customFieldGroups,
|
||||
customFields,
|
||||
customFieldValues,
|
||||
} = await sails.helpers.cards.duplicateOne
|
||||
.with({
|
||||
project,
|
||||
board,
|
||||
list,
|
||||
record: card,
|
||||
values: {
|
||||
...values,
|
||||
project: nextProject,
|
||||
board: nextBoard,
|
||||
list: nextList,
|
||||
creatorUser: currentUser,
|
||||
},
|
||||
request: this.req,
|
||||
})
|
||||
.intercept('positionMustBeInValues', () => Errors.POSITION_MUST_BE_PRESENT)
|
||||
.intercept('listMustBeInValues', () => Errors.LIST_MUST_BE_PRESENT);
|
||||
|
||||
return {
|
||||
item: nextCard,
|
||||
included: {
|
||||
cardMemberships,
|
||||
cardLabels,
|
||||
taskLists,
|
||||
tasks,
|
||||
customFieldGroups,
|
||||
customFields,
|
||||
customFieldValues,
|
||||
attachments: sails.helpers.attachments.presentMany(attachments),
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,306 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /lists/{listId}/cards:
|
||||
* get:
|
||||
* summary: Get cards in list
|
||||
* description: Retrieves cards from an endless list with filtering, search, and pagination support.
|
||||
* tags:
|
||||
* - Cards
|
||||
* operationId: getCards
|
||||
* parameters:
|
||||
* - name: listId
|
||||
* in: path
|
||||
* required: true
|
||||
* description: ID of the list to get cards from (must be an endless list)
|
||||
* schema:
|
||||
* type: string
|
||||
* example: "1357158568008091264"
|
||||
* - name: before[listChangedAt]
|
||||
* in: query
|
||||
* required: false
|
||||
* description: Pagination cursor field `listChangedAt` (use together with `before[id]`)
|
||||
* schema:
|
||||
* type: string
|
||||
* format: date-time
|
||||
* example: 2024-01-01T00:00:00.000Z
|
||||
* - name: before[id]
|
||||
* in: query
|
||||
* required: false
|
||||
* description: Pagination cursor field `id` (use together with `before[listChangedAt]`)
|
||||
* schema:
|
||||
* type: string
|
||||
* example: "1357158568008091265"
|
||||
* - name: search
|
||||
* in: query
|
||||
* required: false
|
||||
* description: Search term to filter cards
|
||||
* schema:
|
||||
* type: string
|
||||
* maxLength: 128
|
||||
* example: bug fix
|
||||
* - name: userIds
|
||||
* in: query
|
||||
* required: false
|
||||
* description: Comma-separated user IDs to filter by members or task assignees
|
||||
* schema:
|
||||
* type: string
|
||||
* example: 1357158568008091266,1357158568008091267
|
||||
* - name: labelIds
|
||||
* in: query
|
||||
* required: false
|
||||
* description: Comma-separated label IDs to filter by labels
|
||||
* schema:
|
||||
* type: string
|
||||
* example: 1357158568008091268,1357158568008091269
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Cards retrieved successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - items
|
||||
* - included
|
||||
* properties:
|
||||
* items:
|
||||
* type: array
|
||||
* items:
|
||||
* allOf:
|
||||
* - $ref: '#/components/schemas/Card'
|
||||
* - type: object
|
||||
* properties:
|
||||
* isSubscribed:
|
||||
* type: boolean
|
||||
* description: Whether the current user is subscribed to the card
|
||||
* example: true
|
||||
* included:
|
||||
* type: object
|
||||
* required:
|
||||
* - users
|
||||
* - cardMemberships
|
||||
* - cardLabels
|
||||
* - taskLists
|
||||
* - tasks
|
||||
* - attachments
|
||||
* - customFieldGroups
|
||||
* - customFields
|
||||
* - customFieldValues
|
||||
* properties:
|
||||
* users:
|
||||
* type: array
|
||||
* description: Related users
|
||||
* items:
|
||||
* $ref: '#/components/schemas/User'
|
||||
* 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: Realted 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'
|
||||
*/
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
const { isId } = require('../../../utils/validators');
|
||||
const { idInput, idsInput } = require('../../../utils/inputs');
|
||||
|
||||
const Errors = {
|
||||
LIST_NOT_FOUND: {
|
||||
listNotFound: 'List not found',
|
||||
},
|
||||
};
|
||||
|
||||
const isBefore = (value) => {
|
||||
if (!_.isPlainObject(value) || _.size(value) !== 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!moment(value.listChangedAt, moment.ISO_8601, true).isValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isId(value.id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
listId: {
|
||||
...idInput,
|
||||
required: true,
|
||||
},
|
||||
before: {
|
||||
type: 'json',
|
||||
custom: isBefore,
|
||||
},
|
||||
search: {
|
||||
type: 'string',
|
||||
isNotEmptyString: true,
|
||||
maxLength: 128,
|
||||
},
|
||||
userIds: idsInput,
|
||||
labelIds: idsInput,
|
||||
},
|
||||
|
||||
exits: {
|
||||
listNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { list, project } = await sails.helpers.lists
|
||||
.getPathToProjectById(inputs.listId)
|
||||
.intercept('pathNotFound', () => Errors.LIST_NOT_FOUND);
|
||||
|
||||
if (currentUser.role !== User.Roles.ADMIN || project.ownerProjectManagerId) {
|
||||
const isProjectManager = await sails.helpers.users.isProjectManager(
|
||||
currentUser.id,
|
||||
project.id,
|
||||
);
|
||||
|
||||
if (!isProjectManager) {
|
||||
const boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
|
||||
list.boardId,
|
||||
currentUser.id,
|
||||
);
|
||||
|
||||
if (!boardMembership) {
|
||||
throw Errors.LIST_NOT_FOUND; // Forbidden
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let filterUserIds;
|
||||
if (inputs.userIds) {
|
||||
const boardMemberships = await BoardMembership.qm.getByBoardId(list.boardId);
|
||||
|
||||
const availableUserIdsSet = new Set(
|
||||
sails.helpers.utils.mapRecords(boardMemberships, 'userId'),
|
||||
);
|
||||
|
||||
filterUserIds = _.uniq(inputs.userIds.split(','));
|
||||
filterUserIds = filterUserIds.filter((userId) => availableUserIdsSet.has(userId));
|
||||
}
|
||||
|
||||
let filterLabelIds;
|
||||
if (inputs.labelIds) {
|
||||
const labels = await Label.qm.getByBoardId(list.boardId);
|
||||
const availableLabelIdsSet = new Set(sails.helpers.utils.mapRecords(labels));
|
||||
|
||||
filterLabelIds = _.uniq(inputs.labelIds.split(','));
|
||||
filterLabelIds = filterLabelIds.filter((labelId) => availableLabelIdsSet.has(labelId));
|
||||
}
|
||||
|
||||
const cards = await Card.qm.getByEndlessListId(list.id, {
|
||||
before: inputs.before,
|
||||
search: inputs.search,
|
||||
userIds: filterUserIds,
|
||||
labelIds: filterLabelIds,
|
||||
});
|
||||
|
||||
const cardIds = sails.helpers.utils.mapRecords(cards);
|
||||
|
||||
const userIds = sails.helpers.utils.mapRecords(cards, 'creatorUserId', true, true);
|
||||
const users = await User.qm.getByIds(userIds);
|
||||
|
||||
const cardSubscriptions = await CardSubscription.qm.getByCardIdsAndUserId(
|
||||
cardIds,
|
||||
currentUser.id,
|
||||
);
|
||||
|
||||
const cardMemberships = await CardMembership.qm.getByCardIds(cardIds);
|
||||
const cardLabels = await CardLabel.qm.getByCardIds(cardIds);
|
||||
|
||||
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 customFieldGroups = await CustomFieldGroup.qm.getByCardIds(cardIds);
|
||||
const customFieldGroupIds = sails.helpers.utils.mapRecords(customFieldGroups);
|
||||
|
||||
const customFields = await CustomField.qm.getByCustomFieldGroupIds(customFieldGroupIds);
|
||||
const customFieldValues = await CustomFieldValue.qm.getByCardIds(cardIds);
|
||||
|
||||
const isSubscribedByCardId = cardSubscriptions.reduce(
|
||||
(result, cardSubscription) => ({
|
||||
...result,
|
||||
[cardSubscription.cardId]: true,
|
||||
}),
|
||||
{},
|
||||
);
|
||||
|
||||
cards.forEach((card) => {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
card.isSubscribed = isSubscribedByCardId[card.id] || false;
|
||||
});
|
||||
|
||||
return {
|
||||
items: cards,
|
||||
included: {
|
||||
cardMemberships,
|
||||
cardLabels,
|
||||
taskLists,
|
||||
tasks,
|
||||
customFieldGroups,
|
||||
customFields,
|
||||
customFieldValues,
|
||||
users: sails.helpers.users.presentMany(users, currentUser),
|
||||
attachments: sails.helpers.attachments.presentMany(attachments),
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,114 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /cards/{id}/read-notifications:
|
||||
* post:
|
||||
* summary: Mark card notifications as read
|
||||
* description: Marks all notifications for a specific card as read for the current user. Requires access to the card.
|
||||
* tags:
|
||||
* - Cards
|
||||
* operationId: readCardNotifications
|
||||
* parameters:
|
||||
* - name: id
|
||||
* in: path
|
||||
* required: true
|
||||
* description: ID of the card to mark notifications as read for
|
||||
* schema:
|
||||
* type: string
|
||||
* example: "1357158568008091264"
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Notifications marked as read successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - item
|
||||
* - included
|
||||
* properties:
|
||||
* item:
|
||||
* $ref: '#/components/schemas/Card'
|
||||
* included:
|
||||
* type: object
|
||||
* required:
|
||||
* - notifications
|
||||
* properties:
|
||||
* notifications:
|
||||
* type: array
|
||||
* description: Related notifications
|
||||
* items:
|
||||
* $ref: '#/components/schemas/Notification'
|
||||
* 400:
|
||||
* $ref: '#/components/responses/ValidationError'
|
||||
* 401:
|
||||
* $ref: '#/components/responses/Unauthorized'
|
||||
* 404:
|
||||
* $ref: '#/components/responses/NotFound'
|
||||
*/
|
||||
|
||||
const { idInput } = require('../../../utils/inputs');
|
||||
|
||||
const Errors = {
|
||||
CARD_NOT_FOUND: {
|
||||
cardNotFound: 'Card not found',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
...idInput,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
cardNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { card, project } = await sails.helpers.cards
|
||||
.getPathToProjectById(inputs.id)
|
||||
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
|
||||
|
||||
if (currentUser.role !== User.Roles.ADMIN || project.ownerProjectManagerId) {
|
||||
const isProjectManager = await sails.helpers.users.isProjectManager(
|
||||
currentUser.id,
|
||||
project.id,
|
||||
);
|
||||
|
||||
if (!isProjectManager) {
|
||||
const boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
|
||||
card.boardId,
|
||||
currentUser.id,
|
||||
);
|
||||
|
||||
if (!boardMembership) {
|
||||
throw Errors.CARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const notifications = await sails.helpers.cards.readNotificationsForUser.with({
|
||||
record: card,
|
||||
user: currentUser,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
return {
|
||||
item: card,
|
||||
included: {
|
||||
notifications,
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
Executable
+189
@@ -0,0 +1,189 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /cards/{id}:
|
||||
* get:
|
||||
* summary: Get card details
|
||||
* description: Retrieves comprehensive card information, including tasks, attachments, and other related data.
|
||||
* tags:
|
||||
* - Cards
|
||||
* operationId: getCard
|
||||
* parameters:
|
||||
* - name: id
|
||||
* in: path
|
||||
* required: true
|
||||
* description: ID of the card to retrieve
|
||||
* schema:
|
||||
* type: string
|
||||
* example: "1357158568008091264"
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Card details retrieved successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - item
|
||||
* - included
|
||||
* properties:
|
||||
* item:
|
||||
* allOf:
|
||||
* - $ref: '#/components/schemas/Card'
|
||||
* - type: object
|
||||
* properties:
|
||||
* isSubscribed:
|
||||
* type: boolean
|
||||
* description: Whether the current user is subscribed to the card
|
||||
* example: true
|
||||
* included:
|
||||
* type: object
|
||||
* required:
|
||||
* - users
|
||||
* - cardMemberships
|
||||
* - cardLabels
|
||||
* - taskLists
|
||||
* - tasks
|
||||
* - attachments
|
||||
* - customFieldGroups
|
||||
* - customFields
|
||||
* - customFieldValues
|
||||
* properties:
|
||||
* users:
|
||||
* type: array
|
||||
* description: Related users
|
||||
* items:
|
||||
* $ref: '#/components/schemas/User'
|
||||
* 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'
|
||||
*/
|
||||
|
||||
const { idInput } = require('../../../utils/inputs');
|
||||
|
||||
const Errors = {
|
||||
CARD_NOT_FOUND: {
|
||||
cardNotFound: 'Card not found',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
...idInput,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
cardNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { card, project } = await sails.helpers.cards
|
||||
.getPathToProjectById(inputs.id)
|
||||
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
|
||||
|
||||
if (currentUser.role !== User.Roles.ADMIN || project.ownerProjectManagerId) {
|
||||
const isProjectManager = await sails.helpers.users.isProjectManager(
|
||||
currentUser.id,
|
||||
project.id,
|
||||
);
|
||||
|
||||
if (!isProjectManager) {
|
||||
const boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
|
||||
card.boardId,
|
||||
currentUser.id,
|
||||
);
|
||||
|
||||
if (!boardMembership) {
|
||||
throw Errors.CARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
card.isSubscribed = await sails.helpers.users.isCardSubscriber(currentUser.id, card.id);
|
||||
|
||||
const users = card.creatorUserId ? await User.qm.getByIds([card.creatorUserId]) : [];
|
||||
const cardMemberships = await CardMembership.qm.getByCardId(card.id);
|
||||
const cardLabels = await CardLabel.qm.getByCardId(card.id);
|
||||
|
||||
const taskLists = await TaskList.qm.getByCardId(card.id);
|
||||
const taskListIds = sails.helpers.utils.mapRecords(taskLists);
|
||||
|
||||
const tasks = await Task.qm.getByTaskListIds(taskListIds);
|
||||
const attachments = await Attachment.qm.getByCardId(card.id);
|
||||
|
||||
const customFieldGroups = await CustomFieldGroup.qm.getByCardId(card.id);
|
||||
const customFieldGroupIds = sails.helpers.utils.mapRecords(customFieldGroups);
|
||||
|
||||
const customFields = await CustomField.qm.getByCustomFieldGroupIds(customFieldGroupIds);
|
||||
const customFieldValues = await CustomFieldValue.qm.getByCardId(card.id);
|
||||
|
||||
return {
|
||||
item: card,
|
||||
included: {
|
||||
cardMemberships,
|
||||
cardLabels,
|
||||
taskLists,
|
||||
tasks,
|
||||
customFieldGroups,
|
||||
customFields,
|
||||
customFieldValues,
|
||||
users: sails.helpers.users.presentMany(users, currentUser),
|
||||
attachments: sails.helpers.attachments.presentMany(attachments),
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
+353
@@ -0,0 +1,353 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /cards/{id}:
|
||||
* patch:
|
||||
* summary: Update card
|
||||
* description: Updates a card. Board editors can update all fields, viewers can only subscribe/unsubscribe.
|
||||
* tags:
|
||||
* - Cards
|
||||
* operationId: updateCard
|
||||
* parameters:
|
||||
* - name: id
|
||||
* in: path
|
||||
* required: true
|
||||
* description: ID of the card to update
|
||||
* schema:
|
||||
* type: string
|
||||
* example: "1357158568008091264"
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* boardId:
|
||||
* type: string
|
||||
* description: ID of the board to move the card to
|
||||
* example: "1357158568008091265"
|
||||
* listId:
|
||||
* type: string
|
||||
* description: ID of the list to move the card to
|
||||
* example: "1357158568008091266"
|
||||
* coverAttachmentId:
|
||||
* type: string
|
||||
* nullable: true
|
||||
* description: ID of the attachment used as cover
|
||||
* example: "1357158568008091267"
|
||||
* type:
|
||||
* type: string
|
||||
* enum: [project, story]
|
||||
* description: Type of the card
|
||||
* example: project
|
||||
* position:
|
||||
* type: number
|
||||
* minimum: 0
|
||||
* nullable: true
|
||||
* description: Position of the card within the list (required when moving card to new list)
|
||||
* example: 65536
|
||||
* name:
|
||||
* type: string
|
||||
* maxLength: 1024
|
||||
* description: Name/title of the card
|
||||
* example: Implement user authentication
|
||||
* description:
|
||||
* type: string
|
||||
* maxLength: 1048576
|
||||
* nullable: true
|
||||
* description: Detailed description of the card
|
||||
* example: Add JWT-based authentication system...
|
||||
* dueDate:
|
||||
* type: string
|
||||
* format: date-time
|
||||
* nullable: true
|
||||
* description: Due date for the card
|
||||
* example: 2024-01-01T00:00:00.000Z
|
||||
* isDueCompleted:
|
||||
* type: boolean
|
||||
* nullable: true
|
||||
* description: Whether the due date is completed
|
||||
* example: false
|
||||
* stopwatch:
|
||||
* type: object
|
||||
* required:
|
||||
* - startedAt
|
||||
* - total
|
||||
* nullable: true
|
||||
* description: Stopwatch data for time tracking
|
||||
* properties:
|
||||
* startedAt:
|
||||
* type: string
|
||||
* format: date-time
|
||||
* description: When the stopwatch was started
|
||||
* example: 2024-01-01T00:00:00.000Z
|
||||
* total:
|
||||
* type: number
|
||||
* description: Total time in seconds
|
||||
* example: 3600
|
||||
* isSubscribed:
|
||||
* type: boolean
|
||||
* description: Whether the current user is subscribed to the card
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Card updated successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - item
|
||||
* properties:
|
||||
* item:
|
||||
* $ref: '#/components/schemas/Card'
|
||||
* 400:
|
||||
* $ref: '#/components/responses/ValidationError'
|
||||
* 401:
|
||||
* $ref: '#/components/responses/Unauthorized'
|
||||
* 403:
|
||||
* $ref: '#/components/responses/Forbidden'
|
||||
* 404:
|
||||
* $ref: '#/components/responses/NotFound'
|
||||
* 422:
|
||||
* $ref: '#/components/responses/UnprocessableEntity'
|
||||
*/
|
||||
|
||||
const { isDueDate, isStopwatch } = require('../../../utils/validators');
|
||||
const { idInput } = require('../../../utils/inputs');
|
||||
|
||||
const Errors = {
|
||||
NOT_ENOUGH_RIGHTS: {
|
||||
notEnoughRights: 'Not enough rights',
|
||||
},
|
||||
CARD_NOT_FOUND: {
|
||||
cardNotFound: 'Card not found',
|
||||
},
|
||||
BOARD_NOT_FOUND: {
|
||||
boardNotFound: 'Board not found',
|
||||
},
|
||||
LIST_NOT_FOUND: {
|
||||
listNotFound: 'List not found',
|
||||
},
|
||||
COVER_ATTACHMENT_NOT_FOUND: {
|
||||
coverAttachmentNotFound: 'Cover attachment not found',
|
||||
},
|
||||
LIST_MUST_BE_PRESENT: {
|
||||
listMustBePresent: 'List must be present',
|
||||
},
|
||||
COVER_ATTACHMENT_MUST_CONTAIN_IMAGE: {
|
||||
coverAttachmentMustContainImage: 'Cover attachment must contain image',
|
||||
},
|
||||
POSITION_MUST_BE_PRESENT: {
|
||||
positionMustBePresent: 'Position must be present',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
...idInput,
|
||||
required: true,
|
||||
},
|
||||
boardId: idInput,
|
||||
listId: idInput,
|
||||
coverAttachmentId: {
|
||||
...idInput,
|
||||
allowNull: true,
|
||||
},
|
||||
type: {
|
||||
type: 'string',
|
||||
isIn: Object.values(Card.Types),
|
||||
},
|
||||
position: {
|
||||
type: 'number',
|
||||
min: 0,
|
||||
allowNull: true,
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
isNotEmptyString: true,
|
||||
maxLength: 1024,
|
||||
},
|
||||
description: {
|
||||
type: 'string',
|
||||
isNotEmptyString: true,
|
||||
maxLength: 1048576,
|
||||
allowNull: true,
|
||||
},
|
||||
dueDate: {
|
||||
type: 'string',
|
||||
custom: isDueDate,
|
||||
allowNull: true,
|
||||
},
|
||||
isDueCompleted: {
|
||||
type: 'boolean',
|
||||
allowNull: true,
|
||||
},
|
||||
stopwatch: {
|
||||
type: 'json',
|
||||
custom: isStopwatch,
|
||||
},
|
||||
isSubscribed: {
|
||||
type: 'boolean',
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
notEnoughRights: {
|
||||
responseType: 'forbidden',
|
||||
},
|
||||
cardNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
boardNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
listNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
coverAttachmentNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
listMustBePresent: {
|
||||
responseType: 'unprocessableEntity',
|
||||
},
|
||||
coverAttachmentMustContainImage: {
|
||||
responseType: 'unprocessableEntity',
|
||||
},
|
||||
positionMustBePresent: {
|
||||
responseType: 'unprocessableEntity',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const pathToProject = await sails.helpers.cards
|
||||
.getPathToProjectById(inputs.id)
|
||||
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
|
||||
|
||||
let { card } = pathToProject;
|
||||
const { list, board, project } = pathToProject;
|
||||
|
||||
let boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
|
||||
board.id,
|
||||
currentUser.id,
|
||||
);
|
||||
|
||||
if (!boardMembership) {
|
||||
throw Errors.CARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
const availableInputKeys = ['id', 'isSubscribed'];
|
||||
if (boardMembership.role === BoardMembership.Roles.EDITOR) {
|
||||
availableInputKeys.push(
|
||||
'boardId',
|
||||
'listId',
|
||||
'coverAttachmentId',
|
||||
'type',
|
||||
'position',
|
||||
'name',
|
||||
'description',
|
||||
'dueDate',
|
||||
'isDueCompleted',
|
||||
'stopwatch',
|
||||
);
|
||||
}
|
||||
|
||||
if (_.difference(Object.keys(inputs), availableInputKeys).length > 0) {
|
||||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
}
|
||||
|
||||
let nextProject;
|
||||
let nextBoard;
|
||||
|
||||
if (!_.isUndefined(inputs.boardId)) {
|
||||
({ board: nextBoard, project: nextProject } = await sails.helpers.boards
|
||||
.getPathToProjectById(inputs.boardId)
|
||||
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND));
|
||||
|
||||
boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
|
||||
nextBoard.id,
|
||||
currentUser.id,
|
||||
);
|
||||
|
||||
if (!boardMembership) {
|
||||
throw Errors.BOARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
if (boardMembership.role !== BoardMembership.Roles.EDITOR) {
|
||||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
}
|
||||
}
|
||||
|
||||
let nextList;
|
||||
if (!_.isUndefined(inputs.listId)) {
|
||||
nextList = await List.qm.getOneById(inputs.listId, {
|
||||
boardId: (nextBoard || board).id,
|
||||
});
|
||||
|
||||
if (!nextList) {
|
||||
throw Errors.LIST_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
let nextCoverAttachment;
|
||||
if (inputs.coverAttachmentId) {
|
||||
nextCoverAttachment = await Attachment.qm.getOneById(inputs.coverAttachmentId, {
|
||||
cardId: card.id,
|
||||
});
|
||||
|
||||
if (!nextCoverAttachment || nextCoverAttachment.type !== Attachment.Types.FILE) {
|
||||
throw Errors.COVER_ATTACHMENT_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, [
|
||||
'coverAttachmentId',
|
||||
'type',
|
||||
'position',
|
||||
'name',
|
||||
'description',
|
||||
'dueDate',
|
||||
'isDueCompleted',
|
||||
'stopwatch',
|
||||
'isSubscribed',
|
||||
]);
|
||||
|
||||
card = await sails.helpers.cards.updateOne
|
||||
.with({
|
||||
project,
|
||||
board,
|
||||
list,
|
||||
record: card,
|
||||
values: {
|
||||
...values,
|
||||
project: nextProject,
|
||||
board: nextBoard,
|
||||
list: nextList,
|
||||
coverAttachment: nextCoverAttachment,
|
||||
},
|
||||
actorUser: currentUser,
|
||||
request: this.req,
|
||||
})
|
||||
.intercept('positionMustBeInValues', () => Errors.POSITION_MUST_BE_PRESENT)
|
||||
.intercept('listMustBeInValues', () => Errors.LIST_MUST_BE_PRESENT)
|
||||
.intercept(
|
||||
'coverAttachmentInValuesMustContainImage',
|
||||
() => Errors.COVER_ATTACHMENT_MUST_CONTAIN_IMAGE,
|
||||
);
|
||||
|
||||
if (!card) {
|
||||
throw Errors.CARD_NOT_FOUND;
|
||||
}
|
||||
|
||||
return {
|
||||
item: card,
|
||||
};
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user