mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +00:00
email_server: Merge domain configuration with app view
Test: - Submit the domain form unchanged. Message is printed that settings are unchanged. - Submit the domain form with changes. Message is printed that domain has been updated. Configuration reflects the new domain. - On page load, the current domain is shown in the domain configuration form. - Clicking the repair button the service alert section triggers the repair operations as seen in the console. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
ae882fea70
commit
4d73d7eb7f
@ -11,10 +11,6 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block subsubmenu %}
|
{% block subsubmenu %}
|
||||||
<a class="btn btn-default" role="button"
|
|
||||||
href="{% url 'email_server:domains' %}">
|
|
||||||
{% trans "Domains" %}
|
|
||||||
</a>
|
|
||||||
<a class="btn btn-default" role="button" href="/rspamd/">
|
<a class="btn btn-default" role="button" href="/rspamd/">
|
||||||
{% trans "Manage Spam" %}
|
{% trans "Manage Spam" %}
|
||||||
<span class="fa fa-external-link"></span>
|
<span class="fa fa-external-link"></span>
|
||||||
|
|||||||
@ -8,8 +8,6 @@ from . import views
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('apps/email_server/', views.EmailServerView.as_view(), name='index'),
|
path('apps/email_server/', views.EmailServerView.as_view(), name='index'),
|
||||||
path('apps/email_server/domains', views.DomainsView.as_view(),
|
|
||||||
name='domains'),
|
|
||||||
path('apps/email_server/my_aliases',
|
path('apps/email_server/my_aliases',
|
||||||
non_admin_view(views.AliasView.as_view()), name='aliases'),
|
non_admin_view(views.AliasView.as_view()), name='aliases'),
|
||||||
path('apps/email_server/config.xml', public(views.XmlView.as_view())),
|
path('apps/email_server/config.xml', public(views.XmlView.as_view())),
|
||||||
|
|||||||
@ -44,16 +44,25 @@ class ExceptionsMixin(View):
|
|||||||
class EmailServerView(ExceptionsMixin, AppView):
|
class EmailServerView(ExceptionsMixin, AppView):
|
||||||
"""Server configuration page"""
|
"""Server configuration page"""
|
||||||
app_id = 'email_server'
|
app_id = 'email_server'
|
||||||
|
form_class = forms.DomainForm
|
||||||
template_name = 'email_server.html'
|
template_name = 'email_server.html'
|
||||||
audit_modules = ('tls', 'rcube')
|
audit_modules = ('tls', 'rcube')
|
||||||
|
|
||||||
|
def get_initial(self):
|
||||||
|
"""Return the initial values to populate in the form."""
|
||||||
|
initial = super().get_initial()
|
||||||
|
domains = audit.domain.get_domains()
|
||||||
|
initial['primary_domain'] = domains['primary_domain']
|
||||||
|
return initial
|
||||||
|
|
||||||
def get_context_data(self, *args, **kwargs):
|
def get_context_data(self, *args, **kwargs):
|
||||||
|
context = super().get_context_data(*args, **kwargs)
|
||||||
|
|
||||||
dlist = []
|
dlist = []
|
||||||
for module_name in self.audit_modules:
|
for module_name in self.audit_modules:
|
||||||
self._get_audit_results(module_name, dlist)
|
self._get_audit_results(module_name, dlist)
|
||||||
dlist.sort(key=audit.models.Diagnosis.sorting_key)
|
dlist.sort(key=audit.models.Diagnosis.sorting_key)
|
||||||
|
|
||||||
context = super().get_context_data(*args, **kwargs)
|
|
||||||
context['related_diagnostics'] = dlist
|
context['related_diagnostics'] = dlist
|
||||||
return context
|
return context
|
||||||
|
|
||||||
@ -75,6 +84,7 @@ class EmailServerView(ExceptionsMixin, AppView):
|
|||||||
|
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
repair_field = request.POST.get('repair')
|
repair_field = request.POST.get('repair')
|
||||||
|
if repair_field:
|
||||||
module_name, sep, action_name = repair_field.partition('.')
|
module_name, sep, action_name = repair_field.partition('.')
|
||||||
if not sep or module_name not in self.audit_modules:
|
if not sep or module_name not in self.audit_modules:
|
||||||
return HttpResponseBadRequest('Bad post data')
|
return HttpResponseBadRequest('Bad post data')
|
||||||
@ -82,6 +92,22 @@ class EmailServerView(ExceptionsMixin, AppView):
|
|||||||
self._repair(module_name, action_name)
|
self._repair(module_name, action_name)
|
||||||
return redirect(request.path)
|
return redirect(request.path)
|
||||||
|
|
||||||
|
return super().post(request)
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
"""Update the settings for changed domain values."""
|
||||||
|
old_data = form.initial
|
||||||
|
new_data = form.cleaned_data
|
||||||
|
if old_data['primary_domain'] != new_data['primary_domain']:
|
||||||
|
try:
|
||||||
|
audit.domain.set_domains(new_data['primary_domain'])
|
||||||
|
messages.success(self.request, _('Configuration updated'))
|
||||||
|
except Exception:
|
||||||
|
messages.success(self.request,
|
||||||
|
_('An error occurred during configuration.'))
|
||||||
|
|
||||||
|
return super().form_valid(form)
|
||||||
|
|
||||||
def _repair(self, module_name, action_name):
|
def _repair(self, module_name, action_name):
|
||||||
"""Repair the configuration of the given audit module."""
|
"""Repair the configuration of the given audit module."""
|
||||||
module = getattr(audit, module_name)
|
module = getattr(audit, module_name)
|
||||||
@ -180,43 +206,6 @@ class AliasView(FormView):
|
|||||||
aliases_module.put(username, form.cleaned_data['alias'])
|
aliases_module.put(username, form.cleaned_data['alias'])
|
||||||
|
|
||||||
|
|
||||||
class DomainsView(FormView):
|
|
||||||
"""View to allow editing domain related settings."""
|
|
||||||
template_name = 'form.html'
|
|
||||||
form_class = forms.DomainForm
|
|
||||||
prefix = 'domain'
|
|
||||||
success_url = reverse_lazy('email_server:domains')
|
|
||||||
|
|
||||||
def get_initial(self):
|
|
||||||
"""Return the initial values to populate in the form."""
|
|
||||||
initial = super().get_initial()
|
|
||||||
domains = audit.domain.get_domains()
|
|
||||||
initial['primary_domain'] = domains['primary_domain']
|
|
||||||
return initial
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
|
||||||
"""Add the title to the document."""
|
|
||||||
context = super().get_context_data(**kwargs)
|
|
||||||
context['title'] = _('Domains')
|
|
||||||
return context
|
|
||||||
|
|
||||||
def form_valid(self, form):
|
|
||||||
"""Update the settings for changed domain values."""
|
|
||||||
old_data = form.initial
|
|
||||||
new_data = form.cleaned_data
|
|
||||||
if old_data['primary_domain'] != new_data['primary_domain']:
|
|
||||||
try:
|
|
||||||
audit.domain.set_domains(new_data['primary_domain'])
|
|
||||||
messages.success(self.request, _('Configuration updated'))
|
|
||||||
except Exception:
|
|
||||||
messages.success(self.request,
|
|
||||||
_('An error occurred during configuration.'))
|
|
||||||
else:
|
|
||||||
messages.info(self.request, _('Setting unchanged'))
|
|
||||||
|
|
||||||
return super().form_valid(form)
|
|
||||||
|
|
||||||
|
|
||||||
class XmlView(TemplateView):
|
class XmlView(TemplateView):
|
||||||
template_name = 'email_autoconfig.xml'
|
template_name = 'email_autoconfig.xml'
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user