From 9f985860ecd73d33ef0c9798ad5e8729657906c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Caux?= <git@jscaux.org> Date: Tue, 25 Jan 2022 06:05:55 +0100 Subject: [PATCH] Fixes SCIPOST-16C --- scipost_django/preprints/views.py | 4 +++- scipost_django/submissions/models/submission.py | 6 +++++- scipost_django/submissions/views.py | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/scipost_django/preprints/views.py b/scipost_django/preprints/views.py index fafc358b3..7055d1ac5 100644 --- a/scipost_django/preprints/views.py +++ b/scipost_django/preprints/views.py @@ -17,7 +17,9 @@ def preprint_pdf_wo_vn_nr(request, identifier_wo_vn_nr): """ submissions = get_list_or_404( Submission, preprint__identifier_w_vn_nr__startswith=identifier_wo_vn_nr) - latest = submissions[0].get_latest_version() + latest = submissions[0].get_latest_public_version() + if not latest: + raise Http404 return redirect(reverse( 'preprints:pdf', kwargs={ 'identifier_w_vn_nr': latest.preprint.identifier_w_vn_nr })) diff --git a/scipost_django/submissions/models/submission.py b/scipost_django/submissions/models/submission.py index d1017b69c..1c1fd659f 100644 --- a/scipost_django/submissions/models/submission.py +++ b/scipost_django/submissions/models/submission.py @@ -364,7 +364,11 @@ class Submission(models.Model): return Submission.objects.filter(thread_hash=self.thread_hash).exclude(pk=self.id) def get_latest_version(self): - """Return the latest known version in the thread of this Submission.""" + """Return the latest version in the thread of this Submission.""" + return self.thread_full.first() + + def get_latest_public_version(self): + """Return the latest publicly-visible version in the thread of this Submission.""" return self.thread.first() def _add_event(self, sort, message): diff --git a/scipost_django/submissions/views.py b/scipost_django/submissions/views.py index 56e692c70..cb61a2649 100644 --- a/scipost_django/submissions/views.py +++ b/scipost_django/submissions/views.py @@ -492,8 +492,8 @@ def submission_detail_wo_vn_nr(request, identifier_wo_vn_nr): """Redirect to the latest Submission's detail page.""" submissions = get_list_or_404( Submission, preprint__identifier_w_vn_nr__startswith=identifier_wo_vn_nr) - latest = submissions[0].get_latest_version() - if not latest: # this can happen if there exists no public version in this thread + latest = submissions[0].get_latest_public_version() + if not latest: raise Http404 return redirect(reverse('submissions:submission', kwargs={ 'identifier_w_vn_nr': latest.preprint.identifier_w_vn_nr })) -- GitLab