The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/server/methods/canAccessRoom.coffee

26 lines
882 B

Meteor.methods
canAccessRoom: (rid, userId) ->
console.log '[methods] canAccessRoom -> '.green, 'userId:', userId, 'rid:', rid
user = RocketChat.models.Users.findOneById userId, fields: username: 1
unless user?.username
throw new Meteor.Error 'not-logged-user', "[methods] canAccessRoom -> User doesn't have enough permissions"
unless rid
throw new Meteor.Error 'invalid-room', '[methods] canAccessRoom -> Cannot access empty room'
room = RocketChat.models.Rooms.findOneById rid, { fields: { usernames: 1, t: 1, name: 1 } }
if room
if room.t is 'c'
canAccess = true
else if room.usernames.indexOf(user.username) isnt -1
canAccess = true
if canAccess isnt true
return false
else
return _.pick room, ['_id', 't', 'name', 'usernames']
else
throw new Meteor.Error 'invalid-room', '[methods] canAccessRoom -> Room ID is invalid'