From 0555e7a615227f70711b69a8f0a8ee76ee25850b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jean-S=C3=A9bastien=20Caux?= <git@jscaux.org>
Date: Tue, 19 Oct 2021 12:33:38 +0200
Subject: [PATCH] Include some facilities for Senior Fellows, beautify overall

---
 .../colleges/submission_fellowships.html      | 12 ++++--
 scipost_django/colleges/views.py              | 10 ++---
 scipost_django/scipost/models.py              |  4 ++
 .../submissions/models/submission.py          |  4 ++
 .../admin/submission_preassign_editors.html   | 30 +++++++------
 .../pool/_hx_submission_details.html          | 22 ++++++----
 .../submissions/pool/_hx_submission_li.html   | 42 +++++++++++--------
 .../pool/_submission_info_table.html          | 28 +++++++++----
 .../submissions/pool/hx_submissions_list.html |  2 +-
 scipost_django/submissions/views.py           | 13 +++---
 10 files changed, 109 insertions(+), 58 deletions(-)

diff --git a/scipost_django/colleges/templates/colleges/submission_fellowships.html b/scipost_django/colleges/templates/colleges/submission_fellowships.html
index 7f8c90b5b..801553bb7 100644
--- a/scipost_django/colleges/templates/colleges/submission_fellowships.html
+++ b/scipost_django/colleges/templates/colleges/submission_fellowships.html
@@ -1,15 +1,19 @@
 {% extends 'submissions/admin/base.html' %}
 
 {% load bootstrap %}
+{% load user_groups %}
 
 {% block breadcrumb_items %}
   {{ block.super }}
   <span class="breadcrumb-item">Submission Fellowships</span>
 {% endblock %}
 
-{% block pagetitle %}: Submission Felloswhips{% endblock pagetitle %}
+{% block pagetitle %}: Submission Fellowships{% endblock pagetitle %}
 
 {% block content %}
+
+  {% is_ed_admin request.user as is_ed_admin %}
+
   <h1>Submission Fellowships</h1>
   <h2 class="text-primary">{{ submission.title }}</h2>
   <h3 class="mb-3">by {{ submission.author_list }}</h3>
@@ -24,7 +28,7 @@
         <th>Fellowship ID</th>
         <th>Fellow</th>
         <th>Type</th>
-        <th colspan="2">Date range</th>
+        <th colspan="2"></th>
       </tr>
     </thead>
     <tbody>
@@ -34,7 +38,9 @@
           <td>{{ fellowship.contributor }}</td>
           <td>{{ fellowship.guest|yesno:"Guest fellowship,Regular fellowship"|safe }}</td>
           <td>
-            <a class="text-danger" href="{% url 'colleges:fellowship_remove_submission' fellowship.id submission.preprint.identifier_w_vn_nr %}">Remove this Fellow from Submission's fellowhship</a>
+	    {% if is_ed_admin %}
+              <a class="text-danger" href="{% url 'colleges:fellowship_remove_submission' fellowship.id submission.preprint.identifier_w_vn_nr %}">Remove this Fellow from Submission's fellowhship</a>
+	    {% endif %}
           </td>
         </tr>
       {% endfor %}
diff --git a/scipost_django/colleges/views.py b/scipost_django/colleges/views.py
index a72888d39..9bd33d25a 100644
--- a/scipost_django/colleges/views.py
+++ b/scipost_django/colleges/views.py
@@ -6,7 +6,7 @@ import datetime
 
 from django.contrib import messages
 from django.contrib.auth.models import Group
-from django.contrib.auth.decorators import login_required, permission_required
+from django.contrib.auth.decorators import login_required, permission_required, user_passes_test
 from django.urls import reverse, reverse_lazy
 from django.http import Http404
 from django.shortcuts import get_object_or_404, render, redirect
@@ -16,6 +16,7 @@ from django.views.generic.edit import CreateView, UpdateView, DeleteView
 from django.views.generic.list import ListView
 
 from submissions.models import Submission
+from submissions.permissions import is_edadmin_or_senior_fellow
 
 from .constants import (
     POTENTIAL_FELLOWSHIP_STATUSES, POTENTIAL_FELLOWSHIP_EVENT_STATUSUPDATED,
@@ -184,7 +185,7 @@ def email_College_Fellows(request, college):
 
 
 @login_required
-@permission_required('scipost.can_manage_college_composition', raise_exception=True)
+@user_passes_test(is_edadmin_or_senior_fellow)
 def submission_fellowships(request, identifier_w_vn_nr):
     """
     List all Fellowships related to Submission.
@@ -198,8 +199,7 @@ def submission_fellowships(request, identifier_w_vn_nr):
 
 
 @login_required
-@login_required
-@permission_required('scipost.can_manage_college_composition', raise_exception=True)
+@user_passes_test(is_edadmin_or_senior_fellow)
 def submission_add_fellowship(request, identifier_w_vn_nr):
     """Add Fellowship to a Submission's Fellowship."""
     submission = get_object_or_404(Submission, preprint__identifier_w_vn_nr=identifier_w_vn_nr)
@@ -223,7 +223,7 @@ def submission_add_fellowship(request, identifier_w_vn_nr):
 @login_required
 @permission_required('scipost.can_manage_college_composition', raise_exception=True)
 def fellowship_remove_submission(request, id, identifier_w_vn_nr):
-    """Remove Submission from the pool of a Fellowship."""
+    """Remove Submission from the Fellowship."""
     fellowship = get_object_or_404(Fellowship, id=id)
     submission = get_object_or_404(
         fellowship.pool.all(), preprint__identifier_w_vn_nr=identifier_w_vn_nr)
diff --git a/scipost_django/scipost/models.py b/scipost_django/scipost/models.py
index 5f27541df..2ec9208b8 100644
--- a/scipost_django/scipost/models.py
+++ b/scipost_django/scipost/models.py
@@ -143,6 +143,10 @@ class Contributor(models.Model):
         """Check if Contributor is a member of the Editorial College."""
         return self.fellowships.active().exists() or self.user.is_superuser
 
+    @property
+    def is_active_senior_fellow(self):
+        return self.fellowships.active().senior().exists()
+
     @property
     def is_vetting_editor(self):
         """Check if Contributor is a Vetting Editor."""
diff --git a/scipost_django/submissions/models/submission.py b/scipost_django/submissions/models/submission.py
index 847550f76..0f7af7f30 100644
--- a/scipost_django/submissions/models/submission.py
+++ b/scipost_django/submissions/models/submission.py
@@ -293,6 +293,10 @@ class Submission(models.Model):
         return Submission.objects.filter(
             thread_hash=self.thread_hash, is_resubmission_of__isnull=True).first().submission_date
 
+    @property
+    def in_prescreening(self):
+        return self.status == STATUS_INCOMING
+
     @property
     def in_refereeing_phase(self):
         """Check if Submission is in active refereeing phase.
diff --git a/scipost_django/submissions/templates/submissions/admin/submission_preassign_editors.html b/scipost_django/submissions/templates/submissions/admin/submission_preassign_editors.html
index 4e4304564..dee12ef43 100644
--- a/scipost_django/submissions/templates/submissions/admin/submission_preassign_editors.html
+++ b/scipost_django/submissions/templates/submissions/admin/submission_preassign_editors.html
@@ -2,6 +2,7 @@
 
 {% load bootstrap %}
 {% load scipost_extras %}
+{% load user_groups %}
 {% load conflict_tags %}
 
 {% block pagetitle %}: Submission Editors{% endblock pagetitle %}
@@ -18,6 +19,7 @@
 
 {% block content %}
 
+  {% is_ed_admin request.user as is_ed_admin %}
 
   <h1 class="highlight">Submission editor invitations</h1>
   <h3><a href="{{ submission.get_absolute_url }}">{{ submission.title }}</a></h3>
@@ -29,17 +31,21 @@
 
   <br>
 
-  <ul>
-    <li><a href="{% url 'submissions:editorial_page' submission.preprint.identifier_w_vn_nr %}">Go to editorial page</a></li>
-    {% if submission.status == 'incoming' %}
-      <li><a href="{% url 'submissions:do_prescreening' submission.preprint.identifier_w_vn_nr %}">Go to pre-screening page</a></li>
-    {% else %}
-      <li><a href="{% url 'submissions:update_authors_screening' submission.preprint.identifier_w_vn_nr 1 %}">Update authors by email (1 week into screening)</a></li>
-      <li><a href="{% url 'submissions:update_authors_screening' submission.preprint.identifier_w_vn_nr 2 %}">Update authors by email (2 weeks into screening)</a></li>
-      <li><a href="{% url 'submissions:assignment_failed' submission.preprint.identifier_w_vn_nr %}">Close: screening failed (failure to find EIC)</a></li>
-    {% endif %}
-  </ul>
-
+  {% if is_ed_admin %}
+    <div class="border border-danger mt-3 p-2">
+      <h3>Editorial Administration</h3>
+      <ul>
+	<li><a href="{% url 'submissions:editorial_page' submission.preprint.identifier_w_vn_nr %}">Go to editorial page</a></li>
+	{% if submission.status == 'incoming' %}
+	  <li><a href="{% url 'submissions:do_prescreening' submission.preprint.identifier_w_vn_nr %}">Go to pre-screening page</a></li>
+	{% else %}
+	  <li><a href="{% url 'submissions:update_authors_screening' submission.preprint.identifier_w_vn_nr 1 %}">Update authors by email (1 week into screening)</a></li>
+	  <li><a href="{% url 'submissions:update_authors_screening' submission.preprint.identifier_w_vn_nr 2 %}">Update authors by email (2 weeks into screening)</a></li>
+	  <li><a href="{% url 'submissions:assignment_failed' submission.preprint.identifier_w_vn_nr %}">Close: screening failed (failure to find EIC)</a></li>
+	{% endif %}
+      </ul>
+    </div>
+  {% endif %}
 
   <h3 class="highlight">Current invitations</h3>
   <table class="submission" id="current-status">
@@ -126,7 +132,7 @@
           </td>
           <td>
             {{ assignment.date_invited|default:'<i>Not invited (yet)</i>' }}
-            {% if assignment.status == 'preassigned' %}
+            {% if is_ed_admin and assignment.status == 'preassigned' %}
               <br>
               <a href="{% url 'submissions:send_editorial_assignment_invitation' submission.preprint.identifier_w_vn_nr assignment.id %}">Send invitation now</a>
             {% endif %}
diff --git a/scipost_django/submissions/templates/submissions/pool/_hx_submission_details.html b/scipost_django/submissions/templates/submissions/pool/_hx_submission_details.html
index 2dbc9ae1e..28fb72c72 100644
--- a/scipost_django/submissions/templates/submissions/pool/_hx_submission_details.html
+++ b/scipost_django/submissions/templates/submissions/pool/_hx_submission_details.html
@@ -60,11 +60,17 @@
       <div class="border border-danger mt-3 p-2">
 	<h3>Editorial Administration</h3>
 	<ul class="ps-4 mb-3">
-	  <li><a href="{% url 'submissions:do_prescreening' submission.preprint.identifier_w_vn_nr %}">Pre-screening</a></li>
+	  <li>
+	    {% if submission.in_prescreening %}
+	      <a href="{% url 'submissions:do_prescreening' submission.preprint.identifier_w_vn_nr %}">Pre-screening</a>
+	    {% else %}
+	      Pre-screening completed
+	    {% endif %}
+	  </li>
 
           {# EIC Assignments #}
           {% if perms.scipost.can_assign_submissions %}
-            <li>Screening:
+            <li>Screening: invitations to take charge
               <ul class="ps-3">
 		{% if not submission.editor_in_charge %}
 		  <li>
@@ -140,13 +146,13 @@
       <ul class="ps-3">
         {% for rec in submission.eicrecommendations.all %}
 	  <li>
-	    {{ rec.get_full_status_display }}
+	    {{ rec.get_full_status_display }}&emsp;
 	    {% if rec.undergoing_voting %}
 	      {% if rec|user_can_vote:request.user %}
-		&emsp;<a href="{% url 'submissions:vote_on_rec' rec_id=rec.id %}">
+		<a href="{% url 'submissions:vote_on_rec' rec_id=rec.id %}">
 		See Recommendation, view votes and/or revise your vote
 		</a>
-	      {% else %}
+	      {% elif not is_ed_admin %}
 		<div id="rights-{{ rec.id }}">
 		  <button type="button" class="btn btn-outline-danger px-1 py-0"
 			  hx-get="{% url 'submissions:claim_voting_right' rec_id=rec.id %}"
@@ -155,10 +161,12 @@
 		    <em><small>only if you can certify that you have no conflict of interest</small></em>
 		  </button>
 		</div>
+	      {% else %}
+		<a href="{% url 'submissions:eic_recommendation_detail' identifier_w_vn_nr=submission.preprint.identifier_w_vn_nr %}">See Recommendation</a>
 	      {% endif %}
 	    {% elif rec.decision_fixed %}
-	      {% if rec|user_can_vote:request.user %}
-		&emsp;<a href="{% url 'submissions:eic_recommendation_detail' identifier_w_vn_nr=rec.submission.preprint.identifier_w_vn_nr %}">
+	      {% if is_ed_admin or rec|user_can_vote:request.user %}
+		<a href="{% url 'submissions:eic_recommendation_detail' identifier_w_vn_nr=rec.submission.preprint.identifier_w_vn_nr %}">
 		See Recommendation
 		</a>
 	      {% endif %}
diff --git a/scipost_django/submissions/templates/submissions/pool/_hx_submission_li.html b/scipost_django/submissions/templates/submissions/pool/_hx_submission_li.html
index a8f113b25..5d7555798 100644
--- a/scipost_django/submissions/templates/submissions/pool/_hx_submission_li.html
+++ b/scipost_django/submissions/templates/submissions/pool/_hx_submission_li.html
@@ -4,16 +4,9 @@
 
 {% is_ed_admin request.user as is_ed_admin %}
 
-<div class="icons">
-  {% include 'submissions/pool/_submission_tooltip.html' with submission=submission %}
-
-  {% if submission.status == 'unassigned' %}
-    <span class="mt-1 px-1 text-danger" data-bs-toggle="tooltip" data-bs-html="true" title="You can volunteer to become Editor-in-charge">{% include 'bi/exclamation-circle-fill.html' %}</span>
-  {% endif %}
-</div>
 
 <div class="pool-item">
-  <div class="row mb-2">
+  <div class="row">
     <div class="col-md-7">
       <a href="{% url 'submissions:submission' submission.preprint.identifier_w_vn_nr %}">{{ submission.title }}</a>
       <br>
@@ -37,14 +30,27 @@
     <div class="col-md-3">
       <small class="text-muted">Editor-in-charge</small>
       <br>
-      {% if submission.status == 'unassigned' %}
-        <span class="card-text text-danger">You can volunteer to become Editor-in-charge by <a href="{% url 'submissions:editorial_assignment' submission.preprint.identifier_w_vn_nr %}">clicking here</a>.</span>
-      {% elif submission.editor_in_charge == request.user.contributor %}
-        <strong>You are the EIC</strong>
-        <a role="button" class="btn btn-info px-1 py-0" href="{% url 'submissions:editorial_page' submission.preprint.identifier_w_vn_nr %}"><small>{% include 'bi/arrow-right.html' %} Editorial&nbsp;page</small></a>
-      {% else %}
-        {{ submission.editor_in_charge }}
-      {% endif %}
+      <ul class="list list-unstyled">
+	{% if submission.status == 'unassigned' %}
+	  {% if is_ed_admin %}
+	    <li>Unassigned</li>
+	  {% else %}
+            <li>You can
+	      <a href="{% url 'submissions:editorial_assignment' submission.preprint.identifier_w_vn_nr %}"><strong class="text-danger">volunteer to become Editor-in-charge</strong></a>
+	    </li>
+	  {% endif %}
+	  {% if request.user.contributor.is_active_senior_fellow %}
+	    <li>As Senior Fellow: <a href="{% url 'submissions:editor_invitations' submission.preprint.identifier_w_vn_nr %}"><strong class="text-danger">view/update editor invitations</strong></a></li>
+	  {% endif %}
+	{% elif submission.editor_in_charge == request.user.contributor %}
+          <li>
+	    <strong>You are the EIC</strong>
+            <a role="button" class="btn btn-info px-1 py-0" href="{% url 'submissions:editorial_page' submission.preprint.identifier_w_vn_nr %}"><small>{% include 'bi/arrow-right.html' %} Editorial&nbsp;page</small></a>
+	  </li>
+	{% else %}
+          <li>{{ submission.editor_in_charge }}</li>
+	{% endif %}
+      </ul>
     </div>
     <div class="col-md-3">
       <small class="text-muted">Original submission date</small>
@@ -102,8 +108,8 @@
     {% endif %}
   {% endif %}
 
-  <div id="details_{{ submission.id }}">
-    <button type="button" class="btn btn-primary p-1"
+  <div id="details_{{ submission.id }}" class="mt-2">
+    <button type="button" class="btn btn-primary p-1 mx-auto"
 	    hx-get="{% url 'submissions:pool_hx_submission_details' submission.preprint.identifier_w_vn_nr %}"
 	    hx-target="#details_{{ submission.id }}"
 	    hx-indicator="#indicator-details-{{ submission.id }}"
diff --git a/scipost_django/submissions/templates/submissions/pool/_submission_info_table.html b/scipost_django/submissions/templates/submissions/pool/_submission_info_table.html
index 3c4510f0e..e5f8016c0 100644
--- a/scipost_django/submissions/templates/submissions/pool/_submission_info_table.html
+++ b/scipost_django/submissions/templates/submissions/pool/_submission_info_table.html
@@ -44,13 +44,27 @@
   <tr>
     <td>Editor-in-charge</td>
     <td>
-      {% if submission.editor_in_charge %}
-        {{ submission.editor_in_charge }}
-      {% elif perms.scipost.can_assign_submissions %}
-        <a href="{% url 'submissions:assign_submission' submission.preprint.identifier_w_vn_nr %}">Send a new assignment request</a>
-      {% else %}
-        <strong class="text-danger">You can volunteer to become Editor-in-charge by <a href="{% url 'submissions:editorial_assignment' submission.preprint.identifier_w_vn_nr %}">clicking here</a>.</strong>
-      {% endif %}
+      <ul class="list list-unstyled">
+	{% if submission.status == 'unassigned' %}
+	  {% if is_ed_admin %}
+	    <li>Unassigned</li>
+	  {% else %}
+            <li>You can
+	      <a href="{% url 'submissions:editorial_assignment' submission.preprint.identifier_w_vn_nr %}"><strong class="text-danger">volunteer to become Editor-in-charge</strong></a>
+	    </li>
+	  {% endif %}
+	  {% if request.user.contributor.is_active_senior_fellow %}
+	    <li>As Senior Fellow: <a href="{% url 'submissions:editor_invitations' submission.preprint.identifier_w_vn_nr %}"><strong class="text-danger">view/update editor invitations</strong></a></li>
+	  {% endif %}
+	{% elif submission.editor_in_charge == request.user.contributor %}
+          <li>
+	    <strong>You are the EIC</strong>
+            <a role="button" class="btn btn-info px-1 py-0" href="{% url 'submissions:editorial_page' submission.preprint.identifier_w_vn_nr %}"><small>{% include 'bi/arrow-right.html' %} Editorial&nbsp;page</small></a>
+	  </li>
+	{% else %}
+          <li>{{ submission.editor_in_charge }}</li>
+	{% endif %}
+      </ul>
     </td>
   </tr>
   <tr>
diff --git a/scipost_django/submissions/templates/submissions/pool/hx_submissions_list.html b/scipost_django/submissions/templates/submissions/pool/hx_submissions_list.html
index 39044b760..72741e68b 100644
--- a/scipost_django/submissions/templates/submissions/pool/hx_submissions_list.html
+++ b/scipost_django/submissions/templates/submissions/pool/hx_submissions_list.html
@@ -1,5 +1,5 @@
 {% for submission in page_obj %}
-  <li class="submission py-2" id="submission_{{ submission.id }}">
+  <li class="submission p-2 mb-2" id="submission_{{ submission.id }}">
     {% include 'submissions/pool/_hx_submission_li.html' with submission=submission %}
   </li>
 {% empty %}
diff --git a/scipost_django/submissions/views.py b/scipost_django/submissions/views.py
index fa943a2c2..cfd294b56 100644
--- a/scipost_django/submissions/views.py
+++ b/scipost_django/submissions/views.py
@@ -8,7 +8,7 @@ import feedparser
 import strings
 
 from django.contrib import messages
-from django.contrib.auth.decorators import login_required, permission_required
+from django.contrib.auth.decorators import user_passes_test, login_required, permission_required
 from django.contrib.auth.mixins import (
     LoginRequiredMixin, PermissionRequiredMixin, UserPassesTestMixin)
 from django.contrib.messages.views import SuccessMessageMixin
@@ -59,9 +59,10 @@ from .forms import (
     EditorialDecisionForm,
     SubmissionPrescreeningForm,
     PreassignEditorsFormSet, SubmissionReassignmentForm)
+from .permissions import is_edadmin_or_senior_fellow
 from .utils import SubmissionUtils
 
-from colleges.models import PotentialFellowship
+from colleges.models import PotentialFellowship, Fellowship
 from colleges.permissions import fellowship_required, fellowship_or_admin_required
 from comments.forms import CommentForm
 from common.helpers import get_new_secrets_key
@@ -2059,12 +2060,14 @@ def remind_Fellows_to_vote(request, rec_id):
     return render(request, 'scipost/acknowledgement.html', context)
 
 
-@permission_required('scipost.can_run_pre_screening', raise_exception=True)
+@login_required
+@user_passes_test(is_edadmin_or_senior_fellow)
 def editor_invitations(request, identifier_w_vn_nr):
-    """Update/show invitations of editors for incoming Submission."""
+    """
+    Update/show invitations of editors for incoming Submission.
+    """
     submission = get_object_or_404(
         Submission.objects.without_eic(), preprint__identifier_w_vn_nr=identifier_w_vn_nr)
-
     assignments = submission.editorial_assignments.order_by('invitation_order')
     context = {
         'submission': submission,
-- 
GitLab