diff --git a/static/js/subs.js b/static/js/subs.js index b9aceecf09..6819db4d9d 100644 --- a/static/js/subs.js +++ b/static/js/subs.js @@ -228,7 +228,7 @@ function add_email_hint(row) { function add_sub_to_table(sub) { $('#create_stream_row').after(templates.render( 'subscription', - _.extend(sub, {'allow_rename': page_params.show_admin}))); + _.extend(sub, {'allow_rename': page_params.is_admin}))); settings_for_sub(sub).collapse('show'); add_email_hint(sub); } @@ -408,7 +408,7 @@ exports.setup_page = function () { // Add in admin options. var sub_rows = []; _.each(all_subs, function (sub) { - sub = _.extend(sub, {'allow_rename': page_params.show_admin}); + sub = _.extend(sub, {'allow_rename': page_params.is_admin}); sub_rows.push(sub); }); diff --git a/static/js/zulip.js b/static/js/zulip.js index b375b2616a..58b37c9d45 100644 --- a/static/js/zulip.js +++ b/static/js/zulip.js @@ -556,7 +556,7 @@ function set_topic_edit_properties(message) { // to encourage updating them. Admins can also edit any topic. if (message.subject === compose.empty_subject_placeholder()) { message.always_visible_topic_edit = true; - } else if (page_params.show_admin) { + } else if (page_params.is_admin) { message.on_hover_topic_edit = true; } } diff --git a/templates/zerver/index.html b/templates/zerver/index.html index 0169667e4c..95a2802b92 100644 --- a/templates/zerver/index.html +++ b/templates/zerver/index.html @@ -53,7 +53,7 @@ var page_params = {{ page_params }};
{% include "zerver/subscriptions.html" %}
- {% if show_admin %} + {% if is_admin %}
{% include "zerver/administration.html" %}
diff --git a/templates/zerver/navbar.html b/templates/zerver/navbar.html index eaaa16ea55..4231dac2d1 100644 --- a/templates/zerver/navbar.html +++ b/templates/zerver/navbar.html @@ -77,7 +77,7 @@
  • - {% if show_admin %} + {% if is_admin %}
  • Administration diff --git a/zerver/models.py b/zerver/models.py index 328998aab0..37644c7d0e 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -254,13 +254,8 @@ class UserProfile(AbstractBaseUser, PermissionsMixin): else: return False - @property - def show_admin(self): - # Logic to determine if the user should see the administration tools. - # Do NOT use this to check if a user is authorized to perform a specific action! - return 0 < self.userobjectpermission_set.filter( - content_type__name="realm", - permission__codename="administer").count() + def is_admin(self): + return self.has_perm('administer', self.realm) @property def public_streams_disabled(self): diff --git a/zerver/views/__init__.py b/zerver/views/__init__.py index df5d192760..61fa03b2a6 100644 --- a/zerver/views/__init__.py +++ b/zerver/views/__init__.py @@ -725,7 +725,7 @@ def home(request): staging = settings.STAGING_DEPLOYED or not settings.DEPLOYED, alert_words = register_ret['alert_words'], muted_topics = register_ret['muted_topics'], - show_admin = user_profile.show_admin, + is_admin = user_profile.is_admin(), notify_for_streams_by_default = notify_for_streams_by_default(user_profile), name_changes_disabled = settings.NAME_CHANGES_DISABLED, has_mobile_devices = num_push_devices_for_user(user_profile) > 0 @@ -749,7 +749,7 @@ def home(request): 'show_debug': settings.DEBUG and ('show_debug' in request.GET), 'show_invites': show_invites, - 'show_admin': user_profile.show_admin, + 'is_admin': user_profile.is_admin(), 'show_webathena': user_profile.realm.domain == "mit.edu", 'enable_feedback': settings.ENABLE_FEEDBACK },