mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
Mailbox quota can now be increased by a super admin (or a reseller) beyond the domain limit.
fixes #278
This commit is contained in:
@@ -487,7 +487,8 @@ class AccountFormMail(forms.Form, DynamicForm):
|
||||
events.raiseEvent("CanCreate", user, "mailboxes")
|
||||
self.mb = Mailbox()
|
||||
self.mb.save_from_user(locpart, domain, account,
|
||||
self.cleaned_data["quota"])
|
||||
self.cleaned_data["quota"],
|
||||
owner=user)
|
||||
grant_access_to_object(user, self.mb, is_owner=True)
|
||||
events.raiseEvent("CreateMailbox", user, self.mb)
|
||||
if user.is_superuser:
|
||||
@@ -502,7 +503,8 @@ class AccountFormMail(forms.Form, DynamicForm):
|
||||
self.mb.address = locpart
|
||||
else:
|
||||
raise AdminError(_("Failed to rename mailbox, check permissions"))
|
||||
self.mb.save(quota=self.cleaned_data["quota"])
|
||||
self.mb.set_quota(self.cleaned_data["quota"], user.has_perm("admin.add_domain"))
|
||||
self.mb.save()
|
||||
|
||||
account.email = self.cleaned_data["email"]
|
||||
account.save()
|
||||
|
||||
@@ -594,6 +594,12 @@ class Mailbox(DatesAware):
|
||||
except KeyError:
|
||||
raise AdminError(_("%s is not a valid gid/groupname" % v_gid))
|
||||
|
||||
def set_quota(self, value, override_domain=False):
|
||||
if value is None or (int(value) > self.domain.quota and not override_domain):
|
||||
self.quota = self.domain.quota
|
||||
else:
|
||||
self.quota = value
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.create_dir():
|
||||
raise AdminError(_("Failed to initialise mailbox, check permissions"))
|
||||
@@ -629,12 +635,8 @@ class Mailbox(DatesAware):
|
||||
user.save()
|
||||
|
||||
self.set_ownership()
|
||||
self.set_quota(kwargs["quota"] if kwargs.has_key("quota") else None)
|
||||
|
||||
if kwargs.has_key("quota") and kwargs["quota"] is not None \
|
||||
and int(kwargs["quota"]) < self.domain.quota:
|
||||
self.quota = kwargs["quota"]
|
||||
else:
|
||||
self.quota = self.domain.quota
|
||||
for kw in ["username", "name", "enabled", "password", "quota"]:
|
||||
try:
|
||||
del kwargs[kw]
|
||||
@@ -642,7 +644,7 @@ class Mailbox(DatesAware):
|
||||
pass
|
||||
super(Mailbox, self).save(*args, **kwargs)
|
||||
|
||||
def save_from_user(self, localpart, domain, user, quota=None):
|
||||
def save_from_user(self, localpart, domain, user, quota=None, owner=None):
|
||||
"""Simple save method called for automatic creations
|
||||
|
||||
:param localpart: the mailbox
|
||||
@@ -655,7 +657,7 @@ class Mailbox(DatesAware):
|
||||
if not self.create_dir():
|
||||
raise AdminError(_("Failed to initialise mailbox, check permissions"))
|
||||
self.set_ownership()
|
||||
self.quota = self.domain.quota if quota is None else quota
|
||||
self.set_quota(quota, True if (owner and owner.has_perm("admin.add_domain")) else False)
|
||||
super(Mailbox, self).save()
|
||||
|
||||
def create_from_csv(self, user, line):
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<head profile="http://www.w3.org/2005/10/profile">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<script type="text/javascript">
|
||||
parent.importdone("{{ status }}", "{{ msg }}");
|
||||
parent.importdone("{{ status }}", "{{ msg|escapejs }}");
|
||||
</script>
|
||||
</head>
|
||||
<body></body>
|
||||
|
||||
@@ -249,7 +249,7 @@ class PermissionsTestCase(ModoTestCase):
|
||||
self.assertEqual(self.clt.login(username="admin@test.com", password="toto"),
|
||||
True)
|
||||
response = self.clt.get("/modoboa/admin/domains/")
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
user = User.objects.get(username="user@test.com")
|
||||
response = self.clt.get("/modoboa/admin/accounts/edit/%d/" % user.id,
|
||||
|
||||
Reference in New Issue
Block a user