diff --git a/client/methods/deleteMessage.coffee b/client/methods/deleteMessage.coffee index 24e418d6d28b..bb2b065480f4 100644 --- a/client/methods/deleteMessage.coffee +++ b/client/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 diff --git a/packages/rocketchat-lib/client/MessageAction.coffee b/packages/rocketchat-lib/client/MessageAction.coffee index 3c096dac6215..9a119506e8cb 100644 --- a/packages/rocketchat-lib/client/MessageAction.coffee +++ b/packages/rocketchat-lib/client/MessageAction.coffee @@ -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 diff --git a/packages/rocketchat-lib/i18n/en.i18n.json b/packages/rocketchat-lib/i18n/en.i18n.json index 4170703aa597..8083994955f7 100644 --- a/packages/rocketchat-lib/i18n/en.i18n.json +++ b/packages/rocketchat-lib/i18n/en.i18n.json @@ -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: Moment.js", + "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" -} \ No newline at end of file +} diff --git a/packages/rocketchat-lib/server/startup/settings.coffee b/packages/rocketchat-lib/server/startup/settings.coffee index a5ce021e8dc4..bcde9bd507a0 100644 --- a/packages/rocketchat-lib/server/startup/settings.coffee +++ b/packages/rocketchat-lib/server/startup/settings.coffee @@ -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 } diff --git a/packages/rocketchat-ui-message/message/message.coffee b/packages/rocketchat-ui-message/message/message.coffee index dfdb81b27e05..09874b7d470a 100644 --- a/packages/rocketchat-ui-message/message/message.coffee +++ b/packages/rocketchat-ui-message/message/message.coffee @@ -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: -> diff --git a/packages/rocketchat-ui/lib/chatMessages.coffee b/packages/rocketchat-ui/lib/chatMessages.coffee index 6f0ae5f51a36..174111cdf0ac 100644 --- a/packages/rocketchat-ui/lib/chatMessages.coffee +++ b/packages/rocketchat-ui/lib/chatMessages.coffee @@ -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 diff --git a/server/methods/deleteMessage.coffee b/server/methods/deleteMessage.coffee index e15cacce36a0..f9dfc7c4d9e4 100644 --- a/server/methods/deleteMessage.coffee +++ b/server/methods/deleteMessage.coffee @@ -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'