mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +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 %}
|
||||
|
||||
{% 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/">
|
||||
{% trans "Manage Spam" %}
|
||||
<span class="fa fa-external-link"></span>
|
||||
|
||||
@ -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())),
|
||||
|
||||
@ -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'
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user