2025-05-10 02:09:06 +02:00
|
|
|
/*!
|
|
|
|
* Copyright (c) 2024 PLANKA Software GmbH
|
|
|
|
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
|
|
|
*/
|
2022-12-26 21:10:50 +01:00
|
|
|
|
2019-08-31 04:07:25 +05:00
|
|
|
module.exports = {
|
|
|
|
inputs: {
|
|
|
|
values: {
|
2022-12-26 21:10:50 +01:00
|
|
|
type: 'ref',
|
2019-11-05 18:01:42 +05:00
|
|
|
required: true,
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
2022-12-16 23:48:06 +01:00
|
|
|
import: {
|
|
|
|
type: 'json',
|
|
|
|
},
|
2024-06-12 00:51:36 +02:00
|
|
|
actorUser: {
|
2021-06-24 01:05:22 +05:00
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
2022-12-16 23:48:06 +01:00
|
|
|
requestId: {
|
|
|
|
type: 'string',
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
request: {
|
2019-11-05 18:01:42 +05:00
|
|
|
type: 'ref',
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
async fn(inputs) {
|
2022-12-26 21:10:50 +01:00
|
|
|
const { values } = inputs;
|
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
const scoper = sails.helpers.projects.makeScoper.with({
|
|
|
|
record: values.project,
|
|
|
|
});
|
|
|
|
|
|
|
|
const boards = await Board.qm.getByProjectId(values.project.id);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
2022-12-26 21:10:50 +01:00
|
|
|
values.position,
|
2019-11-05 18:01:42 +05:00
|
|
|
boards,
|
2019-08-31 04:07:25 +05:00
|
|
|
);
|
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
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,
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2025-05-10 02:09:06 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
});
|
2019-08-31 04:07:25 +05:00
|
|
|
});
|
2024-06-12 00:51:36 +02:00
|
|
|
|
|
|
|
// TODO: send webhooks
|
2025-05-10 02:09:06 +02:00
|
|
|
}
|
|
|
|
}
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
const { board, boardMembership, lists } = await Board.qm.createOne(
|
|
|
|
{
|
|
|
|
...values,
|
|
|
|
projectId: values.project.id,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
user: inputs.actorUser,
|
|
|
|
},
|
|
|
|
);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2022-12-16 23:48:06 +01:00
|
|
|
if (inputs.import && inputs.import.type === Board.ImportTypes.TRELLO) {
|
2025-05-10 02:09:06 +02:00
|
|
|
await sails.helpers.boards.importFromTrello(board, lists, inputs.import.board);
|
2022-12-16 23:48:06 +01:00
|
|
|
}
|
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
scoper.board = board;
|
|
|
|
scoper.boardMemberships = [boardMembership];
|
|
|
|
|
|
|
|
const boardRelatedUserIds = await scoper.getBoardRelatedUserIds();
|
2021-06-24 01:05:22 +05:00
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
boardRelatedUserIds.forEach((userId) => {
|
2019-08-31 04:07:25 +05:00
|
|
|
sails.sockets.broadcast(
|
|
|
|
`user:${userId}`,
|
|
|
|
'boardCreate',
|
|
|
|
{
|
|
|
|
item: board,
|
2025-05-10 02:09:06 +02:00
|
|
|
included: {
|
|
|
|
boardMemberships: userId === boardMembership.userId ? [boardMembership] : [],
|
|
|
|
},
|
2022-12-16 23:48:06 +01:00
|
|
|
requestId: inputs.requestId,
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
2019-11-05 18:01:42 +05:00
|
|
|
inputs.request,
|
2019-08-31 04:07:25 +05:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2025-07-04 22:04:11 +02:00
|
|
|
const webhooks = await Webhook.qm.getAll();
|
|
|
|
|
2024-06-12 00:51:36 +02:00
|
|
|
sails.helpers.utils.sendWebhooks.with({
|
2025-07-04 22:04:11 +02:00
|
|
|
webhooks,
|
|
|
|
event: Webhook.Events.BOARD_CREATE,
|
2025-05-10 02:09:06 +02:00
|
|
|
buildData: () => ({
|
2024-06-12 00:51:36 +02:00
|
|
|
item: board,
|
|
|
|
included: {
|
|
|
|
projects: [values.project],
|
2025-05-10 02:09:06 +02:00
|
|
|
boardMemberships: [boardMembership],
|
2024-06-12 00:51:36 +02:00
|
|
|
},
|
2025-05-10 02:09:06 +02:00
|
|
|
}),
|
2024-06-12 00:51:36 +02:00
|
|
|
user: inputs.actorUser,
|
2024-06-06 20:22:14 +02:00
|
|
|
});
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
return {
|
|
|
|
board,
|
|
|
|
boardMembership,
|
|
|
|
};
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|