From 829c5d1bfb41331d4c990d2d1caf8ac13e3eca73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=95=E3=82=A3=E3=83=B3=E3=83=A1=E3=83=BC=E3=83=A9?= <39674991+vynmera@users.noreply.github.com> Date: Fri, 20 Jul 2018 06:26:33 +0200 Subject: [PATCH] [NEW][BREAK] Message retention policy and pruning (#11236) Closes #6749 Closes #8321 Closes #9374 Closes #2700 Closes #2639 Closes #2355 Closes #1861 Closes #8757 Closes #7228 Closes #10870 Closes #6193 Closes #11299 Closes #11468 Closes #9317 Closes #11300 (will incorporate a fix to this PR's issue) Closes #11046 (will incorporate a fix to this PR's issue) Contributes to #5944 Contributes to #11475 _...and possibly more!_ This PR makes deleting messages (automatically and manually) a lot easier on Rocket.Chat. - [X] Implement a bulk message deletion notification, to quickly push large message deletions to users without reload - [X] Use it in `rooms.cleanHistory` - [X] Use it in user deletions - [X] Completely remove cleanChannelHistory as required by v0.67 - [X] Remove server method `cleanChannelHistory` - [X] Remove REST API `channels.cleanHistory` - [x] Implement a sidebar option to clean history - [x] Basic implementation - [x] Allow excluding pinned messages - [x] Allow attachment-only mode - [x] Allow specifying user(s) to narrow down to - [x] Also update REST API - [x] Also update docs - [x] Break the deletion into multiple different requests, so the client can keep track of progress - [x] Clear animation / progress bar for deleting - [x] Retention policy - [X] Global, set by admin - [X] Global timer that runs every second and deletes messages over the set limit - [X] Can change its timer's resolution to prevent insane CPU overhead - [X] Admin can decide what room types to target (channels, groups and/or DMs) - [X] Allow excluding pinned messages - [X] Allow attachment-only mode - [x] Per-channel, set by those with a new permission - [x] Disabled when master switch off - [x] Set in channel info - [x] Can override global policy with a switch that requires `edit-privileged-setting` - [x] Allow excluding pinned messages - [x] Allow attachment-only mode - [x] Uses same global timer for cleanup - [X] Message at start of channel history / in channel info if there is a retention policy set - [x] Message in channel info if there is a retention policy set on that channel specifically - [X] Make cleaning history also delete files (completely!) - [X] Manual purging - [X] Automatic purging - [x] Make other deletions also delete files - [x] User deletion - [X] Own messages - [x] DMs with them's partner messages - [x] Room deletion - [x] Cleanup - [x] Finish related [docs](https://github.com/RocketChat/docs/pull/815) - [x] Link to the docs in the settings Please suggest any cool changes/additions! Any support is greatly appreciated. **Breaking change:** This PR removes REST API endpoint `channels.cleanHistory` and Meteor callable `cleanChannelHistory` as per the protocol specified for them. ![bzzzzzzzz](https://user-images.githubusercontent.com/39674991/41799087-56d1dea0-7670-11e8-94c0-bc534b1f832d.png) --- .meteor/packages | 2 + .meteor/versions | 2 + packages/rocketchat-api/server/v1/channels.js | 35 -- packages/rocketchat-api/server/v1/rooms.js | 2 +- .../server/startup.js | 3 +- .../client/views/channelSettings.html | 118 +++++- .../client/views/channelSettings.js | 311 +++++++++++++++- .../server/methods/saveRoomSettings.js | 62 ++- packages/rocketchat-i18n/i18n/en.i18n.json | 62 +++ packages/rocketchat-lib/client/UserDeleted.js | 7 + packages/rocketchat-lib/package.js | 3 +- .../server/functions/cleanRoomHistory.js | 43 +++ .../server/functions/deleteUser.js | 18 +- .../server/methods/cleanChannelHistory.js | 10 - .../server/methods/cleanRoomHistory.js | 32 +- .../rocketchat-lib/server/models/Messages.js | 83 +++++ .../rocketchat-lib/server/models/Rooms.js | 67 ++++ .../rocketchat-retention-policy/README.md | 0 .../rocketchat-retention-policy/package.js | 25 ++ .../server/cronPruneMessages.js | 123 ++++++ .../server/startup/settings.js | 107 ++++++ .../client/imports/general/base_old.css | 8 + .../rocketchat-ui-clean-history/README.md | 0 .../client/lib/startup.js | 12 + .../client/views/cleanHistory.html | 142 +++++++ .../client/views/cleanHistory.js | 352 ++++++++++++++++++ .../client/views/stylesheets/cleanHistory.css | 52 +++ .../rocketchat-ui-clean-history/package.js | 27 ++ .../rocketchat-ui-master/public/icons.svg | 14 + .../rocketchat-ui/client/lib/RoomManager.js | 19 +- packages/rocketchat-ui/client/lib/tapi18n.js | 4 +- .../rocketchat-ui/client/views/app/room.html | 19 + .../rocketchat-ui/client/views/app/room.js | 94 +++++ server/methods/eraseRoom.js | 23 +- server/publications/room.js | 1 + tests/end-to-end/api/02-channels.js | 18 - 36 files changed, 1769 insertions(+), 131 deletions(-) create mode 100644 packages/rocketchat-lib/client/UserDeleted.js create mode 100644 packages/rocketchat-lib/server/functions/cleanRoomHistory.js delete mode 100644 packages/rocketchat-lib/server/methods/cleanChannelHistory.js create mode 100644 packages/rocketchat-retention-policy/README.md create mode 100644 packages/rocketchat-retention-policy/package.js create mode 100644 packages/rocketchat-retention-policy/server/cronPruneMessages.js create mode 100644 packages/rocketchat-retention-policy/server/startup/settings.js create mode 100644 packages/rocketchat-ui-clean-history/README.md create mode 100644 packages/rocketchat-ui-clean-history/client/lib/startup.js create mode 100644 packages/rocketchat-ui-clean-history/client/views/cleanHistory.html create mode 100644 packages/rocketchat-ui-clean-history/client/views/cleanHistory.js create mode 100644 packages/rocketchat-ui-clean-history/client/views/stylesheets/cleanHistory.css create mode 100644 packages/rocketchat-ui-clean-history/package.js diff --git a/.meteor/packages b/.meteor/packages index bbe5d3bd8b7..841134b67d8 100644 --- a/.meteor/packages +++ b/.meteor/packages @@ -110,6 +110,7 @@ rocketchat:otr rocketchat:postcss rocketchat:push-notifications rocketchat:reactions +rocketchat:retention-policy rocketchat:apps rocketchat:sandstorm rocketchat:setup-wizard @@ -142,6 +143,7 @@ rocketchat:tutum rocketchat:ui rocketchat:ui-account rocketchat:ui-admin +rocketchat:ui-clean-history rocketchat:ui-flextab rocketchat:ui-login rocketchat:ui-master diff --git a/.meteor/versions b/.meteor/versions index a9bb91cf018..3c16d18873d 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -201,6 +201,7 @@ rocketchat:otr@0.0.1 rocketchat:postcss@1.0.0 rocketchat:push-notifications@0.0.1 rocketchat:reactions@0.0.1 +rocketchat:retention-policy@0.0.1 rocketchat:sandstorm@0.0.1 rocketchat:search@0.0.1 rocketchat:setup-wizard@0.0.1 @@ -234,6 +235,7 @@ rocketchat:tutum@0.0.1 rocketchat:ui@0.1.0 rocketchat:ui-account@0.1.0 rocketchat:ui-admin@0.1.0 +rocketchat:ui-clean-history@0.0.1 rocketchat:ui-flextab@0.1.0 rocketchat:ui-login@0.1.0 rocketchat:ui-master@0.1.0 diff --git a/packages/rocketchat-api/server/v1/channels.js b/packages/rocketchat-api/server/v1/channels.js index 3c13e3e94a3..61d3961a40f 100644 --- a/packages/rocketchat-api/server/v1/channels.js +++ b/packages/rocketchat-api/server/v1/channels.js @@ -80,41 +80,6 @@ RocketChat.API.v1.addRoute('channels.archive', { authRequired: true }, { } }); -/** - DEPRECATED - // TODO: Remove this after three versions have been released. That means at 0.67 this should be gone. - **/ -RocketChat.API.v1.addRoute('channels.cleanHistory', { authRequired: true }, { - post() { - const findResult = findChannelByIdOrName({ params: this.requestParams() }); - - if (!this.bodyParams.latest) { - return RocketChat.API.v1.failure('Body parameter "latest" is required.'); - } - - if (!this.bodyParams.oldest) { - return RocketChat.API.v1.failure('Body parameter "oldest" is required.'); - } - - const latest = new Date(this.bodyParams.latest); - const oldest = new Date(this.bodyParams.oldest); - - let inclusive = false; - if (typeof this.bodyParams.inclusive !== 'undefined') { - inclusive = this.bodyParams.inclusive; - } - - Meteor.runAsUser(this.userId, () => { - Meteor.call('cleanChannelHistory', { roomId: findResult._id, latest, oldest, inclusive }); - }); - - return RocketChat.API.v1.success(this.deprecationWarning({ - endpoint: 'channels.cleanHistory', - versionWillBeRemove: 'v0.67' - })); - } -}); - RocketChat.API.v1.addRoute('channels.close', { authRequired: true }, { post() { const findResult = findChannelByIdOrName({ params: this.requestParams(), checkedArchived: false }); diff --git a/packages/rocketchat-api/server/v1/rooms.js b/packages/rocketchat-api/server/v1/rooms.js index 2f05681c66f..1f9f46581e2 100644 --- a/packages/rocketchat-api/server/v1/rooms.js +++ b/packages/rocketchat-api/server/v1/rooms.js @@ -177,7 +177,7 @@ RocketChat.API.v1.addRoute('rooms.cleanHistory', { authRequired: true }, { } Meteor.runAsUser(this.userId, () => { - Meteor.call('cleanRoomHistory', { roomId: findResult._id, latest, oldest, inclusive }); + Meteor.call('cleanRoomHistory', { roomId: findResult._id, latest, oldest, inclusive, limit: this.bodyParams.limit, excludePinned: this.bodyParams.excludePinned, filesOnly: this.bodyParams.filesOnly, fromUsers: this.bodyParams.users }); }); return RocketChat.API.v1.success(); diff --git a/packages/rocketchat-authorization/server/startup.js b/packages/rocketchat-authorization/server/startup.js index 85c2d02a374..6827f71da1f 100644 --- a/packages/rocketchat-authorization/server/startup.js +++ b/packages/rocketchat-authorization/server/startup.js @@ -20,7 +20,7 @@ Meteor.startup(function() { { _id: 'create-d', roles : ['admin', 'user', 'bot'] }, { _id: 'create-p', roles : ['admin', 'user', 'bot'] }, { _id: 'create-user', roles : ['admin'] }, - { _id: 'clean-channel-history', roles : ['admin'] }, // special permission to bulk delete a channel's mesages + { _id: 'clean-channel-history', roles : ['admin'] }, { _id: 'delete-c', roles : ['admin', 'owner'] }, { _id: 'delete-d', roles : ['admin'] }, { _id: 'delete-message', roles : ['admin', 'owner', 'moderator'] }, @@ -32,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: 'edit-room-retention-policy', roles : ['admin'] }, { _id: 'force-delete-message', roles : ['admin', 'owner'] }, { _id: 'join-without-join-code', roles : ['admin', 'bot'] }, { _id: 'leave-c', roles : ['admin', 'user', 'bot', 'anonymous'] }, diff --git a/packages/rocketchat-channel-settings/client/views/channelSettings.html b/packages/rocketchat-channel-settings/client/views/channelSettings.html index d19d3e8208d..0dc56187495 100644 --- a/packages/rocketchat-channel-settings/client/views/channelSettings.html +++ b/packages/rocketchat-channel-settings/client/views/channelSettings.html @@ -117,12 +117,11 @@ {{/with}} - {{#with settings.reactWhenReadOnly}} {{#if canView}}
-
+
{{_ "React_when_read_only"}}
{{_ "React_when_read_only"}} @@ -136,7 +135,7 @@
-
+
{{_ "Disallow_reacting"}}
{{_ "Disallow_reacting_Description"}} @@ -164,7 +163,7 @@ {{/if}} {{/with}} - {{#with settings.sysMes}} + {{#with settings.sysMes}} {{#if canView}}