Skip to content

Commit

Permalink
Implement review-action-list filtering on versioned _id
Browse files Browse the repository at this point in the history
  • Loading branch information
cslzchen committed Jan 10, 2025
1 parent 1aa3169 commit 73dc626
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
4 changes: 2 additions & 2 deletions api/actions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
28 changes: 25 additions & 3 deletions api/base/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()`.
"""
Expand Down Expand Up @@ -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()`.
"""
Expand All @@ -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)

0 comments on commit 73dc626

Please sign in to comment.