Use a more accurate "is admin?" check.

UserProfile.show_admin was intended to be a check for users that have
administrative rights in other realms, which we've harmlessly but
erroneously been using to check if they are an admin in their realm.

Use the more straightforward check instead, with a more intuitive
name.

(imported from commit d81050c7dbbb19e59c5e31750be303a4630e1456)
This commit is contained in:
Jessica McKellar 2013-11-19 14:21:12 -05:00
parent 2c841042ae
commit d1619b3f3c
6 changed files with 9 additions and 14 deletions

View File

@ -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);
});

View File

@ -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;
}
}

View File

@ -53,7 +53,7 @@ var page_params = {{ page_params }};
<div class="tab-pane" id="subscriptions">
{% include "zerver/subscriptions.html" %}
</div>
{% if show_admin %}
{% if is_admin %}
<div class="tab-pane" id="administration">
{% include "zerver/administration.html" %}
</div>

View File

@ -77,7 +77,7 @@
</a>
</li>
<li class="divider"></li>
{% if show_admin %}
{% if is_admin %}
<li title="Administration">
<a href="#administration" role="button" data-toggle="tab">
<i class="icon-vector-bolt"></i> Administration

View File

@ -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):

View File

@ -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
},