#24914: Include basic permission mixins into Django
------------------------------+------------------------------------
Reporter: raphaelm | Owner: MarkusH
Type: New feature | Status: assigned
Component: contrib.auth | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Comment (by jaysonsantos):
Replying to [comment:13 MarkusH]:
> Thanks for mentioning that, Rundll. The current implementation does not
support stacking them (braces' `LoginRequired` and `PermissionRequired`
mixins do, though). However, neither our `UserPassesTestMixin` nor braces'
allows stacking inherited mixins, either.
>
> That makes me wonder how one is supposed to combine different permission
checks that are used separately and together:
>
> {{{#!python
> class CheckOneMixin(UserPassesTestMixin):
> def test_func(self, user):
> return something_is_true_or_false
>
> class CheckTwoMixin(UserPassesTestMixin):
> def test_func(self, user):
> return something_else_is_true_or_false
>
> class MyView1(CheckOneMixin, View):
> pass
>
> class MyView2(CheckTwoMixin, View):
> pass
>
> class MyView3(CheckOneMixin, CheckTwoMixin, View):
> pass
> }}}
>
> Effectively, `MyView3` will never bother about the value of
`something_else_is_true_or_false` as that function is never called.
About ensuring at least one valid response, I thought something like this:
{{{#!python
class CheckOneMixin:
def test_func(self):
print(self)
return True
class CheckTwoMixin:
def test_func(self):
print(self)
return False
class Dispatcher:
def dispatch(self):
validators = [b.test_func for b in self.__class__.__bases__ if
hasattr(b, 'test_func')]
for validator in validators:
if validator(self):
return 'Dispatch for real'
return 'Invalid permissions'
class MyView1(CheckOneMixin, Dispatcher):
pass
class MyView2(CheckTwoMixin, Dispatcher):
pass
class MyView3(CheckOneMixin, CheckTwoMixin, Dispatcher):
pass
for klass in (MyView1, MyView2, MyView3):
print(klass().dispatch(), '\n')
}}}
In this case the class that act like the real dispatcher could call every
function on View's bases.
--
Ticket URL: <https://code.djangoproject.com/ticket/24914#comment:18>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/066.86c72def28eb4ccd182f93cc174abd15%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.