mirror of
https://github.com/plankanban/planka.git
synced 2025-07-26 00:29:48 +02:00
parent
ad7fb51cfa
commit
2ee1166747
1557 changed files with 76832 additions and 47042 deletions
|
@ -1,41 +1,16 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isFinite(value.position)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.project)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
const importValidator = (value) => {
|
||||
if (!value.type || !Object.values(Board.ImportTypes).includes(value.type)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.board)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
values: {
|
||||
type: 'ref',
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
import: {
|
||||
type: 'json',
|
||||
custom: importValidator,
|
||||
},
|
||||
actorUser: {
|
||||
type: 'ref',
|
||||
|
@ -43,7 +18,6 @@ module.exports = {
|
|||
},
|
||||
requestId: {
|
||||
type: 'string',
|
||||
isNotEmptyString: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
|
@ -53,60 +27,81 @@ module.exports = {
|
|||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
const projectManagerUserIds = await sails.helpers.projects.getManagerUserIds(values.project.id);
|
||||
const boards = await sails.helpers.projects.getBoards(values.project.id);
|
||||
const scoper = sails.helpers.projects.makeScoper.with({
|
||||
record: values.project,
|
||||
});
|
||||
|
||||
const boards = await Board.qm.getByProjectId(values.project.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
boards,
|
||||
);
|
||||
|
||||
repositions.forEach(async ({ id, position: nextPosition }) => {
|
||||
await Board.update({
|
||||
id,
|
||||
projectId: values.project.id,
|
||||
}).set({
|
||||
position: nextPosition,
|
||||
});
|
||||
values.position = position;
|
||||
|
||||
// TODO: move out of loop
|
||||
const boardMemberUserIds = await sails.helpers.boards.getMemberUserIds(id);
|
||||
const boardRelatedUserIds = _.union(projectManagerUserIds, boardMemberUserIds);
|
||||
if (repositions.length > 0) {
|
||||
await scoper.getUserIdsWithFullProjectVisibility();
|
||||
const clonedScoper = scoper.clone();
|
||||
|
||||
boardRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(`user:${userId}`, 'boardUpdate', {
|
||||
item: {
|
||||
id,
|
||||
position: nextPosition,
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const reposition of repositions) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await Board.qm.updateOne(
|
||||
{
|
||||
id: reposition.record.id,
|
||||
projectId: reposition.record.projectId,
|
||||
},
|
||||
{
|
||||
position: reposition.position,
|
||||
},
|
||||
);
|
||||
|
||||
clonedScoper.replaceBoard(reposition.record);
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const boardRelatedUserIds = await clonedScoper.getBoardRelatedUserIds();
|
||||
|
||||
boardRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(`user:${userId}`, 'boardUpdate', {
|
||||
item: {
|
||||
id: reposition.record.id,
|
||||
position: reposition.position,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
// TODO: send webhooks
|
||||
});
|
||||
});
|
||||
|
||||
const board = await Board.create({
|
||||
...values,
|
||||
position,
|
||||
projectId: values.project.id,
|
||||
}).fetch();
|
||||
|
||||
if (inputs.import && inputs.import.type === Board.ImportTypes.TRELLO) {
|
||||
await sails.helpers.boards.importFromTrello(board, inputs.import.board, inputs.actorUser);
|
||||
}
|
||||
}
|
||||
|
||||
const boardMembership = await BoardMembership.create({
|
||||
boardId: board.id,
|
||||
userId: inputs.actorUser.id,
|
||||
role: BoardMembership.Roles.EDITOR,
|
||||
}).fetch();
|
||||
const { board, boardMembership, lists } = await Board.qm.createOne(
|
||||
{
|
||||
...values,
|
||||
projectId: values.project.id,
|
||||
},
|
||||
{
|
||||
user: inputs.actorUser,
|
||||
},
|
||||
);
|
||||
|
||||
projectManagerUserIds.forEach((userId) => {
|
||||
if (inputs.import && inputs.import.type === Board.ImportTypes.TRELLO) {
|
||||
await sails.helpers.boards.importFromTrello(board, lists, inputs.import.board);
|
||||
}
|
||||
|
||||
scoper.board = board;
|
||||
scoper.boardMemberships = [boardMembership];
|
||||
|
||||
const boardRelatedUserIds = await scoper.getBoardRelatedUserIds();
|
||||
|
||||
boardRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
'boardCreate',
|
||||
{
|
||||
item: board,
|
||||
included: {
|
||||
boardMemberships: userId === boardMembership.userId ? [boardMembership] : [],
|
||||
},
|
||||
requestId: inputs.requestId,
|
||||
},
|
||||
inputs.request,
|
||||
|
@ -115,12 +110,13 @@ module.exports = {
|
|||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'boardCreate',
|
||||
data: {
|
||||
buildData: () => ({
|
||||
item: board,
|
||||
included: {
|
||||
projects: [values.project],
|
||||
boardMemberships: [boardMembership],
|
||||
},
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
|
@ -18,18 +23,20 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const boardMemberships = await BoardMembership.destroy({
|
||||
boardId: inputs.record.id,
|
||||
}).fetch();
|
||||
const { boardMemberships } = await sails.helpers.boards.deleteRelated(inputs.record);
|
||||
|
||||
const board = await Board.archiveOne(inputs.record.id);
|
||||
const board = await Board.qm.deleteOne(inputs.record.id);
|
||||
|
||||
if (board) {
|
||||
sails.sockets.removeRoomMembersFromRooms(`board:${board.id}`, `board:${board.id}`);
|
||||
const scoper = sails.helpers.projects.makeScoper.with({
|
||||
board,
|
||||
record: inputs.project,
|
||||
});
|
||||
|
||||
const projectManagerUserIds = await sails.helpers.projects.getManagerUserIds(board.projectId);
|
||||
const boardMemberUserIds = sails.helpers.utils.mapRecords(boardMemberships, 'userId');
|
||||
const boardRelatedUserIds = _.union(projectManagerUserIds, boardMemberUserIds);
|
||||
scoper.boardMemberships = boardMemberships;
|
||||
const boardRelatedUserIds = await scoper.getBoardRelatedUserIds();
|
||||
|
||||
sails.sockets.removeRoomMembersFromRooms(`board:${board.id}`, `board:${board.id}`);
|
||||
|
||||
boardRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(
|
||||
|
@ -44,12 +51,12 @@ module.exports = {
|
|||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'boardDelete',
|
||||
data: {
|
||||
buildData: () => ({
|
||||
item: board,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
},
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
|
|
44
server/api/helpers/boards/delete-related.js
Normal file
44
server/api/helpers/boards/delete-related.js
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
recordOrRecords: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
let boardIdOrIds;
|
||||
if (_.isPlainObject(inputs.recordOrRecords)) {
|
||||
({
|
||||
recordOrRecords: { id: boardIdOrIds },
|
||||
} = inputs);
|
||||
} else if (_.every(inputs.recordOrRecords, _.isPlainObject)) {
|
||||
boardIdOrIds = sails.helpers.utils.mapRecords(inputs.recordOrRecords);
|
||||
}
|
||||
|
||||
const boardMemberships = await BoardMembership.qm.delete({
|
||||
boardId: boardIdOrIds,
|
||||
});
|
||||
|
||||
await Label.qm.delete({
|
||||
boardId: boardIdOrIds,
|
||||
});
|
||||
|
||||
const lists = await List.qm.delete({
|
||||
boardId: boardIdOrIds,
|
||||
});
|
||||
|
||||
await sails.helpers.lists.deleteRelated(lists);
|
||||
|
||||
await NotificationService.qm.delete({
|
||||
boardId: boardIdOrIds,
|
||||
});
|
||||
|
||||
return { boardMemberships };
|
||||
},
|
||||
};
|
|
@ -1,17 +0,0 @@
|
|||
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
return sails.helpers.boardMemberships.getMany({
|
||||
boardId: inputs.idOrIds,
|
||||
});
|
||||
},
|
||||
};
|
|
@ -1,16 +1,18 @@
|
|||
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
id: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const cards = await sails.helpers.boards.getCards(inputs.idOrIds);
|
||||
const cards = await Card.qm.getByBoardId(inputs.id);
|
||||
|
||||
return sails.helpers.utils.mapRecords(cards);
|
||||
},
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
return sails.helpers.cards.getMany({
|
||||
boardId: inputs.idOrIds,
|
||||
});
|
||||
},
|
||||
};
|
23
server/api/helpers/boards/get-finite-lists-by-id.js
Normal file
23
server/api/helpers/boards/get-finite-lists-by-id.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
},
|
||||
exceptListIdOrIds: {
|
||||
type: 'json',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
return List.qm.getByBoardId(inputs.id, {
|
||||
exceptIdOrIds: inputs.exceptListIdOrIds,
|
||||
typeOrTypes: List.FINITE_TYPES,
|
||||
});
|
||||
},
|
||||
};
|
|
@ -1,29 +0,0 @@
|
|||
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
required: true,
|
||||
},
|
||||
exceptLabelIdOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const criteria = {
|
||||
boardId: inputs.idOrIds,
|
||||
};
|
||||
|
||||
if (!_.isUndefined(inputs.exceptLabelIdOrIds)) {
|
||||
criteria.id = {
|
||||
'!=': inputs.exceptLabelIdOrIds,
|
||||
};
|
||||
}
|
||||
|
||||
return sails.helpers.labels.getMany(criteria);
|
||||
},
|
||||
};
|
|
@ -1,29 +0,0 @@
|
|||
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
required: true,
|
||||
},
|
||||
exceptListIdOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const criteria = {
|
||||
boardId: inputs.idOrIds,
|
||||
};
|
||||
|
||||
if (!_.isUndefined(inputs.exceptListIdOrIds)) {
|
||||
criteria.id = {
|
||||
'!=': inputs.exceptListIdOrIds,
|
||||
};
|
||||
}
|
||||
|
||||
return sails.helpers.lists.getMany(criteria);
|
||||
},
|
||||
};
|
|
@ -1,14 +0,0 @@
|
|||
const criteriaValidator = (value) => _.isArray(value) || _.isPlainObject(value);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
custom: criteriaValidator,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
return Board.find(inputs.criteria).sort('position');
|
||||
},
|
||||
};
|
|
@ -1,17 +1,19 @@
|
|||
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
id: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const boardMemberships = await sails.helpers.boards.getBoardMemberships(inputs.idOrIds);
|
||||
const boardMemberships = await BoardMembership.qm.getByBoardId(inputs.id);
|
||||
|
||||
return sails.helpers.utils.mapRecords(boardMemberships, 'userId', _.isArray(inputs.idOrIds));
|
||||
return sails.helpers.utils.mapRecords(boardMemberships, 'userId');
|
||||
},
|
||||
};
|
||||
|
|
19
server/api/helpers/boards/get-notification-services-total.js
Normal file
19
server/api/helpers/boards/get-notification-services-total.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const notificationServices = await NotificationService.qm.getByBoardId(inputs.id);
|
||||
|
||||
return notificationServices.length;
|
||||
},
|
||||
};
|
|
@ -1,7 +1,12 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
id: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
@ -11,13 +16,13 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const board = await Board.findOne(inputs.criteria);
|
||||
const board = await Board.qm.getOneById(inputs.id);
|
||||
|
||||
if (!board) {
|
||||
throw 'pathNotFound';
|
||||
}
|
||||
|
||||
const project = await Project.findOne(board.projectId);
|
||||
const project = await Project.qm.getOneById(board.projectId);
|
||||
|
||||
if (!project) {
|
||||
throw {
|
24
server/api/helpers/boards/get-subscription-user-ids.js
Normal file
24
server/api/helpers/boards/get-subscription-user-ids.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
},
|
||||
exceptUserIdOrIds: {
|
||||
type: 'json',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const boardSubscriptions = await BoardSubscription.qm.getByBoardId(inputs.id, {
|
||||
exceptUserIdOrIds: inputs.exceptUserIdOrIds,
|
||||
});
|
||||
|
||||
return sails.helpers.utils.mapRecords(boardSubscriptions, 'userId');
|
||||
},
|
||||
};
|
|
@ -1,4 +1,9 @@
|
|||
const POSITION_GAP = 65535; // TODO: move to config
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
const { POSITION_GAP } = require('../../../constants');
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
|
@ -6,151 +11,122 @@ module.exports = {
|
|||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
trelloBoard: {
|
||||
type: 'json',
|
||||
lists: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
actorUser: {
|
||||
type: 'ref',
|
||||
trelloBoard: {
|
||||
type: 'json',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const trelloToPlankaLabels = {};
|
||||
const convertLabelColor = (trelloLabelColor) =>
|
||||
Label.COLORS.find((color) => color.includes(trelloLabelColor)) || 'desert-sand';
|
||||
|
||||
const getTrelloLists = () => inputs.trelloBoard.lists.filter((list) => !list.closed);
|
||||
|
||||
const getUsedTrelloLabels = () => {
|
||||
const result = {};
|
||||
inputs.trelloBoard.cards
|
||||
.map((card) => card.labels)
|
||||
.flat()
|
||||
.forEach((label) => {
|
||||
result[label.id] = label;
|
||||
const labelIdByTrelloLabelId = {};
|
||||
await Promise.all(
|
||||
inputs.trelloBoard.labels.map(async (trelloLabel, index) => {
|
||||
const { id } = await Label.qm.createOne({
|
||||
boardId: inputs.board.id,
|
||||
position: POSITION_GAP * (index + 1),
|
||||
name: trelloLabel.name || null,
|
||||
color: convertLabelColor(trelloLabel.color),
|
||||
});
|
||||
|
||||
return Object.values(result);
|
||||
};
|
||||
labelIdByTrelloLabelId[trelloLabel.id] = id;
|
||||
}),
|
||||
);
|
||||
|
||||
const getTrelloCardsOfList = (listId) =>
|
||||
inputs.trelloBoard.cards.filter((card) => card.idList === listId && !card.closed);
|
||||
const openedTrelloLists = inputs.trelloBoard.lists.filter((list) => !list.closed);
|
||||
|
||||
const getAllTrelloCheckItemsOfCard = (cardId) =>
|
||||
inputs.trelloBoard.checklists
|
||||
.filter((checklist) => checklist.idCard === cardId)
|
||||
.map((checklist) => checklist.checkItems)
|
||||
.flat();
|
||||
const listIdByTrelloListId = {};
|
||||
await Promise.all(
|
||||
openedTrelloLists.map(async (trelloList) => {
|
||||
const { id } = await List.qm.createOne({
|
||||
boardId: inputs.board.id,
|
||||
type: List.Types.ACTIVE,
|
||||
position: trelloList.pos,
|
||||
name: trelloList.name,
|
||||
});
|
||||
|
||||
const getTrelloCommentsOfCard = (cardId) =>
|
||||
inputs.trelloBoard.actions.filter(
|
||||
(action) =>
|
||||
action.type === 'commentCard' &&
|
||||
action.data &&
|
||||
action.data.card &&
|
||||
action.data.card.id === cardId,
|
||||
);
|
||||
listIdByTrelloListId[trelloList.id] = id;
|
||||
}),
|
||||
);
|
||||
|
||||
const getPlankaLabelColor = (trelloLabelColor) =>
|
||||
Label.COLORS.find((color) => color.indexOf(trelloLabelColor) !== -1) || 'desert-sand';
|
||||
const { id: archiveListId } = inputs.lists.find((list) => list.type === List.Types.ARCHIVE);
|
||||
|
||||
const importCardLabels = async (plankaCard, trelloCard) => {
|
||||
return Promise.all(
|
||||
trelloCard.labels.map(async (trelloLabel) => {
|
||||
return CardLabel.create({
|
||||
cardId: plankaCard.id,
|
||||
labelId: trelloToPlankaLabels[trelloLabel.id].id,
|
||||
const cardIdByTrelloCardId = {};
|
||||
await Promise.all(
|
||||
inputs.trelloBoard.cards.map(async (trelloCard) => {
|
||||
const values = {
|
||||
boardId: inputs.board.id,
|
||||
type: Card.Types.PROJECT,
|
||||
position: trelloCard.pos,
|
||||
name: trelloCard.name,
|
||||
description: trelloCard.desc || null,
|
||||
dueDate: trelloCard.due,
|
||||
listChangedAt: new Date().toISOString(),
|
||||
};
|
||||
|
||||
const listId = listIdByTrelloListId[trelloCard.idList];
|
||||
|
||||
if (trelloCard.closed) {
|
||||
Object.assign(values, {
|
||||
listId: archiveListId,
|
||||
prevListId: listId,
|
||||
});
|
||||
} else {
|
||||
values.listId = listId || archiveListId;
|
||||
}
|
||||
|
||||
const { id } = await Card.qm.createOne(values);
|
||||
cardIdByTrelloCardId[trelloCard.id] = id;
|
||||
|
||||
return Promise.all(
|
||||
trelloCard.idLabels.map(async (trelloLabelId) =>
|
||||
CardLabel.qm.createOne({
|
||||
cardId: id,
|
||||
labelId: labelIdByTrelloLabelId[trelloLabelId],
|
||||
}),
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
await Promise.all(
|
||||
inputs.trelloBoard.checklists.map(async (trelloChecklist) => {
|
||||
const { id } = await TaskList.qm.createOne({
|
||||
cardId: cardIdByTrelloCardId[trelloChecklist.idCard],
|
||||
position: trelloChecklist.pos,
|
||||
name: trelloChecklist.name,
|
||||
});
|
||||
|
||||
return Promise.all(
|
||||
trelloChecklist.checkItems.map(async (trelloCheckItem) =>
|
||||
Task.qm.createOne({
|
||||
taskListId: id,
|
||||
position: trelloCheckItem.pos,
|
||||
name: trelloCheckItem.name,
|
||||
isCompleted: trelloCheckItem.state === 'complete',
|
||||
}),
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
const trelloCommentActions = inputs.trelloBoard.actions
|
||||
.filter((action) => action.type === 'commentCard')
|
||||
.reverse();
|
||||
|
||||
await Promise.all(
|
||||
trelloCommentActions.map(async (trelloAction) =>
|
||||
Comment.qm.createOne({
|
||||
cardId: cardIdByTrelloCardId[trelloAction.data.card.id],
|
||||
text: `${trelloAction.data.text}\n\n---\n*Note: imported comment, originally posted by\n${trelloAction.memberCreator.fullName} (${trelloAction.memberCreator.username}) on ${trelloAction.date}*`,
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
const importTasks = async (plankaCard, trelloCard) => {
|
||||
// TODO find workaround for tasks/checklist mismapping, see issue trello2planka#5
|
||||
return Promise.all(
|
||||
getAllTrelloCheckItemsOfCard(trelloCard.id).map(async (trelloCheckItem) => {
|
||||
return Task.create({
|
||||
cardId: plankaCard.id,
|
||||
position: trelloCheckItem.pos,
|
||||
name: trelloCheckItem.name,
|
||||
isCompleted: trelloCheckItem.state === 'complete',
|
||||
}).fetch();
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
const importComments = async (plankaCard, trelloCard) => {
|
||||
const trelloComments = getTrelloCommentsOfCard(trelloCard.id);
|
||||
trelloComments.sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime());
|
||||
|
||||
return Promise.all(
|
||||
trelloComments.map(async (trelloComment) => {
|
||||
return Action.create({
|
||||
cardId: plankaCard.id,
|
||||
userId: inputs.actorUser.id,
|
||||
type: 'commentCard',
|
||||
data: {
|
||||
text:
|
||||
`${trelloComment.data.text}\n\n---\n*Note: imported comment, originally posted by ` +
|
||||
`\n${trelloComment.memberCreator.fullName} (${trelloComment.memberCreator.username}) on ${trelloComment.date}*`,
|
||||
},
|
||||
}).fetch();
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
const importCards = async (plankaList, trelloList) => {
|
||||
return Promise.all(
|
||||
getTrelloCardsOfList(trelloList.id).map(async (trelloCard) => {
|
||||
const plankaCard = await Card.create({
|
||||
boardId: inputs.board.id,
|
||||
listId: plankaList.id,
|
||||
creatorUserId: inputs.actorUser.id,
|
||||
position: trelloCard.pos,
|
||||
name: trelloCard.name,
|
||||
description: trelloCard.desc || null,
|
||||
dueDate: trelloCard.due,
|
||||
}).fetch();
|
||||
|
||||
await importCardLabels(plankaCard, trelloCard);
|
||||
await importTasks(plankaCard, trelloCard);
|
||||
await importComments(plankaCard, trelloCard);
|
||||
|
||||
return plankaCard;
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
const importLabels = async () => {
|
||||
return Promise.all(
|
||||
getUsedTrelloLabels().map(async (trelloLabel, index) => {
|
||||
const plankaLabel = await Label.create({
|
||||
boardId: inputs.board.id,
|
||||
position: POSITION_GAP * (index + 1),
|
||||
name: trelloLabel.name || null,
|
||||
color: getPlankaLabelColor(trelloLabel.color),
|
||||
}).fetch();
|
||||
|
||||
trelloToPlankaLabels[trelloLabel.id] = plankaLabel;
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
const importLists = async () => {
|
||||
return Promise.all(
|
||||
getTrelloLists().map(async (trelloList) => {
|
||||
const plankaList = await List.create({
|
||||
boardId: inputs.board.id,
|
||||
name: trelloList.name,
|
||||
position: trelloList.pos,
|
||||
}).fetch();
|
||||
|
||||
return importCards(plankaList, trelloList);
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
await importLabels();
|
||||
await importLists();
|
||||
),
|
||||
);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const { rimraf } = require('rimraf');
|
||||
|
||||
|
@ -13,25 +18,31 @@ module.exports = {
|
|||
invalidFile: {},
|
||||
},
|
||||
|
||||
// TODO: add better validation
|
||||
async fn(inputs) {
|
||||
const content = await fs.promises.readFile(inputs.file.fd);
|
||||
const trelloBoard = JSON.parse(content);
|
||||
|
||||
let trelloBoard;
|
||||
try {
|
||||
trelloBoard = JSON.parse(content);
|
||||
} catch (error) {
|
||||
await rimraf(inputs.file.fd);
|
||||
throw 'invalidFile';
|
||||
}
|
||||
|
||||
if (
|
||||
!trelloBoard ||
|
||||
!_.isArray(trelloBoard.labels) ||
|
||||
!_.isArray(trelloBoard.lists) ||
|
||||
!_.isArray(trelloBoard.cards) ||
|
||||
!_.isArray(trelloBoard.checklists) ||
|
||||
!_.isArray(trelloBoard.actions)
|
||||
) {
|
||||
await rimraf(inputs.file.fd);
|
||||
throw 'invalidFile';
|
||||
}
|
||||
|
||||
try {
|
||||
await rimraf(inputs.file.fd);
|
||||
} catch (error) {
|
||||
console.warn(error.stack); // eslint-disable-line no-console
|
||||
}
|
||||
await rimraf(inputs.file.fd);
|
||||
|
||||
return trelloBoard;
|
||||
},
|
||||
|
|
|
@ -1,14 +1,7 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isUndefined(value.position) && !_.isFinite(value.position)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
|
@ -18,7 +11,6 @@ module.exports = {
|
|||
},
|
||||
values: {
|
||||
type: 'json',
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
|
@ -35,52 +27,72 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
const { isSubscribed, ...values } = inputs.values;
|
||||
|
||||
const projectManagerUserIds = await sails.helpers.projects.getManagerUserIds(
|
||||
inputs.record.projectId,
|
||||
);
|
||||
|
||||
const boardMemberUserIds = await sails.helpers.boards.getMemberUserIds(inputs.record.id);
|
||||
const boardRelatedUserIds = _.union(projectManagerUserIds, boardMemberUserIds);
|
||||
|
||||
if (!_.isUndefined(values.position)) {
|
||||
const boards = await sails.helpers.projects.getBoards(
|
||||
inputs.record.projectId,
|
||||
inputs.record.id,
|
||||
);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
boards,
|
||||
);
|
||||
|
||||
values.position = position;
|
||||
|
||||
repositions.forEach(async ({ id, position: nextPosition }) => {
|
||||
await Board.update({
|
||||
id,
|
||||
projectId: inputs.record.projectId,
|
||||
}).set({
|
||||
position: nextPosition,
|
||||
});
|
||||
|
||||
boardRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(`user:${userId}`, 'boardUpdate', {
|
||||
item: {
|
||||
id,
|
||||
position: nextPosition,
|
||||
},
|
||||
});
|
||||
|
||||
// TODO: send webhooks
|
||||
});
|
||||
let board;
|
||||
if (_.isEmpty(values)) {
|
||||
board = inputs.record;
|
||||
} else {
|
||||
const scoper = sails.helpers.projects.makeScoper.with({
|
||||
record: inputs.project,
|
||||
});
|
||||
}
|
||||
|
||||
const board = await Board.updateOne(inputs.record.id).set({ ...values });
|
||||
if (!_.isUndefined(values.position)) {
|
||||
const boards = await Board.qm.getByProjectId(inputs.record.projectId, {
|
||||
exceptIdOrIds: inputs.record.id,
|
||||
});
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
boards,
|
||||
);
|
||||
|
||||
values.position = position;
|
||||
|
||||
if (repositions.length > 0) {
|
||||
await scoper.getUserIdsWithFullProjectVisibility();
|
||||
const clonedScoper = scoper.clone();
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const reposition of repositions) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await Board.qm.updateOne(
|
||||
{
|
||||
id: reposition.record.id,
|
||||
projectId: reposition.record.projectId,
|
||||
},
|
||||
{
|
||||
position: reposition.position,
|
||||
},
|
||||
);
|
||||
|
||||
clonedScoper.replaceBoard(reposition.record);
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const boardRelatedUserIds = await clonedScoper.getBoardRelatedUserIds();
|
||||
|
||||
boardRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(`user:${userId}`, 'boardUpdate', {
|
||||
item: {
|
||||
id: reposition.record.id,
|
||||
position: reposition.position,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
// TODO: send webhooks
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
board = await Board.qm.updateOne(inputs.record.id, values);
|
||||
|
||||
if (!board) {
|
||||
return board;
|
||||
}
|
||||
|
||||
scoper.board = board;
|
||||
const boardRelatedUserIds = await scoper.getBoardRelatedUserIds();
|
||||
|
||||
if (board) {
|
||||
boardRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
|
@ -94,19 +106,60 @@ module.exports = {
|
|||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'boardUpdate',
|
||||
data: {
|
||||
buildData: () => ({
|
||||
item: board,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
},
|
||||
},
|
||||
prevData: {
|
||||
}),
|
||||
buildPrevData: () => ({
|
||||
item: inputs.record,
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
|
||||
if (!_.isUndefined(isSubscribed)) {
|
||||
const wasSubscribed = await sails.helpers.users.isBoardSubscriber(
|
||||
inputs.actorUser.id,
|
||||
board.id,
|
||||
);
|
||||
|
||||
if (isSubscribed !== wasSubscribed) {
|
||||
if (isSubscribed) {
|
||||
try {
|
||||
await BoardSubscription.qm.createOne({
|
||||
boardId: board.id,
|
||||
userId: inputs.actorUser.id,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error.code !== 'E_UNIQUE') {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
await BoardSubscription.qm.deleteOne({
|
||||
boardId: board.id,
|
||||
userId: inputs.actorUser.id,
|
||||
});
|
||||
}
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`user:${inputs.actorUser.id}`,
|
||||
'boardUpdate',
|
||||
{
|
||||
item: {
|
||||
isSubscribed,
|
||||
id: board.id,
|
||||
},
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
// TODO: send webhooks
|
||||
}
|
||||
}
|
||||
|
||||
return board;
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue