diff --git a/api/actions/views.py b/api/actions/views.py index 5436d7aaea1..28623e3f13d 100644 --- a/api/actions/views.py +++ b/api/actions/views.py @@ -6,7 +6,7 @@ from api.actions.permissions import ReviewActionPermission from api.actions.serializers import NodeRequestActionSerializer, ReviewActionSerializer, PreprintRequestActionSerializer from api.base.exceptions import Conflict -from api.base.filters import ListFilterMixin +from api.base.filters import ReviewActionFilterMixin from api.base.views import JSONAPIBaseView from api.base.parsers import ( JSONAPIMultipleRelationshipsParser, @@ -110,7 +110,7 @@ def get_object(self): return action -class ReviewActionListCreate(JSONAPIBaseView, generics.ListCreateAPIView, ListFilterMixin): +class ReviewActionListCreate(JSONAPIBaseView, generics.ListCreateAPIView, ReviewActionFilterMixin): """List of review actions viewable by this user Actions represent state changes and/or comments on a reviewable object (e.g. a preprint) diff --git a/api/base/filters.py b/api/base/filters.py index ffe5e1b9add..19c0cd20a2d 100644 --- a/api/base/filters.py +++ b/api/base/filters.py @@ -568,8 +568,8 @@ def get_serializer_method(self, field_name): class PreprintFilterMixin(ListFilterMixin): - """View mixin for many preprint listing views, which uses ListFilterMixin, adding postprocessing for preprint - querying by provider, subjects and versioned `_id`. + """View mixin for many preprint listing views. It inherits from ListFilterMixin and customize postprocessing for + preprint querying by provider, subjects and versioned `_id`. Note: Subclasses must define `get_default_queryset()`. """ @@ -615,7 +615,8 @@ def preprints_queryset(self, base_queryset, auth_user, allow_contribs=True, publ class PreprintActionFilterMixin(ListFilterMixin): - """View mixin for `PreprintActionList` which uses ListFilterMixin, adding postprocessing for versioned preprint. + """View mixin for `PreprintActionList`. It inherits from `ListFilterMixin` and customize postprocessing for + versioned preprint. Note: Subclasses must define `get_default_queryset()`. """ @@ -641,3 +642,24 @@ def postprocess_query_param(self, key, field_name, operation): PreprintActionFilterMixin.postprocess_versioned_guid_target_query_param(operation) else: super().postprocess_query_param(key, field_name, operation) + +class ReviewActionFilterMixin(ListFilterMixin): + """View mixin for `ReviewActionListCreate`. It inherits from `ListFilterMixin` and uses `PreprintActionFilterMixin` + to customized postprocessing for handling versioned preprint. + + Note: Subclasses must define `get_default_queryset()`. + """ + def postprocess_query_param(self, key, field_name, operation): + """Handles a special case when filtering on `target` and when `target` is a versioned Preprint. + """ + if field_name == 'target': + referent, version = Guid.load_referent(operation['value']) + if referent: + if version: + PreprintActionFilterMixin.postprocess_versioned_guid_target_query_param(operation) + else: + super().postprocess_query_param(key, field_name, operation) + else: + return + else: + super().postprocess_query_param(key, field_name, operation)