diff --git a/api/base/filters.py b/api/base/filters.py index 4d9bc37a442..0f8708ff789 100644 --- a/api/base/filters.py +++ b/api/base/filters.py @@ -338,6 +338,35 @@ def parse_query_params(self, query_params): }) elif self.should_parse_special_query_params(field_name): query = self.parse_special_query_params(field_name, key, value, query) + elif not isinstance(value, int) and source_field_name == 'target__guids___id': + base_guid, version = Guid.split_guid(value) + if base_guid is None and version is None: + raise InvalidFilterValue( + value=value, + field_type='guid', + ) + guid_filters = { + field_name: { + 'op': 'in', + 'value': self.bulk_get_values(value, field), + 'source_field_name': source_field_name, + }, + } + if version is not None: + guid_filters = { + field_name: { + 'op': 'eq', + 'value': base_guid, + 'source_field_name': 'target__guids___id', + }, + 'target__versioned_guids__version': { + 'op': 'eq', + 'value': version, + 'source_field_name': 'target__versioned_guids__version', + }, + } + + query.get(key).update(guid_filters) else: query.get(key).update({ field_name: { diff --git a/api_tests/preprints/views/test_preprint_list_mixin.py b/api_tests/preprints/views/test_preprint_list_mixin.py index 37ef40942ea..df11d3d0c30 100644 --- a/api_tests/preprints/views/test_preprint_list_mixin.py +++ b/api_tests/preprints/views/test_preprint_list_mixin.py @@ -208,7 +208,8 @@ def test_filter_published_false_admin( res = app.get( f'{url}filter[is_published]=false', auth=user_admin_contrib.auth) - assert len(res.json['data']) == 0 + assert len(res.json['data']) == 1 + assert preprint_unpublished._id in [d['id'] for d in res.json['data']] @pytest.mark.django_db