settings: Warn if server is unable to deliver mobile push notifications.

The "notification settings" page previously advertised support for
mobile push notifications via checkboxes, even if the server hadn't
yet been registered for push notifications.  This was a frequent
source of onboarding pain for new Zulip organizations.

We fix this by providing a clear warning and disabling the relevant
inputs on the settings pages.

Modified significantly by tabbott to correct some tricky logic errors
as well as some copy-paste bugs.

Fixes #10331.
This commit is contained in:
Shikhar Vaish 2018-08-31 02:15:59 +05:30 committed by Tim Abbott
parent f5c3a4aea7
commit 5ffca5e388
4 changed files with 35 additions and 4 deletions

View File

@ -1075,6 +1075,7 @@ run_test('settings_tab', () => {
enable_offline_push_notifications: true, enable_online_push_notifications: true,
enable_digest_emails: true,
realm_name_in_notifications: true,
realm_push_notifications_enabled: true,
};
var page_params = $.extend(page_param_checkbox_options, {
full_name: "Alyssa P. Hacker", password_auth_enabled: true,

View File

@ -62,6 +62,27 @@ Handlebars.registerHelper('if_and', function () {
return options.fn(this);
});
Handlebars.registerHelper('unless_a_not_b', function () {
// Execute the conditional code if at least one condition is false.
// Example usage:
// {{#unless_a_not_b cond1 cond2}}
// <p>a is false or b is true</p>
// {{/unless_a_not_b}}
var options = arguments[arguments.length - 1];
if (arguments[0] && !arguments[1]) {
return options.inverse(this);
}
return options.fn(this);
});
Handlebars.registerHelper('if_not_a_or_b_and_not_c', function () {
var options = arguments[arguments.length - 1];
if (arguments[0] === false || arguments[1] === true && arguments[2] === false) {
return options.fn(this);
}
return options.inverse(this);
});
Handlebars.registerHelper('if_or', function () {
// Execute the conditional code if any of the conditions are true.
// Example usage:

View File

@ -24,6 +24,7 @@
"setting_name" "enable_stream_push_notifications"
"is_checked" page_params.enable_stream_push_notifications
"label" settings_label.enable_stream_push_notifications
"push_notifications_tooltip" true
"end_content" '<div class="propagate_stream_notifications_change"></div>'}}
{{partial "settings_checkbox"
@ -67,14 +68,16 @@
{{partial "settings_checkbox"
"setting_name" "enable_offline_push_notifications"
"is_checked" page_params.enable_offline_push_notifications
"label" settings_label.enable_offline_push_notifications}}
"label" settings_label.enable_offline_push_notifications
"push_notifications_tooltip" true}}
{{partial "settings_checkbox"
"setting_name" "enable_online_push_notifications"
"is_checked" page_params.enable_online_push_notifications
"is_parent_setting_enabled" page_params.enable_offline_push_notifications
"is_nested" true
"label" settings_label.enable_online_push_notifications}}
"label" settings_label.enable_online_push_notifications
"push_notifications_tooltip" true}}
</div>
<div id="other_notifications">

View File

@ -1,15 +1,21 @@
<div class="input-group {{#if is_nested}}disableable{{/if}} {{#is_false is_parent_setting_enabled}}control-label-disabled{{/is_false}}">
<div class="input-group {{#if is_nested}}disableable{{/if}} {{#if_not_a_or_b_and_not_c is_parent_setting_enabled push_notifications_tooltip page_params.realm_push_notifications_enabled}}control-label-disabled{{/if_not_a_or_b_and_not_c}}">
<label class="checkbox">
<input type="checkbox" class="inline-block" name="{{setting_name}}"
id="{{prefix}}{{setting_name}}"
{{#is_false is_parent_setting_enabled}}disabled="disabled"{{/is_false}}
{{#if_not_a_or_b_and_not_c is_parent_setting_enabled push_notifications_tooltip page_params.realm_push_notifications_enabled}}disabled="disabled"{{/if_not_a_or_b_and_not_c}}
{{#if is_checked}}
{{#unless_a_not_b push_notifications_tooltip page_params.realm_push_notifications_enabled}}
checked="checked"
{{/unless_a_not_b}}
{{/if}} />
<span></span>
</label>
<label for="{{prefix}}{{setting_name}}" class="inline-block" id="{{prefix}}{{setting_name}}_label">
{{{label}}}
</label>
{{#if push_notifications_tooltip}}
<i class="fa fa-question-circle settings-info-icon" {{#if page_params.realm_push_notifications_enabled}}style="display:none"{{/if}} data-toggle="tooltip"
title="{{t 'Mobile push notifications are not configured on this server.' }}"></i>
{{/if}}
{{{end_content}}}
</div>