Skip to content

Commit

Permalink
Fix bug where username incorrectly passed to findOneByUsername. Also
Browse files Browse the repository at this point in the history
adds arugment validation.
  • Loading branch information
rwakida committed Sep 23, 2015
1 parent 1875e33 commit 406edf0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions server/methods/addUserToRoom.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
Meteor.methods
addUserToRoom: (data) ->
fromId = Meteor.userId()
# console.log '[methods] addUserToRoom -> '.green, 'fromId:', fromId, 'data:', data
console.log '[methods] addUserToRoom -> '.green, 'data:', data

unless Match.test data?.rid, String
throw new Meteor.Error 'invalid-rid'

unless Match.test data?.username, String
throw new Meteor.Error 'invalid-username'

room = RocketChat.models.Rooms.findOneById data.rid

Expand All @@ -13,7 +19,7 @@ Meteor.methods
if room.usernames.indexOf(data.username) isnt -1
return

newUser = RocketChat.models.Users.findOneByUsername username: data.username
newUser = RocketChat.models.Users.findOneByUsername data.username

RocketChat.models.Rooms.addUsernameById data.rid, data.username

Expand Down

0 comments on commit 406edf0

Please sign in to comment.