mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-18 05:51:26 +02:00
@@ -278,8 +278,6 @@ class AccountFormMail(forms.Form, DynamicForm):
|
||||
Check if quota is >= 0 only when the domain value is not used.
|
||||
"""
|
||||
cleaned_data = super(AccountFormMail, self).clean()
|
||||
if not cleaned_data["email"]:
|
||||
return cleaned_data
|
||||
use_default_domain_quota = cleaned_data["quota_act"]
|
||||
condition = (
|
||||
not use_default_domain_quota and
|
||||
|
||||
@@ -23,7 +23,9 @@ class DomainSerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = models.Domain
|
||||
fields = ("pk", "name", "default_mailbox_quota", "enabled", "type", )
|
||||
fields = (
|
||||
"pk", "name", "quota", "default_mailbox_quota", "enabled", "type",
|
||||
)
|
||||
|
||||
def create(self, validated_data):
|
||||
"""Set permissions."""
|
||||
@@ -236,11 +238,10 @@ class WritableAccountSerializer(AccountSerializer):
|
||||
except lib_exceptions.ModoboaException as inst:
|
||||
raise serializers.ValidationError({
|
||||
"domain": unicode(inst)})
|
||||
quota = data.pop("quota", None)
|
||||
mb = admin_models.Mailbox(
|
||||
user=account, address=address, domain=domain, **data)
|
||||
mb.set_quota(
|
||||
data.get("quota"), creator.has_perm("admin.add_domain")
|
||||
)
|
||||
mb.set_quota(quota, creator.has_perm("admin.add_domain"))
|
||||
mb.save(creator=creator)
|
||||
account.email = full_address
|
||||
return mb
|
||||
|
||||
@@ -44,14 +44,14 @@ class DomainAPITestCase(ModoAPITestCase):
|
||||
"""Check domain creation."""
|
||||
url = reverse("external_api:domain-list")
|
||||
response = self.client.post(
|
||||
url, {"name": "test3.com", "default_mailbox_quota": 10})
|
||||
url, {"name": "test3.com", "quota": 0, "default_mailbox_quota": 10}
|
||||
)
|
||||
self.assertEqual(response.status_code, 201)
|
||||
self.assertTrue(
|
||||
models.Domain.objects.filter(name="test3.com").exists())
|
||||
response = self.client.post(url, {})
|
||||
self.assertEqual(response.status_code, 400)
|
||||
self.assertIn("name", response.data)
|
||||
self.assertIn("default_mailbox_quota", response.data)
|
||||
|
||||
self.client.credentials(
|
||||
HTTP_AUTHORIZATION='Token ' + self.da_token.key)
|
||||
@@ -302,7 +302,7 @@ class AccountAPITestCase(ModoAPITestCase):
|
||||
self.client.credentials(
|
||||
HTTP_AUTHORIZATION='Token ' + self.da_token.key)
|
||||
data = copy.deepcopy(self.ACCOUNT_DATA)
|
||||
data["mailbox"]["quota"] = 20
|
||||
data["mailbox"]["quota"] = 1000
|
||||
url = reverse("external_api:account-list")
|
||||
response = self.client.post(url, data, format="json")
|
||||
self.assertEqual(response.status_code, 400)
|
||||
|
||||
@@ -38,11 +38,12 @@ class DomainAliasTestCase(ModoTestCase):
|
||||
|
||||
def test_form(self):
|
||||
dom = Domain.objects.get(name="test.com")
|
||||
values = dict(
|
||||
name=dom.name, default_mailbox_quota=dom.default_mailbox_quota,
|
||||
enabled=dom.enabled, aliases="domalias.net",
|
||||
aliases_1="domaliasé.com", type="domain"
|
||||
)
|
||||
values = {
|
||||
"name": dom.name, "quota": dom.quota,
|
||||
"default_mailbox_quota": dom.default_mailbox_quota,
|
||||
"enabled": dom.enabled, "aliases": "domalias.net",
|
||||
"aliases_1": "domaliasé.com", "type": "domain"
|
||||
}
|
||||
self.ajax_post(
|
||||
reverse("admin:domain_change",
|
||||
args=[dom.id]),
|
||||
|
||||
@@ -181,13 +181,13 @@ domainalias; domalias1.com; test.com; True
|
||||
self.client.logout()
|
||||
self.client.login(username="admin@test.com", password="toto")
|
||||
f = ContentFile(b"""
|
||||
account; user1@test.com; toto; User; One; True; SimpleUsers; user1@test.com; 20
|
||||
account; user1@test.com; toto; User; One; True; SimpleUsers; user1@test.com; 40
|
||||
""", name="identities.csv")
|
||||
resp = self.client.post(
|
||||
reverse("admin:identity_import"),
|
||||
{"sourcefile": f, "crypt_password": True}
|
||||
)
|
||||
self.assertIn('Quota is greater than the allowed', resp.content)
|
||||
self.assertIn("Domain quota exceeded", resp.content)
|
||||
|
||||
def test_import_missing_quota(self):
|
||||
f = ContentFile(b"""
|
||||
|
||||
@@ -34,6 +34,7 @@ class DomainLimitsTestCase(lib_tests.ModoTestCase):
|
||||
domain = Domain.objects.get(name="test.com")
|
||||
values = {
|
||||
"name": domain.name, "quota": domain.quota,
|
||||
"default_mailbox_quota": domain.default_mailbox_quota,
|
||||
"enabled": domain.enabled, "type": "domain",
|
||||
"mailboxes_limit": 3, "mailbox_aliases_limit": 3,
|
||||
"domain_aliases_limit": 3, "domain_admins_limit": 3
|
||||
@@ -62,6 +63,7 @@ class DomainLimitsTestCase(lib_tests.ModoTestCase):
|
||||
self.assertFalse(limit.is_exceeded())
|
||||
values = {
|
||||
"name": domain.name, "quota": domain.quota,
|
||||
"default_mailbox_quota": domain.default_mailbox_quota,
|
||||
"enabled": domain.enabled, "type": "domain",
|
||||
"mailboxes_limit": 2, "mailbox_aliases_limit": 2,
|
||||
"domain_aliases_limit": 2, "domain_admins_limit": 2,
|
||||
|
||||
@@ -78,7 +78,8 @@ class ResourceTestCase(lib_tests.ModoTestCase):
|
||||
|
||||
def _create_domain(self, name, status=200, withtpl=False):
|
||||
values = {
|
||||
"name": name, "quota": 100, "create_dom_admin": False,
|
||||
"name": name, "quota": 100, "default_mailbox_quota": 10,
|
||||
"create_dom_admin": False,
|
||||
"create_aliases": False, "stepid": "step3", "type": "domain"
|
||||
}
|
||||
if withtpl:
|
||||
@@ -95,16 +96,17 @@ class ResourceTestCase(lib_tests.ModoTestCase):
|
||||
def _domain_alias_operation(self, optype, domain, name, status=200):
|
||||
dom = Domain.objects.get(name=domain)
|
||||
values = {
|
||||
'name': dom.name, 'quota': dom.quota, 'enabled': dom.enabled,
|
||||
"type": "domain"
|
||||
"name": dom.name, "quota": dom.quota, "enabled": dom.enabled,
|
||||
"type": "domain",
|
||||
"default_mailbox_quota": dom.default_mailbox_quota,
|
||||
}
|
||||
aliases = [alias.name for alias in dom.domainalias_set.all()]
|
||||
if optype == 'add':
|
||||
if optype == "add":
|
||||
aliases.append(name)
|
||||
else:
|
||||
aliases.remove(name)
|
||||
for cpt, alias in enumerate(aliases):
|
||||
fname = 'aliases' if not cpt else 'aliases_%d' % cpt
|
||||
fname = "aliases" if not cpt else "aliases_%d" % cpt
|
||||
values[fname] = alias
|
||||
self.ajax_post(
|
||||
reverse("admin:domain_change", args=[dom.id]),
|
||||
|
||||
@@ -23,7 +23,8 @@ class Operations(object):
|
||||
values = {
|
||||
"name": name, "create_dom_admin": False, "type": "relaydomain",
|
||||
"target_host": "external.host.tld", "target_port": 25,
|
||||
"service": srv.id, "enabled": True, "stepid": "step3"
|
||||
"service": srv.id, "enabled": True, "stepid": "step3",
|
||||
"quota": 0, "default_mailbox_quota": 0
|
||||
}
|
||||
return self.ajax_post(
|
||||
reverse("admin:domain_add"),
|
||||
@@ -35,7 +36,8 @@ class Operations(object):
|
||||
values = {
|
||||
"name": rdom.domain.name, "target_host": rdom.target_host,
|
||||
"target_port": rdom.target_port,
|
||||
"type": "relaydomain", "service": rdom.service.id
|
||||
"type": "relaydomain", "service": rdom.service.id,
|
||||
"quota": 0, "default_mailbox_quota": 0
|
||||
}
|
||||
aliases = [alias.name for alias in rdom.domain.domainalias_set.all()]
|
||||
if optype == 'add':
|
||||
@@ -144,7 +146,8 @@ class RelayDomainsTestCase(ModoTestCase, Operations):
|
||||
values = {
|
||||
"name": "relaydomain.org", "target_host": self.rdom.target_host,
|
||||
"target_port": 4040, "type": "relaydomain", "enabled": True,
|
||||
"service": self.rdom.service.id
|
||||
"service": self.rdom.service.id,
|
||||
"quota": 0, "default_mailbox_quota": 0
|
||||
}
|
||||
self.ajax_post(
|
||||
reverse("admin:domain_change", args=[self.rdom.domain.id]),
|
||||
@@ -159,6 +162,8 @@ class RelayDomainsTestCase(ModoTestCase, Operations):
|
||||
values = {
|
||||
"name": "relaydomain.tld",
|
||||
"type": "domain",
|
||||
"quota": 0,
|
||||
"default_mailbox_quota": 0,
|
||||
"enabled": True,
|
||||
"target_host": self.rdom.target_host,
|
||||
"target_port": self.rdom.target_port,
|
||||
@@ -176,6 +181,8 @@ class RelayDomainsTestCase(ModoTestCase, Operations):
|
||||
"name": "relaydomain.tld",
|
||||
"type": "relaydomain",
|
||||
"enabled": True,
|
||||
"quota": 0,
|
||||
"default_mailbox_quota": 0
|
||||
}
|
||||
self.ajax_post(
|
||||
reverse("admin:domain_change", args=[domain_pk]), values)
|
||||
@@ -195,7 +202,8 @@ class RelayDomainsTestCase(ModoTestCase, Operations):
|
||||
"name": "relaydomain.org", "target_host": self.rdom.target_host,
|
||||
"target_port": self.rdom.target_port,
|
||||
"type": "relaydomain", "service": self.rdom.service.id,
|
||||
"aliases": "relaydomainalias.net"
|
||||
"aliases": "relaydomainalias.net",
|
||||
"quota": 0, "default_mailbox_quota": 0
|
||||
}
|
||||
self.ajax_post(
|
||||
reverse('admin:domain_change',
|
||||
|
||||
Reference in New Issue
Block a user