From bfbd372031330298b0374e3dd17494d7b7d27ae4 Mon Sep 17 00:00:00 2001
From: Bryan Brancotte <bryan.brancotte@pasteur.fr>
Date: Thu, 3 Feb 2022 15:07:45 +0100
Subject: [PATCH] allows curators to download former version iff they did the
 change

---
 src/viralhostrange/viralhostrangedb/views.py | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/viralhostrange/viralhostrangedb/views.py b/src/viralhostrange/viralhostrangedb/views.py
index 2190541a..29dcc24a 100644
--- a/src/viralhostrange/viralhostrangedb/views.py
+++ b/src/viralhostrange/viralhostrangedb/views.py
@@ -445,13 +445,17 @@ def get_log_entry_with_permission_check_or_404(request, pk, log_pk, allow_curato
 
 @login_required
 def data_source_history_download(request, pk, log_pk):
-    data_source, le = get_log_entry_with_permission_check_or_404(
-        request,
-        pk,
-        log_pk,
-        allow_curator=True,
-        user_id=request.user.id,
-    )
+    try:
+        data_source, le = get_log_entry_with_permission_check_or_404(request, pk, log_pk)
+    except Http404:
+        # if we cannot get it, then allows curators, but only on their own entry
+        data_source, le = get_log_entry_with_permission_check_or_404(
+            request,
+            pk,
+            log_pk,
+            allow_curator=True,
+            user_id=request.user.id,
+        )
     file_path = business_process.get_backup_file_path(le, test_if_exists=True)
 
     if file_path is None:
-- 
GitLab