Skip to content

Commit

Permalink
feat: update threads create authorization to disallow moderated threa…
Browse files Browse the repository at this point in the history
…ds if board disables them
  • Loading branch information
akinsey committed Jun 26, 2020
1 parent f2e159f commit 7c2e012
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion modules/ept-threads/authorization/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ module.exports = function (server, auth, payload) {
userId: userId
});

// board self mod check
var selfmod = server.authorization.build({
error: Boom.forbidden('Board does not allow self moderated threads'),
type: 'dbValue',
method: function(boardId) {
return server.db.boards.find(boardId)
.then(function(board) {
if (payload.moderated && board.disable_selfmod) {
return false;
}
else { return true; }
});
},
args: [boardId]
});

// user is not banned from this board
var notBannedFromBoard = server.authorization.common.isNotBannedFromBoard(Boom.forbidden('You are banned from this board'), server, userId, { boardId: boardId });

Expand Down Expand Up @@ -79,5 +95,5 @@ module.exports = function (server, auth, payload) {
else { return reject(Boom.forbidden()); }
});

return Promise.all([allowed, read, write, notBannedFromBoard, active, pollData, moderated]);
return Promise.all([allowed, read, write, selfmod, notBannedFromBoard, active, pollData, moderated]);
};

0 comments on commit 7c2e012

Please sign in to comment.