From abf77b8263d462d7eb23da136078e038dd926be6 Mon Sep 17 00:00:00 2001
From: Jonathan Weth <git@jonathanweth.de>
Date: Sat, 14 Nov 2020 18:08:49 +0100
Subject: [PATCH] Show registered data checks in list view

---
 .../core/templates/core/data_check/list.html  | 100 +++++++++++-------
 aleksis/core/views.py                         |   9 +-
 2 files changed, 70 insertions(+), 39 deletions(-)

diff --git a/aleksis/core/templates/core/data_check/list.html b/aleksis/core/templates/core/data_check/list.html
index e1d763f5c..c528a4320 100644
--- a/aleksis/core/templates/core/data_check/list.html
+++ b/aleksis/core/templates/core/data_check/list.html
@@ -35,42 +35,68 @@
   {% endif %}
 
   {% if results %}
-    <table>
-      <thead>
-      <tr>
-        <th></th>
-        <th colspan="2">{% trans "Affected object" %}</th>
-        <th>{% trans "Detected problem" %}</th>
-        <th>{% trans "Show details" %}</th>
-        <th>{% trans "Options to solve the problem" %}</th>
-      </tr>
-      </thead>
-      <tbody>
-      {% for result in results %}
-        <tr>
-          <td>
-            <code>{{ result.id }}</code>
-          </td>
-          <td>{% verbose_name_object result.related_object %}</td>
-          <td>{{ result.related_object }}</td>
-
-
-          <td>{{ result.related_check.problem_name }}</td>
-          <td>
-            <a class="btn-flat waves-effect waves-light" href="{{ result.related_object.get_absolute_url }}">
-              {% trans "Show object" %}
-            </a>
-          </td>
-          <td>
-            {% for option_name, option in result.related_check.solve_options.items %}
-              <a class="btn waves-effect waves-light" href="{% url "data_check_solve" result.pk option_name %}">
-                {{ option.verbose_name }}
-              </a>
-            {% endfor %}
-          </td>
-        </tr>
-      {% endfor %}
-      </tbody>
-    </table>
+    <div class="card">
+      <div class="card-content">
+        <div class="card-title">{% trans "Detected problems" %}</div>
+        <table>
+          <thead>
+          <tr>
+            <th></th>
+            <th colspan="2">{% trans "Affected object" %}</th>
+            <th>{% trans "Detected problem" %}</th>
+            <th>{% trans "Show details" %}</th>
+            <th>{% trans "Options to solve the problem" %}</th>
+          </tr>
+          </thead>
+          <tbody>
+          {% for result in results %}
+            <tr>
+              <td>
+                <code>{{ result.id }}</code>
+              </td>
+              <td>{% verbose_name_object result.related_object %}</td>
+              <td>{{ result.related_object }}</td>
+              <td>{{ result.related_check.problem_name }}</td>
+              <td>
+                <a class="btn-flat waves-effect waves-light" href="{{ result.related_object.get_absolute_url }}">
+                  {% trans "Show object" %}
+                </a>
+              </td>
+              <td>
+                {% for option_name, option in result.related_check.solve_options.items %}
+                  <a class="btn waves-effect waves-light" href="{% url "data_check_solve" result.pk option_name %}">
+                    {{ option.verbose_name }}
+                  </a>
+                {% endfor %}
+              </td>
+            </tr>
+          {% endfor %}
+          </tbody>
+        </table>
+      </div>
+    </div>
   {% endif %}
+  </div>
+
+  <div class="card hundred-percent">
+    <div class="card-content">
+      <div class="card-title">{% trans "Registered checks" %}</div>
+      <div class="alert primary">
+        <div>
+          <i class="material-icons left">info</i>
+          {% blocktrans %}
+            The system will check for the following problems:
+          {% endblocktrans %}
+        </div>
+      </div>
+      <ul class="collection">
+        {% for check in registered_checks %}
+          <li class="collection-item">
+            <i class="material-icons left">check</i>
+            {{ check.verbose_name }}
+          </li>
+        {% endfor %}
+      </ul>
+    </div>
+  </div>
 {% endblock %}
diff --git a/aleksis/core/views.py b/aleksis/core/views.py
index a0b1a14d0..afd81df6f 100644
--- a/aleksis/core/views.py
+++ b/aleksis/core/views.py
@@ -1,4 +1,4 @@
-from typing import Optional
+from typing import Any, Dict, Optional
 
 from django.apps import apps
 from django.conf import settings
@@ -21,7 +21,7 @@ from haystack.views import SearchView
 from health_check.views import MainView
 from rules.contrib.views import PermissionRequiredMixin, permission_required
 
-from aleksis.core.data_checks import check_data
+from aleksis.core.data_checks import DATA_CHECK_REGISTRY, check_data
 
 from .filters import GroupFilter, PersonFilter
 from .forms import (
@@ -696,6 +696,11 @@ class DataCheckView(ListView):
     def get_queryset(self) -> QuerySet:
         return DataCheckResult.objects.filter(solved=False).order_by("check")
 
+    def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:
+        context = super().get_context_data(**kwargs)
+        context["registered_checks"] = DATA_CHECK_REGISTRY.data_checks
+        return context
+
 
 def run_data_checks(request: HttpRequest) -> HttpResponse:
     check_data()
-- 
GitLab