diff --git a/modoboa/admin/forms.py b/modoboa/admin/forms.py index 2f23c97f9..f11ef85ae 100644 --- a/modoboa/admin/forms.py +++ b/modoboa/admin/forms.py @@ -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() diff --git a/modoboa/admin/models.py b/modoboa/admin/models.py index beaddc155..7486791a7 100644 --- a/modoboa/admin/models.py +++ b/modoboa/admin/models.py @@ -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): diff --git a/modoboa/admin/templates/admin/import_done.html b/modoboa/admin/templates/admin/import_done.html index 6c9af854e..a95ddfcd1 100644 --- a/modoboa/admin/templates/admin/import_done.html +++ b/modoboa/admin/templates/admin/import_done.html @@ -4,7 +4,7 @@
diff --git a/modoboa/admin/tests.py b/modoboa/admin/tests.py index 7da2f831e..0597714ac 100644 --- a/modoboa/admin/tests.py +++ b/modoboa/admin/tests.py @@ -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,