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

feat: Permissions for board members

Closes #262
This commit is contained in:
Maksim Eltyshev 2022-08-19 14:00:40 +02:00
parent 281cb4a71b
commit f9e0147f33
61 changed files with 1063 additions and 191 deletions

View file

@ -1,4 +1,7 @@
const Errors = {
NOT_ENOUGH_RIGHTS: {
notEnoughRights: 'Not enough rights',
},
CARD_NOT_FOUND: {
cardNotFound: 'Card not found',
},
@ -18,6 +21,9 @@ module.exports = {
},
exits: {
notEnoughRights: {
responseType: 'forbidden',
},
cardNotFound: {
responseType: 'notFound',
},
@ -30,12 +36,19 @@ module.exports = {
.getProjectPath(inputs.cardId)
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
const isBoardMember = await sails.helpers.users.isBoardMember(currentUser.id, card.boardId);
const boardMembership = await BoardMembership.findOne({
boardId: card.boardId,
userId: currentUser.id,
});
if (!isBoardMember) {
if (!boardMembership) {
throw Errors.CARD_NOT_FOUND; // Forbidden
}
if (boardMembership.role !== BoardMembership.Roles.EDITOR && !boardMembership.canComment) {
throw Errors.NOT_ENOUGH_RIGHTS;
}
const values = {
type: Action.Types.COMMENT_CARD,
data: _.pick(inputs, ['text']),

View file

@ -1,4 +1,7 @@
const Errors = {
NOT_ENOUGH_RIGHTS: {
notEnoughRights: 'Not enough rights',
},
COMMENT_ACTION_NOT_FOUND: {
commentActionNotFound: 'Comment action not found',
},
@ -14,6 +17,9 @@ module.exports = {
},
exits: {
notEnoughRights: {
responseType: 'forbidden',
},
commentActionNotFound: {
responseType: 'notFound',
},
@ -39,11 +45,18 @@ module.exports = {
throw Errors.COMMENT_ACTION_NOT_FOUND; // Forbidden
}
const isBoardMember = await sails.helpers.users.isBoardMember(currentUser.id, board.id);
const boardMembership = await BoardMembership.findOne({
boardId: board.id,
userId: currentUser.id,
});
if (!isBoardMember) {
if (!boardMembership) {
throw Errors.COMMENT_ACTION_NOT_FOUND; // Forbidden
}
if (boardMembership.role !== BoardMembership.Roles.EDITOR && !boardMembership.canComment) {
throw Errors.NOT_ENOUGH_RIGHTS;
}
}
action = await sails.helpers.actions.deleteOne(action, board, this.req);

View file

@ -1,4 +1,7 @@
const Errors = {
NOT_ENOUGH_RIGHTS: {
notEnoughRights: 'Not enough rights',
},
COMMENT_ACTION_NOT_FOUND: {
commentActionNotFound: 'Comment action not found',
},
@ -18,6 +21,9 @@ module.exports = {
},
exits: {
notEnoughRights: {
responseType: 'forbidden',
},
commentActionNotFound: {
responseType: 'notFound',
},
@ -43,11 +49,18 @@ module.exports = {
throw Errors.COMMENT_ACTION_NOT_FOUND; // Forbidden
}
const isBoardMember = await sails.helpers.users.isBoardMember(currentUser.id, board.id);
const boardMembership = await BoardMembership.findOne({
boardId: board.id,
userId: currentUser.id,
});
if (!isBoardMember) {
if (!boardMembership) {
throw Errors.COMMENT_ACTION_NOT_FOUND; // Forbidden
}
if (boardMembership.role !== BoardMembership.Roles.EDITOR && !boardMembership.canComment) {
throw Errors.NOT_ENOUGH_RIGHTS;
}
}
const values = {