1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-08-05 05:25:29 +02:00

feat: Implemented moving a list between boards with instant UI update. Fixed authorization for socket requests (automatic token injection). After moving a list, user is automatically switched to the target board. Added translations for the new move list action to all locale files.

This commit is contained in:
symonbaikov 2025-06-11 14:17:12 +03:00
parent 18c7ff093b
commit 9c08ce51f1
39 changed files with 331 additions and 171 deletions

View file

@ -0,0 +1,82 @@
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, // listId
},
targetBoardId: {
...idInput,
required: true,
},
},
exits: {
notEnoughRights: {
responseType: 'forbidden',
},
listNotFound: {
responseType: 'notFound',
},
boardNotFound: {
responseType: 'notFound',
},
},
async fn(inputs) {
const { currentUser } = this.req;
const { list, board: sourceBoard } = await sails.helpers.lists
.getPathToProjectById(inputs.id)
.intercept('pathNotFound', () => Errors.LIST_NOT_FOUND);
const targetBoard = await Board.qm.getOneById(inputs.targetBoardId);
if (!targetBoard) {
throw Errors.BOARD_NOT_FOUND;
}
const sourceMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
sourceBoard.id,
currentUser.id,
);
const targetMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
targetBoard.id,
currentUser.id,
);
if (
!sourceMembership ||
!targetMembership ||
sourceMembership.role !== BoardMembership.Roles.EDITOR ||
targetMembership.role !== BoardMembership.Roles.EDITOR
) {
throw Errors.NOT_ENOUGH_RIGHTS;
}
const { updatedList, updatedCards } = await sails.helpers.lists.moveToBoard.with({
list,
targetBoard,
actorUser: currentUser,
request: this.req,
});
return {
item: updatedList,
included: {
cards: updatedCards,
},
};
},
};

View file

@ -0,0 +1,66 @@
module.exports = {
inputs: {
list: {
type: 'ref',
required: true,
},
targetBoard: {
type: 'ref',
required: true,
},
actorUser: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
},
async fn(inputs) {
const updatedList = await List.updateOne(
{ id: inputs.list.id },
{ boardId: inputs.targetBoard.id },
);
const updatedCards = await Card.update(
{ listId: inputs.list.id },
{ boardId: inputs.targetBoard.id },
).fetch();
const migrateLabelsPromises = updatedCards.map(async (card) => {
const cardLabels = await CardLabel.find({ cardId: card.id });
return Promise.all(
cardLabels.map(async (cardLabel) => {
const oldLabel = await Label.findOne({ id: cardLabel.labelId });
if (!oldLabel) return;
let newLabel = await Label.findOne({
boardId: inputs.targetBoard.id,
name: oldLabel.name,
color: oldLabel.color,
});
if (!newLabel) {
const maxPosArr = await Label.find({ boardId: inputs.targetBoard.id })
.sort('position DESC')
.limit(1);
const maxPos = maxPosArr.length > 0 ? maxPosArr[0].position : 0;
newLabel = await Label.create({
boardId: inputs.targetBoard.id,
name: oldLabel.name,
color: oldLabel.color,
position: maxPos + 65536,
}).fetch();
}
await CardLabel.destroy({ cardId: card.id, labelId: cardLabel.labelId });
await CardLabel.create({ cardId: card.id, labelId: newLabel.id });
}),
);
});
await Promise.all(migrateLabelsPromises);
return {
updatedList,
updatedCards,
};
},
};