[FIX] Rename method to clean history of messages (#10498)
* Rename method to clean history of messages * Add test case with user without permission to delete room messagespull/10532/head
parent
fe663cf674
commit
6f2702df6a
@ -1,34 +1,10 @@ |
||||
Meteor.methods({ |
||||
cleanChannelHistory({roomId, latest, oldest, inclusive}) { |
||||
check(roomId, String); |
||||
check(latest, Date); |
||||
check(oldest, Date); |
||||
check(inclusive, Boolean); |
||||
|
||||
if (!Meteor.userId()) { |
||||
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'cleanChannelHistory' }); |
||||
} |
||||
|
||||
if (!RocketChat.authz.hasPermission(Meteor.userId(), 'clean-channel-history')) { |
||||
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'cleanChannelHistory' }); |
||||
} |
||||
|
||||
if (inclusive) { |
||||
RocketChat.models.Messages.remove({ |
||||
rid: roomId, |
||||
ts: { |
||||
$gte: oldest, |
||||
$lte: latest |
||||
} |
||||
}); |
||||
} else { |
||||
RocketChat.models.Messages.remove({ |
||||
rid: roomId, |
||||
ts: { |
||||
$gt: oldest, |
||||
$lt: latest |
||||
} |
||||
}); |
||||
} |
||||
/** |
||||
DEPRECATED |
||||
// TODO: Remove this after three versions have been released. That means at 0.67 this should be gone.
|
||||
*/ |
||||
cleanChannelHistory({ roomId, latest, oldest, inclusive }) { |
||||
console.warn('The method "cleanChannelHistory" is deprecated and will be removed after version 0.67, please use "cleanRoomHistory" instead'); |
||||
Meteor.call('cleanRoomHistory', { roomId, latest, oldest, inclusive }); |
||||
} |
||||
}); |
||||
|
@ -0,0 +1,34 @@ |
||||
Meteor.methods({ |
||||
cleanRoomHistory({ roomId, latest, oldest, inclusive }) { |
||||
check(roomId, String); |
||||
check(latest, Date); |
||||
check(oldest, Date); |
||||
check(inclusive, Boolean); |
||||
|
||||
if (!Meteor.userId()) { |
||||
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'cleanRoomHistory' }); |
||||
} |
||||
|
||||
if (!RocketChat.authz.hasPermission(Meteor.userId(), 'clean-channel-history')) { |
||||
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'cleanRoomHistory' }); |
||||
} |
||||
|
||||
if (inclusive) { |
||||
RocketChat.models.Messages.remove({ |
||||
rid: roomId, |
||||
ts: { |
||||
$gte: oldest, |
||||
$lte: latest |
||||
} |
||||
}); |
||||
} else { |
||||
RocketChat.models.Messages.remove({ |
||||
rid: roomId, |
||||
ts: { |
||||
$gt: oldest, |
||||
$lt: latest |
||||
} |
||||
}); |
||||
} |
||||
} |
||||
}); |
Loading…
Reference in new issue