wip: Per-domain policy support

* The domain edition form was converted to a "TabsForm"
* New events added : "ExtraDomainForm" and "FillDomainInstances"
* Creation and modification of policies work

see #260
This commit is contained in:
Antoine Nguyen
2012-06-07 09:31:51 +02:00
parent 069f90a1bd
commit 4f9bc5ea27
10 changed files with 174 additions and 66 deletions
+29
View File
@@ -92,6 +92,17 @@ def menu(target, user):
]
return []
@events.observe("DeleteDomain")
def on_delete_domain(domain):
from models import Users
try:
u = Users.objects.get(email="@%s" % domain.name)
except Users.DoesNotExist:
return
u.policy.delete()
u.delete()
@events.observe("CreateMailbox")
def create_user_record(user, mailbox):
from models import Users
@@ -170,3 +181,21 @@ def display_requests(user):
return [tpl.render(Context(dict(
label=_("%d pending requests" % nbrequests), url=url, css=css
)))]
@events.observe("ExtraDomainForm")
def extra_domain_form(user, domain):
from forms import DomainPolicyForm
if not user.is_superuser and not user.belongs_to_group("Resellers"):
return []
return [
dict(
id="amavis", title=_("Amavis"), cls=DomainPolicyForm
)
]
@events.observe("FillDomainInstances")
def fill_domain_instances(user, domain, instances):
if not user.is_superuser and not user.belongs_to_group("Resellers"):
return
instances["amavis"] = domain
+46
View File
@@ -0,0 +1,46 @@
# coding: utf-8
from django import forms
from models import Policy, Users
class DomainPolicyForm(forms.ModelForm):
class Meta:
model = Policy
fields = ('bypass_virus_checks', 'bypass_spam_checks', 'spam_modifies_subj',
'spam_tag2_level', 'spam_kill_level')
widgets = {
'bypass_spam_checks' : forms.Select(attrs={'class' : 'span1'}),
'bypass_virus_checks' : forms.Select(attrs={'class' : 'span1'}),
'spam_modifies_subj' : forms.Select(attrs={'class' : 'span1'}),
'spam_tag2_level' : forms.TextInput(attrs={'class' : 'span1'}),
'spam_kill_level' : forms.TextInput(attrs={'class' : 'span1'}),
}
def __init__(self, *args, **kwargs):
if kwargs.has_key("instance"):
self.domain = kwargs["instance"]
try:
policy = Users.objects.get(email="@%s" % self.domain.name).policy
kwargs["instance"] = policy
except (Users.DoesNotExist, Policy.DoesNotExist), e:
del kwargs["instance"]
super(DomainPolicyForm, self).__init__(*args, **kwargs)
def save(self, commit=True):
p = super(DomainPolicyForm, self).save(commit=False)
if commit:
p.save()
print p.id
try:
u = Users.objects.get(policy__id=p.id)
except Users.DoesNotExist:
u = Users()
u.email = "@%s" % self.domain.name
u.fullname = self.domain.name
u.policy = p
u.local = "1"
u.priority = 7
u.save()
p.save()
return p
+22 -8
View File
@@ -10,6 +10,7 @@
# Original Amavis version : 2.6.2
from django.db import models
from django.utils.translation import ugettext as _, ugettext_lazy
class Maddr(models.Model):
partition_tag = models.IntegerField(unique=True, null=True, blank=True)
@@ -68,17 +69,26 @@ class Msgrcpt(models.Model):
unique_together = ("mail", "rid")
class Policy(models.Model):
id = models.IntegerField(primary_key=True)
id = models.AutoField(primary_key=True)
policy_name = models.CharField(max_length=96, blank=True)
virus_lover = models.CharField(max_length=3, blank=True)
spam_lover = models.CharField(max_length=3, blank=True)
banned_files_lover = models.CharField(max_length=3, blank=True)
bad_header_lover = models.CharField(max_length=3, blank=True)
bypass_virus_checks = models.CharField(max_length=3, blank=True)
bypass_spam_checks = models.CharField(max_length=3, blank=True)
bypass_virus_checks = models.CharField(
ugettext_lazy("Bypass virus checks"), max_length=3,
choices=(('Y', 'yes'), ('N', 'no')), blank=True
)
bypass_spam_checks = models.CharField(
ugettext_lazy("Bypass spam checks"), max_length=3,
choices=(('Y', 'yes'), ('N', 'no')), blank=True
)
bypass_banned_checks = models.CharField(max_length=3, blank=True)
bypass_header_checks = models.CharField(max_length=3, blank=True)
spam_modifies_subj = models.CharField(max_length=3, blank=True)
spam_modifies_subj = models.CharField(
ugettext_lazy("Modify spam subject"),
choices=(('Y', 'yes'), ('N', 'no')), max_length=3, blank=True
)
virus_quarantine_to = models.CharField(max_length=192, blank=True)
spam_quarantine_to = models.CharField(max_length=192, blank=True)
banned_quarantine_to = models.CharField(max_length=192, blank=True)
@@ -86,8 +96,12 @@ class Policy(models.Model):
clean_quarantine_to = models.CharField(max_length=192, blank=True)
other_quarantine_to = models.CharField(max_length=192, blank=True)
spam_tag_level = models.FloatField(null=True, blank=True)
spam_tag2_level = models.FloatField(null=True, blank=True)
spam_kill_level = models.FloatField(null=True, blank=True)
spam_tag2_level = models.FloatField(
ugettext_lazy("Spam tag2 level"), null=True, blank=True
)
spam_kill_level = models.FloatField(
ugettext_lazy("Spam kill level"), null=True, blank=True
)
spam_dsn_cutoff_level = models.FloatField(null=True, blank=True)
spam_quarantine_cutoff_level = models.FloatField(null=True, blank=True)
addr_extension_virus = models.CharField(max_length=192, blank=True)
@@ -122,9 +136,9 @@ class Quarantine(models.Model):
unique_together = ("mail", "chunk_ind")
class Users(models.Model):
id = models.IntegerField(primary_key=True)
id = models.AutoField(primary_key=True)
priority = models.IntegerField()
policy_id = models.IntegerField()
policy = models.ForeignKey(Policy)
email = models.CharField(unique=True, max_length=255)
fullname = models.CharField(max_length=765, blank=True)
local = models.CharField(max_length=3, blank=True)