mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-18 05:51:26 +02:00
@@ -32,7 +32,10 @@ class ObjectLimitMixin(object):
|
||||
|
||||
def is_exceeded(self, count=1):
|
||||
"""Check if limit will be reached if we add count object(s)."""
|
||||
return self.current_value + 1 > self.max_value
|
||||
return (
|
||||
self.max_value != -1 and
|
||||
self.current_value + 1 > self.max_value
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
"""Display current usage."""
|
||||
@@ -89,10 +92,6 @@ class UserObjectLimit(ObjectLimitMixin, models.Model):
|
||||
return 100
|
||||
return int(float(self.current_value) / self.max_value * 100)
|
||||
|
||||
def is_exceeded(self, count=1):
|
||||
"""Check if limit will be reached if we add count object(s)."""
|
||||
return self.current_value + 1 > self.max_value
|
||||
|
||||
def __str__(self):
|
||||
"""Display current usage."""
|
||||
if self.max_value == -1:
|
||||
|
||||
@@ -111,7 +111,7 @@ class DomainLimitsTestCase(lib_tests.ModoTestCase):
|
||||
self.assertFalse(limit.is_exceeded())
|
||||
username = "toto@test.com"
|
||||
values = {
|
||||
"username": username,
|
||||
"username": "toto@test.com",
|
||||
"first_name": "Tester", "last_name": "Toto",
|
||||
"password1": "Toto1234", "password2": "Toto1234",
|
||||
"role": "SimpleUsers", "quota_act": True,
|
||||
@@ -120,9 +120,16 @@ class DomainLimitsTestCase(lib_tests.ModoTestCase):
|
||||
self.ajax_post(reverse("admin:account_add"), values, 200)
|
||||
self.assertTrue(limit.is_exceeded())
|
||||
|
||||
username = "titi@test.com"
|
||||
values["username"] = "titi@test.com"
|
||||
values["email"] = "titi@test.com"
|
||||
self.ajax_post(reverse("admin:account_add"), values, 400)
|
||||
|
||||
# Set unlimited value
|
||||
limit.max_value = -1
|
||||
limit.save(update_fields=["max_value"])
|
||||
self.ajax_post(reverse("admin:account_add"), values)
|
||||
self.assertFalse(limit.is_exceeded())
|
||||
|
||||
def test_mailbox_aliases_limit(self):
|
||||
"""Try to exceed defined limits."""
|
||||
domain = Domain.objects.get(name="test.com")
|
||||
|
||||
@@ -154,12 +154,17 @@ class DomainAdminTestCase(ResourceTestCase):
|
||||
self._check_limit('mailbox_aliases', 2, 2)
|
||||
self._create_alias('alias3@test.com', status=403)
|
||||
self._check_limit('mailbox_aliases', 2, 2)
|
||||
# Set unlimited value
|
||||
self.user.userobjectlimit_set.filter(name="mailbox_aliases").update(
|
||||
max_value=-1)
|
||||
self._create_alias('alias3@test.com')
|
||||
self._check_limit('mailbox_aliases', 3, -1)
|
||||
self.ajax_post(
|
||||
reverse('admin:alias_delete') + '?selection=%d'
|
||||
% Alias.objects.get(address='alias2@test.com').id,
|
||||
{}
|
||||
)
|
||||
self._check_limit('mailbox_aliases', 1, 2)
|
||||
self._check_limit('mailbox_aliases', 2, -1)
|
||||
|
||||
def test_aliases_limit_through_account_form(self):
|
||||
user = User.objects.get(username='user@test.com')
|
||||
|
||||
Reference in New Issue
Block a user