From 146dfa6f0b7b6e81f6420ffff5e824ed3179d7bd Mon Sep 17 00:00:00 2001 From: Durga Akhil Mundroy Date: Sun, 16 Jul 2017 09:00:44 +0000 Subject: [PATCH] org-permissions: Add allow_edit_history organiztion setting. This new setting controls whether or not users are allowed to see the edit history in a Zulip organization. It controls access through 2 key mechanisms: * For long-ago edited messages, get_messages removes the edit history content from messages it sends to clients. * For newly edited messages, clients are responsible for checking the setting and not saving the edit history data. Since the webapp was the only client displaying it before this change, this just required some changes in message_events.js. Significantly modified by tabbott to fix some logic bugs and add a test. --- docs/security-model.md | 5 +-- static/js/admin.js | 1 + static/js/message_events.js | 33 ++++++++++-------- static/js/popovers.js | 2 +- static/js/server_events_dispatch.js | 2 ++ static/js/settings_org.js | 5 +++ .../organization-permissions-admin.handlebars | 13 +++++++ zerver/lib/actions.py | 8 +++++ .../0091_realm_allow_edit_history.py | 20 +++++++++++ zerver/models.py | 2 ++ zerver/tests/test_home.py | 1 + zerver/tests/test_messages.py | 34 +++++++++++++++++++ zerver/views/messages.py | 6 ++++ zerver/views/realm.py | 3 +- 14 files changed, 116 insertions(+), 19 deletions(-) create mode 100644 zerver/migrations/0091_realm_allow_edit_history.py diff --git a/docs/security-model.md b/docs/security-model.md index 0fe3fcd5e8..354fd3ccc1 100644 --- a/docs/security-model.md +++ b/docs/security-model.md @@ -123,8 +123,9 @@ your organization. content (e.g. a password) shared unintentionally. Other users may have seen and saved the content of the original message, or have an integration (e.g. push notifications) forwarding all messages they - receive to another service. Zulip also stores and sends to clients - the content of every historical version of a message. + receive to another service. Zulip stores the edit history of + messages, but it may or may not be available to clients, depending + on an organization-level setting. ## Users and Bots diff --git a/static/js/admin.js b/static/js/admin.js index 403630f992..d083d8f0ff 100644 --- a/static/js/admin.js +++ b/static/js/admin.js @@ -43,6 +43,7 @@ function _setup_page() { realm_message_content_edit_limit_minutes: Math.ceil(page_params.realm_message_content_edit_limit_seconds / 60), realm_message_retention_days: page_params.realm_message_retention_days, + realm_allow_edit_history: page_params.realm_allow_edit_history, language_list: page_params.language_list, realm_default_language: page_params.realm_default_language, realm_waiting_period_threshold: page_params.realm_waiting_period_threshold, diff --git a/static/js/message_events.js b/static/js/message_events.js index 3a1be769d5..48eb54903a 100644 --- a/static/js/message_events.js +++ b/static/js/message_events.js @@ -198,22 +198,25 @@ exports.update_messages = function update_messages(events) { } if (event.orig_content !== undefined) { - // Most correctly, we should do this for topic edits as - // well; but we don't use the data except for content - // edits anyway. - var edit_history_entry = { - edited_by: event.edited_by, - prev_content: event.orig_content, - prev_rendered_content: event.orig_rendered_content, - prev_rendered_content_version: event.prev_rendered_content_version, - timestamp: event.edit_timestamp, - }; - // Add message's edit_history in message dict - // For messages that are edited, edit_history needs to be added to message in frontend. - if (msg.edit_history === undefined) { - msg.edit_history = []; + if (page_params.realm_allow_edit_history) { + // Most correctly, we should do this for topic edits as + // well; but we don't use the data except for content + // edits anyway. + var edit_history_entry = { + edited_by: event.edited_by, + prev_content: event.orig_content, + prev_rendered_content: event.orig_rendered_content, + prev_rendered_content_version: event.prev_rendered_content_version, + timestamp: event.edit_timestamp, + }; + // Add message's edit_history in message dict + // For messages that are edited, edit_history needs to + // be added to message in frontend. + if (msg.edit_history === undefined) { + msg.edit_history = []; + } + msg.edit_history = [edit_history_entry].concat(msg.edit_history); } - msg.edit_history = [edit_history_entry].concat(msg.edit_history); message_content_edited = true; // Update raw_content, so that editing a few times in a row is fast. diff --git a/static/js/popovers.js b/static/js/popovers.js index a2c3419288..8e0caae458 100644 --- a/static/js/popovers.js +++ b/static/js/popovers.js @@ -161,7 +161,7 @@ exports.toggle_actions_popover = function (element, id) { var should_display_edit_history_option = _.any(message.edit_history, function (entry) { return entry.prev_content !== undefined; - }); + }) && page_params.realm_allow_edit_history; var should_display_delete_option = page_params.is_admin; var args = { message: message, diff --git a/static/js/server_events_dispatch.js b/static/js/server_events_dispatch.js index 2d7d1ba41a..1ad7dce8bd 100644 --- a/static/js/server_events_dispatch.js +++ b/static/js/server_events_dispatch.js @@ -76,6 +76,8 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) { } else if (event.op === 'update' && event.property === 'add_emoji_by_admins_only') { page_params.realm_add_emoji_by_admins_only = event.value; settings_emoji.update_custom_emoji_ui(); + } else if (event.op === 'update' && event.property === 'allow_edit_history') { + page_params.realm_allow_edit_history = event.value; } else if (event.op === 'update' && event.property === 'restricted_to_domain') { page_params.realm_restricted_to_domain = event.value; } else if (event.op === 'update' && event.property === 'message_retention_days') { diff --git a/static/js/settings_org.js b/static/js/settings_org.js index bf09ce9c67..d3f1a0a572 100644 --- a/static/js/settings_org.js +++ b/static/js/settings_org.js @@ -206,6 +206,11 @@ function _set_up() { checked_msg: i18n.t("Only administrators may now add new emoji!"), unchecked_msg: i18n.t("Any user may now add new emoji!"), }, + allow_edit_history: { + type: 'bool', + checked_msg: i18n.t("Users can view message edit history!"), + unchecked_msg: i18n.t("Users can no longer view message edit history!"), + }, create_stream_by_admins_only: { type: 'bool', checked_msg: i18n.t("Only administrators may now create new streams!"), diff --git a/static/templates/settings/organization-permissions-admin.handlebars b/static/templates/settings/organization-permissions-admin.handlebars index aecd6d08dd..d06d10eaf3 100644 --- a/static/templates/settings/organization-permissions-admin.handlebars +++ b/static/templates/settings/organization-permissions-admin.handlebars @@ -9,6 +9,7 @@
+
@@ -155,6 +156,18 @@ {{#unless realm_allow_message_editing}}disabled="disabled"{{/unless}} /> +
+ + +
+ {{#if false}}