forked from RocketChat/Rocket.Chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Qi Yin
committed
May 26, 2017
1 parent
3018807
commit 231cdaa
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
Meteor.methods({ | ||
getRoomNameById(rid) { | ||
check(rid, String); | ||
|
||
if (!Meteor.userId()) { | ||
throw new Meteor.Error('error-invalid-user', 'Invalid user', { | ||
method: 'getRoomNameById' | ||
}); | ||
} | ||
|
||
const room = RocketChat.models.Rooms.findOneById(rid); | ||
|
||
if (room == null) { | ||
throw new Meteor.Error('error-not-allowed', 'Not allowed', { | ||
method: 'getRoomNameById' | ||
}); | ||
} | ||
|
||
const user = Meteor.user(); | ||
if (user && user.username && room.usernames.indexOf(user.username) !== -1) { | ||
return room.name; | ||
} | ||
|
||
if (room.t !== 'c' || RocketChat.authz.hasPermission(Meteor.userId(), 'view-c-room') !== true) { | ||
throw new Meteor.Error('error-not-allowed', 'Not allowed', { | ||
method: 'getRoomNameById' | ||
}); | ||
} | ||
|
||
return room.name; | ||
} | ||
}); |