Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added checks to updateMessage and deleteMessage #621

Merged
merged 3 commits into from
Aug 29, 2015
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions server/methods/deleteMessage.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Meteor.methods
if not RocketChat.settings.get 'Message_AllowDeleting'
throw new Meteor.Error 'message-deleting-not-allowed', "[methods] updateMessage -> Message deleting not allowed"

user = Meteor.users.findOne Meteor.userId()

unless user?.admin is true or message.u._id is Meteor.userId()
throw new Meteor.Error 'not-authorized', '[methods] deleteMessage -> Not authorized'

console.log '[methods] deleteMessage -> '.green, 'userId:', Meteor.userId(), 'arguments:', arguments

Expand All @@ -25,7 +29,7 @@ Meteor.methods
_id: message._id
'u._id': Meteor.userId()
,
$set:
$set:
_hidden: true

else
Expand All @@ -39,7 +43,7 @@ Meteor.methods
_id: message._id
'u._id': Meteor.userId()
,
$set:
$set:
msg: ''
t: 'rm'
ets: new Date()
Expand Down
10 changes: 3 additions & 7 deletions server/methods/deleteUser.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ Meteor.methods
deleteUser: (userId) ->
if not Meteor.userId()
throw new Meteor.Error('invalid-user', "[methods] deleteUser -> Invalid user")

user = Meteor.users.findOne userId

user = Meteor.users.findOne Meteor.userId()
unless user?.admin is true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only can delete admin users?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah my bad. Forgot this is an action being done only by the admin. Reverted

throw new Meteor.Error 'not-authorized', '[methods] deleteUser -> Not authorized'

user = Meteor.users.findOne userId
unless user?
throw new Meteor.Error 'not-found', '[methods] deleteUser -> User not found'

Expand All @@ -18,10 +18,6 @@ Meteor.methods
if room.t isnt 'c' and room.usernames.length is 1
ChatRoom.remove subscription.rid # Remove non-channel rooms with only 1 user (the one being deleted)





ChatSubscription.remove { "u._id": userId } # Remove user subscriptions

rooms = ChatRoom.find({ "u._id": userId }).fetch()
Expand All @@ -31,4 +27,4 @@ Meteor.methods
ChatRoom.update {}, { $pull: { usernames: user.username } }, { multi: true } # Remove user from all other rooms
Meteor.users.remove { _id: userId } # Remove user from users database

return true
return true
7 changes: 6 additions & 1 deletion server/methods/updateMessage.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Meteor.methods
if not RocketChat.settings.get 'Message_AllowEditing'
throw new Meteor.Error 'message-editing-not-allowed', "[methods] updateMessage -> Message editing not allowed"

user = Meteor.users.findOne Meteor.userId()

unless user?.admin is true or message.u._id is Meteor.userId()
throw new Meteor.Error 'not-authorized', '[methods] updateMessage -> Not authorized'

console.log '[methods] updateMessage -> '.green, 'userId:', Meteor.userId(), 'arguments:', arguments

# If we keep history of edits, insert a new message to store history information
Expand All @@ -31,4 +36,4 @@ Meteor.methods
$set: message

# Meteor.defer ->
# RocketChat.callbacks.run 'afterSaveMessage', ChatMessage.findOne(message.id)
# RocketChat.callbacks.run 'afterSaveMessage', ChatMessage.findOne(message.id)