Skip to content

Commit

Permalink
Close #2829 Add setting for blocking message exclusion (#2933)
Browse files Browse the repository at this point in the history
  • Loading branch information
marceloschmidt authored and engelgabriel committed Apr 18, 2016
1 parent 452374a commit 4e33344
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 4 deletions.
7 changes: 7 additions & 0 deletions client/methods/deleteMessage.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ Meteor.methods
unless hasPermission or (deleteAllowed and deleteOwn)
throw new Meteor.Error 'message-deleting-not-allowed', t('Message_deleting_not_allowed')

blockDeleteInMinutes = RocketChat.settings.get 'Message_AllowDeleting_BlockDeleteInMinutes'
if blockDeleteInMinutes? and blockDeleteInMinutes isnt 0
msgTs = moment(message.ts) if message.ts?
currentTsDiff = moment().diff(msgTs, 'minutes') if msgTs?
if currentTsDiff > blockDeleteInMinutes
toastr.error t('Message_deleting_blocked')
throw new Meteor.Error 'message-deleting-blocked'

Tracker.nonreactive ->
ChatMessage.remove
Expand Down
14 changes: 13 additions & 1 deletion packages/rocketchat-lib/client/MessageAction.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,19 @@ Meteor.startup ->
chatMessages[Session.get('openedRoom')].clearEditing(message)
chatMessages[Session.get('openedRoom')].deleteMsg(message)
validation: (message) ->
return RocketChat.authz.hasAtLeastOnePermission('delete-message', message.rid ) or RocketChat.settings.get('Message_AllowDeleting') and message.u?._id is Meteor.userId()
hasPermission = RocketChat.authz.hasAtLeastOnePermission('delete-message', message.rid)
isDeleteAllowed = RocketChat.settings.get 'Message_AllowDeleting'
deleteOwn = message.u?._id is Meteor.userId()

return unless hasPermission or (isDeleteAllowed and deleteOwn)

blockDeleteInMinutes = RocketChat.settings.get 'Message_AllowDeleting_BlockDeleteInMinutes'
if blockDeleteInMinutes? and blockDeleteInMinutes isnt 0
msgTs = moment(message.ts) if message.ts?
currentTsDiff = moment().diff(msgTs, 'minutes') if msgTs?
return currentTsDiff < blockDeleteInMinutes
else
return true
order: 2

RocketChat.MessageAction.addButton
Expand Down
5 changes: 4 additions & 1 deletion packages/rocketchat-lib/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,8 @@
"Mentions_default" : "Mentions (default)",
"Message" : "Message",
"Message_AllowDeleting" : "Allow Message Deleting",
"Message_AllowDeleting_BlockDeleteInMinutes" : "Block Message Deleting After (n) Minutes",
"Message_AllowDeleting_BlockDeleteInMinutesDescription" : "Enter 0 to disable blocking.",
"Message_AllowEditing" : "Allow Message Editing",
"Message_AllowEditing_BlockEditInMinutes" : "Block Message Editing After (n) Minutes",
"Message_AllowEditing_BlockEditInMinutesDescription" : "Enter 0 to disable blocking.",
Expand All @@ -555,6 +557,7 @@
"Message_AudioRecorderEnabledDescription" : "Requires 'audio/wav' files to be an accepted media type within 'File Upload' settings.",
"Message_DateFormat" : "Date Format",
"Message_DateFormat_Description" : "See also: <a href=\"http://momentjs.com/docs/#/displaying/format/\" target=\"momemt\">Moment.js</a>",
"Message_deleting_blocked" : "This message cannot be deleted anymore",
"Message_deleting_not_allowed" : "Message deleting not allowed",
"Message_editing_blocked" : "This message cannot be edited anymore",
"Message_editing_not_allowed" : "Message editing not allowed",
Expand Down Expand Up @@ -1077,4 +1080,4 @@
"Your_Open_Source_solution" : "Your own Open Source chat solution",
"Your_password_is_wrong" : "Your password is wrong!",
"Your_push_was_sent_to_s_devices" : "Your push was sent to %s devices"
}
}
1 change: 1 addition & 0 deletions packages/rocketchat-lib/server/startup/settings.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ RocketChat.settings.addGroup 'Message', ->
@add 'Message_AllowEditing', true, { type: 'boolean', public: true }
@add 'Message_AllowEditing_BlockEditInMinutes', 0, { type: 'int', public: true, i18nDescription: 'Message_AllowEditing_BlockEditInMinutesDescription' }
@add 'Message_AllowDeleting', true, { type: 'boolean', public: true }
@add 'Message_AllowDeleting_BlockDeleteInMinutes', 0, { type: 'int', public: true, i18nDescription: 'Message_AllowDeleting_BlockDeleteInMinutes' }
@add 'Message_AllowPinning', true, { type: 'boolean', public: true }
@add 'Message_ShowEditedStatus', true, { type: 'boolean', public: true }
@add 'Message_ShowDeletedStatus', false, { type: 'boolean', public: true }
Expand Down
14 changes: 12 additions & 2 deletions packages/rocketchat-ui-message/message/message.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,20 @@ Template.message.helpers
return true

canDelete: ->
if RocketChat.authz.hasAtLeastOnePermission('delete-message', this.rid )
hasPermission = RocketChat.authz.hasAtLeastOnePermission('delete-message', this.rid )
isDeleteAllowed = RocketChat.settings.get('Message_AllowDeleting')
deleteOwn = this.u?._id is Meteor.userId()

return unless hasPermission or (isDeleteAllowed and deleteOwn)

blockDeleteInMinutes = RocketChat.settings.get 'Message_AllowDeleting_BlockDeleteInMinutes'
if blockDeleteInMinutes? and blockDeleteInMinutes isnt 0
msgTs = moment(this.ts) if this.ts?
currentTsDiff = moment().diff(msgTs, 'minutes') if msgTs?
return currentTsDiff < blockDeleteInMinutes
else
return true

return RocketChat.settings.get('Message_AllowDeleting') and this.u?._id is Meteor.userId()
showEditedStatus: ->
return RocketChat.settings.get 'Message_ShowEditedStatus'
label: ->
Expand Down
8 changes: 8 additions & 0 deletions packages/rocketchat-ui/lib/chatMessages.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ class @ChatMessages
Meteor.call 'sendMessage', msgObject

deleteMsg: (message) ->
blockDeleteInMinutes = RocketChat.settings.get 'Message_AllowDeleting_BlockDeleteInMinutes'
if blockDeleteInMinutes? and blockDeleteInMinutes isnt 0
msgTs = moment(message.ts) if message.ts?
currentTsDiff = moment().diff(msgTs, 'minutes') if msgTs?
if currentTsDiff > blockDeleteInMinutes
toastr.error(t('Message_deleting_blocked'))
return

Meteor.call 'deleteMessage', message, (error, result) ->
if error
return toastr.error error.reason
Expand Down
9 changes: 9 additions & 0 deletions server/methods/deleteMessage.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ Meteor.methods
unless hasPermission or (deleteAllowed and deleteOwn)
throw new Meteor.Error 'message-deleting-not-allowed', "[methods] deleteMessage -> Message deleting not allowed"

blockDeleteInMinutes = RocketChat.settings.get 'Message_AllowDeleting_BlockDeleteInMinutes'
if blockDeleteInMinutes? and blockDeleteInMinutes isnt 0
msgTs = moment(originalMessage.ts) if originalMessage.ts?
currentTsDiff = moment().diff(msgTs, 'minutes') if msgTs?
if currentTsDiff > blockDeleteInMinutes
toastr.error t('Message_deleting_blocked')
throw new Meteor.Error 'message-deleting-blocked'


keepHistory = RocketChat.settings.get 'Message_KeepHistory'
showDeletedStatus = RocketChat.settings.get 'Message_ShowDeletedStatus'

Expand Down

0 comments on commit 4e33344

Please sign in to comment.