mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-18 05:51:26 +02:00
@@ -290,9 +290,8 @@ class Mailbox(AdminObject):
|
||||
newaddress = self.user.username
|
||||
if newaddress is not None:
|
||||
local_part, domname = split_mailbox(newaddress)
|
||||
try:
|
||||
domain = Domain.objects.get(name=domname)
|
||||
except Domain.DoesNotExist:
|
||||
domain = Domain.objects.filter(name=domname).first()
|
||||
if domain is None:
|
||||
raise lib_exceptions.NotFound(_("Domain does not exist"))
|
||||
if not user.can_access(domain):
|
||||
raise lib_exceptions.PermDeniedException
|
||||
|
||||
@@ -146,7 +146,7 @@ class CreateAccountSerializer(AccountSerializer):
|
||||
if mailbox_data:
|
||||
creator = self.context["request"].user
|
||||
if instance.mailbox:
|
||||
# FIXME: compat, to remove.
|
||||
# FIXME: compat, to remove ASAP.
|
||||
mailbox_data["email"] = mailbox_data["full_address"]
|
||||
instance.mailbox.update_from_dict(creator, mailbox_data)
|
||||
else:
|
||||
|
||||
@@ -44,8 +44,7 @@ class AccountTestCase(ModoTestCase):
|
||||
alias__internal=True).exists()
|
||||
)
|
||||
|
||||
values.update({
|
||||
"username": "pouet@test.com", "email": "pouet@test.com"})
|
||||
values.update({"username": "pouet@test.com"})
|
||||
self.ajax_post(
|
||||
reverse("admin:account_change", args=[account.id]), values
|
||||
)
|
||||
|
||||
@@ -211,6 +211,22 @@ class AccountAPITestCase(ModoAPITestCase):
|
||||
account.refresh_from_db()
|
||||
self.assertEqual(account.email, account.mailbox.full_address)
|
||||
|
||||
def test_update_account_wrong_address(self):
|
||||
"""Try to update an account."""
|
||||
account = core_models.User.objects.get(username="user@test.com")
|
||||
url = reverse("external_api:account-detail", args=[account.pk])
|
||||
data = {
|
||||
"username": "fromapi@test3.com",
|
||||
"role": account.role,
|
||||
"password": "Toto1234",
|
||||
"mailbox": {
|
||||
"full_address": "fromapi@test3.com",
|
||||
"quota": account.mailbox.quota
|
||||
}
|
||||
}
|
||||
response = self.client.put(url, data, format="json")
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
def test_delete_account(self):
|
||||
"""Try to delete an account."""
|
||||
account = core_models.User.objects.get(username="user@test.com")
|
||||
|
||||
Reference in New Issue
Block a user