From 65d953b2afba7af20c1a17c2dcdb7988cea55724 Mon Sep 17 00:00:00 2001 From: sahil839 Date: Wed, 8 Apr 2020 03:53:15 +0530 Subject: [PATCH] settings: Add option to disable video call in org settings. Option is added to video_chat_provider settings for disabling video calls. Video call icon is hidden in two cases- 1. video_chat_provider is set to disabled. 2. video_chat_provider is set to Jitsi and settings.JITSI_SERVER_URL is none. Relevant tests are added and modified. Fixes #14483 --- frontend_tests/node_tests/compose.js | 102 ++++++++++++++++++++----- frontend_tests/node_tests/dispatch.js | 4 + frontend_tests/node_tests/ui_init.js | 3 + static/js/compose.js | 30 +++++++- static/js/message_edit.js | 3 + static/js/server_events_dispatch.js | 2 +- static/js/settings_org.js | 2 +- static/templates/message_edit_form.hbs | 2 + templates/zerver/app/compose.html | 2 - zerver/models.py | 4 + zerver/tests/test_realm.py | 10 ++- 11 files changed, 134 insertions(+), 30 deletions(-) diff --git a/frontend_tests/node_tests/compose.js b/frontend_tests/node_tests/compose.js index 1f8058cbc3..ad18e86fc5 100644 --- a/frontend_tests/node_tests/compose.js +++ b/frontend_tests/node_tests/compose.js @@ -79,6 +79,22 @@ people.small_avatar_url_for_person = function () { return 'http://example.com/example.png'; }; +function stub_out_video_calls() { + const elem = $("#below-compose-content .video_link"); + elem.toggle = (show) => { + if (show) { + elem.show(); + } else { + elem.hide(); + } + }; +} + +function reset_jquery() { + // Avoid leaks. + set_global('$', global.make_zjquery()); +} + const new_user = { email: 'new_user@example.com', user_id: 101, @@ -912,6 +928,29 @@ run_test('initialize', () => { }; }; + page_params.realm_available_video_chat_providers = { + disabled: { + id: 0, + name: "disabled", + }, + jitsi_meet: { + id: 1, + name: "Jitsi Meet", + }, + google_hangouts: { + id: 2, + name: "Google Hangouts", + }, + zoom: { + id: 3, + name: "Zoom", + }, + }; + + page_params.realm_video_chat_provider = + page_params.realm_available_video_chat_providers.disabled.id; + + stub_out_video_calls(); compose.initialize(); assert(resize_watch_manual_resize_checked); @@ -919,11 +958,6 @@ run_test('initialize', () => { assert(!$("#compose #attach_files").hasClass("notdisplayed")); assert(setup_upload_called); - function reset_jquery() { - // Avoid leaks. - set_global('$', global.make_zjquery()); - } - let compose_actions_start_checked; function set_up_compose_start_mock(expected_opts) { @@ -942,6 +976,7 @@ run_test('initialize', () => { page_params.narrow = true; reset_jquery(); + stub_out_video_calls(); set_up_compose_start_mock({}); compose.initialize(); @@ -953,6 +988,7 @@ run_test('initialize', () => { page_params.narrow_topic = 'testing'; reset_jquery(); + stub_out_video_calls(); set_up_compose_start_mock({topic: 'testing'}); compose.initialize(); @@ -964,6 +1000,7 @@ run_test('initialize', () => { $("#compose-send-button").attr('disabled', 'disabled'); reset_jquery(); + stub_out_video_calls(); compose.initialize(); compose.abort_xhr(); @@ -1381,16 +1418,6 @@ run_test('on_events', () => { to_$: () => textarea, }, }; - page_params.realm_available_video_chat_providers = { - google_hangouts: { - id: 2, - name: "Google Hangouts", - }, - zoom: { - id: 3, - name: "Zoom", - }, - }; compose_ui.insert_syntax_and_focus = function (syntax) { syntax_to_insert = syntax; @@ -1401,11 +1428,21 @@ run_test('on_events', () => { $('#compose-textarea').val(''); handler(ev); + assert(!called); + + page_params.realm_video_chat_provider = + page_params.realm_available_video_chat_providers.jitsi_meet.id; + handler(ev); // video link ids consist of 15 random digits let video_link_regex = /\[Click to join video call\]\(https:\/\/meet.jit.si\/\d{15}\)/; assert(video_link_regex.test(syntax_to_insert)); + page_params.jitsi_server_url = null; + called = false; + handler(ev); + assert(!called); + page_params.realm_video_chat_provider = page_params.realm_available_video_chat_providers.google_hangouts.id; page_params.realm_google_hangouts_domain = 'zulip'; @@ -1430,11 +1467,6 @@ run_test('on_events', () => { video_link_regex = /\[Click to join video call\]\(example\.zoom\.com\)/; assert(video_link_regex.test(syntax_to_insert)); - page_params.jitsi_server_url = null; - called = false; - - handler(ev); - assert(!called); }()); (function test_markdown_preview_compose_clicked() { @@ -1672,3 +1704,33 @@ run_test('narrow_button_titles', () => { assert.equal($("#left_bar_compose_stream_button_big").text(), i18n.t("New topic")); assert.equal($("#left_bar_compose_private_button_big").text(), i18n.t("New private message")); }); + +run_test('test_video_chat_button_toggle', () => { + reset_jquery(); + stub_out_video_calls(); + + page_params.realm_video_chat_provider = + page_params.realm_available_video_chat_providers.disabled.id; + compose.initialize(); + assert.equal($("#below-compose-content .video_link").visible(), false); + + reset_jquery(); + stub_out_video_calls(); + page_params.realm_video_chat_provider = + page_params.realm_available_video_chat_providers.jitsi_meet.id; + compose.initialize(); + assert.equal($("#below-compose-content .video_link").visible(), false); + + reset_jquery(); + stub_out_video_calls(); + page_params.jitsi_server_url = 'https://meet.jit.si'; + compose.initialize(); + assert.equal($("#below-compose-content .video_link").visible(), true); + + reset_jquery(); + stub_out_video_calls(); + page_params.realm_video_chat_provider = + page_params.realm_available_video_chat_providers.google_hangouts.id; + compose.initialize(); + assert.equal($("#below-compose-content .video_link").visible(), true); +}); diff --git a/frontend_tests/node_tests/dispatch.js b/frontend_tests/node_tests/dispatch.js index 546b7565b4..f1b984f662 100644 --- a/frontend_tests/node_tests/dispatch.js +++ b/frontend_tests/node_tests/dispatch.js @@ -50,6 +50,10 @@ set_global('settings_bots', { update_bot_permissions_ui: noop, }); +set_global('compose', { + update_video_chat_button_display: noop, +}); + set_global('settings_exports', { populate_exports_table: function (exports) { return exports; diff --git a/frontend_tests/node_tests/ui_init.js b/frontend_tests/node_tests/ui_init.js index 84c491a134..84f2452f24 100644 --- a/frontend_tests/node_tests/ui_init.js +++ b/frontend_tests/node_tests/ui_init.js @@ -187,6 +187,9 @@ $(".top_left_starred_messages").set_find_results('.count', count_stub); $("#tab_list .stream").length = 0; +compose.compute_show_video_chat_button = () => {}; +$("#below-compose-content .video_link").toggle = () => {}; + run_test('initialize_everything', () => { ui_init.initialize_everything(); }); diff --git a/static/js/compose.js b/static/js/compose.js index 8d85ac9a9b..90b4454bd0 100644 --- a/static/js/compose.js +++ b/static/js/compose.js @@ -48,6 +48,26 @@ function show_all_everyone_warnings() { user_acknowledged_all_everyone = false; } +exports.compute_show_video_chat_button = function () { + const available_providers = page_params.realm_available_video_chat_providers; + if (page_params.realm_video_chat_provider === available_providers.disabled.id) { + return false; + } + + if (page_params.realm_video_chat_provider === available_providers.jitsi_meet.id && + !page_params.jitsi_server_url) { + return false; + } + + return true; +}; + +exports.update_video_chat_button_display = function () { + const show_video_chat_button = exports.compute_show_video_chat_button(); + $("#below-compose-content .video_link").toggle(show_video_chat_button); + $(".message-edit-feature-group .video_link").toggle(show_video_chat_button); +}; + exports.clear_all_everyone_warnings = function () { $("#compose-all-everyone").hide(); $("#compose-all-everyone").empty(); @@ -906,6 +926,7 @@ exports.warn_if_mentioning_unsubscribed_user = function (mentioned) { }; exports.initialize = function () { + $("#below-compose-content .video_link").toggle(exports.compute_show_video_chat_button()); $('#stream_message_recipient_stream,#stream_message_recipient_topic,#private_message_recipient').on('keyup', update_fade); $('#stream_message_recipient_stream,#stream_message_recipient_topic,#private_message_recipient').on('change', update_fade); $('#compose-textarea').on('keydown', function (event) { @@ -1048,13 +1069,14 @@ exports.initialize = function () { target_textarea = $("#message_edit_content_" + edit_message_id); } - if (page_params.jitsi_server_url === null) { - return; - } - let video_call_link; const video_call_id = util.random_int(100000000000000, 999999999999999); const available_providers = page_params.realm_available_video_chat_providers; + const show_video_chat_button = exports.compute_show_video_chat_button(); + + if (!show_video_chat_button) { + return; + } if (page_params.realm_video_chat_provider === available_providers.google_hangouts.id) { video_call_link = "https://hangouts.google.com/hangouts/_/" + page_params.realm_google_hangouts_domain + "/" + video_call_id; diff --git a/static/js/message_edit.js b/static/js/message_edit.js index 573f08a811..9284ba9191 100644 --- a/static/js/message_edit.js +++ b/static/js/message_edit.js @@ -234,6 +234,8 @@ function edit_message(row, raw_content) { file_upload_enabled = true; } + const show_video_chat_button = compose.compute_show_video_chat_button(); + const form = $(render_message_edit_form({ is_stream: message.type === 'stream', message_id: message.id, @@ -243,6 +245,7 @@ function edit_message(row, raw_content) { topic: message.topic, content: raw_content, file_upload_enabled: file_upload_enabled, + show_video_chat_button: show_video_chat_button, minutes_to_edit: Math.floor(page_params.realm_message_content_edit_limit_seconds / 60), })); diff --git a/static/js/server_events_dispatch.js b/static/js/server_events_dispatch.js index f699547a96..afcdacadae 100644 --- a/static/js/server_events_dispatch.js +++ b/static/js/server_events_dispatch.js @@ -118,7 +118,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) { message_content_allowed_in_email_notifications: noop, signup_notifications_stream_id: noop, emails_restricted_to_domains: noop, - video_chat_provider: noop, + video_chat_provider: compose.update_video_chat_button_display, waiting_period_threshold: noop, zoom_user_id: noop, zoom_api_key: noop, diff --git a/static/js/settings_org.js b/static/js/settings_org.js index c5ef3c744e..e44d0dc98b 100644 --- a/static/js/settings_org.js +++ b/static/js/settings_org.js @@ -890,7 +890,7 @@ exports.build_page = function () { input_elem = $(input_elem); if (check_property_changed(input_elem)) { const input_value = exports.get_input_element_value(input_elem); - if (input_value) { + if (input_value !== null) { const property_name = input_elem.attr('id').replace("id_realm_", ""); data[property_name] = JSON.stringify(input_value); } diff --git a/static/templates/message_edit_form.hbs b/static/templates/message_edit_form.hbs index d43cc23647..c5af94c2d7 100644 --- a/static/templates/message_edit_form.hbs +++ b/static/templates/message_edit_form.hbs @@ -44,7 +44,9 @@ {{#if file_upload_enabled}} {{/if}} + {{#if show_video_chat_button}} + {{/if}} diff --git a/templates/zerver/app/compose.html b/templates/zerver/app/compose.html index a5286627df..95517e4ac3 100644 --- a/templates/zerver/app/compose.html +++ b/templates/zerver/app/compose.html @@ -100,9 +100,7 @@ {% if max_file_upload_size > 0 %} {% endif %} - {% if jitsi_server_url %} - {% endif %} {{ _('Drafts') }} diff --git a/zerver/models.py b/zerver/models.py index 03f8617aa3..a8caf02fc6 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -301,6 +301,10 @@ class Realm(models.Model): upload_quota_gb = models.IntegerField(null=True) # type: Optional[int] VIDEO_CHAT_PROVIDERS = { + 'disabled': { + 'name': u"None", + 'id': 0 + }, 'jitsi_meet': { 'name': u"Jitsi Meet", 'id': 1 diff --git a/zerver/tests/test_realm.py b/zerver/tests/test_realm.py index 8d8315dd49..77b8953751 100644 --- a/zerver/tests/test_realm.py +++ b/zerver/tests/test_realm.py @@ -498,7 +498,7 @@ class RealmTest(ZulipTestCase): invite_to_stream_policy=10, email_address_visibility=10, message_retention_days=10, - video_chat_provider=0, + video_chat_provider=4, waiting_period_threshold=-10, digest_weekday=10, user_group_edit_policy=10, @@ -533,12 +533,18 @@ class RealmTest(ZulipTestCase): self.assertEqual(get_realm('zulip').video_chat_provider, Realm.VIDEO_CHAT_PROVIDERS['jitsi_meet']['id']) self.login('iago') - invalid_video_chat_provider_value = 0 + invalid_video_chat_provider_value = 4 req = {"video_chat_provider": ujson.dumps(invalid_video_chat_provider_value)} result = self.client_patch('/json/realm', req) self.assert_json_error(result, ("Invalid video_chat_provider {}").format(invalid_video_chat_provider_value)) + req = {"video_chat_provider": ujson.dumps(Realm.VIDEO_CHAT_PROVIDERS['disabled']['id'])} + result = self.client_patch('/json/realm', req) + self.assert_json_success(result) + self.assertEqual(get_realm('zulip').video_chat_provider, + Realm.VIDEO_CHAT_PROVIDERS['disabled']['id']) + req = {"video_chat_provider": ujson.dumps(Realm.VIDEO_CHAT_PROVIDERS['google_hangouts']['id'])} result = self.client_patch('/json/realm', req) self.assert_json_error(result, "Invalid domain: Domain can't be empty.")