From 15d647104b347d539c9c05516dbac6d04cb4d016 Mon Sep 17 00:00:00 2001
From: George Katsikas <giorgakis.katsikas@gmail.com>
Date: Tue, 21 Jan 2025 17:23:23 +0100
Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=9B=82=20allow=20pub=20officers=20?=
 =?UTF-8?q?to=20access=20tools?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Add publications tools to publications detail page when user is in the Publication Officers group
---
 .../journals/_publication_actions.html        | 24 ++++++++++---------
 .../journals/publication_detail.html          |  3 ++-
 .../scipost/templatetags/user_groups.py       |  9 +++++++
 3 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/scipost_django/journals/templates/journals/_publication_actions.html b/scipost_django/journals/templates/journals/_publication_actions.html
index 8e5ddef48..5eff3be7d 100644
--- a/scipost_django/journals/templates/journals/_publication_actions.html
+++ b/scipost_django/journals/templates/journals/_publication_actions.html
@@ -94,20 +94,22 @@
       </li>
     </ul>
 
-    {% if journal.autogeneratedfilecontenttemplate_set.all %}
-      Autogenerated files
-      <ul>
+    {% with journal=publication.get_journal %}
+      {% if journal.autogeneratedfilecontenttemplate_set.all %}
+        Autogenerated files
+        <ul>
 
-        {% for autotemplate in journal.autogeneratedfilecontenttemplate_set.all %}
-          <li>
-            <a href="{% url 'journals:view_autogenerated_file' doi_label=publication.doi_label autotemplate_id=autotemplate.id %}"
-               target="_blank">{{ autotemplate.name }} ({{ autotemplate.description }})</a>
-          </li>
-        {% endfor %}
+          {% for autotemplate in journal.autogeneratedfilecontenttemplate_set.all %}
+            <li>
+              <a href="{% url 'journals:view_autogenerated_file' doi_label=publication.doi_label autotemplate_id=autotemplate.id %}"
+                target="_blank">{{ autotemplate.name }} ({{ autotemplate.description }})</a>
+            </li>
+          {% endfor %}
 
 
-      </ul>
-    {% endif %}
+        </ul>
+      {% endif %}
+    {% endwith %}
 
   </div>
 </div>
diff --git a/scipost_django/journals/templates/journals/publication_detail.html b/scipost_django/journals/templates/journals/publication_detail.html
index dde0f5ade..d41156f27 100644
--- a/scipost_django/journals/templates/journals/publication_detail.html
+++ b/scipost_django/journals/templates/journals/publication_detail.html
@@ -43,6 +43,7 @@
 {% block content %}
   {% is_scipost_admin request.user as is_scipost_admin %}
   {% is_ed_admin request.user as is_ed_admin %}
+  {% is_pub_officer request.user as is_pub_officer %}
 
   {{ block.super }}
 
@@ -249,7 +250,7 @@
       </div>
     </div>
   {% endif %}
-  {% if is_ed_admin %}
+  {% if is_ed_admin or is_pub_officer %}
     <hr class="divider">
     <div class="row">
       <div class="col-12">
diff --git a/scipost_django/scipost/templatetags/user_groups.py b/scipost_django/scipost/templatetags/user_groups.py
index f05b154fd..1f6f95c80 100644
--- a/scipost_django/scipost/templatetags/user_groups.py
+++ b/scipost_django/scipost/templatetags/user_groups.py
@@ -132,6 +132,15 @@ def is_editor_in_charge(user, submission):
     return submission.editor_in_charge == user.contributor
 
 
+@register.simple_tag
+def is_pub_officer(user):
+    """
+    Assign template variable (boolean) to check if user is Publication Officer.
+    This assignment is limited to a certain context block!
+    """
+    return user.groups.filter(name="Publication Officers").exists() or user.is_superuser
+
+
 @register.simple_tag
 def recommend_new_totp_device(user):
     """
-- 
GitLab