settings: Rewrite logic for whether users can change name.

This moves this somewhat complicated, duplicated logic into a single
JavaScript function.
This commit is contained in:
Tim Abbott 2019-07-15 14:12:31 -07:00
parent 8b538d8b8d
commit d2f1c84001
3 changed files with 16 additions and 8 deletions

View File

@ -140,6 +140,7 @@ exports.build_page = function () {
push_notification_tooltip:
settings_notifications.all_notifications.push_notification_tooltip,
display_settings: settings_display.all_display_settings,
user_can_change_name: settings_account.user_can_change_name(),
});
$(".settings-box").html(rendered_settings_tab);

View File

@ -28,9 +28,18 @@ exports.update_full_name = function (new_full_name) {
}
};
exports.user_can_change_name = function () {
if (page_params.is_admin) {
return true;
}
if (page_params.realm_name_changes_disabled || page_params.server_name_changes_disabled) {
return false;
}
return true;
};
exports.update_name_change_display = function () {
if ((page_params.realm_name_changes_disabled || page_params.server_name_changes_disabled)
&& !page_params.is_admin) {
if (!exports.user_can_change_name()) {
$('#full_name').attr('disabled', 'disabled');
$(".change_name_tooltip").show();
} else {
@ -295,8 +304,7 @@ exports.set_up = function () {
$("#change_full_name").on('click', function (e) {
e.preventDefault();
e.stopPropagation();
if (!page_params.realm_name_changes_disabled && !page_params.server_name_changes_disabled
|| page_params.is_admin) {
if (exports.user_can_change_name()) {
$('#change_full_name_modal').find("input[name='full_name']").val(page_params.full_name);
overlays.open_modal('change_full_name_modal');
}

View File

@ -49,10 +49,9 @@
<div class="input-group inline-block grid user-name-parent">
<div class="user-name-section inline-block">
<label for="full_name" class="inline-block title">{{t "Full name" }}</label>
<a id="change_full_name"
{{#unless page_params.is_admin}}{{#if page_params.realm_name_changes_disabled}}{{else}}{{#unless page_params.server_name_changes_disabled}}href="#change_email"{{/unless}}{{/if}}{{/unless}}>
<a id="change_full_name" {{#if user_can_change_name}}href="#change_email"{{/if}}>
<button type="button" class="button small white rounded inline-block" id="full_name"
{{#unless page_params.is_admin}}{{#if page_params.realm_name_changes_disabled}}disabled="disabled"{{else}}{{#if page_params.server_name_changes_disabled}}disabled="disabled"{{/if}}{{/if}}{{/unless}}>
{{#unless user_can_change_name}}disabled="disabled"{{/unless}}>
{{~#if true~}}
<span id="full_name_value">{{page_params.full_name}}</span>
<i class="fa fa-pencil"></i>
@ -60,7 +59,7 @@
</button>
</a>
<i class="fa fa-question-circle change_name_tooltip settings-info-icon" data-toggle="tooltip"
{{#if (or page_params.is_admin (not (or page_params.realm_name_changes_disabled page_params.server_name_changes_disabled)))}}style="display:none"{{/if}}
{{#if user_can_change_name}}style="display:none"{{/if}}
title="{{t 'Name changes are disabled in this organization. Contact an administrator to change your name.' }}"/>
</div>
<div id="change_full_name_modal" class="modal modal-bg hide fade" tabindex="-1" role="dialog"