Skip to content

Commit

Permalink
feat: Events via webhook (#771)
Browse files Browse the repository at this point in the history
Closes #215, closes #656
  • Loading branch information
HannesOberreiter authored Jun 6, 2024
1 parent 4124ab1 commit 3779bdb
Show file tree
Hide file tree
Showing 38 changed files with 416 additions and 9 deletions.
3 changes: 3 additions & 0 deletions server/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ SECRET_KEY=notsecretkey
# SLACK_BOT_TOKEN=
# SLACK_CHANNEL_ID=

# WEBHOOK_URL=
# WEBHOOK_BEARER=

## Do not edit this

TZ=UTC
3 changes: 2 additions & 1 deletion server/api/controllers/attachments/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = {
async fn(inputs, exits) {
const { currentUser } = this.req;

const { card } = await sails.helpers.cards
const { card, board } = await sails.helpers.cards
.getProjectPath(inputs.cardId)
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);

Expand Down Expand Up @@ -88,6 +88,7 @@ module.exports = {
card,
creatorUser: currentUser,
},
board,
requestId: inputs.requestId,
request: this.req,
});
Expand Down
3 changes: 2 additions & 1 deletion server/api/controllers/card-memberships/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = {
async fn(inputs) {
const { currentUser } = this.req;

const { card } = await sails.helpers.cards
const { card, board } = await sails.helpers.cards
.getProjectPath(inputs.cardId)
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);

Expand Down Expand Up @@ -74,6 +74,7 @@ module.exports = {
card,
userId: inputs.userId,
},
board,
request: this.req,
})
.intercept('userAlreadyCardMember', () => Errors.USER_ALREADY_CARD_MEMBER);
Expand Down
3 changes: 2 additions & 1 deletion server/api/controllers/card-memberships/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = {
async fn(inputs) {
const { currentUser } = this.req;

const { board } = await sails.helpers.cards
const { board, card } = await sails.helpers.cards
.getProjectPath(inputs.cardId)
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);

Expand Down Expand Up @@ -67,6 +67,7 @@ module.exports = {

cardMembership = await sails.helpers.cardMemberships.deleteOne.with({
board,
card,
record: cardMembership,
request: this.req,
});
Expand Down
3 changes: 2 additions & 1 deletion server/api/controllers/comment-actions/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = {
.intercept('pathNotFound', () => Errors.COMMENT_ACTION_NOT_FOUND);

let { action } = path;
const { board, project } = path;
const { board, project, card } = path;

const isProjectManager = await sails.helpers.users.isProjectManager(currentUser.id, project.id);

Expand All @@ -61,6 +61,7 @@ module.exports = {

action = await sails.helpers.actions.deleteOne.with({
board,
card,
record: action,
request: this.req,
});
Expand Down
3 changes: 2 additions & 1 deletion server/api/controllers/comment-actions/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports = {
.intercept('pathNotFound', () => Errors.COMMENT_ACTION_NOT_FOUND);

let { action } = path;
const { board, project } = path;
const { board, project, card } = path;

const isProjectManager = await sails.helpers.users.isProjectManager(currentUser.id, project.id);

Expand Down Expand Up @@ -69,6 +69,7 @@ module.exports = {

action = await sails.helpers.actions.updateOne.with({
values,
card,
board,
record: action,
request: this.req,
Expand Down
4 changes: 3 additions & 1 deletion server/api/controllers/lists/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ module.exports = {
async fn(inputs) {
const { currentUser } = this.req;

let { list } = await sails.helpers.lists
// eslint-disable-next-line prefer-const
let { list, board } = await sails.helpers.lists
.getProjectPath(inputs.id)
.intercept('pathNotFound', () => Errors.LIST_NOT_FOUND);

Expand All @@ -47,6 +48,7 @@ module.exports = {

list = await sails.helpers.lists.deleteOne.with({
record: list,
board,
request: this.req,
});

Expand Down
4 changes: 3 additions & 1 deletion server/api/controllers/lists/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ module.exports = {
async fn(inputs) {
const { currentUser } = this.req;

let { list } = await sails.helpers.lists
// eslint-disable-next-line prefer-const
let { list, board } = await sails.helpers.lists
.getProjectPath(inputs.id)
.intercept('pathNotFound', () => Errors.LIST_NOT_FOUND);

Expand All @@ -56,6 +57,7 @@ module.exports = {

list = await sails.helpers.lists.updateOne.with({
values,
board,
record: list,
request: this.req,
});
Expand Down
3 changes: 2 additions & 1 deletion server/api/controllers/tasks/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = {
async fn(inputs) {
const { currentUser } = this.req;

const { card } = await sails.helpers.cards
const { card, board } = await sails.helpers.cards
.getProjectPath(inputs.cardId)
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);

Expand All @@ -63,6 +63,7 @@ module.exports = {
...values,
card,
},
board,
request: this.req,
});

Expand Down
9 changes: 9 additions & 0 deletions server/api/helpers/actions/create-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ module.exports = {
buildAndSendSlackMessage(values.user, values.card, action);
}

await sails.helpers.utils.sendWebhook.with({
event: 'ACTION_CREATE',
data: action,
projectId: inputs.board.projectId,
user: inputs.request.currentUser,
card: values.card,
board: inputs.board,
});

return action;
},
};
13 changes: 13 additions & 0 deletions server/api/helpers/actions/delete-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ module.exports = {
type: 'ref',
required: true,
},
card: {
type: 'ref',
required: true,
},
board: {
type: 'ref',
required: true,
Expand All @@ -25,6 +29,15 @@ module.exports = {
},
inputs.request,
);

await sails.helpers.utils.sendWebhook.with({
event: 'ACTION_DELETE',
data: action,
projectId: inputs.board.projectId,
user: inputs.request.currentUser,
card: inputs.card,
board: inputs.board,
});
}

return action;
Expand Down
13 changes: 13 additions & 0 deletions server/api/helpers/actions/update-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ module.exports = {
type: 'json',
required: true,
},
card: {
type: 'ref',
required: true,
},
board: {
type: 'ref',
required: true,
Expand All @@ -31,6 +35,15 @@ module.exports = {
},
inputs.request,
);

await sails.helpers.utils.sendWebhook.with({
event: 'ACTION_UPDATE',
data: action,
projectId: inputs.board.projectId,
user: inputs.request.currentUser,
card: inputs.card,
board: inputs.board,
});
}

return action;
Expand Down
17 changes: 16 additions & 1 deletion server/api/helpers/attachments/create-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ module.exports = {
custom: valuesValidator,
required: true,
},
board: {
type: 'ref',
required: true,
},
requestId: {
type: 'string',
isNotEmptyString: true,
Expand All @@ -31,7 +35,7 @@ module.exports = {
},

async fn(inputs) {
const { values } = inputs;
const { values, board } = inputs;

const attachment = await Attachment.create({
...values,
Expand All @@ -55,9 +59,20 @@ module.exports = {
values: {
coverAttachmentId: attachment.id,
},
board,
request: inputs.request,
});
}

await sails.helpers.utils.sendWebhook.with({
event: 'ATTACHMENT_CREATE',
data: attachment,
projectId: board.projectId,
user: inputs.request.currentUser,
card: values.card,
board,
});

return attachment;
},
};
9 changes: 9 additions & 0 deletions server/api/helpers/attachments/delete-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ module.exports = {
},
inputs.request,
);

await sails.helpers.utils.sendWebhook.with({
event: 'ATTACHMENT_DELETE',
data: attachment,
projectId: inputs.board.projectId,
user: inputs.request.currentUser,
card: inputs.card,
board: inputs.board,
});
}

return attachment;
Expand Down
8 changes: 8 additions & 0 deletions server/api/helpers/attachments/update-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ module.exports = {
},
inputs.request,
);

await sails.helpers.utils.sendWebhook.with({
event: 'ATTACHMENT_UPDATE',
data: attachment,
projectId: inputs.board.projectId,
user: inputs.request.currentUser,
board: inputs.board,
});
}

return attachment;
Expand Down
8 changes: 8 additions & 0 deletions server/api/helpers/boards/create-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ module.exports = {
);
});

await sails.helpers.utils.sendWebhook.with({
event: 'BOARD_CREATE',
data: board,
projectId: board.projectId,
user: inputs.request.currentUser,
board,
});

return {
board,
boardMembership,
Expand Down
8 changes: 8 additions & 0 deletions server/api/helpers/boards/delete-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ module.exports = {
});
}

await sails.helpers.utils.sendWebhook.with({
event: 'BOARD_DELETE',
data: board,
projectId: board.projectId,
user: inputs.request.currentUser,
board,
});

return board;
},
};
8 changes: 8 additions & 0 deletions server/api/helpers/boards/update-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ module.exports = {
});
}

await sails.helpers.utils.sendWebhook.with({
event: 'BOARD_UPDATE',
data: board,
projectId: board.projectId,
user: inputs.request.currentUser,
board,
});

return board;
},
};
13 changes: 13 additions & 0 deletions server/api/helpers/card-memberships/create-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ module.exports = {
custom: valuesValidator,
required: true,
},
board: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
Expand Down Expand Up @@ -75,6 +79,15 @@ module.exports = {
);
}

await sails.helpers.utils.sendWebhook.with({
event: 'CARD_MEMBERSHIP_CREATE',
data: cardMembership,
projectId: inputs.board.projectId,
user: inputs.request.currentUser,
card: values.card,
board: inputs.board,
});

return cardMembership;
},
};
13 changes: 13 additions & 0 deletions server/api/helpers/card-memberships/delete-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ module.exports = {
type: 'ref',
required: true,
},
card: {
type: 'ref',
required: true,
},
board: {
type: 'ref',
required: true,
Expand Down Expand Up @@ -40,6 +44,15 @@ module.exports = {
},
});
}

await sails.helpers.utils.sendWebhook.with({
event: 'CARD_MEMBERSHIP_DELETE',
data: cardMembership,
projectId: inputs.board.projectId,
user: inputs.request.currentUser,
card: inputs.card,
board: inputs.board,
});
}

return cardMembership;
Expand Down
Loading

0 comments on commit 3779bdb

Please sign in to comment.