1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-24 15:49:46 +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,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 = {
PROJECT_NOT_FOUND: {
projectNotFound: 'Project not found',
@ -13,16 +20,17 @@ const Errors = {
module.exports = {
inputs: {
projectId: {
type: 'string',
regex: /^[0-9]+$/,
...idInput,
required: true,
},
position: {
type: 'number',
min: 0,
required: true,
},
name: {
type: 'string',
maxLength: 128,
required: true,
},
importType: {
@ -32,6 +40,7 @@ module.exports = {
requestId: {
type: 'string',
isNotEmptyString: true,
maxLength: 128,
},
},
@ -42,6 +51,9 @@ module.exports = {
noImportFileWasUploaded: {
responseType: 'unprocessableEntity',
},
invalidImportFile: {
responseType: 'unprocessableEntity',
},
uploadError: {
responseType: 'unprocessableEntity',
},
@ -50,7 +62,7 @@ module.exports = {
async fn(inputs) {
const { currentUser } = this.req;
const project = await Project.findOne(inputs.projectId);
const project = await Project.qm.getOneById(inputs.projectId);
if (!project) {
throw Errors.PROJECT_NOT_FOUND;
@ -62,10 +74,8 @@ module.exports = {
throw Errors.PROJECT_NOT_FOUND; // Forbidden
}
const values = _.pick(inputs, ['position', 'name']);
let boardImport;
if (inputs.importType && Object.values(Board.ImportTypes).includes(inputs.importType)) {
if (inputs.importType) {
let files;
try {
files = await sails.helpers.utils.receiveFile('importFile', this.req);
@ -80,13 +90,19 @@ module.exports = {
const file = _.last(files);
if (inputs.importType === Board.ImportTypes.TRELLO) {
const trelloBoard = await sails.helpers.boards
.processUploadedTrelloImportFile(file)
.intercept('invalidFile', () => Errors.INVALID_IMPORT_FILE);
boardImport = {
type: inputs.importType,
board: await sails.helpers.boards.processUploadedTrelloImportFile(file),
board: trelloBoard,
};
}
}
const values = _.pick(inputs, ['position', 'name']);
const { board, boardMembership } = await sails.helpers.boards.createOne.with({
values: {
...values,

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 = {
BOARD_NOT_FOUND: {
boardNotFound: 'Board not found',
@ -7,8 +14,7 @@ const Errors = {
module.exports = {
inputs: {
id: {
type: 'string',
regex: /^[0-9]+$/,
...idInput,
required: true,
},
},
@ -22,16 +28,12 @@ module.exports = {
async fn(inputs) {
const { currentUser } = this.req;
const path = await sails.helpers.boards
.getProjectPath(inputs.id)
const pathToProject = await sails.helpers.boards
.getPathToProjectById(inputs.id)
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND);
let { board } = path;
const { project } = path;
if (!board) {
throw Errors.BOARD_NOT_FOUND;
}
let { board } = pathToProject;
const { project } = pathToProject;
const isProjectManager = await sails.helpers.users.isProjectManager(currentUser.id, project.id);

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 = {
BOARD_NOT_FOUND: {
boardNotFound: 'Board not found',
@ -7,8 +14,7 @@ const Errors = {
module.exports = {
inputs: {
id: {
type: 'string',
regex: /^[0-9]+$/,
...idInput,
required: true,
},
subscribe: {
@ -26,42 +32,67 @@ module.exports = {
const { currentUser } = this.req;
const { board, project } = await sails.helpers.boards
.getProjectPath(inputs.id)
.getPathToProjectById(inputs.id)
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND);
const isBoardMember = await sails.helpers.users.isBoardMember(currentUser.id, board.id);
if (!isBoardMember) {
if (currentUser.role !== User.Roles.ADMIN || project.ownerProjectManagerId) {
const isProjectManager = await sails.helpers.users.isProjectManager(
currentUser.id,
project.id,
);
if (!isProjectManager) {
throw Errors.BOARD_NOT_FOUND; // Forbidden
const boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
board.id,
currentUser.id,
);
if (!boardMembership) {
throw Errors.BOARD_NOT_FOUND; // Forbidden
}
}
}
const boardMemberships = await sails.helpers.boards.getBoardMemberships(board.id);
board.isSubscribed = await sails.helpers.users.isBoardSubscriber(currentUser.id, board.id);
const userIds = sails.helpers.utils.mapRecords(boardMemberships, 'userId');
const users = await sails.helpers.users.getMany(userIds);
const boardMemberships = await BoardMembership.qm.getByBoardId(board.id);
const labels = await Label.qm.getByBoardId(board.id);
const lists = await List.qm.getByBoardId(board.id);
const labels = await sails.helpers.boards.getLabels(board.id);
const lists = await sails.helpers.boards.getLists(board.id);
const finiteLists = lists.filter((list) => sails.helpers.lists.isFinite(list));
const finiteListIds = sails.helpers.utils.mapRecords(finiteLists);
const cards = await sails.helpers.boards.getCards(board.id);
const cards = await Card.qm.getByListIds(finiteListIds);
const cardIds = sails.helpers.utils.mapRecords(cards);
const cardSubscriptions = await sails.helpers.cardSubscriptions.getMany({
cardId: cardIds,
userId: currentUser.id,
});
const userIds = _.union(
sails.helpers.utils.mapRecords(boardMemberships, 'userId'),
sails.helpers.utils.mapRecords(cards, 'creatorUserId', true, true),
);
const cardMemberships = await sails.helpers.cards.getCardMemberships(cardIds);
const cardLabels = await sails.helpers.cards.getCardLabels(cardIds);
const tasks = await sails.helpers.cards.getTasks(cardIds);
const attachments = await sails.helpers.cards.getAttachments(cardIds);
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 boardCustomFieldGroups = await CustomFieldGroup.qm.getByBoardId(board.id);
const cardCustomFieldGroups = await CustomFieldGroup.qm.getByCardIds(cardIds);
const customFieldGroups = [...boardCustomFieldGroups, ...cardCustomFieldGroups];
const customFieldGroupIds = sails.helpers.utils.mapRecords(customFieldGroups);
const customFields = await CustomField.qm.getByCustomFieldGroupIds(customFieldGroupIds);
const customFieldValues = await CustomFieldValue.qm.getByCardIds(cardIds);
const cardSubscriptions = await CardSubscription.qm.getByCardIdsAndUserId(
cardIds,
currentUser.id,
);
const isSubscribedByCardId = cardSubscriptions.reduce(
(result, cardSubscription) => ({
@ -83,16 +114,20 @@ module.exports = {
return {
item: board,
included: {
users,
boardMemberships,
labels,
lists,
cards,
cardMemberships,
cardLabels,
taskLists,
tasks,
attachments,
customFieldGroups,
customFields,
customFieldValues,
users: sails.helpers.users.presentMany(users, currentUser),
projects: [project],
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 = {
BOARD_NOT_FOUND: {
boardNotFound: 'Board not found',
@ -7,16 +14,36 @@ const Errors = {
module.exports = {
inputs: {
id: {
type: 'string',
regex: /^[0-9]+$/,
...idInput,
required: true,
},
position: {
type: 'number',
min: 0,
},
name: {
type: 'string',
isNotEmptyString: true,
maxLength: 128,
},
defaultView: {
type: 'string',
isIn: Object.values(Board.Views),
},
defaultCardType: {
type: 'string',
isIn: Object.values(Card.Types),
allowNull: true,
},
limitCardTypesToDefaultOne: {
type: 'boolean',
allowNull: true,
},
alwaysDisplayCardCreator: {
type: 'boolean',
},
isSubscribed: {
type: 'boolean',
},
},
@ -29,24 +56,48 @@ module.exports = {
async fn(inputs) {
const { currentUser } = this.req;
const path = await sails.helpers.boards
.getProjectPath(inputs.id)
const pathToProject = await sails.helpers.boards
.getPathToProjectById(inputs.id)
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND);
let { board } = path;
const { project } = path;
if (!board) {
throw Errors.BOARD_NOT_FOUND;
}
let { board } = pathToProject;
const { project } = pathToProject;
const isProjectManager = await sails.helpers.users.isProjectManager(currentUser.id, project.id);
const isBoardMember = await sails.helpers.users.isBoardMember(currentUser.id, board.id);
if (!isProjectManager) {
if (!isProjectManager && !isBoardMember) {
throw Errors.BOARD_NOT_FOUND; // Forbidden
}
const values = _.pick(inputs, ['position', 'name']);
const availableInputKeys = ['id'];
if (isProjectManager) {
availableInputKeys.push(
'position',
'name',
'defaultView',
'defaultCardType',
'limitCardTypesToDefaultOne',
'alwaysDisplayCardCreator',
);
}
if (isBoardMember) {
availableInputKeys.push('isSubscribed');
}
if (_.difference(Object.keys(inputs), availableInputKeys).length > 0) {
throw Errors.NOT_ENOUGH_RIGHTS;
}
const values = _.pick(inputs, [
'position',
'name',
'defaultView',
'defaultCardType',
'limitCardTypesToDefaultOne',
'alwaysDisplayCardCreator',
'isSubscribed',
]);
board = await sails.helpers.boards.updateOne.with({
values,