diff --git a/plinth/modules/diagnostics/__init__.py b/plinth/modules/diagnostics/__init__.py
index 13fed1628..f763b239c 100644
--- a/plinth/modules/diagnostics/__init__.py
+++ b/plinth/modules/diagnostics/__init__.py
@@ -128,7 +128,7 @@ def _run_on_all_enabled_modules():
app_results = {
'diagnosis': [],
'exception': None,
- 'show_rerun_setup': False,
+ 'show_repair': False,
}
try:
@@ -140,7 +140,7 @@ def _run_on_all_enabled_modules():
for check in app_results['diagnosis']:
if check.result in [Result.FAILED, Result.WARNING]:
- app_results['show_rerun_setup'] = True
+ app_results['show_repair'] = True
break
with results_lock:
diff --git a/plinth/modules/diagnostics/templates/diagnostics_app.html b/plinth/modules/diagnostics/templates/diagnostics_app.html
index ba2eb77e7..70d06526c 100644
--- a/plinth/modules/diagnostics/templates/diagnostics_app.html
+++ b/plinth/modules/diagnostics/templates/diagnostics_app.html
@@ -12,12 +12,12 @@
{% blocktrans %}App: {{ app_name }}{% endblocktrans %}
- {% if show_rerun_setup %}
-
{% endif %}
diff --git a/plinth/modules/diagnostics/templates/diagnostics_full.html b/plinth/modules/diagnostics/templates/diagnostics_full.html
index 836abd505..a71a6ca57 100644
--- a/plinth/modules/diagnostics/templates/diagnostics_full.html
+++ b/plinth/modules/diagnostics/templates/diagnostics_full.html
@@ -40,12 +40,12 @@
{% endblocktrans %}
- {% if app_data.show_rerun_setup %}
-
{% endif %}
diff --git a/plinth/modules/diagnostics/urls.py b/plinth/modules/diagnostics/urls.py
index 215e5d070..b89e831a0 100644
--- a/plinth/modules/diagnostics/urls.py
+++ b/plinth/modules/diagnostics/urls.py
@@ -14,4 +14,6 @@ urlpatterns = [
name='full'),
re_path(r'^sys/diagnostics/(?P[1-9a-z\-_]+)/$', views.diagnose_app,
name='app'),
+ re_path(r'^sys/diagnostics/repair/(?P[1-9a-z\-_]+)/$',
+ views.repair, name='repair'),
]
diff --git a/plinth/modules/diagnostics/views.py b/plinth/modules/diagnostics/views.py
index 6102db56e..8c8648ac2 100644
--- a/plinth/modules/diagnostics/views.py
+++ b/plinth/modules/diagnostics/views.py
@@ -7,7 +7,9 @@ import logging
from django.contrib import messages
from django.http import Http404
+from django.shortcuts import redirect
from django.template.response import TemplateResponse
+from django.urls import NoReverseMatch, reverse
from django.utils.translation import gettext_lazy as _
from django.views.decorators.http import require_POST
from django.views.generic import TemplateView
@@ -16,6 +18,7 @@ from plinth import operation
from plinth.app import App
from plinth.diagnostic_check import Result
from plinth.modules import diagnostics
+from plinth.setup import run_repair_on_app
from plinth.views import AppView
from .forms import ConfigureForm
@@ -100,10 +103,10 @@ def diagnose_app(request, app_id):
exception)
diagnosis_exception = str(exception)
- show_rerun_setup = False
+ show_repair = False
for check in diagnosis:
if check.result in [Result.FAILED, Result.WARNING]:
- show_rerun_setup = True
+ show_repair = True
break
return TemplateResponse(
@@ -113,5 +116,34 @@ def diagnose_app(request, app_id):
'app_name': app_name,
'results': diagnosis,
'exception': diagnosis_exception,
- 'show_rerun_setup': show_rerun_setup,
+ 'show_repair': show_repair,
})
+
+
+@require_POST
+def repair(request, app_id):
+ """Try to repair failed diagnostics on an app.
+
+ Allows apps and components to customize the repair method. Re-run setup is
+ the default if not specified.
+ """
+ try:
+ app = App.get(app_id)
+ except KeyError:
+ raise Http404('App does not exist')
+
+ try:
+ finish_url = reverse(f'{app_id}:index')
+ except NoReverseMatch:
+ # for apps like apache that don't have an index route
+ finish_url = reverse('diagnostics:index')
+
+ current_version = app.get_setup_version()
+ if not current_version:
+ logger.warning('App %s is not installed, cannot repair', app_id)
+ message = _('App {app_id} is not installed, cannot repair')
+ messages.error(request, str(message).format(app_id=app_id))
+ return redirect(finish_url)
+
+ run_repair_on_app(app_id)
+ return redirect(finish_url)