Skip to content

Commit

Permalink
fix(messages): invalid permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed May 29, 2022
1 parent 3145408 commit a9e38f2
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/controllers/messages.js
Expand Up @@ -90,7 +90,7 @@ messagesController.get = function (req, res) {
})
}

messagesController.getConversation = function (req, res) {
messagesController.getConversation = async (req, res) => {
const cid = req.params.convoid
if (_.isUndefined(cid)) return handleError(res, 'Invalid Conversation ID!')

Expand Down Expand Up @@ -181,6 +181,16 @@ messagesController.getConversation = function (req, res) {
}

const c = convo.toObject()

let isPart = false
_.each(c.participants, function (p) {
if (p._id.toString() === req.user._id.toString()) isPart = true
})

if (!isPart) {
return res.redirect('/messages')
}

messageSchema.getConversationWithObject(
{ cid: c._id, userMeta: convo.userMeta, requestingUser: req.user },
function (err, messages) {
Expand Down

0 comments on commit a9e38f2

Please sign in to comment.