Skip to content

Commit 9257392

Browse files
committed
Merge pull request #621 from geekgonecrazy/permission-checks
Added checks to updateMessage and deleteMessage
2 parents f95c79c + 3538f9e commit 9257392

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

server/methods/deleteMessage.coffee

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ Meteor.methods
66
if not RocketChat.settings.get 'Message_AllowDeleting'
77
throw new Meteor.Error 'message-deleting-not-allowed', "[methods] updateMessage -> Message deleting not allowed"
88

9+
user = Meteor.users.findOne Meteor.userId()
10+
11+
unless user?.admin is true or message.u._id is Meteor.userId()
12+
throw new Meteor.Error 'not-authorized', '[methods] deleteMessage -> Not authorized'
913

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

@@ -25,7 +29,7 @@ Meteor.methods
2529
_id: message._id
2630
'u._id': Meteor.userId()
2731
,
28-
$set:
32+
$set:
2933
_hidden: true
3034

3135
else
@@ -39,7 +43,7 @@ Meteor.methods
3943
_id: message._id
4044
'u._id': Meteor.userId()
4145
,
42-
$set:
46+
$set:
4347
msg: ''
4448
t: 'rm'
4549
ets: new Date()

server/methods/updateMessage.coffee

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ Meteor.methods
66
if not RocketChat.settings.get 'Message_AllowEditing'
77
throw new Meteor.Error 'message-editing-not-allowed', "[methods] updateMessage -> Message editing not allowed"
88

9+
user = Meteor.users.findOne Meteor.userId()
10+
11+
unless user?.admin is true or message.u._id is Meteor.userId()
12+
throw new Meteor.Error 'not-authorized', '[methods] updateMessage -> Not authorized'
13+
914
console.log '[methods] updateMessage -> '.green, 'userId:', Meteor.userId(), 'arguments:', arguments
1015

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

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

0 commit comments

Comments
 (0)