mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-19 05:58:34 +02:00
wip: per-domain policies
* new settings added * yes/no settings are now displayed using radio buttons see #260
This commit is contained in:
@@ -186,16 +186,16 @@ def display_requests(user):
|
||||
def extra_domain_form(user, domain):
|
||||
from forms import DomainPolicyForm
|
||||
|
||||
if not user.is_superuser and not user.belongs_to_group("Resellers"):
|
||||
if not user.has_perm("admin.view_domains"):
|
||||
return []
|
||||
return [
|
||||
dict(
|
||||
id="amavis", title=_("Amavis"), cls=DomainPolicyForm
|
||||
id="amavis", title=_("Content filter"), cls=DomainPolicyForm
|
||||
)
|
||||
]
|
||||
|
||||
@events.observe("FillDomainInstances")
|
||||
def fill_domain_instances(user, domain, instances):
|
||||
if not user.is_superuser and not user.belongs_to_group("Resellers"):
|
||||
if not user.has_perm("admin.view_domains"):
|
||||
return
|
||||
instances["amavis"] = domain
|
||||
|
||||
@@ -2,17 +2,19 @@
|
||||
|
||||
from django import forms
|
||||
from models import Policy, Users
|
||||
from modoboa.lib.formutils import InlineRadioSelect
|
||||
|
||||
class DomainPolicyForm(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = Policy
|
||||
fields = ('bypass_virus_checks', 'bypass_spam_checks', 'spam_modifies_subj',
|
||||
'spam_tag2_level', 'spam_kill_level')
|
||||
fields = ('bypass_virus_checks', 'bypass_spam_checks',
|
||||
'spam_tag2_level', 'spam_modifies_subj',
|
||||
'spam_kill_level', 'bypass_banned_checks')
|
||||
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'}),
|
||||
'bypass_spam_checks' : InlineRadioSelect(),
|
||||
'bypass_virus_checks' : InlineRadioSelect(),
|
||||
'bypass_banned_checks' : InlineRadioSelect(),
|
||||
'spam_modifies_subj' : InlineRadioSelect(attrs={'class' : 'span1'}),
|
||||
'spam_tag2_level' : forms.TextInput(attrs={'class' : 'span1'}),
|
||||
'spam_kill_level' : forms.TextInput(attrs={'class' : 'span1'}),
|
||||
}
|
||||
@@ -27,11 +29,10 @@ class DomainPolicyForm(forms.ModelForm):
|
||||
del kwargs["instance"]
|
||||
super(DomainPolicyForm, self).__init__(*args, **kwargs)
|
||||
|
||||
def save(self, commit=True):
|
||||
def save(self, user, 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:
|
||||
|
||||
@@ -76,18 +76,21 @@ class Policy(models.Model):
|
||||
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(
|
||||
ugettext_lazy("Bypass virus checks"), max_length=3,
|
||||
choices=(('Y', 'yes'), ('N', 'no')), blank=True
|
||||
ugettext_lazy("Enable virus filter"), max_length=3,
|
||||
choices=(('Y', 'yes'), ('N', 'no')), blank=False, default='Y'
|
||||
)
|
||||
bypass_spam_checks = models.CharField(
|
||||
ugettext_lazy("Bypass spam checks"), max_length=3,
|
||||
choices=(('Y', 'yes'), ('N', 'no')), blank=True
|
||||
ugettext_lazy("Enable spam filter"), max_length=3,
|
||||
choices=(('Y', 'yes'), ('N', 'no')), blank=False, default='Y'
|
||||
)
|
||||
bypass_banned_checks = models.CharField(
|
||||
ugettext_lazy("Enable banned filter"), max_length=3,
|
||||
choices=(('Y', 'yes'), ('N', 'no')), blank=False, default='Y'
|
||||
)
|
||||
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(
|
||||
ugettext_lazy("Modify spam subject"),
|
||||
choices=(('Y', 'yes'), ('N', 'no')), max_length=3, blank=True
|
||||
ugettext_lazy("Indicate spam in subject"),
|
||||
choices=(('Y', 'yes'), ('N', 'no')), max_length=3, blank=False, default='Y'
|
||||
)
|
||||
virus_quarantine_to = models.CharField(max_length=192, blank=True)
|
||||
spam_quarantine_to = models.CharField(max_length=192, blank=True)
|
||||
@@ -97,10 +100,10 @@ class Policy(models.Model):
|
||||
other_quarantine_to = models.CharField(max_length=192, blank=True)
|
||||
spam_tag_level = models.FloatField(null=True, blank=True)
|
||||
spam_tag2_level = models.FloatField(
|
||||
ugettext_lazy("Spam tag2 level"), null=True, blank=True
|
||||
ugettext_lazy("Spam score"), null=True, blank=True
|
||||
)
|
||||
spam_kill_level = models.FloatField(
|
||||
ugettext_lazy("Spam kill level"), null=True, blank=True
|
||||
ugettext_lazy("Discard spam beyond"), null=True, blank=True
|
||||
)
|
||||
spam_dsn_cutoff_level = models.FloatField(null=True, blank=True)
|
||||
spam_quarantine_cutoff_level = models.FloatField(null=True, blank=True)
|
||||
|
||||
@@ -5,6 +5,9 @@ from django import forms
|
||||
from django.forms.widgets import MultiWidget, TextInput
|
||||
from django.forms.fields import MultiValueField
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils.encoding import force_unicode
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.html import conditional_escape
|
||||
|
||||
class CreationWizard(object):
|
||||
def __init__(self, done_cb):
|
||||
@@ -166,3 +169,23 @@ class DomainNameField(forms.CharField):
|
||||
def clean(self, value):
|
||||
value = self.to_python(value).strip()
|
||||
return super(DomainNameField, self).clean(value)
|
||||
|
||||
class BootstrapRadioInput(forms.widgets.RadioInput):
|
||||
def __unicode__(self):
|
||||
if 'id' in self.attrs:
|
||||
label_for = ' for="%s_%s"' % (self.attrs['id'], self.index)
|
||||
else:
|
||||
label_for = ''
|
||||
choice_label = conditional_escape(force_unicode(self.choice_label))
|
||||
return mark_safe(u'<label%s class="radio inline">%s %s</label>' % (label_for, self.tag(), choice_label))
|
||||
|
||||
class InlineRadioFieldRenderer(forms.widgets.RadioFieldRenderer):
|
||||
def __iter__(self):
|
||||
for i, choice in enumerate(self.choices):
|
||||
yield BootstrapRadioInput(self.name, self.value, self.attrs.copy(), choice, i)
|
||||
|
||||
def render(self):
|
||||
return mark_safe(u'\n%s\n' % u'\n'.join([u'%s' % force_unicode(w) for w in self]))
|
||||
|
||||
class InlineRadioSelect(forms.widgets.RadioSelect):
|
||||
renderer = InlineRadioFieldRenderer
|
||||
|
||||
Reference in New Issue
Block a user