Skip to content

Commit

Permalink
feat: Webhooks configuration, all events support, refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
meltyshev committed Jun 11, 2024
1 parent 3779bdb commit c065566
Show file tree
Hide file tree
Showing 96 changed files with 1,274 additions and 503 deletions.
9 changes: 9 additions & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ services:
# - SMTP_PASSWORD=
# - SMTP_FROM="Demo Demo" <demo@demo.demo>

# Optional fields: accessToken, events, excludedEvents
# - |
# WEBHOOKS=[{
# "url": "http://localhost:3001",
# "accessToken": "notaccesstoken",
# "events": ["cardCreate", "cardUpdate", "cardDelete"],
# "excludedEvents": ["notificationCreate", "notificationUpdate"]
# }]

# - SLACK_BOT_TOKEN=
# - SLACK_CHANNEL_ID=

Expand Down
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ services:
# - SMTP_PASSWORD=
# - SMTP_FROM="Demo Demo" <demo@demo.demo>

# Optional fields: accessToken, events, excludedEvents
# - |
# WEBHOOKS=[{
# "url": "http://localhost:3001",
# "accessToken": "notaccesstoken",
# "events": ["cardCreate", "cardUpdate", "cardDelete"],
# "excludedEvents": ["notificationCreate", "notificationUpdate"]
# }]

# - SLACK_BOT_TOKEN=
# - SLACK_CHANNEL_ID=
depends_on:
Expand Down
11 changes: 8 additions & 3 deletions server/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ SECRET_KEY=notsecretkey
# SMTP_PASSWORD=
# SMTP_FROM="Demo Demo" <demo@demo.demo>

# Optional fields: accessToken, events, excludedEvents
# WEBHOOKS='[{
# "url": "http://localhost:3001",
# "accessToken": "notaccesstoken",
# "events": ["cardCreate", "cardUpdate", "cardDelete"],
# "excludedEvents": ["notificationCreate", "notificationUpdate"]
# }]'

# SLACK_BOT_TOKEN=
# SLACK_CHANNEL_ID=

# WEBHOOK_URL=
# WEBHOOK_BEARER=

## Do not edit this

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

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

const boardMembership = await BoardMembership.findOne({
boardId: card.boardId,
boardId: board.id,
userId: currentUser.id,
});

Expand Down Expand Up @@ -83,12 +83,14 @@ module.exports = {
const fileData = await sails.helpers.attachments.processUploadedFile(file);

const attachment = await sails.helpers.attachments.createOne.with({
project,
board,
list,
values: {
...fileData,
card,
creatorUser: currentUser,
},
board,
requestId: inputs.requestId,
request: this.req,
});
Expand Down
5 changes: 4 additions & 1 deletion server/api/controllers/attachments/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = {
.intercept('pathNotFound', () => Errors.ATTACHMENT_NOT_FOUND);

let { attachment } = path;
const { card, board } = path;
const { card, list, board, project } = path;

const boardMembership = await BoardMembership.findOne({
boardId: board.id,
Expand All @@ -49,9 +49,12 @@ module.exports = {
}

attachment = await sails.helpers.attachments.deleteOne.with({
project,
board,
list,
card,
record: attachment,
actorUser: currentUser,
request: this.req,
});

Expand Down
6 changes: 5 additions & 1 deletion server/api/controllers/attachments/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = {
.intercept('pathNotFound', () => Errors.ATTACHMENT_NOT_FOUND);

let { attachment } = path;
const { board } = path;
const { card, list, board, project } = path;

const boardMembership = await BoardMembership.findOne({
boardId: board.id,
Expand All @@ -56,8 +56,12 @@ module.exports = {

attachment = await sails.helpers.attachments.updateOne.with({
values,
project,
board,
list,
card,
record: attachment,
actorUser: currentUser,
request: this.req,
});

Expand Down
9 changes: 4 additions & 5 deletions server/api/controllers/board-memberships/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,11 @@ module.exports = {
async fn(inputs) {
const { currentUser } = this.req;

const { board } = await sails.helpers.boards
const { board, project } = await sails.helpers.boards
.getProjectPath(inputs.boardId)
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND);

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

if (!isProjectManager) {
throw Errors.BOARD_NOT_FOUND; // Forbidden
Expand All @@ -71,11 +68,13 @@ module.exports = {

const boardMembership = await sails.helpers.boardMemberships.createOne
.with({
project,
values: {
...values,
board,
user,
},
actorUser: currentUser,
request: this.req,
})
.intercept('userAlreadyBoardMember', () => Errors.USER_ALREADY_BOARD_MEMBER);
Expand Down
4 changes: 3 additions & 1 deletion server/api/controllers/board-memberships/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = {
.intercept('pathNotFound', () => Errors.BOARD_MEMBERSHIP_NOT_FOUND);

let { boardMembership } = path;
const { project } = path;
const { board, project } = path;

if (boardMembership.userId !== currentUser.id) {
const isProjectManager = await sails.helpers.users.isProjectManager(
Expand All @@ -42,7 +42,9 @@ module.exports = {

boardMembership = await sails.helpers.boardMemberships.deleteOne.with({
project,
board,
record: boardMembership,
actorUser: currentUser,
request: this.req,
});

Expand Down
5 changes: 4 additions & 1 deletion server/api/controllers/board-memberships/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = {
.intercept('pathNotFound', () => Errors.BOARD_MEMBERSHIP_NOT_FOUND);

let { boardMembership } = path;
const { project } = path;
const { board, project } = path;

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

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

boardMembership = await sails.helpers.boardMemberships.updateOne.with({
values,
project,
board,
record: boardMembership,
actorUser: currentUser,
request: this.req,
});

Expand Down
2 changes: 1 addition & 1 deletion server/api/controllers/boards/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ module.exports = {
project,
},
import: boardImport,
user: currentUser,
actorUser: currentUser,
requestId: inputs.requestId,
request: this.req,
});
Expand Down
12 changes: 7 additions & 5 deletions server/api/controllers/boards/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,27 @@ module.exports = {
async fn(inputs) {
const { currentUser } = this.req;

let { board } = await sails.helpers.boards
const path = await sails.helpers.boards
.getProjectPath(inputs.id)
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND);

let { board } = path;
const { project } = path;

if (!board) {
throw Errors.BOARD_NOT_FOUND;
}

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

if (!isProjectManager) {
throw Errors.BOARD_NOT_FOUND; // Forbidden
}

board = await sails.helpers.boards.deleteOne.with({
project,
record: board,
actorUser: currentUser,
request: this.req,
});

Expand Down
12 changes: 7 additions & 5 deletions server/api/controllers/boards/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ module.exports = {
async fn(inputs) {
const { currentUser } = this.req;

let { board } = await sails.helpers.boards
const path = await sails.helpers.boards
.getProjectPath(inputs.id)
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND);

let { board } = path;
const { project } = path;

if (!board) {
throw Errors.BOARD_NOT_FOUND;
}

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

if (!isProjectManager) {
throw Errors.BOARD_NOT_FOUND; // Forbidden
Expand All @@ -50,7 +50,9 @@ module.exports = {

board = await sails.helpers.boards.updateOne.with({
values,
project,
record: board,
actorUser: currentUser,
request: this.req,
});

Expand Down
10 changes: 7 additions & 3 deletions server/api/controllers/card-labels/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ module.exports = {
async fn(inputs) {
const { currentUser } = this.req;

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

const boardMembership = await BoardMembership.findOne({
boardId: card.boardId,
boardId: board.id,
userId: currentUser.id,
});

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

const label = await Label.findOne({
id: inputs.labelId,
boardId: card.boardId,
boardId: board.id,
});

if (!label) {
Expand All @@ -73,10 +73,14 @@ module.exports = {

const cardLabel = await sails.helpers.cardLabels.createOne
.with({
project,
board,
list,
values: {
card,
label,
},
actorUser: currentUser,
request: this.req,
})
.intercept('labelAlreadyInCard', () => Errors.LABEL_ALREADY_IN_CARD);
Expand Down
6 changes: 5 additions & 1 deletion server/api/controllers/card-labels/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 { card, list, board, project } = await sails.helpers.cards
.getProjectPath(inputs.cardId)
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);

Expand All @@ -66,8 +66,12 @@ module.exports = {
}

cardLabel = await sails.helpers.cardLabels.deleteOne.with({
project,
board,
list,
card,
record: cardLabel,
actorUser: currentUser,
request: this.req,
});

Expand Down
11 changes: 7 additions & 4 deletions server/api/controllers/card-memberships/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ module.exports = {
async fn(inputs) {
const { currentUser } = this.req;

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

const boardMembership = await BoardMembership.findOne({
boardId: card.boardId,
boardId: board.id,
userId: currentUser.id,
});

Expand All @@ -62,19 +62,22 @@ module.exports = {
throw Errors.NOT_ENOUGH_RIGHTS;
}

const isBoardMember = await sails.helpers.users.isBoardMember(inputs.userId, card.boardId);
const isBoardMember = await sails.helpers.users.isBoardMember(inputs.userId, board.id);

if (!isBoardMember) {
throw Errors.USER_NOT_FOUND;
}

const cardMembership = await sails.helpers.cardMemberships.createOne
.with({
project,
board,
list,
values: {
card,
userId: inputs.userId,
},
board,
actorUser: currentUser,
request: this.req,
})
.intercept('userAlreadyCardMember', () => Errors.USER_ALREADY_CARD_MEMBER);
Expand Down
5 changes: 4 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, card } = await sails.helpers.cards
const { card, list, board, project } = await sails.helpers.cards
.getProjectPath(inputs.cardId)
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);

Expand All @@ -66,9 +66,12 @@ module.exports = {
}

cardMembership = await sails.helpers.cardMemberships.deleteOne.with({
project,
board,
list,
card,
record: cardMembership,
actorUser: currentUser,
request: this.req,
});

Expand Down
Loading

0 comments on commit c065566

Please sign in to comment.