From 35d70c8793b07d32e42a7700bd962d11661c7e79 Mon Sep 17 00:00:00 2001 From: Ostap Zherebetskyi Date: Fri, 10 Jan 2025 15:07:43 +0200 Subject: [PATCH 1/2] updated preprint filters --- api/base/filters.py | 2 +- osf/models/preprint.py | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/api/base/filters.py b/api/base/filters.py index 19c0cd20a2d..df3083c31ba 100644 --- a/api/base/filters.py +++ b/api/base/filters.py @@ -610,7 +610,7 @@ def preprints_queryset(self, base_queryset, auth_user, allow_contribs=True, publ public_only=public_only, ) if latest_only: - preprints = preprints.filter(pk__in=[obj.pk for obj in preprints if obj.is_latest_version]) + preprints = preprints.filter(guids__isnull=False) return preprints diff --git a/osf/models/preprint.py b/osf/models/preprint.py index 15d8c3c0930..8505d864f90 100644 --- a/osf/models/preprint.py +++ b/osf/models/preprint.py @@ -663,9 +663,7 @@ def csl(self): # formats node information into CSL format for citation parsing @property def is_latest_version(self): - if not self.date_published: - return False - return self.versioned_guids.first().guid.referent.version == self.version + return self.guids.exists() def get_preprint_versions(self): guids = self.versioned_guids.first().guid.versions.all() From 4182a15edec947939a78baa3ab709e86a0fce454 Mon Sep 17 00:00:00 2001 From: Ostap Zherebetskyi Date: Fri, 10 Jan 2025 15:47:27 +0200 Subject: [PATCH 2/2] revert commit 45d7615 changes --- api/collections/views.py | 2 +- api_tests/nodes/views/test_node_preprints.py | 2 +- api_tests/preprints/views/test_preprint_list_mixin.py | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/api/collections/views.py b/api/collections/views.py index e4dad133877..53d29fb9113 100644 --- a/api/collections/views.py +++ b/api/collections/views.py @@ -80,7 +80,7 @@ def collection_preprints(self, collection, user, latest_only=False): user=user, ) if latest_only: - preprints = preprints.filter(pk__in=[obj.pk for obj in preprints if obj.is_latest_version]) + preprints = preprints.filter(guids__isnull=False) return preprints def get_collection_submission(self, check_object_permissions=True): diff --git a/api_tests/nodes/views/test_node_preprints.py b/api_tests/nodes/views/test_node_preprints.py index b3a2810bd53..75d663cd23b 100644 --- a/api_tests/nodes/views/test_node_preprints.py +++ b/api_tests/nodes/views/test_node_preprints.py @@ -154,7 +154,7 @@ def test_unpublished_visible_to_admins( preprint_unpublished, preprint_published, url): res = app.get(url, auth=user_admin_contrib.auth) - assert len(res.json['data']) == 1 + assert len(res.json['data']) == 2 assert preprint_published._id in [d['id'] for d in res.json['data']] def test_unpublished_invisible_to_write_contribs( 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