Close #2829 Add setting for blocking message exclusion (#2933)

pull/2934/merge
Marcelo Schmidt 10 years ago committed by Gabriel Engel
parent 452374a285
commit 4e33344ea8
  1. 7
      client/methods/deleteMessage.coffee
  2. 14
      packages/rocketchat-lib/client/MessageAction.coffee
  3. 5
      packages/rocketchat-lib/i18n/en.i18n.json
  4. 1
      packages/rocketchat-lib/server/startup/settings.coffee
  5. 14
      packages/rocketchat-ui-message/message/message.coffee
  6. 8
      packages/rocketchat-ui/lib/chatMessages.coffee
  7. 9
      server/methods/deleteMessage.coffee

@ -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

@ -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

@ -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.",
@ -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",
@ -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"
}
}

@ -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 }

@ -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: ->

@ -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

@ -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'

Loading…
Cancel
Save