mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-18 05:51:26 +02:00
@@ -235,8 +235,8 @@ class Mailbox(AdminObject):
|
||||
self.quota = 0
|
||||
elif int(value) > self.domain.quota and not override_rules:
|
||||
raise lib_exceptions.BadRequest(
|
||||
_("Quota is greater than the allowed domain's limit (%dM)"
|
||||
% self.domain.quota)
|
||||
_("Quota is greater than the allowed domain's limit (%dM)")
|
||||
% self.domain.quota
|
||||
)
|
||||
else:
|
||||
self.quota = value
|
||||
|
||||
@@ -113,6 +113,9 @@ class CreateAccountSerializer(AccountSerializer):
|
||||
address, domain_name = email_utils.split_mailbox(full_address)
|
||||
domain = get_object_or_404(
|
||||
admin_models.Domain, name=domain_name)
|
||||
if not creator.can_access(domain):
|
||||
raise serializers.ValidationError({
|
||||
"domain": _("Permission denied.")})
|
||||
mb = admin_models.Mailbox(
|
||||
user=account, address=address, domain=domain, **data)
|
||||
mb.set_quota(
|
||||
|
||||
@@ -183,6 +183,24 @@ class AccountAPITestCase(ModoAPITestCase):
|
||||
errors = json.loads(response.content)
|
||||
self.assertIn("password", errors)
|
||||
|
||||
def test_create_account_as_domadmin(self):
|
||||
"""As DomainAdmin, try to create a new account."""
|
||||
self.client.credentials(
|
||||
HTTP_AUTHORIZATION='Token ' + self.da_token.key)
|
||||
data = copy.deepcopy(self.ACCOUNT_DATA)
|
||||
data["mailbox"]["quota"] = 20
|
||||
url = reverse("external_api:account-list")
|
||||
response = self.client.post(url, data, format="json")
|
||||
self.assertEqual(response.status_code, 400)
|
||||
data["username"] = "fromapi@test2.com"
|
||||
data["mailbox"].update({"full_address": "fromapi@test2.com",
|
||||
"quota": 10})
|
||||
url = reverse("external_api:account-list")
|
||||
response = self.client.post(url, data, format="json")
|
||||
self.assertEqual(response.status_code, 400)
|
||||
errors = json.loads(response.content)
|
||||
self.assertIn("domain", errors)
|
||||
|
||||
def test_create_account_bad_master_user(self):
|
||||
"""Try to create a new account."""
|
||||
data = copy.deepcopy(self.ACCOUNT_DATA)
|
||||
|
||||
Reference in New Issue
Block a user