diff --git a/static/js/settings.js b/static/js/settings.js index 2e47304dd0..bd8c6af802 100644 --- a/static/js/settings.js +++ b/static/js/settings.js @@ -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); diff --git a/static/js/settings_account.js b/static/js/settings_account.js index 86d65ee693..100dd57e38 100644 --- a/static/js/settings_account.js +++ b/static/js/settings_account.js @@ -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'); } diff --git a/static/templates/settings/account_settings.hbs b/static/templates/settings/account_settings.hbs index 77e763c177..912a5cee02 100644 --- a/static/templates/settings/account_settings.hbs +++ b/static/templates/settings/account_settings.hbs @@ -49,10 +49,9 @@