mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-18 05:51:26 +02:00
@@ -196,6 +196,7 @@ def import_account_mailbox(user, account, row):
|
||||
@events.observe("AccountAutoCreated")
|
||||
def account_auto_created(user):
|
||||
from modoboa.core.models import User
|
||||
from modoboa.extensions.admin.lib import check_if_domain_exists
|
||||
from modoboa.lib.permissions import grant_access_to_object
|
||||
|
||||
if parameters.get_admin("LDAP_CREATE_DOMAIN_MAILBOX", app="core") == "no":
|
||||
@@ -207,6 +208,9 @@ def account_auto_created(user):
|
||||
try:
|
||||
domain = Domain.objects.get(name=domname)
|
||||
except Domain.DoesNotExist:
|
||||
label = check_if_domain_exists(domname)
|
||||
if label is not None:
|
||||
return
|
||||
domain = Domain(name=domname, enabled=True, quota=0)
|
||||
domain.save(creator=sadmins[0])
|
||||
for su in sadmins[1:]:
|
||||
|
||||
@@ -7,6 +7,7 @@ from modoboa.lib.formutils import (
|
||||
DomainNameField, YesNoField, DynamicForm, TabForms
|
||||
)
|
||||
from modoboa.core.models import User
|
||||
from modoboa.extensions.admin.lib import check_if_domain_exists
|
||||
from modoboa.extensions.admin.models import (
|
||||
Domain, DomainAlias, Mailbox, Alias, Quota
|
||||
)
|
||||
@@ -71,18 +72,13 @@ class DomainFormGeneral(forms.ModelForm, DynamicForm):
|
||||
|
||||
cleaned_data = self.cleaned_data
|
||||
name = cleaned_data["name"]
|
||||
dtypes = events.raiseQueryEvent('CheckDomainName')
|
||||
for dtype, label in [(DomainAlias, _('domain alias'))] + dtypes:
|
||||
try:
|
||||
dtype.objects.get(name=name)
|
||||
except dtype.DoesNotExist:
|
||||
pass
|
||||
else:
|
||||
self._errors["name"] = self.error_class(
|
||||
[_("A %s with this name already exists" % unicode(label))]
|
||||
)
|
||||
del cleaned_data["name"]
|
||||
break
|
||||
label = check_if_domain_exists(name)
|
||||
if label is not None:
|
||||
self._errors["name"] = self.error_class(
|
||||
[_("A %s with this name already exists" % unicode(label))]
|
||||
)
|
||||
del cleaned_data["name"]
|
||||
|
||||
for k in cleaned_data.keys():
|
||||
if not k.startswith("aliases"):
|
||||
continue
|
||||
|
||||
@@ -10,7 +10,7 @@ from modoboa.lib import parameters, events
|
||||
from modoboa.lib.exceptions import PermDeniedException
|
||||
from modoboa.lib.emailutils import split_mailbox
|
||||
from modoboa.extensions.admin.models import (
|
||||
Domain, Alias
|
||||
Domain, DomainAlias, Alias
|
||||
)
|
||||
|
||||
|
||||
@@ -137,3 +137,21 @@ def get_domains(user, domfilter=None, searchquery=None, **extrafilters):
|
||||
'ExtraDomainEntries', user, domfilter, searchquery, **extrafilters
|
||||
)
|
||||
return chain(domains, extra_domain_entries)
|
||||
|
||||
|
||||
def check_if_domain_exists(name):
|
||||
"""Check if a domain already exists.
|
||||
|
||||
We not only look for domains, we also look for every object that
|
||||
could conflict with a domain (domain alias, etc.)
|
||||
|
||||
"""
|
||||
dtypes = events.raiseQueryEvent('CheckDomainName')
|
||||
for dtype, label in [(DomainAlias, _('domain alias'))] + dtypes:
|
||||
try:
|
||||
dtype.objects.get(name=name)
|
||||
except dtype.DoesNotExist:
|
||||
pass
|
||||
else:
|
||||
return label
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user