From feeb646d37664da2c3c0ffe350d32771e91c0e75 Mon Sep 17 00:00:00 2001
From: George Katsikas <giorgakis.katsikas@gmail.com>
Date: Tue, 13 Aug 2024 16:39:07 +0200
Subject: [PATCH] warn of unvetted objects in earlier editorial page

---
 .../submissions/managers/submission.py        | 23 +++++++++++++++++++
 .../submissions/pool/editorial_page.html      | 20 ++++++++++++++--
 2 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/scipost_django/submissions/managers/submission.py b/scipost_django/submissions/managers/submission.py
index 5c26f03fe..89733fb80 100644
--- a/scipost_django/submissions/managers/submission.py
+++ b/scipost_django/submissions/managers/submission.py
@@ -5,8 +5,11 @@ __license__ = "AGPL v3"
 import datetime
 
 from django.db import models
+from django.db.models import Q
 from django.utils import timezone
 
+from comments.models import Comment
+
 from .. import constants
 
 from typing import TYPE_CHECKING
@@ -397,6 +400,26 @@ class SubmissionQuerySet(models.QuerySet):
             .exclude(has_qualification=True, has_readiness=True, has_clearance=True)
         )
 
+    def comments_set_complete(self):
+        """Return Comments on Submissions, Reports and other Comments."""
+        qs = Comment.objects.filter(
+            Q(submissions__in=self)
+            | Q(reports__submission__in=self)
+            | Q(comments__reports__submission__in=self)
+            | Q(comments__submissions__in=self)
+        )
+        # Add recursive comments:
+        for c in qs:
+            if c.nested_comments:
+                qs = qs | c.all_nested_comments().all()
+        return qs.distinct()
+
+    def reports(self):
+        """Return all Reports for Submissions."""
+        from submissions.models import Report
+
+        return Report.objects.filter(submission__in=self)
+
 
 class SubmissionEventQuerySet(models.QuerySet):
     def for_edadmin(self):
diff --git a/scipost_django/submissions/templates/submissions/pool/editorial_page.html b/scipost_django/submissions/templates/submissions/pool/editorial_page.html
index 9840c7fc2..d8ac0f299 100644
--- a/scipost_django/submissions/templates/submissions/pool/editorial_page.html
+++ b/scipost_django/submissions/templates/submissions/pool/editorial_page.html
@@ -373,7 +373,15 @@ container border border-warning border-3
               </ul>
             </li>
           {% else %}
-            <li>All Reports have been vetted.</li>
+            {% with submission.other_versions.reports.awaiting_vetting as other_reports %}
+              <li>All Reports on this version have been vetted.
+                {% if other_reports %}
+                  <span class="text-warning ms-1">{% include "bi/exclamation-triangle-fill.html" %}</span>
+                  There {{ other_reports|pluralize:"is,are" }} still {{ other_reports.count }} 
+                  Report{{ other_reports|pluralize }} awaiting vetting on other versions.
+                {% endif %}
+              </li>
+            {% endwith %}
           {% endif %}
         {% endwith %}
 
@@ -388,7 +396,15 @@ container border border-warning border-3
               </ul>
             </li>
           {% else %}
-            <li>All Comments have been vetted.</li>
+            {% with submission.other_versions.comments_set_complete.awaiting_vetting as other_comments %}
+              <li>All Comments on this version have been vetted.
+                {% if other_comments %}
+                  <span class="text-warning ms-1">{% include "bi/exclamation-triangle-fill.html" %}</span>
+                  There {{ other_comments|pluralize:"is,are" }} still {{ other_comments.count }} 
+                  Comment{{ other_comments|pluralize }} awaiting vetting on other versions.
+                {% endif %}
+              </li>
+            {% endwith %}
           {% endif %}
         {% endwith %}
         {% if submission.eic_recommendation_required %}
-- 
GitLab