1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 13:19: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

@ -1,25 +1,33 @@
/*!
* 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',
},
CARD_NOT_FOUND: {
cardNotFound: 'Card not found',
TASK_LIST_NOT_FOUND: {
taskListNotFound: 'Task list not found',
},
};
module.exports = {
inputs: {
cardId: {
type: 'string',
regex: /^[0-9]+$/,
taskListId: {
...idInput,
required: true,
},
position: {
type: 'number',
min: 0,
required: true,
},
name: {
type: 'string',
maxLength: 1024,
required: true,
},
isCompleted: {
@ -31,7 +39,7 @@ module.exports = {
notEnoughRights: {
responseType: 'forbidden',
},
cardNotFound: {
taskListNotFound: {
responseType: 'notFound',
},
},
@ -39,17 +47,17 @@ module.exports = {
async fn(inputs) {
const { currentUser } = this.req;
const { card, list, board, project } = await sails.helpers.cards
.getProjectPath(inputs.cardId)
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
const { taskList, card, list, board, project } = await sails.helpers.taskLists
.getPathToProjectById(inputs.taskListId)
.intercept('pathNotFound', () => Errors.TASK_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.CARD_NOT_FOUND; // Forbidden
throw Errors.TASK_LIST_NOT_FOUND; // Forbidden
}
if (boardMembership.role !== BoardMembership.Roles.EDITOR) {
@ -62,9 +70,10 @@ module.exports = {
project,
board,
list,
card,
values: {
...values,
card,
taskList,
},
actorUser: currentUser,
request: this.req,

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,17 +34,17 @@ module.exports = {
async fn(inputs) {
const { currentUser } = this.req;
const path = await sails.helpers.tasks
.getProjectPath(inputs.id)
const pathToProject = await sails.helpers.tasks
.getPathToProjectById(inputs.id)
.intercept('pathNotFound', () => Errors.TASK_NOT_FOUND);
let { task } = path;
const { card, list, board, project } = path;
let { task } = pathToProject;
const { taskList, card, list, 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.TASK_NOT_FOUND; // Forbidden
@ -53,6 +59,7 @@ module.exports = {
board,
list,
card,
taskList,
record: task,
actorUser: currentUser,
request: this.req,

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,21 +12,33 @@ const Errors = {
TASK_NOT_FOUND: {
taskNotFound: 'Task not found',
},
TASK_LIST_NOT_FOUND: {
taskListNotFound: 'Task list not found',
},
USER_NOT_FOUND: {
userNotFound: 'User not found',
},
};
module.exports = {
inputs: {
id: {
type: 'string',
regex: /^[0-9]+$/,
...idInput,
required: true,
},
taskListId: idInput,
assigneeUserId: {
...idInput,
allowNull: true,
},
position: {
type: 'number',
min: 0,
},
name: {
type: 'string',
isNotEmptyString: true,
maxLength: 1024,
},
isCompleted: {
type: 'boolean',
@ -33,22 +52,28 @@ module.exports = {
taskNotFound: {
responseType: 'notFound',
},
taskListNotFound: {
responseType: 'notFound',
},
userNotFound: {
responseType: 'notFound',
},
},
async fn(inputs) {
const { currentUser } = this.req;
const path = await sails.helpers.tasks
.getProjectPath(inputs.id)
const pathToProject = await sails.helpers.tasks
.getPathToProjectById(inputs.id)
.intercept('pathNotFound', () => Errors.TASK_NOT_FOUND);
let { task } = path;
const { card, list, board, project } = path;
let { task } = pathToProject;
const { taskList, card, list, 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.TASK_NOT_FOUND; // Forbidden
@ -58,15 +83,41 @@ module.exports = {
throw Errors.NOT_ENOUGH_RIGHTS;
}
const values = _.pick(inputs, ['position', 'name', 'isCompleted']);
let nextTaskList;
if (!_.isUndefined(inputs.taskListId)) {
nextTaskList = await TaskList.qm.getOneById(inputs.taskListId, {
cardId: card.id,
});
if (!nextTaskList) {
throw Errors.TASK_LIST_NOT_FOUND;
}
}
if (inputs.assigneeUserId) {
const isBoardMember = await sails.helpers.users.isBoardMember(
inputs.assigneeUserId,
board.id,
);
if (!isBoardMember) {
throw Errors.USER_NOT_FOUND;
}
}
const values = _.pick(inputs, ['assigneeUserId', 'position', 'name', 'isCompleted']);
task = await sails.helpers.tasks.updateOne.with({
values,
project,
board,
list,
card,
taskList,
record: task,
values: {
...values,
taskList: nextTaskList,
},
actorUser: currentUser,
request: this.req,
});