1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-24 07:39:44 +02:00

feat: Version 2

Closes #627, closes #1047
This commit is contained in:
Maksim Eltyshev 2025-05-10 02:09:06 +02:00
parent ad7fb51cfa
commit 2ee1166747
1557 changed files with 76832 additions and 47042 deletions

View file

@ -0,0 +1,75 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
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,
};
},
};

View file

@ -1,3 +1,10 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
const { idInput } = require('../../../utils/inputs');
const Errors = {
NOT_ENOUGH_RIGHTS: {
notEnoughRights: 'Not enough rights',
@ -10,16 +17,22 @@ const Errors = {
module.exports = {
inputs: {
boardId: {
...idInput,
required: true,
},
type: {
type: 'string',
regex: /^[0-9]+$/,
isIn: List.FINITE_TYPES,
required: true,
},
position: {
type: 'number',
min: 0,
required: true,
},
name: {
type: 'string',
maxLength: 128,
required: true,
},
},
@ -37,13 +50,13 @@ module.exports = {
const { currentUser } = this.req;
const { board, project } = await sails.helpers.boards
.getProjectPath(inputs.boardId)
.getPathToProjectById(inputs.boardId)
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND);
const boardMembership = await BoardMembership.findOne({
boardId: board.id,
userId: currentUser.id,
});
const boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
board.id,
currentUser.id,
);
if (!boardMembership) {
throw Errors.BOARD_NOT_FOUND; // Forbidden
@ -53,7 +66,7 @@ module.exports = {
throw Errors.NOT_ENOUGH_RIGHTS;
}
const values = _.pick(inputs, ['position', 'name']);
const values = _.pick(inputs, ['type', 'position', 'name']);
const list = await sails.helpers.lists.createOne.with({
project,

View file

@ -1,3 +1,10 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
const { idInput } = require('../../../utils/inputs');
const Errors = {
NOT_ENOUGH_RIGHTS: {
notEnoughRights: 'Not enough rights',
@ -10,8 +17,7 @@ const Errors = {
module.exports = {
inputs: {
id: {
type: 'string',
regex: /^[0-9]+$/,
...idInput,
required: true,
},
},
@ -28,27 +34,31 @@ module.exports = {
async fn(inputs) {
const { currentUser } = this.req;
const path = await sails.helpers.lists
.getProjectPath(inputs.id)
const pathToProject = await sails.helpers.lists
.getPathToProjectById(inputs.id)
.intercept('pathNotFound', () => Errors.LIST_NOT_FOUND);
let { list } = path;
const { board, project } = path;
let { list } = pathToProject;
const { board, project } = pathToProject;
const boardMembership = await BoardMembership.findOne({
boardId: board.id,
userId: currentUser.id,
});
const boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
board.id,
currentUser.id,
);
if (!boardMembership) {
throw Errors.LIST_NOT_FOUND; // Forbidden
}
if (!sails.helpers.lists.isFinite(list)) {
throw Errors.NOT_ENOUGH_RIGHTS;
}
if (boardMembership.role !== BoardMembership.Roles.EDITOR) {
throw Errors.NOT_ENOUGH_RIGHTS;
}
list = await sails.helpers.lists.deleteOne.with({
const result = await sails.helpers.lists.deleteOne.with({
project,
board,
record: list,
@ -56,12 +66,18 @@ module.exports = {
request: this.req,
});
({ list } = result);
const { cards } = result;
if (!list) {
throw Errors.LIST_NOT_FOUND;
}
return {
item: list,
included: {
cards,
},
};
},
};

View file

@ -0,0 +1,95 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
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,
},
};
},
};

View file

@ -0,0 +1,112 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
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),
},
};
},
};

View file

@ -1,3 +1,10 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
const { idInput } = require('../../../utils/inputs');
const Errors = {
NOT_ENOUGH_RIGHTS: {
notEnoughRights: 'Not enough rights',
@ -5,18 +12,25 @@ const Errors = {
LIST_NOT_FOUND: {
listNotFound: 'List not found',
},
CANNOT_BE_SORTED_AS_ENDLESS_LIST: {
cannotBeSortedAsEndlessList: 'Cannot be sorted as endless list',
},
};
module.exports = {
inputs: {
id: {
type: 'string',
regex: /^[0-9]+$/,
...idInput,
required: true,
},
type: {
fieldName: {
type: 'string',
isIn: Object.values(List.SortTypes),
isIn: Object.values(List.SortFieldNames),
required: true,
},
order: {
type: 'string',
isIn: Object.values(List.SortOrders),
},
},
@ -27,36 +41,43 @@ module.exports = {
listNotFound: {
responseType: 'notFound',
},
cannotBeSortedAsEndlessList: {
responseType: 'unprocessableEntity',
},
},
async fn(inputs) {
const { currentUser } = this.req;
const { list, board, project } = await sails.helpers.lists
.getProjectPath(inputs.id)
.getPathToProjectById(inputs.id)
.intercept('pathNotFound', () => Errors.LIST_NOT_FOUND);
const boardMembership = await BoardMembership.findOne({
boardId: board.id,
userId: currentUser.id,
});
const boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
board.id,
currentUser.id,
);
if (!boardMembership) {
throw Errors.LIST_NOT_FOUND;
throw Errors.LIST_NOT_FOUND; // Forbidden
}
if (boardMembership.role !== BoardMembership.Roles.EDITOR) {
throw Errors.NOT_ENOUGH_RIGHTS;
}
const cards = await sails.helpers.lists.sortOne.with({
project,
board,
record: list,
type: inputs.type,
actorUser: currentUser,
request: this.req,
});
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,

View file

@ -1,3 +1,10 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
const { idInput } = require('../../../utils/inputs');
const Errors = {
NOT_ENOUGH_RIGHTS: {
notEnoughRights: 'Not enough rights',
@ -10,16 +17,21 @@ const Errors = {
module.exports = {
inputs: {
id: {
type: 'string',
regex: /^[0-9]+$/,
...idInput,
required: true,
},
type: {
type: 'string',
isIn: List.FINITE_TYPES,
},
position: {
type: 'number',
min: 0,
},
name: {
type: 'string',
isNotEmptyString: true,
maxLength: 128,
},
color: {
type: 'string',
@ -40,27 +52,31 @@ module.exports = {
async fn(inputs) {
const { currentUser } = this.req;
const path = await sails.helpers.lists
.getProjectPath(inputs.id)
const pathToProject = await sails.helpers.lists
.getPathToProjectById(inputs.id)
.intercept('pathNotFound', () => Errors.LIST_NOT_FOUND);
let { list } = path;
const { board, project } = path;
let { list } = pathToProject;
const { board, project } = pathToProject;
const boardMembership = await BoardMembership.findOne({
boardId: board.id,
userId: currentUser.id,
});
const boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
board.id,
currentUser.id,
);
if (!boardMembership) {
throw Errors.LIST_NOT_FOUND; // Forbidden
}
if (!sails.helpers.lists.isFinite(list)) {
throw Errors.NOT_ENOUGH_RIGHTS;
}
if (boardMembership.role !== BoardMembership.Roles.EDITOR) {
throw Errors.NOT_ENOUGH_RIGHTS;
}
const values = _.pick(inputs, ['position', 'name', 'color']);
const values = _.pick(inputs, ['type', 'position', 'name', 'color']);
list = await sails.helpers.lists.updateOne.with({
values,