Skip to content
Snippets Groups Projects
Unverified Commit 9cf1bcc0 authored by Philip Hutchins's avatar Philip Hutchins
Browse files

Changing name of delete-any-message to force-delete-message

parent 64104549
No related branches found
No related tags found
No related merge requests found
......@@ -11,18 +11,18 @@ Meteor.methods({
message = ChatMessage.findOne({ _id: message._id });
const hasPermission = RocketChat.authz.hasAtLeastOnePermission('delete-message', message.rid);
const deleteAny = RocketChat.authz.hasAtLeastOnePermission('delete-any-message', message.rid);
const forceDelete = RocketChat.authz.hasAtLeastOnePermission('force-delete-message', message.rid);
const deleteAllowed = RocketChat.settings.get('Message_AllowDeleting');
let deleteOwn = false;
if (message && message.u && message.u._id) {
deleteOwn = message.u._id === Meteor.userId();
}
if (!(deleteAny || hasPermission || (deleteAllowed && deleteOwn))) {
if (!(forceDelete || hasPermission || (deleteAllowed && deleteOwn))) {
return false;
}
const blockDeleteInMinutes = RocketChat.settings.get('Message_AllowDeleting_BlockDeleteInMinutes');
if (!(deleteAny) || (_.isNumber(blockDeleteInMinutes) && blockDeleteInMinutes !== 0)) {
if (!(forceDelete) || (_.isNumber(blockDeleteInMinutes) && blockDeleteInMinutes !== 0)) {
if (message.ts) {
const msgTs = moment(message.ts);
if (msgTs) {
......
......@@ -24,7 +24,6 @@ Meteor.startup(function() {
{ _id: 'delete-c', roles : ['admin'] },
{ _id: 'delete-d', roles : ['admin'] },
{ _id: 'delete-message', roles : ['admin', 'owner', 'moderator'] },
{ _id: 'delete-any-message', roles : ['admin', 'owner'] },
{ _id: 'delete-p', roles : ['admin'] },
{ _id: 'delete-user', roles : ['admin'] },
{ _id: 'edit-message', roles : ['admin', 'owner', 'moderator'] },
......@@ -33,6 +32,7 @@ Meteor.startup(function() {
{ _id: 'edit-other-user-password', roles : ['admin'] },
{ _id: 'edit-privileged-setting', roles : ['admin'] },
{ _id: 'edit-room', roles : ['admin', 'owner', 'moderator'] },
{ _id: 'force-delete-message', roles : ['admin', 'owner'] },
{ _id: 'join-without-join-code', roles : ['admin', 'bot'] },
{ _id: 'manage-assets', roles : ['admin'] },
{ _id: 'manage-emoji', roles : ['admin'] },
......
......@@ -180,15 +180,15 @@ Meteor.startup(function() {
if (RocketChat.models.Subscriptions.findOne({rid: message.rid}) == null) {
return false;
}
const deleteAny = RocketChat.authz.hasAtLeastOnePermission('delete-any-message', message.rid);
const forceDelete = RocketChat.authz.hasAtLeastOnePermission('force-delete-message', message.rid);
const hasPermission = RocketChat.authz.hasAtLeastOnePermission('delete-message', message.rid);
const isDeleteAllowed = RocketChat.settings.get('Message_AllowDeleting');
const deleteOwn = message.u && message.u._id === Meteor.userId();
if (!(hasPermission || (isDeleteAllowed && deleteOwn) || deleteAny)) {
if (!(hasPermission || (isDeleteAllowed && deleteOwn) || forceDelete)) {
return;
}
const blockDeleteInMinutes = RocketChat.settings.get('Message_AllowDeleting_BlockDeleteInMinutes');
if ((blockDeleteInMinutes != null) && blockDeleteInMinutes !== 0 && !(deleteAny)) {
if ((blockDeleteInMinutes != null) && blockDeleteInMinutes !== 0 && !(forceDelete)) {
let msgTs;
if (message.ts != null) {
msgTs = moment(message.ts);
......
......@@ -23,18 +23,18 @@ Meteor.methods({
action: 'Delete_message'
});
}
const deleteAny = RocketChat.authz.hasPermission(Meteor.userId(), 'delete-any-message', originalMessage.rid);
const forceDelete = RocketChat.authz.hasPermission(Meteor.userId(), 'force-delete-message', originalMessage.rid);
const hasPermission = RocketChat.authz.hasPermission(Meteor.userId(), 'delete-message', originalMessage.rid);
const deleteAllowed = RocketChat.settings.get('Message_AllowDeleting');
const deleteOwn = originalMessage && originalMessage.u && originalMessage.u._id === Meteor.userId();
if (!(hasPermission || (deleteAllowed && deleteOwn)) && !(deleteAny)) {
if (!(hasPermission || (deleteAllowed && deleteOwn)) && !(forceDelete)) {
throw new Meteor.Error('error-action-not-allowed', 'Not allowed', {
method: 'deleteMessage',
action: 'Delete_message'
});
}
const blockDeleteInMinutes = RocketChat.settings.get('Message_AllowDeleting_BlockDeleteInMinutes');
if ((blockDeleteInMinutes != null && blockDeleteInMinutes !== 0) || !(deleteAny)) {
if ((blockDeleteInMinutes != null && blockDeleteInMinutes !== 0) || !(forceDelete)) {
if (originalMessage.ts == null) {
return;
}
......
......@@ -250,9 +250,9 @@ class @ChatMessages
$('.sweet-alert').addClass 'visible'
deleteMsg: (message) ->
deleteAny = RocketChat.authz.hasAtLeastOnePermission('delete-any-message', message.rid)
forceDelete = RocketChat.authz.hasAtLeastOnePermission('force-delete-message', message.rid)
blockDeleteInMinutes = RocketChat.settings.get 'Message_AllowDeleting_BlockDeleteInMinutes'
if blockDeleteInMinutes? and blockDeleteInMinutes isnt 0 and deleteAny is false
if blockDeleteInMinutes? and blockDeleteInMinutes isnt 0 and forceDelete is false
msgTs = moment(message.ts) if message.ts?
currentTsDiff = moment().diff(msgTs, 'minutes') if msgTs?
if currentTsDiff > blockDeleteInMinutes
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment