Skip to content

Commit

Permalink
Fix files uploaded by other users not being able to be deleted by use…
Browse files Browse the repository at this point in the history
…rs with permission
  • Loading branch information
graywolf336 committed Jan 20, 2017
1 parent 1bae5c5 commit b618e77
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions client/methods/deleteMessage.js
Expand Up @@ -7,6 +7,9 @@ Meteor.methods({
return false;
}

//We're now only passed in the `_id` property to lower the amount of data sent to the server
message = ChatMessage.findOne({ _id: message._id });

const hasPermission = RocketChat.authz.hasAtLeastOnePermission('delete-message', message.rid);
const deleteAllowed = RocketChat.settings.get('Message_AllowDeleting');
let deleteOwn = false;
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-file-upload/lib/FileUploadBase.js
Expand Up @@ -9,7 +9,7 @@ UploadFS.config.defaultStorePermissions = new UploadFS.StorePermissions({
return userId === doc.userId;
},
remove: function(userId, doc) {
return userId === doc.userId;
return RocketChat.authz.hasPermission(Meteor.userId(), 'delete-message', doc.rid) || (RocketChat.settings.get('Message_AllowDeleting') && userId === doc.userId);
}
});

Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-ui/lib/chatMessages.coffee
Expand Up @@ -253,7 +253,7 @@ class @ChatMessages
toastr.error(t('Message_deleting_blocked'))
return

Meteor.call 'deleteMessage', message, (error, result) ->
Meteor.call 'deleteMessage', { _id: message._id }, (error, result) ->
if error
return handleError(error)

Expand Down
9 changes: 8 additions & 1 deletion server/methods/deleteFileMessage.js
@@ -1,7 +1,14 @@
/* global FileUpload */
Meteor.methods({
deleteFileMessage: function(fileID) {
check(fileID, String);

return Meteor.call('deleteMessage', RocketChat.models.Messages.getMessageByFileId(fileID));
const msg = RocketChat.models.Messages.getMessageByFileId(fileID);

if (msg) {
return Meteor.call('deleteMessage', msg);
}

return FileUpload.delete(fileID);
}
});

0 comments on commit b618e77

Please sign in to comment.