Skip to content

Commit

Permalink
Fix for #173. Board can be removed by owner/admin
Browse files Browse the repository at this point in the history
  • Loading branch information
callapa1 authored Apr 29, 2021
1 parent c2a3571 commit 3f59bb2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions api/controllers/board.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,26 @@ async function getPublicBoards(req, res) {
}

async function deleteBoard(req, res) {
const id = req.swagger.params.id.value;
Board.findByIdAndRemove(id, function (err, boards) {
Board.findByIdAndRemove(req, function (err, board) {
const id = req.swagger.params.id.value;
if (err) {
return res.status(404).json({
message: 'Board not found. Board Id: ' + id,
error: err.message
});
}
if (!boards) {
if (!board) {
return res.status(404).json({
message: 'Board not found. Board Id: ' + id,
error: 'Board not found.'
});
}
return res.status(200).json(boards);
if (!req.user.isAdmin && req.user !== board.author) {
return res.status(403).json({
message: "You are not authorized to delete this user's board."
});
}
return res.status(200).json(board);
});
}

Expand Down

0 comments on commit 3f59bb2

Please sign in to comment.