From aecf173c9bd13fa5f96dfa31c479bfaafc834695 Mon Sep 17 00:00:00 2001
From: George Katsikas <giorgakis.katsikas@gmail.com>
Date: Tue, 27 Feb 2024 15:40:49 +0100
Subject: [PATCH] add CI guard to referee invitation

---
 scipost_django/submissions/views/__init__.py | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/scipost_django/submissions/views/__init__.py b/scipost_django/submissions/views/__init__.py
index 5dc1efe2f..766b7fb85 100644
--- a/scipost_django/submissions/views/__init__.py
+++ b/scipost_django/submissions/views/__init__.py
@@ -1348,6 +1348,23 @@ def invite_referee(
     profile = get_object_or_404(Profile, pk=profile_id)
     auto_reminders_allowed = auto_reminders_allowed == "True"
 
+    # Guard against profiles with competing interests
+    if not (
+        Profile.objects.filter(profile=profile)
+        .without_competing_interests_against_submission_authors_of(submission)
+        .exists()
+    ):
+        messages.error(
+            request,
+            "This Profile has a competing interest with the authors of the Submission.",
+        )
+        return redirect(
+            reverse(
+                "submissions:editorial_page",
+                kwargs={"identifier_w_vn_nr": identifier_w_vn_nr},
+            )
+        )
+
     # We cannot proceed if the Profile has no email address
     # or if the email address is not linked to the Profile.
     profile_email = profile.emails.get(email=profile_email)
-- 
GitLab