Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
User .get_all_permissions() vs. .has_perm() inconsistency
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
dslowik  
View profile  
 More options Feb 10, 7:01 pm
From: dslowik <dslo...@tellink.net>
Date: Fri, 10 Feb 2012 16:01:30 -0800 (PST)
Local: Fri, Feb 10 2012 7:01 pm
Subject: User .get_all_permissions() vs. .has_perm() inconsistency
Here is the code form my Python 2.6.6 session which is puzzling me:

>>> from django.contrib.auth.models import User
>>> u = User.objects.get(username='clint')
>>> u.get_all_permissions()

set([u'wb.delete_libraryitem', u'wb.change_libraryitem'])
>>> u.has_perm("wb.change_libraryitem")

True

...Shouldn't that be False?

I'm really trying to use permission checking as in:
{% if perms.foo.can_vote %}
as discussed in:
https://docs.djangoproject.com/en/1.2/topics/auth/#authentication-dat...
, where I was expecting a False and got that True, but I've tracked
the problem down to the above puzzle.

I'm running

>>> django.VERSION

(1, 2, 3, 'final', 0)

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andy McKay  
View profile  
 More options Feb 10, 10:49 pm
From: Andy McKay <a...@clearwind.ca>
Date: Fri, 10 Feb 2012 19:49:03 -0800
Local: Fri, Feb 10 2012 10:49 pm
Subject: Re: User .get_all_permissions() vs. .has_perm() inconsistency

On Fri, Feb 10, 2012 at 4:01 PM, dslowik <dslo...@tellink.net> wrote:
>>>> u.get_all_permissions()
> set([u'wb.delete_libraryitem', u'wb.change_libraryitem'])
>>>> u.has_perm("wb.change_libraryitem")
> True

> ...Shouldn't that be False?

Why would it be False? get_all_permissions: Returns a set of
permission strings that the user has.... has_perm: Returns True if the
user has the specified permission.

https://docs.djangoproject.com/en/1.2/topics/auth/#django.contrib.aut...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
dslowik  
View profile  
 More options Feb 11, 10:38 am
From: dslowik <dslo...@tellink.net>
Date: Sat, 11 Feb 2012 07:38:03 -0800 (PST)
Local: Sat, Feb 11 2012 10:38 am
Subject: Re: User .get_all_permissions() vs. .has_perm() inconsistency
Yes, I have to agree entirely..
I bungled the OP. Here is what the code snippet should have been:
>>> from django.contrib.auth.models import User
>>> u = User.objects.get(username='clint')
>>> u.get_all_permissions()

set([u'wb.delete_libraryitem', u'wb.change_libraryitem'])
>>> u.has_perm("wb.add_libraryitem")

True

How can that be?

Your reply did prod me into realizing that I had made a similar typo
while trying to resolve this question last night. Anyway, here is the
answer:

>>> u.is_superuser

True

If the user is not superuser, it returns False. u.has_perm() returns
true for ANY permission if u is superuser.

>>> u.has_perm("wb.anything")

True

This solves the problem. Thanks for the help Andy. :)

Don Slowik

On Feb 10, 10:49 pm, Andy McKay <a...@clearwind.ca> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »