[Django] #29220: Auth: change user_passes_test func, new arg arg_position add

6 views
Skip to first unread message

Django

unread,
Mar 14, 2018, 4:49:11 PM3/14/18
to django-...@googlegroups.com
#29220: Auth: change user_passes_test func, new arg arg_position add
-------------------------------------+-------------------------------------
Reporter: Oscar | Owner: nobody
Lopez |
Type: | Status: new
Uncategorized |
Component: | Version: 1.11
contrib.auth | Keywords: Auth,
Severity: Normal | user_passes_test, decorator
Triage Stage: | Has patch: 1
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
I had problems Add my decorations user_passes_test functions, because
decorator _wrapped_view assume, the first arg is the requests parameter,
when i call user_passes_test from a view into a class, that not work, it
take the arg self look like a arg request

example:
`def index(self, request):`

Fatal error: Class don't have attribute user.

This Change work for Django 1.11
but i see that file dont change a lot in Django 2.X

Now i can call the auth:
@user_passes_test(role_client_check, arg_position=0)
def index(self, request):

arg_position can be specific when the first argument isn't "request"
arg_position is a integer with the position of request on view function

I created my own user_passes_test function to solve this feature.

--
Ticket URL: <https://code.djangoproject.com/ticket/29220>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 14, 2018, 4:50:35 PM3/14/18
to django-...@googlegroups.com
#29220: Auth: change user_passes_test func, new arg arg_position add
-------------------------------------+-------------------------------------
Reporter: Oscar Lopez | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.auth | Version: 1.11
Severity: Normal | Resolution:
Keywords: Auth, | Triage Stage:
user_passes_test, decorator | Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Oscar Lopez):

* Attachment "decorators.py" added.

\django\contrib\auth\decorators.py just one file update

Django

unread,
Mar 14, 2018, 4:57:57 PM3/14/18
to django-...@googlegroups.com
#29220: Auth: change user_passes_test func, new arg arg_position add
-------------------------------------+-------------------------------------
Reporter: Oscar Lopez | Owner: nobody
Type: New feature | Status: new

Component: contrib.auth | Version: 1.11
Severity: Normal | Resolution:
Keywords: Auth, | Triage Stage:
user_passes_test, decorator | Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Oscar Lopez):

* type: Uncategorized => New feature


Old description:

> I had problems Add my decorations user_passes_test functions, because
> decorator _wrapped_view assume, the first arg is the requests parameter,
> when i call user_passes_test from a view into a class, that not work, it
> take the arg self look like a arg request
>
> example:
> `def index(self, request):`
>
> Fatal error: Class don't have attribute user.
>
> This Change work for Django 1.11
> but i see that file dont change a lot in Django 2.X
>
> Now i can call the auth:
> @user_passes_test(role_client_check, arg_position=0)
> def index(self, request):
>
> arg_position can be specific when the first argument isn't "request"
> arg_position is a integer with the position of request on view function
>
> I created my own user_passes_test function to solve this feature.

New description:

I had problems Add my decorations user_passes_test functions, because

decorator _wrapped_view assume, the first arg is the `request` var


parameter, when i call user_passes_test from a view into a class, that not
work, it take the arg `self` look like a arg `request`

example:
`@user_passes_test(role_client_check)`
`def index(self, request):`

Fatal error: Class don't have attribute user.

The next new change work for Django 1.11
but i see that Django 2.X file, doesn't change a lot

Now i can call the auth:
`@user_passes_test(role_client_check, arg_position=0)`
`def index(self, request):`

`arg_position` can be specific when the first argument isn't "request"
`arg_position` is a integer with the position of request on view function

I created my own user_passes_test function to solve this feature.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/29220#comment:1>

Django

unread,
Mar 14, 2018, 4:58:11 PM3/14/18
to django-...@googlegroups.com
#29220: Auth: change user_passes_test func, new arg arg_position add
-------------------------------------+-------------------------------------
Reporter: Oscar Lopez | Owner: nobody
Type: New feature | Status: new
Component: contrib.auth | Version: 1.11
Severity: Normal | Resolution:
Keywords: Auth, | Triage Stage:
user_passes_test, decorator | Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Oscar Lopez):

* cc: Oscar Lopez (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/29220#comment:2>

Django

unread,
Mar 15, 2018, 5:32:04 AM3/15/18
to django-...@googlegroups.com
#29220: Auth: change user_passes_test func, new arg arg_position add
-------------------------------------+-------------------------------------
Reporter: Oscar Lopez | Owner: nobody
Type: New feature | Status: closed
Component: contrib.auth | Version: 1.11
Severity: Normal | Resolution: invalid

Keywords: Auth, | Triage Stage:
user_passes_test, decorator | Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Nick Pope):

* status: new => closed
* resolution: => invalid


Comment:

It looks like you have misunderstood how this works.

When using a class-based view (CBV) you need to use
[https://docs.djangoproject.com/en/stable/topics/auth/default/#django.contrib.auth.mixins.UserPassesTestMixin
UserPassesTestMixin] instead of the `@user_passes_test` decorator.

(Alternatively, you can use `@method_decorator` to make this work - see
https://stackoverflow.com/q/8082670/ - but the using the mixin is
straightforward.)

--
Ticket URL: <https://code.djangoproject.com/ticket/29220#comment:3>

Django

unread,
Mar 15, 2018, 10:15:50 AM3/15/18
to django-...@googlegroups.com
#29220: Auth: change user_passes_test func, new arg arg_position add
-------------------------------------+-------------------------------------
Reporter: Oscar Lopez | Owner: nobody
Type: New feature | Status: closed
Component: contrib.auth | Version: 1.11
Severity: Normal | Resolution: invalid
Keywords: Auth, | Triage Stage:
user_passes_test, decorator | Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Oscar Lopez):

Oh Yes, i'm Sorry!

--
Ticket URL: <https://code.djangoproject.com/ticket/29220#comment:4>

Django

unread,
Mar 15, 2018, 11:08:32 AM3/15/18
to django-...@googlegroups.com
#29220: Auth: change user_passes_test func, new arg arg_position add
-------------------------------------+-------------------------------------
Reporter: Oscar Lopez | Owner: nobody
Type: New feature | Status: closed
Component: contrib.auth | Version: 1.11
Severity: Normal | Resolution: invalid
Keywords: Auth, | Triage Stage:
user_passes_test, decorator | Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Oscar Lopez):

Replying to [comment:3 Nick Pope]:


> It looks like you have misunderstood how this works.
>
> When using a class-based view (CBV) you need to use
[https://docs.djangoproject.com/en/stable/topics/auth/default/#django.contrib.auth.mixins.UserPassesTestMixin
UserPassesTestMixin] instead of the `@user_passes_test` decorator.
>
> (Alternatively, you can use `@method_decorator` to make this work - see

https://stackoverflow.com/q/8082670/ - but using the mixin is
straightforward.)

Oh y tried django.contrib.auth.mixins.UserPassesTestMixin but this work
only when using class-based views, im going to try the stackoverflow
method

--
Ticket URL: <https://code.djangoproject.com/ticket/29220#comment:5>

Reply all
Reply to author
Forward
0 new messages