Skip to content

Commit a9e38f2

Browse files
committed
fix(messages): invalid permissions
1 parent 3145408 commit a9e38f2

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/controllers/messages.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ messagesController.get = function (req, res) {
9090
})
9191
}
9292

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

@@ -181,6 +181,16 @@ messagesController.getConversation = function (req, res) {
181181
}
182182

183183
const c = convo.toObject()
184+
185+
let isPart = false
186+
_.each(c.participants, function (p) {
187+
if (p._id.toString() === req.user._id.toString()) isPart = true
188+
})
189+
190+
if (!isPart) {
191+
return res.redirect('/messages')
192+
}
193+
184194
messageSchema.getConversationWithObject(
185195
{ cid: c._id, userMeta: convo.userMeta, requestingUser: req.user },
186196
function (err, messages) {

0 commit comments

Comments
 (0)