mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-18 05:51:26 +02:00
Prevent the creation of a domain alias using the same name as a domain.
fixes #498
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import reversion
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext as _, ugettext_lazy
|
||||
from modoboa.lib.exceptions import BadRequest
|
||||
from modoboa.lib.exceptions import BadRequest, Conflict
|
||||
from .base import AdminObject
|
||||
from .domain import Domain
|
||||
|
||||
@@ -38,6 +38,12 @@ class DomainAlias(AdminObject):
|
||||
if len(row) < 4:
|
||||
raise BadRequest(_("Invalid line"))
|
||||
self.name = row[1].strip()
|
||||
try:
|
||||
Domain.objects.get(name=self.name)
|
||||
except Domain.DoesNotExist:
|
||||
pass
|
||||
else:
|
||||
raise Conflict(_("A domain %s already exists" % self.name))
|
||||
domname = row[2].strip()
|
||||
try:
|
||||
self.target = Domain.objects.get(name=domname)
|
||||
|
||||
@@ -40,6 +40,17 @@ domainalias; domalias1.com; domain1.com; True
|
||||
self.assertFalse(dom.enabled)
|
||||
self.assertTrue(admin.is_owner(dom))
|
||||
|
||||
def test_import_domains_with_conflict(self):
|
||||
f = ContentFile(b"""domain;test.alias;10;True
|
||||
domainalias;test.alias;test.com;True
|
||||
""", name="domains.csv")
|
||||
resp = self.clt.post(
|
||||
reverse("modoboa.extensions.admin.views.import.import_domains"), {
|
||||
"sourcefile": f
|
||||
}
|
||||
)
|
||||
self.assertIn('A domain test.alias already exists', resp.content)
|
||||
|
||||
def test_identities_import(self):
|
||||
f = ContentFile(b"""
|
||||
account; user1@test.com; toto; User; One; True; SimpleUsers; user1@test.com
|
||||
|
||||
Reference in New Issue
Block a user