Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#24501 closed Cleanup/optimization (fixed)

Documentation for user_passes_test is wrong and confusing

Reported by: Janne Enberg Owned by: Matt Seymour
Component: Documentation Version: 1.7
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

On the page https://docs.djangoproject.com/en/1.7/topics/auth/default/ it says on "Limiting access to logged-in users that pass a test" ( https://docs.djangoproject.com/en/1.7/topics/auth/default/#limiting-access-to-logged-in-users-that-pass-a-test ) the following:

The simple way is to run your test on request.user in the view directly. For example, this view checks to make sure the user has an email in the desired domain:

def my_view(request):
    if not request.user.email.endswith('@example.com'):
        return HttpResponse("You can't vote in this poll.")
    # ...

Then under that there's the "user_passes_test" -documentation and it's mentioned to be a shortcut for the above.

This is just plain wrong, user_passes_test checks for something, then redirects to login page if the test fails. It does not return HttpResponse("You can't vote in this poll.") and it definitely does not return the 403 that makes me expect it to return.

Also there is only a very casual mention of the "login_url" argument but no mention of what it could possibly be used for, e.g. redirecting users there if the test fails.

Change History (6)

comment:1 by Baptiste Mispelon, 9 years ago

Easy pickings: set
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

Hi,

You're right, the two examples are inconsistent and can be confusing.

There's definitely room for improvement here.

Thanks.

comment:2 by Matt Seymour, 9 years ago

Owner: changed from nobody to Matt Seymour
Status: newassigned

comment:3 by Matt Seymour, 9 years ago

Has patch: set

comment:4 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In fca14cd3:

Fixed #24501 -- Improved auth.decorators.user_passes_test() example.

comment:5 by Tim Graham <timograham@…>, 9 years ago

In 388dc33f:

[1.7.x] Fixed #24501 -- Improved auth.decorators.user_passes_test() example.

Backport of fca14cd3f27a01f7ba1fe32ea9587fa75b85713a from master

comment:6 by Tim Graham <timograham@…>, 9 years ago

In 09933ae:

[1.8.x] Fixed #24501 -- Improved auth.decorators.user_passes_test() example.

Backport of fca14cd3f27a01f7ba1fe32ea9587fa75b85713a from master

Note: See TracTickets for help on using tickets.
Back to Top