import Planka upstream
This commit is contained in:
@@ -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
|
||||
* /lists/{id}/clear:
|
||||
* post:
|
||||
* summary: Clear list
|
||||
* description: Deletes all cards from a list. Only works with trash-type lists. Requires project manager or board editor permissions.
|
||||
* tags:
|
||||
* - Lists
|
||||
* operationId: clearList
|
||||
* parameters:
|
||||
* - name: id
|
||||
* in: path
|
||||
* required: true
|
||||
* description: ID of the list to clear (must be a trash-type list)
|
||||
* schema:
|
||||
* type: string
|
||||
* example: "1357158568008091264"
|
||||
* responses:
|
||||
* 200:
|
||||
* description: List cleared successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - item
|
||||
* properties:
|
||||
* item:
|
||||
* $ref: '#/components/schemas/List'
|
||||
* 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',
|
||||
},
|
||||
LIST_NOT_FOUND: {
|
||||
listNotFound: 'List not found',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
...idInput,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
notEnoughRights: {
|
||||
responseType: 'forbidden',
|
||||
},
|
||||
listNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { list, board, project } = await sails.helpers.lists
|
||||
.getPathToProjectById(inputs.id)
|
||||
.intercept('pathNotFound', () => Errors.LIST_NOT_FOUND);
|
||||
|
||||
const isProjectManager = await sails.helpers.users.isProjectManager(currentUser.id, project.id);
|
||||
|
||||
if (!isProjectManager) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: allow for other types?
|
||||
if (list.type !== List.Types.TRASH) {
|
||||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
}
|
||||
|
||||
await sails.helpers.lists.clearOne.with({
|
||||
project,
|
||||
board,
|
||||
record: list,
|
||||
actorUser: currentUser,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
return {
|
||||
item: list,
|
||||
};
|
||||
},
|
||||
};
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /boards/{boardId}/lists:
|
||||
* post:
|
||||
* summary: Create list
|
||||
* description: Creates a list within a board. Requires board editor permissions.
|
||||
* tags:
|
||||
* - Lists
|
||||
* operationId: createList
|
||||
* parameters:
|
||||
* - name: boardId
|
||||
* in: path
|
||||
* required: true
|
||||
* description: ID of the board to create the list in
|
||||
* schema:
|
||||
* type: string
|
||||
* example: "1357158568008091264"
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - type
|
||||
* - position
|
||||
* - name
|
||||
* properties:
|
||||
* type:
|
||||
* type: string
|
||||
* enum: [active, closed]
|
||||
* description: Type/status of the list
|
||||
* example: active
|
||||
* position:
|
||||
* type: number
|
||||
* minimum: 0
|
||||
* description: Position of the list within the board
|
||||
* example: 65536
|
||||
* name:
|
||||
* type: string
|
||||
* maxLength: 128
|
||||
* description: Name/title of the list
|
||||
* example: To Do
|
||||
* responses:
|
||||
* 200:
|
||||
* description: List created successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - item
|
||||
* properties:
|
||||
* item:
|
||||
* $ref: '#/components/schemas/List'
|
||||
* 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',
|
||||
},
|
||||
BOARD_NOT_FOUND: {
|
||||
boardNotFound: 'Board not found',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
boardId: {
|
||||
...idInput,
|
||||
required: true,
|
||||
},
|
||||
type: {
|
||||
type: 'string',
|
||||
isIn: List.KANBAN_TYPES,
|
||||
required: true,
|
||||
},
|
||||
position: {
|
||||
type: 'number',
|
||||
min: 0,
|
||||
required: true,
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
maxLength: 128,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
notEnoughRights: {
|
||||
responseType: 'forbidden',
|
||||
},
|
||||
boardNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { board, project } = await sails.helpers.boards
|
||||
.getPathToProjectById(inputs.boardId)
|
||||
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND);
|
||||
|
||||
const boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
|
||||
board.id,
|
||||
currentUser.id,
|
||||
);
|
||||
|
||||
if (!boardMembership) {
|
||||
throw Errors.BOARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
if (boardMembership.role !== BoardMembership.Roles.EDITOR) {
|
||||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, ['type', 'position', 'name']);
|
||||
|
||||
const list = await sails.helpers.lists.createOne.with({
|
||||
project,
|
||||
values: {
|
||||
...values,
|
||||
board,
|
||||
},
|
||||
actorUser: currentUser,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
return {
|
||||
item: list,
|
||||
};
|
||||
},
|
||||
};
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /lists/{id}:
|
||||
* delete:
|
||||
* summary: Delete list
|
||||
* description: Deletes a list and moves its cards to a trash list. Can only delete finite lists. Requires board editor permissions.
|
||||
* tags:
|
||||
* - Lists
|
||||
* operationId: deleteList
|
||||
* parameters:
|
||||
* - name: id
|
||||
* in: path
|
||||
* required: true
|
||||
* description: ID of the list to delete
|
||||
* schema:
|
||||
* type: string
|
||||
* example: "1357158568008091264"
|
||||
* responses:
|
||||
* 200:
|
||||
* description: List deleted successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - item
|
||||
* - included
|
||||
* properties:
|
||||
* item:
|
||||
* $ref: '#/components/schemas/List'
|
||||
* included:
|
||||
* type: object
|
||||
* required:
|
||||
* - cards
|
||||
* properties:
|
||||
* cards:
|
||||
* type: array
|
||||
* description: Related cards
|
||||
* items:
|
||||
* $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',
|
||||
},
|
||||
LIST_NOT_FOUND: {
|
||||
listNotFound: 'List not found',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
...idInput,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
notEnoughRights: {
|
||||
responseType: 'forbidden',
|
||||
},
|
||||
listNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const pathToProject = await sails.helpers.lists
|
||||
.getPathToProjectById(inputs.id)
|
||||
.intercept('pathNotFound', () => Errors.LIST_NOT_FOUND);
|
||||
|
||||
let { list } = pathToProject;
|
||||
const { board, project } = pathToProject;
|
||||
|
||||
const boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
|
||||
board.id,
|
||||
currentUser.id,
|
||||
);
|
||||
|
||||
if (!boardMembership) {
|
||||
throw Errors.LIST_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
if (!sails.helpers.lists.isKanban(list)) {
|
||||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
}
|
||||
|
||||
if (boardMembership.role !== BoardMembership.Roles.EDITOR) {
|
||||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
}
|
||||
|
||||
const result = await sails.helpers.lists.deleteOne.with({
|
||||
project,
|
||||
board,
|
||||
record: list,
|
||||
actorUser: currentUser,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
({ list } = result);
|
||||
const { cards } = result;
|
||||
|
||||
if (!list) {
|
||||
throw Errors.LIST_NOT_FOUND;
|
||||
}
|
||||
|
||||
return {
|
||||
item: list,
|
||||
included: {
|
||||
cards,
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,164 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /lists/{id}/move-cards:
|
||||
* post:
|
||||
* summary: Move cards
|
||||
* description: Moves all cards from a closed list to an archive list. Requires board editor permissions.
|
||||
* tags:
|
||||
* - Lists
|
||||
* operationId: moveListCards
|
||||
* parameters:
|
||||
* - name: id
|
||||
* in: path
|
||||
* required: true
|
||||
* description: ID of the source list (must be a closed-type list)
|
||||
* schema:
|
||||
* type: string
|
||||
* example: "1357158568008091264"
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - listId
|
||||
* properties:
|
||||
* listId:
|
||||
* type: string
|
||||
* description: ID of the target list (must be an archive-type list)
|
||||
* example: "1357158568008091265"
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Cards moved successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - item
|
||||
* - included
|
||||
* properties:
|
||||
* item:
|
||||
* $ref: '#/components/schemas/List'
|
||||
* included:
|
||||
* type: object
|
||||
* required:
|
||||
* - cards
|
||||
* - actions
|
||||
* properties:
|
||||
* cards:
|
||||
* type: array
|
||||
* description: Related cards
|
||||
* items:
|
||||
* $ref: '#/components/schemas/Card'
|
||||
* actions:
|
||||
* type: array
|
||||
* description: Related actions
|
||||
* items:
|
||||
* $ref: '#/components/schemas/Action'
|
||||
* 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',
|
||||
},
|
||||
LIST_NOT_FOUND: {
|
||||
listNotFound: 'List not found',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
...idInput,
|
||||
required: true,
|
||||
},
|
||||
listId: {
|
||||
...idInput,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
notEnoughRights: {
|
||||
responseType: 'forbidden',
|
||||
},
|
||||
listNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { list, board, project } = await sails.helpers.lists
|
||||
.getPathToProjectById(inputs.id)
|
||||
.intercept('pathNotFound', () => Errors.LIST_NOT_FOUND);
|
||||
|
||||
const boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
|
||||
board.id,
|
||||
currentUser.id,
|
||||
);
|
||||
|
||||
if (!boardMembership) {
|
||||
throw Errors.LIST_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
// TODO: allow for other types?
|
||||
if (list.type !== List.Types.CLOSED) {
|
||||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
}
|
||||
|
||||
if (boardMembership.role !== BoardMembership.Roles.EDITOR) {
|
||||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
}
|
||||
|
||||
const nextList = await List.qm.getOneById(inputs.listId, {
|
||||
boardId: board.id,
|
||||
});
|
||||
|
||||
if (!nextList) {
|
||||
throw Errors.LIST_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
// TODO: allow for other types?
|
||||
if (nextList.type !== List.Types.ARCHIVE) {
|
||||
throw Errors.LIST_NOT_FOUND;
|
||||
}
|
||||
|
||||
const { cards, actions } = await sails.helpers.lists.moveCards.with({
|
||||
project,
|
||||
board,
|
||||
record: list,
|
||||
values: {
|
||||
list: nextList,
|
||||
},
|
||||
actorUser: currentUser,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
return {
|
||||
item: list,
|
||||
included: {
|
||||
cards,
|
||||
actions,
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -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/{id}:
|
||||
* get:
|
||||
* summary: Get list details
|
||||
* description: Retrieves comprehensive list information, including cards, attachments, and other related data. Requires access to the board.
|
||||
* tags:
|
||||
* - Lists
|
||||
* operationId: getList
|
||||
* parameters:
|
||||
* - name: id
|
||||
* in: path
|
||||
* required: true
|
||||
* description: ID of the list to retrieve
|
||||
* schema:
|
||||
* type: string
|
||||
* example: "1357158568008091264"
|
||||
* responses:
|
||||
* 200:
|
||||
* description: List details retrieved successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - item
|
||||
* - included
|
||||
* properties:
|
||||
* item:
|
||||
* $ref: '#/components/schemas/List'
|
||||
* included:
|
||||
* type: object
|
||||
* required:
|
||||
* - users
|
||||
* - cards
|
||||
* - cardMemberships
|
||||
* - cardLabels
|
||||
* - taskLists
|
||||
* - tasks
|
||||
* - attachments
|
||||
* - customFieldGroups
|
||||
* - customFields
|
||||
* - customFieldValues
|
||||
* properties:
|
||||
* users:
|
||||
* type: array
|
||||
* description: Related users
|
||||
* items:
|
||||
* $ref: '#/components/schemas/User'
|
||||
* 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'
|
||||
*/
|
||||
|
||||
const { idInput } = require('../../../utils/inputs');
|
||||
|
||||
const Errors = {
|
||||
LIST_NOT_FOUND: {
|
||||
listNotFound: 'List not found',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
...idInput,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
listNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { list, project } = await sails.helpers.lists
|
||||
.getPathToProjectById(inputs.id)
|
||||
.intercept('pathNotFound', () => Errors.LIST_NOT_FOUND);
|
||||
|
||||
if (!sails.helpers.lists.isFinite(list)) {
|
||||
throw 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const cards = await Card.qm.getByListId(list.id);
|
||||
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 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 cardSubscriptions = await CardSubscription.qm.getByCardIdsAndUserId(
|
||||
cardIds,
|
||||
currentUser.id,
|
||||
);
|
||||
|
||||
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 {
|
||||
item: list,
|
||||
included: {
|
||||
cards,
|
||||
cardMemberships,
|
||||
cardLabels,
|
||||
taskLists,
|
||||
tasks,
|
||||
customFieldGroups,
|
||||
customFields,
|
||||
customFieldValues,
|
||||
users: sails.helpers.users.presentMany(users, currentUser),
|
||||
attachments: sails.helpers.attachments.presentMany(attachments),
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,157 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /lists/{id}/sort:
|
||||
* post:
|
||||
* summary: Sort cards in list
|
||||
* description: Sorts all cards within a list. Requires board editor permissions.
|
||||
* tags:
|
||||
* - Lists
|
||||
* operationId: sortList
|
||||
* parameters:
|
||||
* - name: id
|
||||
* in: path
|
||||
* required: true
|
||||
* description: ID of the list to sort
|
||||
* schema:
|
||||
* type: string
|
||||
* example: "1357158568008091264"
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - fieldName
|
||||
* properties:
|
||||
* fieldName:
|
||||
* type: string
|
||||
* enum: [name, dueDate, createdAt]
|
||||
* description: Field to sort cards by
|
||||
* example: name
|
||||
* order:
|
||||
* type: string
|
||||
* enum: [asc, desc]
|
||||
* description: Sorting order
|
||||
* example: asc
|
||||
* responses:
|
||||
* 200:
|
||||
* description: List sorted successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - item
|
||||
* properties:
|
||||
* item:
|
||||
* $ref: '#/components/schemas/List'
|
||||
* included:
|
||||
* type: object
|
||||
* properties:
|
||||
* cards:
|
||||
* type: array
|
||||
* description: Related cards
|
||||
* items:
|
||||
* $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 { idInput } = require('../../../utils/inputs');
|
||||
|
||||
const Errors = {
|
||||
NOT_ENOUGH_RIGHTS: {
|
||||
notEnoughRights: 'Not enough rights',
|
||||
},
|
||||
LIST_NOT_FOUND: {
|
||||
listNotFound: 'List not found',
|
||||
},
|
||||
CANNOT_BE_SORTED_AS_ENDLESS_LIST: {
|
||||
cannotBeSortedAsEndlessList: 'Cannot be sorted as endless list',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
...idInput,
|
||||
required: true,
|
||||
},
|
||||
fieldName: {
|
||||
type: 'string',
|
||||
isIn: Object.values(List.SortFieldNames),
|
||||
required: true,
|
||||
},
|
||||
order: {
|
||||
type: 'string',
|
||||
isIn: Object.values(List.SortOrders),
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
notEnoughRights: {
|
||||
responseType: 'forbidden',
|
||||
},
|
||||
listNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
cannotBeSortedAsEndlessList: {
|
||||
responseType: 'unprocessableEntity',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { list, board, project } = await sails.helpers.lists
|
||||
.getPathToProjectById(inputs.id)
|
||||
.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 options = _.pick(inputs, ['fieldName', 'order']);
|
||||
|
||||
const cards = await sails.helpers.lists.sortOne
|
||||
.with({
|
||||
options,
|
||||
project,
|
||||
board,
|
||||
record: list,
|
||||
actorUser: currentUser,
|
||||
request: this.req,
|
||||
})
|
||||
.intercept('cannotBeSortedAsEndlessList', () => Errors.CANNOT_BE_SORTED_AS_ENDLESS_LIST);
|
||||
|
||||
return {
|
||||
item: list,
|
||||
included: {
|
||||
cards,
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
+202
@@ -0,0 +1,202 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /lists/{id}:
|
||||
* patch:
|
||||
* summary: Update list
|
||||
* description: Updates a list. Can move lists between boards. Requires board editor permissions.
|
||||
* tags:
|
||||
* - Lists
|
||||
* operationId: updateList
|
||||
* parameters:
|
||||
* - name: id
|
||||
* in: path
|
||||
* required: true
|
||||
* description: ID of the list 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 list to
|
||||
* example: "1357158568008091265"
|
||||
* type:
|
||||
* type: string
|
||||
* enum: [active, closed]
|
||||
* description: Type/status of the list
|
||||
* example: active
|
||||
* position:
|
||||
* type: number
|
||||
* minimum: 0
|
||||
* description: Position of the list within the board
|
||||
* example: 65536
|
||||
* name:
|
||||
* type: string
|
||||
* maxLength: 128
|
||||
* description: Name/title of the list
|
||||
* example: To Do
|
||||
* color:
|
||||
* type: string
|
||||
* enum: [berry-red, pumpkin-orange, lagoon-blue, pink-tulip, light-mud, orange-peel, bright-moss, antique-blue, dark-granite, turquoise-sea]
|
||||
* nullable: true
|
||||
* description: Color for the list
|
||||
* example: lagoon-blue
|
||||
* responses:
|
||||
* 200:
|
||||
* description: List updated successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - item
|
||||
* properties:
|
||||
* item:
|
||||
* $ref: '#/components/schemas/List'
|
||||
* 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',
|
||||
},
|
||||
LIST_NOT_FOUND: {
|
||||
listNotFound: 'List not found',
|
||||
},
|
||||
BOARD_NOT_FOUND: {
|
||||
boardNotFound: 'Board not found',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
...idInput,
|
||||
required: true,
|
||||
},
|
||||
boardId: idInput,
|
||||
type: {
|
||||
type: 'string',
|
||||
isIn: List.KANBAN_TYPES,
|
||||
},
|
||||
position: {
|
||||
type: 'number',
|
||||
min: 0,
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
isNotEmptyString: true,
|
||||
maxLength: 128,
|
||||
},
|
||||
color: {
|
||||
type: 'string',
|
||||
isIn: List.COLORS,
|
||||
allowNull: true,
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
notEnoughRights: {
|
||||
responseType: 'forbidden',
|
||||
},
|
||||
listNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
boardNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const pathToProject = await sails.helpers.lists
|
||||
.getPathToProjectById(inputs.id)
|
||||
.intercept('pathNotFound', () => Errors.LIST_NOT_FOUND);
|
||||
|
||||
let { list } = pathToProject;
|
||||
const { board, project } = pathToProject;
|
||||
|
||||
let boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
|
||||
board.id,
|
||||
currentUser.id,
|
||||
);
|
||||
|
||||
if (!boardMembership) {
|
||||
throw Errors.LIST_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
if (!sails.helpers.lists.isKanban(list)) {
|
||||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
}
|
||||
|
||||
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.role !== BoardMembership.Roles.EDITOR) {
|
||||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
}
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, ['type', 'position', 'name', 'color']);
|
||||
|
||||
list = await sails.helpers.lists.updateOne.with({
|
||||
project,
|
||||
board,
|
||||
record: list,
|
||||
values: {
|
||||
...values,
|
||||
project: nextProject,
|
||||
board: nextBoard,
|
||||
},
|
||||
actorUser: currentUser,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
if (!list) {
|
||||
throw Errors.LIST_NOT_FOUND;
|
||||
}
|
||||
|
||||
return {
|
||||
item: list,
|
||||
};
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user