diff --git a/plinth/modules/email_server/templates/email_server.html b/plinth/modules/email_server/templates/email_server.html
index 9635bbca3..c963e1cff 100644
--- a/plinth/modules/email_server/templates/email_server.html
+++ b/plinth/modules/email_server/templates/email_server.html
@@ -11,10 +11,6 @@
{% endblock %}
{% block subsubmenu %}
-
- {% trans "Domains" %}
-
{% trans "Manage Spam" %}
diff --git a/plinth/modules/email_server/urls.py b/plinth/modules/email_server/urls.py
index 2109efd42..cd56f03c8 100644
--- a/plinth/modules/email_server/urls.py
+++ b/plinth/modules/email_server/urls.py
@@ -8,8 +8,6 @@ from . import views
urlpatterns = [
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',
non_admin_view(views.AliasView.as_view()), name='aliases'),
path('apps/email_server/config.xml', public(views.XmlView.as_view())),
diff --git a/plinth/modules/email_server/views.py b/plinth/modules/email_server/views.py
index daa799c01..f1ad566c6 100644
--- a/plinth/modules/email_server/views.py
+++ b/plinth/modules/email_server/views.py
@@ -44,16 +44,25 @@ class ExceptionsMixin(View):
class EmailServerView(ExceptionsMixin, AppView):
"""Server configuration page"""
app_id = 'email_server'
+ form_class = forms.DomainForm
template_name = 'email_server.html'
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):
+ context = super().get_context_data(*args, **kwargs)
+
dlist = []
for module_name in self.audit_modules:
self._get_audit_results(module_name, dlist)
dlist.sort(key=audit.models.Diagnosis.sorting_key)
- context = super().get_context_data(*args, **kwargs)
context['related_diagnostics'] = dlist
return context
@@ -75,12 +84,29 @@ class EmailServerView(ExceptionsMixin, AppView):
def post(self, request):
repair_field = request.POST.get('repair')
- module_name, sep, action_name = repair_field.partition('.')
- if not sep or module_name not in self.audit_modules:
- return HttpResponseBadRequest('Bad post data')
+ if repair_field:
+ module_name, sep, action_name = repair_field.partition('.')
+ if not sep or module_name not in self.audit_modules:
+ return HttpResponseBadRequest('Bad post data')
- self._repair(module_name, action_name)
- return redirect(request.path)
+ self._repair(module_name, action_name)
+ 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):
"""Repair the configuration of the given audit module."""
@@ -180,43 +206,6 @@ class AliasView(FormView):
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):
template_name = 'email_autoconfig.xml'