mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +00:00
diagnostics: Change "Re-run setup" to "Try to repair"
Signed-off-by: James Valleroy <jvalleroy@mailbox.org> [sunil: Fix issue with formatting i18n message] Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
parent
35c2326261
commit
f5f687c8fd
@ -128,7 +128,7 @@ def _run_on_all_enabled_modules():
|
|||||||
app_results = {
|
app_results = {
|
||||||
'diagnosis': [],
|
'diagnosis': [],
|
||||||
'exception': None,
|
'exception': None,
|
||||||
'show_rerun_setup': False,
|
'show_repair': False,
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -140,7 +140,7 @@ def _run_on_all_enabled_modules():
|
|||||||
|
|
||||||
for check in app_results['diagnosis']:
|
for check in app_results['diagnosis']:
|
||||||
if check.result in [Result.FAILED, Result.WARNING]:
|
if check.result in [Result.FAILED, Result.WARNING]:
|
||||||
app_results['show_rerun_setup'] = True
|
app_results['show_repair'] = True
|
||||||
break
|
break
|
||||||
|
|
||||||
with results_lock:
|
with results_lock:
|
||||||
|
|||||||
@ -12,12 +12,12 @@
|
|||||||
<div class="row align-items-center justify-content-between">
|
<div class="row align-items-center justify-content-between">
|
||||||
<h3>{% blocktrans %}App: {{ app_name }}{% endblocktrans %}</h3>
|
<h3>{% blocktrans %}App: {{ app_name }}{% endblocktrans %}</h3>
|
||||||
|
|
||||||
{% if show_rerun_setup %}
|
{% if show_repair %}
|
||||||
<form class="form form-diagnostics-rerun-setup-button" method="post"
|
<form class="form form-diagnostics-repair-button" method="post"
|
||||||
action="{% url 'rerun-setup' app_id=app_id %}">
|
action="{% url 'diagnostics:repair' app_id=app_id %}">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input type="submit" class="btn btn-default"
|
<input type="submit" class="btn btn-default"
|
||||||
name="rerun-setup" value="{% trans "Re-run setup" %}"/>
|
name="repair" value="{% trans "Try to repair" %}"/>
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -40,12 +40,12 @@
|
|||||||
{% endblocktrans %}
|
{% endblocktrans %}
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
{% if app_data.show_rerun_setup %}
|
{% if app_data.show_repair %}
|
||||||
<form class="form form-diagnostics-rerun-setup-button" method="post"
|
<form class="form form-diagnostics-repair-button" method="post"
|
||||||
action="{% url 'rerun-setup' app_id=app_id %}">
|
action="{% url 'diagnostics:repair' app_id=app_id %}">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input type="submit" class="btn btn-default"
|
<input type="submit" class="btn btn-default"
|
||||||
name="rerun-setup" value="{% trans "Re-run setup" %}"/>
|
name="repair" value="{% trans "Try to repair" %}"/>
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -14,4 +14,6 @@ urlpatterns = [
|
|||||||
name='full'),
|
name='full'),
|
||||||
re_path(r'^sys/diagnostics/(?P<app_id>[1-9a-z\-_]+)/$', views.diagnose_app,
|
re_path(r'^sys/diagnostics/(?P<app_id>[1-9a-z\-_]+)/$', views.diagnose_app,
|
||||||
name='app'),
|
name='app'),
|
||||||
|
re_path(r'^sys/diagnostics/repair/(?P<app_id>[1-9a-z\-_]+)/$',
|
||||||
|
views.repair, name='repair'),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -7,7 +7,9 @@ import logging
|
|||||||
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
|
from django.shortcuts import redirect
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
|
from django.urls import NoReverseMatch, reverse
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.views.decorators.http import require_POST
|
from django.views.decorators.http import require_POST
|
||||||
from django.views.generic import TemplateView
|
from django.views.generic import TemplateView
|
||||||
@ -16,6 +18,7 @@ from plinth import operation
|
|||||||
from plinth.app import App
|
from plinth.app import App
|
||||||
from plinth.diagnostic_check import Result
|
from plinth.diagnostic_check import Result
|
||||||
from plinth.modules import diagnostics
|
from plinth.modules import diagnostics
|
||||||
|
from plinth.setup import run_repair_on_app
|
||||||
from plinth.views import AppView
|
from plinth.views import AppView
|
||||||
|
|
||||||
from .forms import ConfigureForm
|
from .forms import ConfigureForm
|
||||||
@ -100,10 +103,10 @@ def diagnose_app(request, app_id):
|
|||||||
exception)
|
exception)
|
||||||
diagnosis_exception = str(exception)
|
diagnosis_exception = str(exception)
|
||||||
|
|
||||||
show_rerun_setup = False
|
show_repair = False
|
||||||
for check in diagnosis:
|
for check in diagnosis:
|
||||||
if check.result in [Result.FAILED, Result.WARNING]:
|
if check.result in [Result.FAILED, Result.WARNING]:
|
||||||
show_rerun_setup = True
|
show_repair = True
|
||||||
break
|
break
|
||||||
|
|
||||||
return TemplateResponse(
|
return TemplateResponse(
|
||||||
@ -113,5 +116,34 @@ def diagnose_app(request, app_id):
|
|||||||
'app_name': app_name,
|
'app_name': app_name,
|
||||||
'results': diagnosis,
|
'results': diagnosis,
|
||||||
'exception': diagnosis_exception,
|
'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)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user