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
This commit is contained in:
sahil839 2020-04-08 03:53:15 +05:30 committed by Tim Abbott
parent f9caf522f0
commit 65d953b2af
11 changed files with 134 additions and 30 deletions

View File

@ -79,6 +79,22 @@ people.small_avatar_url_for_person = function () {
return 'http://example.com/example.png'; 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 = { const new_user = {
email: 'new_user@example.com', email: 'new_user@example.com',
user_id: 101, 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(); compose.initialize();
assert(resize_watch_manual_resize_checked); assert(resize_watch_manual_resize_checked);
@ -919,11 +958,6 @@ run_test('initialize', () => {
assert(!$("#compose #attach_files").hasClass("notdisplayed")); assert(!$("#compose #attach_files").hasClass("notdisplayed"));
assert(setup_upload_called); assert(setup_upload_called);
function reset_jquery() {
// Avoid leaks.
set_global('$', global.make_zjquery());
}
let compose_actions_start_checked; let compose_actions_start_checked;
function set_up_compose_start_mock(expected_opts) { function set_up_compose_start_mock(expected_opts) {
@ -942,6 +976,7 @@ run_test('initialize', () => {
page_params.narrow = true; page_params.narrow = true;
reset_jquery(); reset_jquery();
stub_out_video_calls();
set_up_compose_start_mock({}); set_up_compose_start_mock({});
compose.initialize(); compose.initialize();
@ -953,6 +988,7 @@ run_test('initialize', () => {
page_params.narrow_topic = 'testing'; page_params.narrow_topic = 'testing';
reset_jquery(); reset_jquery();
stub_out_video_calls();
set_up_compose_start_mock({topic: 'testing'}); set_up_compose_start_mock({topic: 'testing'});
compose.initialize(); compose.initialize();
@ -964,6 +1000,7 @@ run_test('initialize', () => {
$("#compose-send-button").attr('disabled', 'disabled'); $("#compose-send-button").attr('disabled', 'disabled');
reset_jquery(); reset_jquery();
stub_out_video_calls();
compose.initialize(); compose.initialize();
compose.abort_xhr(); compose.abort_xhr();
@ -1381,16 +1418,6 @@ run_test('on_events', () => {
to_$: () => textarea, 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) { compose_ui.insert_syntax_and_focus = function (syntax) {
syntax_to_insert = syntax; syntax_to_insert = syntax;
@ -1401,11 +1428,21 @@ run_test('on_events', () => {
$('#compose-textarea').val(''); $('#compose-textarea').val('');
handler(ev); 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 // video link ids consist of 15 random digits
let video_link_regex = /\[Click to join video call\]\(https:\/\/meet.jit.si\/\d{15}\)/; let video_link_regex = /\[Click to join video call\]\(https:\/\/meet.jit.si\/\d{15}\)/;
assert(video_link_regex.test(syntax_to_insert)); 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_video_chat_provider =
page_params.realm_available_video_chat_providers.google_hangouts.id; page_params.realm_available_video_chat_providers.google_hangouts.id;
page_params.realm_google_hangouts_domain = 'zulip'; 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\)/; video_link_regex = /\[Click to join video call\]\(example\.zoom\.com\)/;
assert(video_link_regex.test(syntax_to_insert)); 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() { (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_stream_button_big").text(), i18n.t("New topic"));
assert.equal($("#left_bar_compose_private_button_big").text(), i18n.t("New private message")); 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);
});

View File

@ -50,6 +50,10 @@ set_global('settings_bots', {
update_bot_permissions_ui: noop, update_bot_permissions_ui: noop,
}); });
set_global('compose', {
update_video_chat_button_display: noop,
});
set_global('settings_exports', { set_global('settings_exports', {
populate_exports_table: function (exports) { populate_exports_table: function (exports) {
return exports; return exports;

View File

@ -187,6 +187,9 @@ $(".top_left_starred_messages").set_find_results('.count', count_stub);
$("#tab_list .stream").length = 0; $("#tab_list .stream").length = 0;
compose.compute_show_video_chat_button = () => {};
$("#below-compose-content .video_link").toggle = () => {};
run_test('initialize_everything', () => { run_test('initialize_everything', () => {
ui_init.initialize_everything(); ui_init.initialize_everything();
}); });

View File

@ -48,6 +48,26 @@ function show_all_everyone_warnings() {
user_acknowledged_all_everyone = false; 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 () { exports.clear_all_everyone_warnings = function () {
$("#compose-all-everyone").hide(); $("#compose-all-everyone").hide();
$("#compose-all-everyone").empty(); $("#compose-all-everyone").empty();
@ -906,6 +926,7 @@ exports.warn_if_mentioning_unsubscribed_user = function (mentioned) {
}; };
exports.initialize = function () { 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('keyup', update_fade);
$('#stream_message_recipient_stream,#stream_message_recipient_topic,#private_message_recipient').on('change', update_fade); $('#stream_message_recipient_stream,#stream_message_recipient_topic,#private_message_recipient').on('change', update_fade);
$('#compose-textarea').on('keydown', function (event) { $('#compose-textarea').on('keydown', function (event) {
@ -1048,13 +1069,14 @@ exports.initialize = function () {
target_textarea = $("#message_edit_content_" + edit_message_id); target_textarea = $("#message_edit_content_" + edit_message_id);
} }
if (page_params.jitsi_server_url === null) {
return;
}
let video_call_link; let video_call_link;
const video_call_id = util.random_int(100000000000000, 999999999999999); const video_call_id = util.random_int(100000000000000, 999999999999999);
const available_providers = page_params.realm_available_video_chat_providers; 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) { 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; video_call_link = "https://hangouts.google.com/hangouts/_/" + page_params.realm_google_hangouts_domain + "/" + video_call_id;

View File

@ -234,6 +234,8 @@ function edit_message(row, raw_content) {
file_upload_enabled = true; file_upload_enabled = true;
} }
const show_video_chat_button = compose.compute_show_video_chat_button();
const form = $(render_message_edit_form({ const form = $(render_message_edit_form({
is_stream: message.type === 'stream', is_stream: message.type === 'stream',
message_id: message.id, message_id: message.id,
@ -243,6 +245,7 @@ function edit_message(row, raw_content) {
topic: message.topic, topic: message.topic,
content: raw_content, content: raw_content,
file_upload_enabled: file_upload_enabled, 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), minutes_to_edit: Math.floor(page_params.realm_message_content_edit_limit_seconds / 60),
})); }));

View File

@ -118,7 +118,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
message_content_allowed_in_email_notifications: noop, message_content_allowed_in_email_notifications: noop,
signup_notifications_stream_id: noop, signup_notifications_stream_id: noop,
emails_restricted_to_domains: noop, emails_restricted_to_domains: noop,
video_chat_provider: noop, video_chat_provider: compose.update_video_chat_button_display,
waiting_period_threshold: noop, waiting_period_threshold: noop,
zoom_user_id: noop, zoom_user_id: noop,
zoom_api_key: noop, zoom_api_key: noop,

View File

@ -890,7 +890,7 @@ exports.build_page = function () {
input_elem = $(input_elem); input_elem = $(input_elem);
if (check_property_changed(input_elem)) { if (check_property_changed(input_elem)) {
const input_value = exports.get_input_element_value(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_", ""); const property_name = input_elem.attr('id').replace("id_realm_", "");
data[property_name] = JSON.stringify(input_value); data[property_name] = JSON.stringify(input_value);
} }

View File

@ -44,7 +44,9 @@
{{#if file_upload_enabled}} {{#if file_upload_enabled}}
<a class="message-control-button fa fa-paperclip notdisplayed" aria-hidden="true" id="attach_files_{{message_id}}" href="#" title="{{t "Attach files" }}"></a> <a class="message-control-button fa fa-paperclip notdisplayed" aria-hidden="true" id="attach_files_{{message_id}}" href="#" title="{{t "Attach files" }}"></a>
{{/if}} {{/if}}
{{#if show_video_chat_button}}
<a class="message-control-button fa fa-video-camera video_link" aria-hidden="true" href="#" data-message-id="{{message_id}}" title="{{t "Add video call" }}"></a> <a class="message-control-button fa fa-video-camera video_link" aria-hidden="true" href="#" data-message-id="{{message_id}}" title="{{t "Add video call" }}"></a>
{{/if}}
<a id="undo_markdown_preview_{{message_id}}" class="message-control-button fa fa-edit" aria-hidden="true" style="display:none;" title="{{t 'Write' }}"></a> <a id="undo_markdown_preview_{{message_id}}" class="message-control-button fa fa-edit" aria-hidden="true" style="display:none;" title="{{t 'Write' }}"></a>
<a id="markdown_preview_{{message_id}}" class="message-control-button fa fa-eye" aria-hidden="true" title="{{t 'Preview' }}"></a> <a id="markdown_preview_{{message_id}}" class="message-control-button fa fa-eye" aria-hidden="true" title="{{t 'Preview' }}"></a>
</div> </div>

View File

@ -100,9 +100,7 @@
{% if max_file_upload_size > 0 %} {% if max_file_upload_size > 0 %}
<a class="message-control-button fa fa-paperclip notdisplayed" aria-hidden="true" id="attach_files" href="#" title="{{ _('Attach files') }}"></a> <a class="message-control-button fa fa-paperclip notdisplayed" aria-hidden="true" id="attach_files" href="#" title="{{ _('Attach files') }}"></a>
{% endif %} {% endif %}
{% if jitsi_server_url %}
<a class="message-control-button fa fa-video-camera video_link" aria-hidden="true" href="#" title="{{ _('Add video call') }}"></a> <a class="message-control-button fa fa-video-camera video_link" aria-hidden="true" href="#" title="{{ _('Add video call') }}"></a>
{% endif %}
<a id="undo_markdown_preview" class="message-control-button fa fa-edit" aria-hidden="true" style="display:none;" title="{{ _('Write') }}"></a> <a id="undo_markdown_preview" class="message-control-button fa fa-edit" aria-hidden="true" style="display:none;" title="{{ _('Write') }}"></a>
<a id="markdown_preview" class="message-control-button fa fa-eye" aria-hidden="true" title="{{ _('Preview') }}"></a> <a id="markdown_preview" class="message-control-button fa fa-eye" aria-hidden="true" title="{{ _('Preview') }}"></a>
<a class="drafts-link" href="#drafts" title="{{ _('Drafts') }} (d)">{{ _('Drafts') }}</a> <a class="drafts-link" href="#drafts" title="{{ _('Drafts') }} (d)">{{ _('Drafts') }}</a>

View File

@ -301,6 +301,10 @@ class Realm(models.Model):
upload_quota_gb = models.IntegerField(null=True) # type: Optional[int] upload_quota_gb = models.IntegerField(null=True) # type: Optional[int]
VIDEO_CHAT_PROVIDERS = { VIDEO_CHAT_PROVIDERS = {
'disabled': {
'name': u"None",
'id': 0
},
'jitsi_meet': { 'jitsi_meet': {
'name': u"Jitsi Meet", 'name': u"Jitsi Meet",
'id': 1 'id': 1

View File

@ -498,7 +498,7 @@ class RealmTest(ZulipTestCase):
invite_to_stream_policy=10, invite_to_stream_policy=10,
email_address_visibility=10, email_address_visibility=10,
message_retention_days=10, message_retention_days=10,
video_chat_provider=0, video_chat_provider=4,
waiting_period_threshold=-10, waiting_period_threshold=-10,
digest_weekday=10, digest_weekday=10,
user_group_edit_policy=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.assertEqual(get_realm('zulip').video_chat_provider, Realm.VIDEO_CHAT_PROVIDERS['jitsi_meet']['id'])
self.login('iago') 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)} req = {"video_chat_provider": ujson.dumps(invalid_video_chat_provider_value)}
result = self.client_patch('/json/realm', req) result = self.client_patch('/json/realm', req)
self.assert_json_error(result, self.assert_json_error(result,
("Invalid video_chat_provider {}").format(invalid_video_chat_provider_value)) ("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'])} req = {"video_chat_provider": ujson.dumps(Realm.VIDEO_CHAT_PROVIDERS['google_hangouts']['id'])}
result = self.client_patch('/json/realm', req) result = self.client_patch('/json/realm', req)
self.assert_json_error(result, "Invalid domain: Domain can't be empty.") self.assert_json_error(result, "Invalid domain: Domain can't be empty.")