1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 05:09:43 +02:00

feat: Webhooks configuration, all events support, refactoring

This commit is contained in:
Maksim Eltyshev 2024-06-12 00:51:36 +02:00
parent 193daf6cfb
commit 87683fe523
96 changed files with 1280 additions and 509 deletions

View file

@ -37,7 +37,7 @@ module.exports = {
type: 'json',
custom: importValidator,
},
user: {
actorUser: {
type: 'ref',
required: true,
},
@ -80,6 +80,8 @@ module.exports = {
position: nextPosition,
},
});
// TODO: send webhooks
});
});
@ -90,12 +92,12 @@ module.exports = {
}).fetch();
if (inputs.import && inputs.import.type === Board.ImportTypes.TRELLO) {
await sails.helpers.boards.importFromTrello(inputs.user, board, inputs.import.board);
await sails.helpers.boards.importFromTrello(board, inputs.import.board, inputs.actorUser);
}
const boardMembership = await BoardMembership.create({
boardId: board.id,
userId: inputs.user.id,
userId: inputs.actorUser.id,
role: BoardMembership.Roles.EDITOR,
}).fetch();
@ -111,12 +113,15 @@ module.exports = {
);
});
await sails.helpers.utils.sendWebhook.with({
event: 'BOARD_CREATE',
data: board,
projectId: board.projectId,
user: inputs.request.currentUser,
board,
sails.helpers.utils.sendWebhooks.with({
event: 'boardCreate',
data: {
item: board,
included: {
projects: [values.project],
},
},
user: inputs.actorUser,
});
return {

View file

@ -4,6 +4,14 @@ module.exports = {
type: 'ref',
required: true,
},
project: {
type: 'ref',
required: true,
},
actorUser: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
@ -33,15 +41,18 @@ module.exports = {
inputs.request,
);
});
}
await sails.helpers.utils.sendWebhook.with({
event: 'BOARD_DELETE',
data: board,
projectId: board.projectId,
user: inputs.request.currentUser,
board,
});
sails.helpers.utils.sendWebhooks.with({
event: 'boardDelete',
data: {
item: board,
included: {
projects: [inputs.project],
},
},
user: inputs.actorUser,
});
}
return board;
},

View file

@ -2,10 +2,6 @@ const POSITION_GAP = 65535; // TODO: move to config
module.exports = {
inputs: {
user: {
type: 'ref',
required: true,
},
board: {
type: 'ref',
required: true,
@ -14,6 +10,10 @@ module.exports = {
type: 'json',
required: true,
},
actorUser: {
type: 'ref',
required: true,
},
},
async fn(inputs) {
@ -87,7 +87,7 @@ module.exports = {
trelloComments.map(async (trelloComment) => {
return Action.create({
cardId: plankaCard.id,
userId: inputs.user.id,
userId: inputs.actorUser.id,
type: 'commentCard',
data: {
text:
@ -105,7 +105,7 @@ module.exports = {
const plankaCard = await Card.create({
boardId: inputs.board.id,
listId: plankaList.id,
creatorUserId: inputs.user.id,
creatorUserId: inputs.actorUser.id,
position: trelloCard.pos,
name: trelloCard.name,
description: trelloCard.desc || null,

View file

@ -21,6 +21,14 @@ module.exports = {
custom: valuesValidator,
required: true,
},
project: {
type: 'ref',
required: true,
},
actorUser: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
@ -64,6 +72,8 @@ module.exports = {
position: nextPosition,
},
});
// TODO: send webhooks
});
});
}
@ -81,15 +91,18 @@ module.exports = {
inputs.request,
);
});
}
await sails.helpers.utils.sendWebhook.with({
event: 'BOARD_UPDATE',
data: board,
projectId: board.projectId,
user: inputs.request.currentUser,
board,
});
sails.helpers.utils.sendWebhooks.with({
event: 'boardUpdate',
data: {
item: board,
included: {
projects: [inputs.project],
},
},
user: inputs.actorUser,
});
}
return board;
},