Skip to content

Commit

Permalink
chore(core)!: drop unused ViewPassesTestMixin
Browse files Browse the repository at this point in the history
The ViewPassesTestMixin was used some time ago in the former
detail_generic module which was dropped. Its not used anywhere else, so
it seems fine to just drop it. Marking this as a breaking change
nonetheless, to downstream projects using this are aware.
  • Loading branch information
b1rger committed Nov 19, 2024
1 parent 6b44299 commit ed3dfa0
Showing 1 changed file with 0 additions and 32 deletions.
32 changes: 0 additions & 32 deletions apis_core/core/mixins.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,4 @@
from django.conf import settings
from django.contrib.auth.mixins import AccessMixin

from apis_core.utils.utils import access_for_all


class ViewPassesTestMixin(AccessMixin):
"""
Deny a request with a permission error if the test_func() method returns
False. This is mostly a copy of Django's UserPassesTestMixin, but it allows
to set the APIS_VIEW_PASSES_TEST setting to define a function that receives
the view and can perform checks on any of the views attributes.
If such a setting does not exist, it falls back to APIS' access_for_all
function.
"""

def test_func(self):
if hasattr(settings, "APIS_VIEW_PASSES_TEST"):
return settings.APIS_VIEW_PASSES_TEST(self)
# fall back to more general access check
return access_for_all(self, viewtype="detail")

def get_test_func(self):
"""
Override this method to use a different test_func method.
"""
return self.test_func

def dispatch(self, request, *args, **kwargs):
view_test_result = self.get_test_func()()
if not view_test_result:
return self.handle_no_permission()
return super().dispatch(request, *args, **kwargs)


class ListViewObjectFilterMixin:
Expand Down

0 comments on commit ed3dfa0

Please sign in to comment.