This was not made clear by the documentation and has wasted considerable
amount of time tracking down until i hit upon this
[http://stackoverflow.com/questions/10102918/cant-change-user-permissions-
during-unittest-in-django Stack Overflow].
--
Ticket URL: <https://code.djangoproject.com/ticket/20834>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_docs: => 0
* type: Uncategorized => New feature
* needs_tests: => 0
* needs_better_patch: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/20834#comment:1>
* stage: Unreviewed => Accepted
Comment:
Yes, this seems like a good thing to mention. Do you think you could write
up a patch or simply some text about what you would say?
--
Ticket URL: <https://code.djangoproject.com/ticket/20834#comment:2>
Comment (by Giggaflop):
I would do something along the lines of.
It may be required that the User object is reobtained if dynamically
adding permissions. This is due to them being cached by Django.
{{{
def user_gains_perms(request, user_id):
user = get_object_or_404(pk=user_id)
permission = Permission.objects.get(codename="all_the_things")
user.user_permissions.add(permission)
# Note the user object has not gained the permission
user.has_perms('all_the_things') # False
# Request new instance of User
user = get_object_or_404(pk=user_id)
# Now note how the permissions have been updated
user.has_perms('all_the_things') # True
return HttpResponseRedirect(reverse('index'))
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/20834#comment:3>
* keywords: => afraid-to-commit
* cc: EvilDMP (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/20834#comment:4>
Comment (by EvilDMP):
I've marked this ticket as especially suitable for first-time committers
or people following the [http://dont-be-afraid-to-commit.readthedocs.org/
Don't be afraid to commit] tutorial. If you're tackling this ticket,
please don't hesitate to ask me for guidance if you'd like any, either
here or on the Django IRC channels, where I can be found as ''EvilDMP''.
--
Ticket URL: <https://code.djangoproject.com/ticket/20834#comment:5>
Comment (by Jennifer):
I notice that the documentation referred to in the original report is
for django 1.3 here is the link for the latest documentation version:
https://docs.djangoproject.com/en/dev/ref/contrib/auth/#methods
--
Ticket URL: <https://code.djangoproject.com/ticket/20834#comment:6>
* owner: nobody => Jennifer
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/20834#comment:7>
Comment (by Jennifer):
I have made pull request for review
https://github.com/django/django/pull/1754
--
Ticket URL: <https://code.djangoproject.com/ticket/20834#comment:8>
* needs_better_patch: 0 => 1
* has_patch: 0 => 1
Comment:
I left some comments for improvement on the pull request.
--
Ticket URL: <https://code.djangoproject.com/ticket/20834#comment:9>
* needs_better_patch: 1 => 0
Comment:
Here's a [https://github.com/django/django/pull/2179 PR] for review.
--
Ticket URL: <https://code.djangoproject.com/ticket/20834#comment:10>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"5f9790072d52443aff9a0e04f1552f1e29489521"]:
{{{
#!CommitTicketReference repository=""
revision="5f9790072d52443aff9a0e04f1552f1e29489521"
Fixed #20834 -- Described how caching of user permissions works.
Thanks Giggaflop and Jennifer Casavantes.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/20834#comment:11>
Comment (by Tim Graham <timograham@…>):
In [changeset:"8eca53f0bef783e5c11877fe18a6651543605af1"]:
{{{
#!CommitTicketReference repository=""
revision="8eca53f0bef783e5c11877fe18a6651543605af1"
[1.6.x] Fixed #20834 -- Described how caching of user permissions works.
Thanks Giggaflop and Jennifer Casavantes.
Backport of 5f9790072d from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/20834#comment:12>