From 4c96994345f0c0b618953c95893d1b2c6145f491 Mon Sep 17 00:00:00 2001
From: George Katsikas <giorgakis.katsikas@gmail.com>
Date: Thu, 5 Oct 2023 13:20:39 +0200
Subject: [PATCH] guard invited referees from submitting a comment

fixes #85
---
 .../templates/comments/new_comment.html       | 28 +++++++++++++++----
 .../_submission_quick_actions.html            | 10 ++++---
 2 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/scipost_django/comments/templates/comments/new_comment.html b/scipost_django/comments/templates/comments/new_comment.html
index 454bde094..c33bee158 100644
--- a/scipost_django/comments/templates/comments/new_comment.html
+++ b/scipost_django/comments/templates/comments/new_comment.html
@@ -2,21 +2,37 @@
 
 {% if user.is_authenticated and open_for_commenting and perms.scipost.can_submit_comments %}
 
-  <hr class="divider">
-
-  <h2 class="highlight" id="contribute_comment">Contribute a Comment</h2>
   {% if user_is_referee and submission %}
     <h4 class="text-danger my-3">
       {% include 'bi/exclamation-triangle-fill.html' %}
       You are an invited referee, please <a href="{% url 'submissions:submit_report' submission.preprint.identifier_w_vn_nr %}">submit a Report</a> instead.
     </h4>
+
+    <details id="contribute_comment">
+      <summary class="highlight fs-5 p-2">I'm know, but let me contribute a Comment anyway</summary>
+
+      {% url 'comments:new_comment' object_id=object_id type_of_object=type_of_object as url %}
+      {% include 'comments/_add_comment_form.html' with form=form url=url %}
+
+    </details>
+  {% else %}
+
+    <details open id="contribute_comment">
+      <summary class="highlight fs-5 p-2">Contribute a Comment</summary>
+
+      {% url 'comments:new_comment' object_id=object_id type_of_object=type_of_object as url %}
+      {% include 'comments/_add_comment_form.html' with form=form url=url %}
+
+    </details>
   {% endif %}
 
-  {% url 'comments:new_comment' object_id=object_id type_of_object=type_of_object as url %}
-  {% include 'comments/_add_comment_form.html' with form=form url=url %}
+ 
 
+ 
 {% elif not user.is_authenticated %}
 
-  <h3 class="text-center my-3"><a href="{% url 'scipost:login' %}?next={{ request.path }}">Login to comment</a></h3>
+  <h3 class="text-center my-3">
+    <a href="{% url 'scipost:login' %}?next={{ request.path }}">Login to comment</a>
+  </h3>
 
 {% endif %}
diff --git a/scipost_django/submissions/templates/submissions/_submission_quick_actions.html b/scipost_django/submissions/templates/submissions/_submission_quick_actions.html
index 3134d2066..c47688219 100644
--- a/scipost_django/submissions/templates/submissions/_submission_quick_actions.html
+++ b/scipost_django/submissions/templates/submissions/_submission_quick_actions.html
@@ -1,3 +1,5 @@
+{% load submissions_extras %}
+
 {% if perms.scipost.can_submit_comments %}
   <div class="submission-quick-actions">
     <h3>Actions</h3>
@@ -52,10 +54,10 @@
       {% endif %}
 
       {% if submission.open_for_commenting %}
-	{% if perms.scipost.can_submit_comments %}
-	  <li class="pt-1">
-	    <h4><a href="#contribute_comment">Contribute a Comment</a></h4>
-	  </li>
+	{% if perms.scipost.can_submit_comments and submission and not submission|user_is_referee:request.user  %}
+    <li class="pt-1">
+      <h4><a href="#contribute_comment">Contribute a Comment</a></h4>
+    </li>
 	{% endif %}
       {% else %}
 	<li class="py-1">Commenting on this Submission is closed.</li>
-- 
GitLab