diff --git a/submissions/factories.py b/submissions/factories.py index 9eb4eb4f24ca9edd3e2745605ea0b0d3f321479e..39aab654c692e00a6518a5e7ecc633acf1b59f99 100644 --- a/submissions/factories.py +++ b/submissions/factories.py @@ -38,7 +38,7 @@ class SubmissionFactory(factory.django.DjangoModelFactory): '''Fill empty arxiv fields.''' self.arxiv_link = 'https://arxiv.org/abs/%s' % self.arxiv_identifier_wo_vn_nr self.arxiv_identifier_w_vn_nr = '%sv1' % self.arxiv_identifier_wo_vn_nr - self.arxiv_vn_nr = 1 + self.arxiv_vn_nr = kwargs.get('arxiv_vn_nr', 1) @factory.post_generation def contributors(self, create, extracted, **kwargs): diff --git a/submissions/managers.py b/submissions/managers.py index ddff884029fae485b0589446aa9b947d341ee5cc..f1ce5d8a9ec241367cdfa27d31e7624bbea4c4ac 100644 --- a/submissions/managers.py +++ b/submissions/managers.py @@ -8,6 +8,22 @@ from .constants import SUBMISSION_STATUS_OUT_OF_POOL, SUBMISSION_STATUS_PUBLICLY class SubmissionManager(models.Manager): + def _newest_version_only(self, queryset): + """ + The current Queryset should return only the latest version + of the Arxiv submissions known to SciPost. + + Method only compatible with PostGresQL + """ + # This method used a double query, which is a consequence of the complex distinct() + # filter combined with the PostGresQL engine. Without the double query, ordering + # on a specific field after filtering would be impossible. + ids = (queryset + .order_by('arxiv_identifier_wo_vn_nr', '-arxiv_vn_nr') + .distinct('arxiv_identifier_wo_vn_nr') + .values_list('id', flat=True)) + return queryset.filter(id__in=ids) + def user_filter(self, user): """ Prevent conflic of interest by filtering submissions possible related to user. @@ -54,7 +70,8 @@ class SubmissionManager(models.Manager): This query contains an overcomplete set of public submissions, i.e. also containing submissions with status "published" or "resubmitted". """ - return self.exclude(status__in=SUBMISSION_STATUS_PUBLICLY_INVISIBLE) + queryset = self.exclude(status__in=SUBMISSION_STATUS_PUBLICLY_INVISIBLE) + return self._newest_version_only(queryset) class EditorialAssignmentManager(models.Manager): diff --git a/submissions/test_views.py b/submissions/test_views.py index 2d05701eb185fbd40ed0219d7d8e014f8c11efe9..11e9c210a19bd604c2791a96a4359d6f1c7672b4 100644 --- a/submissions/test_views.py +++ b/submissions/test_views.py @@ -223,6 +223,17 @@ class SubmissionListTest(BaseContributorTestCase): visible_submission_ids.append(EICassignedSubmissionFactory.create().id) visible_submission_ids.append(PublishedSubmissionFactory.create().id) + # Extra submission with multiple versions where the newest is publicly visible + # again. Earlier versions should therefore be invisible! + arxiv_id_resubmission = random_arxiv_identifier_without_version_number() + ResubmittedSubmissionFactory.create(arxiv_identifier_wo_vn_nr=arxiv_id_resubmission) + visible_submission_ids.append( + EICassignedSubmissionFactory.create( + arxiv_identifier_wo_vn_nr=arxiv_id_resubmission, + fill_arxiv_fields__arxiv_vn_nr=2 + ).id + ) + # Check with hardcoded URL as this url shouldn't change! client = Client() response = client.get('/submissions/')