Increase coverage.

see #879
This commit is contained in:
Antoine Nguyen
2016-06-08 18:37:32 +02:00
parent 4db98c0739
commit f2c8736d02
5 changed files with 32 additions and 4 deletions
+10
View File
@@ -51,6 +51,16 @@ ADMIN_EVENTS = [
class AdminParametersForm(parameters.AdminParametersForm):
app = "admin"
dom_sep = SeparatorField(label=ugettext_lazy("Domains"))
enable_dnsbl_checks = YesNoField(
label=ugettext_lazy("Enable DNSBL checks"),
initial="yes",
help_text=ugettext_lazy(
"Check every domain against major DNSBL providers"
)
)
mbsep = SeparatorField(label=ugettext_lazy("Mailboxes"))
handle_mailboxes = YesNoField(
@@ -11,6 +11,7 @@ from django.core.management.base import BaseCommand
from modoboa.admin import constants
from modoboa.admin import models
from modoboa.lib import parameters
class CheckDNSBLCommand(BaseCommand):
@@ -58,6 +59,9 @@ class CheckDNSBLCommand(BaseCommand):
finally:
if address is not None:
ip_list.append(address)
print domain.name, ip_list
if len(ip_list) == 0:
return
if not hasattr(settings, "DNSBL_PROVIDERS"):
providers = constants.DNSBL_PROVIDERS
else:
@@ -78,5 +82,7 @@ class CheckDNSBLCommand(BaseCommand):
def handle(self, *args, **options):
"""Command entry point."""
if parameters.get_admin("ENABLE_DNSBL_CHECKS") == "no":
return
for domain in models.Domain.objects.filter(enabled=True):
self.check_domain(domain, options.get("timeout"))
+9 -2
View File
@@ -3,6 +3,7 @@
from django.db import models
from django.db.models.manager import Manager
from django.utils.encoding import python_2_unicode_compatible, smart_text
from django.utils.functional import cached_property
from django.utils.translation import ugettext as _, ugettext_lazy
from django.contrib.contenttypes.fields import GenericRelation
@@ -101,9 +102,15 @@ class Domain(AdminObject):
def aliases(self):
return self.domainalias_set
def is_in_dnsbl(self):
@cached_property
def dnsbl_status_color(self):
"""Shortcut to DNSBL results."""
return self.dnsblresult_set.blacklisted().exists()
if not self.dnsblresult_set.exists():
return "warning"
elif self.dnsblresult_set.blacklisted().exists():
return "danger"
else:
return "success"
def add_admin(self, account):
"""Add a new administrator to this domain.
@@ -3,7 +3,7 @@
{% load i18n %}
{% block modalbody %}
{% if domain.is_in_dnsbl %}
{% if domain.dnsbl_status_color == "danger" %}
<table class="table">
<thead>
<tr>
@@ -24,7 +24,12 @@
</tbody>
</table>
{% else %}
{% if domain.dnsbl_status_color == "success" %}
<div class="alert alert-success">
{% trans "Everything is fine, this domain is not listed." %}</div>
{% else %}
<div class="alert alert-warning">
{% trans "No information available for this domain." %}</div>
{% endif %}
{% endif %}
{% endblock %}
@@ -7,7 +7,7 @@
<td name="tags">{% render_tags domain.tags %}</td>
<td name="auth">
<small>
<a href="{% url 'admin:dnsbl_domain_detail' domain.pk %}" data-toggle="ajaxmodal"><span class="label label-mini label-{% if domain.is_in_dnsbl %}danger{% else %}success{% endif %}">DNSBL</span></a>
<span class="label label-mini label-{{ domain.dnsbl_status_color }}"><a href="{% url 'admin:dnsbl_domain_detail' domain.pk %}" data-toggle="ajaxmodal">DNSBL</a></span>
</small>
</td>
<td name="actions">{% domain_actions user domain %}</td>