Domain conflict check fixed.

see #591
This commit is contained in:
Antoine Nguyen
2014-08-24 14:06:40 +02:00
parent 2bbc464c36
commit 8a43b442ca
3 changed files with 11 additions and 10 deletions
+2 -1
View File
@@ -208,7 +208,8 @@ def account_auto_created(user):
try:
domain = Domain.objects.get(name=domname)
except Domain.DoesNotExist:
label = check_if_domain_exists(domname)
label = check_if_domain_exists(
domname, [(DomainAlias, _('domain alias'))])
if label is not None:
return
domain = Domain(name=domname, enabled=True, quota=0)
+5 -7
View File
@@ -72,7 +72,7 @@ class DomainFormGeneral(forms.ModelForm, DynamicForm):
cleaned_data = self.cleaned_data
name = cleaned_data["name"]
label = check_if_domain_exists(name)
label = check_if_domain_exists(name, [(DomainAlias, _('domain alias'))])
if label is not None:
self._errors["name"] = self.error_class(
[_("A %s with this name already exists" % unicode(label))]
@@ -85,16 +85,14 @@ class DomainFormGeneral(forms.ModelForm, DynamicForm):
if cleaned_data[k] == "":
del cleaned_data[k]
continue
for dtype, label in [(Domain, _('domain'))] + dtypes:
try:
dtype.objects.get(name=cleaned_data[k])
except dtype.DoesNotExist:
continue
label = check_if_domain_exists(
cleaned_data[k], [(Domain, _('domain'))])
if label is not None:
self._errors[k] = self.error_class(
[_("A %s with this name already exists" % unicode(label))]
)
del cleaned_data[k]
break
return cleaned_data
def update_mailbox_quotas(self, domain):
+4 -2
View File
@@ -139,7 +139,7 @@ def get_domains(user, domfilter=None, searchquery=None, **extrafilters):
return chain(domains, extra_domain_entries)
def check_if_domain_exists(name):
def check_if_domain_exists(name, extra_checks=None):
"""Check if a domain already exists.
We not only look for domains, we also look for every object that
@@ -147,7 +147,9 @@ def check_if_domain_exists(name):
"""
dtypes = events.raiseQueryEvent('CheckDomainName')
for dtype, label in [(DomainAlias, _('domain alias'))] + dtypes:
if extra_checks is not None:
dtypes = extra_checks + dtypes
for dtype, label in dtypes:
try:
dtype.objects.get(name=name)
except dtype.DoesNotExist: