-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(generic)!: APIS_ANON_VIEWS_ALLOWED setting
BREAKING CHANGE: APIS_LIST_VIEWS_ALLOWED and APIS_DETAIL_VIEWS_ALLOWED are replaced with a single setting APIS_ANON_VIEWS_ALLOWED When APIS_ANON_VIEWS_ALLOWED is set to True List views and Detail views will be open to anyone, without having to login. APIS_LIST_VIEW_OBJECT_FILTER and APIS_VIEW_PASSES_TEST are no longer supported. Custom managers should be used instead. fixes #1400
- Loading branch information
Showing
3 changed files
with
10 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,13 @@ | ||
from django.conf import settings | ||
|
||
|
||
class ListViewObjectFilterMixin: | ||
class ViewPermissionMixin: | ||
""" | ||
Filter a queryset of a listview using the APIS_LIST_VIEW_OBJECT_FILTER | ||
setting if it exists. A child class has to call the `filter_queryset` | ||
method somewhere, most likely in the `get_queryset` method. | ||
This mixin ensures that no permissions are required for the view | ||
if APIS_ANON_VIEWS_ALLOWED is set. | ||
""" | ||
|
||
def filter_queryset(self, queryset): | ||
if hasattr(super(), "filter_queryset"): | ||
queryset = super().filter_queryset(queryset) | ||
if hasattr(settings, "APIS_LIST_VIEW_OBJECT_FILTER"): | ||
return settings.APIS_LIST_VIEW_OBJECT_FILTER(self, queryset) | ||
return queryset | ||
|
||
def get_permission_required(self): | ||
if getattr(settings, "APIS_LIST_VIEWS_ALLOWED", False): | ||
if getattr(settings, "APIS_ANON_VIEWS_ALLOWED", False): | ||
return [] | ||
return super().get_permission_required() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters