-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor assessment permissions in django views and API (#732)
* remove custom mixins in favor of AssessmentPermissionsMixin * wip todo stubs * Flesh out DRF assessment permission class, fix server breaking errors * Further seperated assessment api into seperate modules * Fix bug with OPTIONS requests * Clean up remaining merge conflicts * Fix circular import in CI * Update animal permissions * Update assessment permissions * Update bmd permissions * Update epi permissions * Update epimeta permissions * Update epiv2 permissions * Update invitro permissions * Updated lit permissions * Updated mgmt permissions * Updated rob permissions * Updated study permissions * Updated summary permissions * Fix tests; can_edit_object permissions should apply to reference tag import * Check object permissions on rob_settings * Moved DisabledPagination to common app * Refactoring, added documentation * fix error * updates from review * rename Viewset to ViewSet * rename a few permission methods * move methods around * cleanup * undo comment * review views.py * remove unused methods * updatesr * fix bug --------- Co-authored-by: Daniel Rabstejnek <rabstejnek@gmail.com>
- Loading branch information
1 parent
ca7ce6a
commit efaa660
Showing
43 changed files
with
973 additions
and
1,041 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from .filters import * # noqa: F401,F403 | ||
from .helper import * # noqa: F401,F403 | ||
from .permissions import * # noqa: F401,F403 | ||
from .viewsets import * # noqa: F401,F403 |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from rest_framework import filters | ||
|
||
from .helper import get_assessment_from_query | ||
|
||
|
||
class InAssessmentFilter(filters.BaseFilterBackend): | ||
""" | ||
Filter objects which are in a particular assessment. | ||
""" | ||
|
||
default_list_actions = ["list"] | ||
|
||
def filter_queryset(self, request, queryset, view): | ||
list_actions = getattr(view, "list_actions", self.default_list_actions) | ||
if view.action not in list_actions: | ||
return queryset | ||
|
||
if not hasattr(view, "assessment"): | ||
view.assessment = get_assessment_from_query(request) | ||
|
||
if not view.assessment_filter_args: | ||
raise ValueError("Viewset requires the `assessment_filter_args` argument") | ||
|
||
filters = {view.assessment_filter_args: view.assessment.id} | ||
return queryset.filter(**filters) |
Oops, something went wrong.