1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-23 15:19:44 +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 3779bdb053
commit c065566c15
96 changed files with 1280 additions and 509 deletions

View file

@ -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,
});
@ -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,
});

View file

@ -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,
@ -49,9 +49,12 @@ module.exports = {
}
attachment = await sails.helpers.attachments.deleteOne.with({
project,
board,
list,
card,
record: attachment,
actorUser: currentUser,
request: this.req,
});

View file

@ -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,
@ -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,
});

View file

@ -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
@ -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);

View file

@ -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(
@ -42,7 +42,9 @@ module.exports = {
boardMembership = await sails.helpers.boardMemberships.deleteOne.with({
project,
board,
record: boardMembership,
actorUser: currentUser,
request: this.req,
});

View file

@ -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);
@ -47,7 +47,10 @@ module.exports = {
boardMembership = await sails.helpers.boardMemberships.updateOne.with({
values,
project,
board,
record: boardMembership,
actorUser: currentUser,
request: this.req,
});

View file

@ -103,7 +103,7 @@ module.exports = {
project,
},
import: boardImport,
user: currentUser,
actorUser: currentUser,
requestId: inputs.requestId,
request: this.req,
});

View file

@ -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,
});

View file

@ -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
@ -50,7 +50,9 @@ module.exports = {
board = await sails.helpers.boards.updateOne.with({
values,
project,
record: board,
actorUser: currentUser,
request: this.req,
});

View file

@ -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,
});
@ -64,7 +64,7 @@ module.exports = {
const label = await Label.findOne({
id: inputs.labelId,
boardId: card.boardId,
boardId: board.id,
});
if (!label) {
@ -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);

View file

@ -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);
@ -66,8 +66,12 @@ module.exports = {
}
cardLabel = await sails.helpers.cardLabels.deleteOne.with({
project,
board,
list,
card,
record: cardLabel,
actorUser: currentUser,
request: this.req,
});

View file

@ -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,
});
@ -62,7 +62,7 @@ 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;
@ -70,11 +70,14 @@ module.exports = {
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);

View file

@ -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);
@ -66,9 +66,12 @@ module.exports = {
}
cardMembership = await sails.helpers.cardMemberships.deleteOne.with({
project,
board,
list,
card,
record: cardMembership,
actorUser: currentUser,
request: this.req,
});

View file

@ -78,7 +78,7 @@ module.exports = {
async fn(inputs) {
const { currentUser } = this.req;
const { board, list } = await sails.helpers.lists
const { list, board, project } = await sails.helpers.lists
.getProjectPath(inputs.listId)
.intercept('pathNotFound', () => Errors.LIST_NOT_FOUND);
@ -99,6 +99,7 @@ module.exports = {
const card = await sails.helpers.cards.createOne
.with({
project,
board,
values: {
...values,

View file

@ -28,12 +28,15 @@ module.exports = {
async fn(inputs) {
const { currentUser } = this.req;
let { card } = await sails.helpers.cards
const path = await sails.helpers.cards
.getProjectPath(inputs.id)
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
let { card } = path;
const { list, board, project } = path;
const boardMembership = await BoardMembership.findOne({
boardId: card.boardId,
boardId: board.id,
userId: currentUser.id,
});
@ -46,8 +49,11 @@ module.exports = {
}
card = await sails.helpers.cards.deleteOne.with({
project,
board,
list,
record: card,
user: currentUser,
actorUser: currentUser,
request: this.req,
});

View file

@ -35,12 +35,12 @@ module.exports = {
async fn(inputs) {
const { currentUser } = this.req;
const { card, list, board } = await sails.helpers.cards
const { card, list, board, project } = await sails.helpers.cards
.getProjectPath(inputs.id)
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
const boardMembership = await BoardMembership.findOne({
boardId: card.boardId,
boardId: board.id,
userId: currentUser.id,
});
@ -60,6 +60,7 @@ module.exports = {
cardLabels,
tasks,
} = await sails.helpers.cards.duplicateOne.with({
project,
board,
list,
record: card,

View file

@ -118,7 +118,7 @@ module.exports = {
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
let { card } = path;
const { list, board } = path;
const { list, board, project } = path;
let boardMembership = await BoardMembership.findOne({
boardId: board.id,
@ -133,9 +133,11 @@ module.exports = {
throw Errors.NOT_ENOUGH_RIGHTS;
}
let nextProject;
let nextBoard;
if (!_.isUndefined(inputs.boardId)) {
({ board: nextBoard } = await sails.helpers.boards
({ board: nextBoard, project: nextProject } = await sails.helpers.boards
.getProjectPath(inputs.boardId)
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND));
@ -177,15 +179,17 @@ module.exports = {
card = await sails.helpers.cards.updateOne
.with({
project,
board,
list,
record: card,
values: {
...values,
project: nextProject,
board: nextBoard,
list: nextList,
},
user: currentUser,
actorUser: currentUser,
request: this.req,
})
.intercept('positionMustBeInValues', () => Errors.POSITION_MUST_BE_PRESENT)

View file

@ -32,7 +32,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);
@ -55,7 +55,9 @@ module.exports = {
};
const action = await sails.helpers.actions.createOne.with({
project,
board,
list,
values: {
...values,
card,

View file

@ -36,7 +36,7 @@ module.exports = {
.intercept('pathNotFound', () => Errors.COMMENT_ACTION_NOT_FOUND);
let { action } = path;
const { board, project, card } = path;
const { card, list, board, project } = path;
const isProjectManager = await sails.helpers.users.isProjectManager(currentUser.id, project.id);
@ -60,9 +60,12 @@ module.exports = {
}
action = await sails.helpers.actions.deleteOne.with({
project,
board,
list,
card,
record: action,
actorUser: currentUser,
request: this.req,
});

View file

@ -40,7 +40,7 @@ module.exports = {
.intercept('pathNotFound', () => Errors.COMMENT_ACTION_NOT_FOUND);
let { action } = path;
const { board, project, card } = path;
const { card, list, board, project } = path;
const isProjectManager = await sails.helpers.users.isProjectManager(currentUser.id, project.id);
@ -69,9 +69,12 @@ module.exports = {
action = await sails.helpers.actions.updateOne.with({
values,
card,
project,
board,
list,
card,
record: action,
actorUser: currentUser,
request: this.req,
});

View file

@ -42,7 +42,7 @@ 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);
@ -62,10 +62,12 @@ module.exports = {
const values = _.pick(inputs, ['position', 'name', 'color']);
const label = await sails.helpers.labels.createOne.with({
project,
values: {
...values,
board,
},
actorUser: currentUser,
request: this.req,
});

View file

@ -28,12 +28,15 @@ module.exports = {
async fn(inputs) {
const { currentUser } = this.req;
let { label } = await sails.helpers.labels
const path = await sails.helpers.labels
.getProjectPath(inputs.id)
.intercept('pathNotFound', () => Errors.LABEL_NOT_FOUND);
let { label } = path;
const { board, project } = path;
const boardMembership = await BoardMembership.findOne({
boardId: label.boardId,
boardId: board.id,
userId: currentUser.id,
});
@ -46,7 +49,10 @@ module.exports = {
}
label = await sails.helpers.labels.deleteOne.with({
project,
board,
record: label,
actorUser: currentUser,
request: this.req,
});

View file

@ -40,12 +40,15 @@ module.exports = {
async fn(inputs) {
const { currentUser } = this.req;
let { label } = await sails.helpers.labels
const path = await sails.helpers.labels
.getProjectPath(inputs.id)
.intercept('pathNotFound', () => Errors.LABEL_NOT_FOUND);
let { label } = path;
const { board, project } = path;
const boardMembership = await BoardMembership.findOne({
boardId: label.boardId,
boardId: board.id,
userId: currentUser.id,
});
@ -61,7 +64,10 @@ module.exports = {
label = await sails.helpers.labels.updateOne.with({
values,
project,
board,
record: label,
actorUser: currentUser,
request: this.req,
});

View file

@ -36,7 +36,7 @@ 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);
@ -56,10 +56,12 @@ module.exports = {
const values = _.pick(inputs, ['position', 'name']);
const list = await sails.helpers.lists.createOne.with({
project,
values: {
...values,
board,
},
actorUser: currentUser,
request: this.req,
});

View file

@ -28,13 +28,15 @@ module.exports = {
async fn(inputs) {
const { currentUser } = this.req;
// eslint-disable-next-line prefer-const
let { list, board } = await sails.helpers.lists
const path = await sails.helpers.lists
.getProjectPath(inputs.id)
.intercept('pathNotFound', () => Errors.LIST_NOT_FOUND);
let { list } = path;
const { board, project } = path;
const boardMembership = await BoardMembership.findOne({
boardId: list.boardId,
boardId: board.id,
userId: currentUser.id,
});
@ -47,8 +49,10 @@ module.exports = {
}
list = await sails.helpers.lists.deleteOne.with({
record: list,
project,
board,
record: list,
actorUser: currentUser,
request: this.req,
});

View file

@ -32,12 +32,12 @@ module.exports = {
async fn(inputs) {
const { currentUser } = this.req;
const { list } = await sails.helpers.lists
const { list, board, project } = await sails.helpers.lists
.getProjectPath(inputs.id)
.intercept('pathNotFound', () => Errors.LIST_NOT_FOUND);
const boardMembership = await BoardMembership.findOne({
boardId: list.boardId,
boardId: board.id,
userId: currentUser.id,
});
@ -50,8 +50,11 @@ module.exports = {
}
const cards = await sails.helpers.lists.sortOne.with({
project,
board,
record: list,
type: inputs.type,
actorUser: currentUser,
request: this.req,
});

View file

@ -35,13 +35,15 @@ module.exports = {
async fn(inputs) {
const { currentUser } = this.req;
// eslint-disable-next-line prefer-const
let { list, board } = await sails.helpers.lists
const path = await sails.helpers.lists
.getProjectPath(inputs.id)
.intercept('pathNotFound', () => Errors.LIST_NOT_FOUND);
let { list } = path;
const { board, project } = path;
const boardMembership = await BoardMembership.findOne({
boardId: list.boardId,
boardId: board.id,
userId: currentUser.id,
});
@ -57,8 +59,10 @@ module.exports = {
list = await sails.helpers.lists.updateOne.with({
values,
project,
board,
record: list,
actorUser: currentUser,
request: this.req,
});

View file

@ -18,7 +18,7 @@ module.exports = {
const notifications = await sails.helpers.notifications.updateMany.with({
values,
recordsOrIds: inputs.ids.split(','),
user: currentUser,
actorUser: currentUser,
request: this.req,
});

View file

@ -63,6 +63,7 @@ module.exports = {
project,
user,
},
actorUser: currentUser,
request: this.req,
})
.intercept('userAlreadyProjectManager', () => Errors.USER_ALREADY_PROJECT_MANAGER);

View file

@ -40,6 +40,7 @@ module.exports = {
// TODO: check if the last one
projectManager = await sails.helpers.projectManagers.deleteOne.with({
record: projectManager,
actorUser: currentUser,
request: this.req,
});

View file

@ -13,7 +13,7 @@ module.exports = {
const { project, projectManager } = await sails.helpers.projects.createOne.with({
values,
user: currentUser,
actorUser: currentUser,
request: this.req,
});

View file

@ -36,6 +36,7 @@ module.exports = {
project = await sails.helpers.projects.deleteOne.with({
record: project,
actorUser: currentUser,
request: this.req,
});

View file

@ -90,6 +90,7 @@ module.exports = {
values: {
backgroundImage: fileData,
},
actorUser: currentUser,
request: this.req,
});

View file

@ -81,6 +81,7 @@ module.exports = {
project = await sails.helpers.projects.updateOne.with({
values,
record: project,
actorUser: currentUser,
request: this.req,
});

View file

@ -39,12 +39,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,
});
@ -59,11 +59,14 @@ module.exports = {
const values = _.pick(inputs, ['position', 'name', 'isCompleted']);
const task = await sails.helpers.tasks.createOne.with({
project,
board,
list,
values: {
...values,
card,
},
board,
actorUser: currentUser,
request: this.req,
});

View file

@ -33,7 +33,7 @@ module.exports = {
.intercept('pathNotFound', () => Errors.TASK_NOT_FOUND);
let { task } = path;
const { board } = path;
const { card, list, board, project } = path;
const boardMembership = await BoardMembership.findOne({
boardId: board.id,
@ -49,8 +49,12 @@ module.exports = {
}
task = await sails.helpers.tasks.deleteOne.with({
project,
board,
list,
card,
record: task,
actorUser: currentUser,
request: this.req,
});

View file

@ -43,7 +43,7 @@ module.exports = {
.intercept('pathNotFound', () => Errors.TASK_NOT_FOUND);
let { task } = path;
const { board } = path;
const { card, list, board, project } = path;
const boardMembership = await BoardMembership.findOne({
boardId: board.id,
@ -62,8 +62,12 @@ module.exports = {
task = await sails.helpers.tasks.updateOne.with({
values,
project,
board,
list,
card,
record: task,
actorUser: currentUser,
request: this.req,
});

View file

@ -71,6 +71,8 @@ module.exports = {
},
async fn(inputs) {
const { currentUser } = this.req;
if (sails.config.custom.oidcEnforced) {
throw Errors.NOT_ENOUGH_RIGHTS;
}
@ -89,6 +91,7 @@ module.exports = {
const user = await sails.helpers.users.createOne
.with({
values,
actorUser: currentUser,
request: this.req,
})
.intercept('emailAlreadyInUse', () => Errors.EMAIL_ALREADY_IN_USE)

View file

@ -26,6 +26,8 @@ module.exports = {
},
async fn(inputs) {
const { currentUser } = this.req;
let user = await sails.helpers.users.getOne(inputs.id);
if (!user) {
@ -38,6 +40,7 @@ module.exports = {
user = await sails.helpers.users.deleteOne.with({
record: user,
actorUser: currentUser,
request: this.req,
});

View file

@ -91,7 +91,7 @@ module.exports = {
values: {
avatar: fileData,
},
user: currentUser,
actorUser: currentUser,
request: this.req,
});

View file

@ -82,7 +82,7 @@ module.exports = {
.with({
values,
record: user,
user: currentUser,
actorUser: currentUser,
request: this.req,
})
.intercept('emailAlreadyInUse', () => Errors.EMAIL_ALREADY_IN_USE);

View file

@ -80,7 +80,7 @@ module.exports = {
user = await sails.helpers.users.updateOne.with({
values,
record: user,
user: currentUser,
actorUser: currentUser,
request: this.req,
});

View file

@ -83,7 +83,7 @@ module.exports = {
.with({
values,
record: user,
user: currentUser,
actorUser: currentUser,
request: this.req,
})
.intercept('usernameAlreadyInUse', () => Errors.USERNAME_ALREADY_IN_USE);

View file

@ -95,7 +95,7 @@ module.exports = {
user = await sails.helpers.users.updateOne.with({
values,
record: user,
user: currentUser,
actorUser: currentUser,
request: this.req,
});