mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-18 05:51:26 +02:00
Bugfix on permissions verification (on domain admin was able to access any domain :p)
Added help tips when filling forms (domain, mailbox, etc.) French translation update. Tips class added to mootools-more.js is not the official version (1.2.4.2). There are some bugs with this version so I've decided to integrate modifications coming from here : https://mootools.lighthouseapp.com/projects/24057/tickets/167-tips-class-issues-in-more-1242
This commit is contained in:
+12
-6
@@ -14,10 +14,13 @@ class DomainForm(forms.ModelForm):
|
||||
|
||||
class MailboxForm(forms.ModelForm):
|
||||
quota = forms.IntegerField(label=_("Quota"), required=False)
|
||||
password1 = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
|
||||
password2 = forms.CharField(label=_("Confirmation"), widget=forms.PasswordInput)
|
||||
password1 = forms.CharField(label=_("Password"), widget=forms.PasswordInput,
|
||||
help_text=_("Password used to log in"))
|
||||
password2 = forms.CharField(label=_("Confirmation"), widget=forms.PasswordInput,
|
||||
help_text=_("Password confirmation"))
|
||||
enabled = forms.BooleanField(label=gender("Enabled", "f"), required=False,
|
||||
initial=True)
|
||||
initial=True,
|
||||
help_text=_("Check to activate this mailbox"))
|
||||
|
||||
class Meta:
|
||||
model = Mailbox
|
||||
@@ -50,8 +53,11 @@ class AliasForm(forms.ModelForm):
|
||||
|
||||
class PermissionForm(forms.Form):
|
||||
domain = forms.ModelChoiceField(queryset=Domain.objects.all(), label=_("Domain"),
|
||||
required=True)
|
||||
user = forms.ChoiceField(label=_("User"), required=True)
|
||||
required=True,
|
||||
help_text=_("Select a domain in the list"))
|
||||
user = forms.ChoiceField(label=_("User"), required=True,
|
||||
help_text=_("Select a user in the list"))
|
||||
role = forms.ChoiceField(label=_("Role"), required=True,
|
||||
choices=(("SuperAdmins", _("Super administrator")),
|
||||
("DomainAdmins", _("Domain administrator"))))
|
||||
("DomainAdmins", _("Domain administrator"))),
|
||||
help_text=_("Select the role you want this user to have"))
|
||||
|
||||
+16
-9
@@ -6,9 +6,11 @@ from mailng.lib import exec_pipe, exec_as_vuser
|
||||
import os
|
||||
|
||||
class Domain(models.Model):
|
||||
name = models.CharField(_('name'), max_length=100)
|
||||
quota = models.IntegerField()
|
||||
enabled = models.BooleanField(_('enabled'))
|
||||
name = models.CharField(_('name'), max_length=100,
|
||||
help_text=_("The domain name"))
|
||||
quota = models.IntegerField(help_text=_("Default quota in MB applied to mailboxes"))
|
||||
enabled = models.BooleanField(_('enabled'),
|
||||
help_text=_("Check to activate this domain"))
|
||||
|
||||
class Meta:
|
||||
permissions = (
|
||||
@@ -33,11 +35,13 @@ class Domain(models.Model):
|
||||
return self.name
|
||||
|
||||
class Mailbox(models.Model):
|
||||
name = models.CharField(_('name'), max_length=100)
|
||||
address = models.CharField(_('address'), max_length=100)
|
||||
name = models.CharField(_('name'), max_length=100,
|
||||
help_text=_("First name and last name of mailbox owner"))
|
||||
address = models.CharField(_('address'), max_length=100,
|
||||
help_text=_("Mailbox address (without the @domain.tld part)"))
|
||||
full_address = models.CharField(max_length=150)
|
||||
password = models.CharField(_('password'), max_length=100)
|
||||
quota = models.IntegerField()
|
||||
quota = models.IntegerField(help_text=_("Mailbox quota in MB (default to domain quota if blank)"))
|
||||
uid = models.IntegerField()
|
||||
gid = models.IntegerField()
|
||||
path = models.CharField(max_length=200)
|
||||
@@ -99,10 +103,13 @@ class Mailbox(models.Model):
|
||||
self.domain.name, self.address))
|
||||
|
||||
class Alias(models.Model):
|
||||
address = models.CharField(_('address'), max_length=100)
|
||||
address = models.CharField(_('address'), max_length=100,
|
||||
help_text=_("The alias address (without the domain part)"))
|
||||
full_address = models.CharField(max_length=150)
|
||||
mbox = models.ForeignKey(Mailbox, verbose_name=_('mailbox'))
|
||||
enabled = models.BooleanField(_('enabled'))
|
||||
mbox = models.ForeignKey(Mailbox, verbose_name=_('mailbox'),
|
||||
help_text=_("The mailbox this alias points to"))
|
||||
enabled = models.BooleanField(_('enabled'),
|
||||
help_text=_("Check to activate this alias"))
|
||||
|
||||
class Meta:
|
||||
permissions = (
|
||||
|
||||
+27
-6
@@ -4,6 +4,7 @@ from django.template import RequestContext
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.utils import simplejson
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.utils.http import urlquote
|
||||
from django.core import serializers
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.contrib.auth.decorators \
|
||||
@@ -23,6 +24,21 @@ def is_superuser(user):
|
||||
return False
|
||||
return True
|
||||
|
||||
def good_domain(f):
|
||||
def dec(request, dom_id, **kwargs):
|
||||
if request.user.is_superuser:
|
||||
return f(request, dom_id, **kwargs)
|
||||
mb = Mailbox.objects.get(user=request.user.id)
|
||||
domid = isinstance(dom_id, str) and "%d" % dom_id or dom_id
|
||||
if domid == mb.domain.id:
|
||||
return f(request, domid, **kwargs)
|
||||
|
||||
from django.conf import settings
|
||||
path = urlquote(request.get_full_path())
|
||||
login_url = settings.LOGIN_URL
|
||||
return HttpResponseRedirect("%s?next=%s" % (login_url, path))
|
||||
return dec
|
||||
|
||||
@login_required
|
||||
def domains(request):
|
||||
if not request.user.has_perm("admin.view_domains"):
|
||||
@@ -41,10 +57,8 @@ def domains(request):
|
||||
})
|
||||
|
||||
@login_required
|
||||
@permission_required("admin.add_mailbox")
|
||||
@permission_required("admin.add_domain")
|
||||
def newdomain(request):
|
||||
if not is_superuser(request.user):
|
||||
return mailboxes(request, dom_id)
|
||||
if request.method == "POST":
|
||||
form = DomainForm(request.POST)
|
||||
error = None
|
||||
@@ -71,10 +85,8 @@ def newdomain(request):
|
||||
})
|
||||
|
||||
@login_required
|
||||
@permission_required("admin.change_mailbox")
|
||||
@permission_required("admin.change_domain")
|
||||
def editdomain(request, dom_id):
|
||||
if not is_superuser(request.user):
|
||||
return mailboxes(request, dom_id)
|
||||
domain = Domain.objects.get(pk=dom_id)
|
||||
if request.method == "POST":
|
||||
form = DomainForm(request.POST, instance=domain)
|
||||
@@ -110,6 +122,7 @@ def deldomain(request, dom_id):
|
||||
return HttpResponseRedirect('/mailng/admin/')
|
||||
|
||||
@login_required
|
||||
@good_domain
|
||||
@permission_required("admin.view_mailboxes")
|
||||
def mailboxes(request, dom_id=None):
|
||||
domain = Domain.objects.get(pk=dom_id)
|
||||
@@ -119,6 +132,7 @@ def mailboxes(request, dom_id=None):
|
||||
})
|
||||
|
||||
@login_required
|
||||
@good_domain
|
||||
@permission_required("admin.view_mailboxes")
|
||||
def mailboxes_raw(request, dom_id=None):
|
||||
mailboxes = Mailbox.objects.filter(domain=dom_id)
|
||||
@@ -127,6 +141,7 @@ def mailboxes_raw(request, dom_id=None):
|
||||
})
|
||||
|
||||
@login_required
|
||||
@good_domain
|
||||
@permission_required("admin.add_mailbox")
|
||||
def newmailbox(request, dom_id=None):
|
||||
domain = Domain.objects.get(pk=dom_id)
|
||||
@@ -183,6 +198,7 @@ def newmailbox(request, dom_id=None):
|
||||
})
|
||||
|
||||
@login_required
|
||||
@good_domain
|
||||
@permission_required("admin.change_mailbox")
|
||||
def editmailbox(request, dom_id, mbox_id=None):
|
||||
mb = Mailbox.objects.get(pk=mbox_id)
|
||||
@@ -231,6 +247,7 @@ def editmailbox(request, dom_id, mbox_id=None):
|
||||
})
|
||||
|
||||
@login_required
|
||||
@good_domain
|
||||
@permission_required("admin.delete_mailbox")
|
||||
def delmailbox(request, dom_id, mbox_id=None):
|
||||
mb = Mailbox.objects.get(pk=mbox_id)
|
||||
@@ -246,6 +263,7 @@ def delmailbox(request, dom_id, mbox_id=None):
|
||||
# args=[dom_id]))
|
||||
|
||||
@login_required
|
||||
@good_domain
|
||||
@permission_required("admin.view_aliases")
|
||||
def aliases(request, dom_id=None, mbox_id=None):
|
||||
domain = Domain.objects.get(pk=dom_id)
|
||||
@@ -261,6 +279,7 @@ def aliases(request, dom_id=None, mbox_id=None):
|
||||
})
|
||||
|
||||
@login_required
|
||||
@good_domain
|
||||
@permission_required("admin.add_alias")
|
||||
def newalias(request, dom_id, mbox_id):
|
||||
mbox = Mailbox.objects.get(pk=mbox_id)
|
||||
@@ -289,6 +308,7 @@ def newalias(request, dom_id, mbox_id):
|
||||
})
|
||||
|
||||
@login_required
|
||||
@good_domain
|
||||
@permission_required("admin.change_alias")
|
||||
def editalias(request, dom_id, alias_id):
|
||||
alias = Alias.objects.get(pk=alias_id)
|
||||
@@ -318,6 +338,7 @@ def editalias(request, dom_id, alias_id):
|
||||
})
|
||||
|
||||
@login_required
|
||||
@good_domain
|
||||
@permission_required("admin.delete_alias")
|
||||
def delalias(request, dom_id, alias_id):
|
||||
alias = Alias.objects.get(pk=alias_id)
|
||||
|
||||
Reference in New Issue
Block a user