From bec591d85b1e4695024b54bbd902559ec7727ea6 Mon Sep 17 00:00:00 2001 From: Elrond Date: Mon, 14 Nov 2011 19:08:43 +0100 Subject: [PATCH] Dot-Notation for Users.is_admin --- mediagoblin/decorators.py | 2 +- mediagoblin/edit/lib.py | 2 +- mediagoblin/edit/views.py | 4 ++-- mediagoblin/gmg_commands/users.py | 2 +- mediagoblin/templates/mediagoblin/user_pages/media.html | 4 ++-- mediagoblin/templates/mediagoblin/user_pages/user.html | 2 +- mediagoblin/user_pages/views.py | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mediagoblin/decorators.py b/mediagoblin/decorators.py index d6a054f8..229664d7 100644 --- a/mediagoblin/decorators.py +++ b/mediagoblin/decorators.py @@ -59,7 +59,7 @@ def user_may_delete_media(controller): def wrapper(request, *args, **kwargs): uploader = request.db.MediaEntry.find_one( {'_id': ObjectId(request.matchdict['media'])}).get_uploader() - if not (request.user['is_admin'] or + if not (request.user.is_admin or request.user._id == uploader._id): return exc.HTTPForbidden() diff --git a/mediagoblin/edit/lib.py b/mediagoblin/edit/lib.py index 458b704e..4ce2d42f 100644 --- a/mediagoblin/edit/lib.py +++ b/mediagoblin/edit/lib.py @@ -19,6 +19,6 @@ def may_edit_media(request, media): """Check, if the request's user may edit the media details""" if media['uploader'] == request.user._id: return True - if request.user['is_admin']: + if request.user.is_admin: return True return False diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index 61a61d4c..e766b6d8 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -78,7 +78,7 @@ def edit_media(request, media): return exc.HTTPFound( location=media.url_for_self(request.urlgen)) - if request.user['is_admin'] \ + if request.user.is_admin \ and media['uploader'] != request.user._id \ and request.method != 'POST': messages.add_message( @@ -147,7 +147,7 @@ def edit_attachments(request, media): def edit_profile(request): # admins may edit any user profile given a username in the querystring edit_username = request.GET.get('username') - if request.user['is_admin'] and request.user.username != edit_username: + if request.user.is_admin and request.user.username != edit_username: user = request.db.User.find_one({'username': edit_username}) # No need to warn again if admin just submitted an edited profile if request.method != 'POST': diff --git a/mediagoblin/gmg_commands/users.py b/mediagoblin/gmg_commands/users.py index 7b23ba34..4bfe30a5 100644 --- a/mediagoblin/gmg_commands/users.py +++ b/mediagoblin/gmg_commands/users.py @@ -73,7 +73,7 @@ def makeadmin(args): user = db.User.one({'username': unicode(args.username.lower())}) if user: - user['is_admin'] = True + user.is_admin = True user.save() print 'The user is now Admin' else: diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index 7fc60c3f..89fd104d 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -116,7 +116,7 @@ {% include "mediagoblin/utils/prev_next.html" %} {% if media['uploader'] == request.user._id or - request.user['is_admin'] %} + request.user.is_admin %}

{% set edit_url = request.urlgen('mediagoblin.edit.edit_media', user= media.get_uploader().username, @@ -146,7 +146,7 @@ {% if app_config['allow_attachments'] and (media['uploader'] == request.user._id - or request.user['is_admin']) %} + or request.user.is_admin) %}

{% include "mediagoblin/utils/profile.html" %} - {% if request.user._id == user._id or request.user['is_admin'] %} + {% if request.user._id == user._id or request.user.is_admin %} {%- trans %}Edit profile{% endtrans -%} diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py index 4b311822..dc549567 100644 --- a/mediagoblin/user_pages/views.py +++ b/mediagoblin/user_pages/views.py @@ -191,7 +191,7 @@ def media_confirm_delete(request, media): return exc.HTTPFound( location=media.url_for_self(request.urlgen)) - if ((request.user[u'is_admin'] and + if ((request.user.is_admin and request.user._id != media.get_uploader()._id)): messages.add_message( request, messages.WARNING, -- 2.25.1