VMM/{,cli/}handler: Moved the 'address-in-use check' (introduced
with changeset ef99be5b7ec0) to {alias,relocated,user}_add().
--- a/VirtualMailManager/cli/handler.py Wed Jan 19 23:58:06 2011 +0000
+++ b/VirtualMailManager/cli/handler.py Thu Jan 20 00:22:52 2011 +0000
@@ -11,7 +11,7 @@
import os
from VirtualMailManager.errors import VMMError
-from VirtualMailManager.handler import Handler
+from VirtualMailManager.handler import Handler, TYPE_ACCOUNT
from VirtualMailManager.cli import read_pass
from VirtualMailManager.cli.config import CliConfig as Cfg
from VirtualMailManager.constants import ACCOUNT_EXISTS, INVALID_SECTION, \
@@ -76,6 +76,7 @@
if acc:
raise VMMError(_(u"The account '%s' already exists.") %
acc.address, ACCOUNT_EXISTS)
+ other = self._is_other_address(acc.address, TYPE_ACCOUNT)
rand_pass = self._cfg.dget('account.random_password')
if password is None:
password = (read_pass, randompw)[rand_pass]()
--- a/VirtualMailManager/handler.py Wed Jan 19 23:58:06 2011 +0000
+++ b/VirtualMailManager/handler.py Thu Jan 20 00:22:52 2011 +0000
@@ -246,21 +246,18 @@
"""Return an Account instances for the given address (str)."""
address = EmailAddress(address)
self._db_connect()
- self._is_other_address(address, TYPE_ACCOUNT)
return Account(self._dbh, address)
def _get_alias(self, address):
"""Return an Alias instances for the given address (str)."""
address = EmailAddress(address)
self._db_connect()
- self._is_other_address(address, TYPE_ALIAS)
return Alias(self._dbh, address)
def _get_relocated(self, address):
"""Return a Relocated instances for the given address (str)."""
address = EmailAddress(address)
self._db_connect()
- self._is_other_address(address, TYPE_RELOCATED)
return Relocated(self._dbh, address)
def _get_domain(self, domainname):
@@ -553,6 +550,7 @@
if acc:
raise VMMError(_(u"The account '%s' already exists.") %
acc.address, ACCOUNT_EXISTS)
+ other = self._is_other_address(acc.address, TYPE_ACCOUNT)
acc.set_password(password)
acc.save()
self._make_account_dirs(acc)
@@ -561,6 +559,8 @@
"""Creates a new `Alias` entry for the given *aliasaddress* with
the given *targetaddresses*."""
alias = self._get_alias(aliasaddress)
+ if not alias:
+ self._is_other_address(alias.address, TYPE_ALIAS)
destinations = [DestinationEmailAddress(addr, self._dbh) \
for addr in targetaddresses]
warnings = []
@@ -711,6 +711,8 @@
already a relocated user with the given *emailaddress*, only the
*targetaddress* for the relocated user will be updated."""
relocated = self._get_relocated(emailaddress)
+ if not relocated:
+ self._is_other_address(relocated.address, TYPE_RELOCATED)
destination = DestinationEmailAddress(targetaddress, self._dbh)
relocated.set_destination(destination)
if destination.gid and \