summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mailman/database/alembic/versions/46e92facee7_add_serverowner_domainowner.py25
-rw-r--r--src/mailman/interfaces/domain.py4
-rw-r--r--src/mailman/model/docs/domains.rst8
-rw-r--r--src/mailman/model/domain.py25
-rw-r--r--src/mailman/model/tests/test_domain.py15
-rw-r--r--src/mailman/model/user.py6
-rw-r--r--src/mailman/rest/domains.py4
-rw-r--r--src/mailman/rest/tests/test_domains.py5
8 files changed, 40 insertions, 52 deletions
diff --git a/src/mailman/database/alembic/versions/46e92facee7_add_serverowner_domainowner.py b/src/mailman/database/alembic/versions/46e92facee7_add_serverowner_domainowner.py
index 613e4d22d..e4dc25ab8 100644
--- a/src/mailman/database/alembic/versions/46e92facee7_add_serverowner_domainowner.py
+++ b/src/mailman/database/alembic/versions/46e92facee7_add_serverowner_domainowner.py
@@ -15,31 +15,22 @@ import sqlalchemy as sa
def upgrade():
- ### commands auto generated by Alembic - please adjust! ###
- op.create_table('owner',
- sa.Column('user_id', sa.Integer(), nullable=False),
- sa.Column('domain_id', sa.Integer(), nullable=False),
- sa.ForeignKeyConstraint(['domain_id'], ['domain.id'], ),
- sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
- sa.PrimaryKeyConstraint('user_id', 'domain_id')
+ op.create_table('domain_owner',
+ sa.Column('user_id', sa.Integer(), nullable=False),
+ sa.Column('domain_id', sa.Integer(), nullable=False),
+ sa.ForeignKeyConstraint(['domain_id'], ['domain.id'], ),
+ sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
+ sa.PrimaryKeyConstraint('user_id', 'domain_id')
)
op.add_column('user', sa.Column('is_server_owner', sa.Boolean(),
nullable=True))
if op.get_bind().dialect.name != 'sqlite':
op.drop_column('domain', 'contact_address')
- # The migration below may be because the first migration was created
- # before we changed this attribute to a primary_key
- op.create_foreign_key('_preferred_address', 'user', 'address',
- ['_preferred_address_id'], ['id'])
- ### end Alembic commands ###
def downgrade():
- ### commands auto generated by Alembic - please adjust! ###
- op.drop_column('user', 'is_server_owner')
if op.get_bind().dialect.name != 'sqlite':
+ op.drop_column('user', 'is_server_owner')
op.add_column('domain', sa.Column('contact_address', sa.VARCHAR(),
nullable=True))
- op.drop_constraint('_preferred_address', 'user', type_='foreignkey')
- op.drop_table('owner')
- ### end Alembic commands ###
+ op.drop_table('domain_owner')
diff --git a/src/mailman/interfaces/domain.py b/src/mailman/interfaces/domain.py
index fd889a720..94a9eefd3 100644
--- a/src/mailman/interfaces/domain.py
+++ b/src/mailman/interfaces/domain.py
@@ -122,8 +122,8 @@ class IDomainManager(Interface):
interface of the domain. If not given, it defaults to
http://`mail_host`/
:type base_url: string
- :param owner_id: Owner of the domain, defaults to None
- :type owner_id: integer
+ :param owner: Owner of the domain, defaults to None
+ :type owner: `Iuser`
:return: The new domain object
:rtype: `IDomain`
:raises `BadDomainSpecificationError`: when the `mail_host` is
diff --git a/src/mailman/model/docs/domains.rst b/src/mailman/model/docs/domains.rst
index 491c0e612..dd0904f2b 100644
--- a/src/mailman/model/docs/domains.rst
+++ b/src/mailman/model/docs/domains.rst
@@ -9,10 +9,10 @@ Domains
>>> manager = getUtility(IDomainManager)
>>> manager.remove('example.com')
<Domain example.com...>
- >>> from mailman.interfaces.usermanager import IUserManager
- >>> user_manager = getUtility(IUserManager)
+ >>> from mailman.interfaces.usermanager import IUserManager
+ >>> user_manager = getUtility(IUserManager)
>>> user = user_manager.create_user('test@example.org')
- >>> config.db.commit()
+ >>> config.db.commit()
Domains are how Mailman interacts with email host names and web host names.
::
@@ -58,7 +58,7 @@ Domains can have explicit descriptions.
... 'example.net',
... base_url='http://lists.example.net',
... description='The example domain',
- ... owner_id=1)
+ ... owner=user)
<Domain example.net, The example domain,
base_url: http://lists.example.net>
diff --git a/src/mailman/model/domain.py b/src/mailman/model/domain.py
index a3a059cb9..6809688d6 100644
--- a/src/mailman/model/domain.py
+++ b/src/mailman/model/domain.py
@@ -29,7 +29,7 @@ from mailman.interfaces.domain import (
BadDomainSpecificationError, DomainCreatedEvent, DomainCreatingEvent,
DomainDeletedEvent, DomainDeletingEvent, IDomain, IDomainManager)
from mailman.model.mailinglist import MailingList
-from mailman.model.user import User, Owner
+from mailman.model.user import User, DomainOwner
from urllib.parse import urljoin, urlparse
from sqlalchemy import Column, Integer, Unicode
from sqlalchemy.orm import relationship, backref
@@ -50,7 +50,7 @@ class Domain(Model):
base_url = Column(Unicode)
description = Column(Unicode)
owners = relationship("User",
- secondary="owner",
+ secondary="domain_owner",
backref="domains")
def __init__(self, mail_host,
@@ -68,7 +68,7 @@ class Domain(Model):
`mail_host` using the http protocol.
:type base_url: string
:param owner: The `User` who is the owner of this domain
- :type owner: mailman.models.user.User
+ :type owner: `IUser`
"""
self.mail_host = mail_host
self.base_url = (base_url
@@ -111,11 +111,15 @@ class Domain(Model):
'base_url: {0.base_url}>').format(self)
def add_owner(self, owner):
- """ Add a domain owner"""
+ """Add a domain owner"""
self.owners.append(owner)
- @dbconnection
- def remove_owner(self, store, owner):
+ def add_owners(self, owners):
+ """Add multiple owners"""
+ for each in owners:
+ self.owners.append(each)
+
+ def remove_owner(self, owner):
""" Remove a domain owner"""
self.owners.remove(owner)
@@ -129,20 +133,13 @@ class DomainManager:
mail_host,
description=None,
base_url=None,
- owner_id=None):
+ owner=None):
"""See `IDomainManager`."""
# Be sure the mail_host is not already registered. This is probably
# a constraint that should (also) be maintained in the database.
if self.get(mail_host) is not None:
raise BadDomainSpecificationError(
'Duplicate email host: %s' % mail_host)
- # Be sure that the owner exists
- owner = None
- if owner_id is not None:
- owner = store.query(User).get(owner_id)
- if owner is None:
- raise BadDomainSpecificationError(
- 'Owner of this domain does not exist')
notify(DomainCreatingEvent(mail_host))
domain = Domain(mail_host, description, base_url, owner)
diff --git a/src/mailman/model/tests/test_domain.py b/src/mailman/model/tests/test_domain.py
index ffa79e32e..950c34969 100644
--- a/src/mailman/model/tests/test_domain.py
+++ b/src/mailman/model/tests/test_domain.py
@@ -81,18 +81,14 @@ class TestDomainManager(unittest.TestCase):
self.assertRaises(KeyError, self._manager.remove, 'doesnotexist.com')
def test_domain_create_with_owner(self):
- user = getUtility(IUserManager).create_user('someuser@somedomain.org')
+ user = getUtility(IUserManager).create_user('someuser@example.org')
config.db.commit()
- domain = self._manager.add('example.org', owner_id=user.id)
+ domain = self._manager.add('example.org', owner=user)
self.assertEqual(len(domain.owners), 1)
self.assertEqual(domain.owners[0].id, user.id)
- def test_domain_create_with_non_existent_owner(self):
- with self.assertRaises(BadDomainSpecificationError):
- self._manager.add('testdomain.org', owner_id=100)
-
def test_add_domain_owner(self):
- user = getUtility(IUserManager).create_user('someuser@somedomain.org')
+ user = getUtility(IUserManager).create_user('someuser@example.org')
config.db.commit()
domain = self._manager.add('example.org')
domain.add_owner(user)
@@ -102,7 +98,7 @@ class TestDomainManager(unittest.TestCase):
def test_remove_domain_owner(self):
user = getUtility(IUserManager).create_user('someuser@somedomain.org')
config.db.commit()
- domain = self._manager.add('example.org', owner_id=user.id)
+ domain = self._manager.add('example.org', owner=user)
domain.remove_owner(user)
self.assertEqual(len(domain.owners), 0)
@@ -140,5 +136,4 @@ class TestDomainLifecycleEvents(unittest.TestCase):
self.assertEqual(listmanager.get('fly@example.com'), fly)
def test_owners_are_deleted_when_domain_is(self):
- #TODO: Complete this
- pass
+ self._domainmanager.remove('example.net')
diff --git a/src/mailman/model/user.py b/src/mailman/model/user.py
index b75a3f077..a8bc556cd 100644
--- a/src/mailman/model/user.py
+++ b/src/mailman/model/user.py
@@ -179,9 +179,9 @@ class User(Model):
return Memberships(self)
-class Owner(Model):
- """Doomain to owners(user) association class"""
+class DomainOwner(Model):
+ """Domain to owners(user) association class"""
- __tablename__ = 'owner'
+ __tablename__ = 'domain_owner'
user_id = Column(Integer, ForeignKey('user.id'), primary_key=True)
domain_id = Column(Integer, ForeignKey('domain.id'), primary_key=True)
diff --git a/src/mailman/rest/domains.py b/src/mailman/rest/domains.py
index d312737df..2f41ecfd9 100644
--- a/src/mailman/rest/domains.py
+++ b/src/mailman/rest/domains.py
@@ -110,9 +110,9 @@ class AllDomains(_DomainBase):
validator = Validator(mail_host=str,
description=str,
base_url=str,
- owner_id=int,
+ owner=int,
_optional=('description', 'base_url',
- 'owner_id'))
+ 'owner'))
domain = domain_manager.add(**validator(request))
except BadDomainSpecificationError as error:
bad_request(response, str(error))
diff --git a/src/mailman/rest/tests/test_domains.py b/src/mailman/rest/tests/test_domains.py
index bf53c8e70..9ebc0c0d8 100644
--- a/src/mailman/rest/tests/test_domains.py
+++ b/src/mailman/rest/tests/test_domains.py
@@ -41,6 +41,11 @@ class TestDomains(unittest.TestCase):
with transaction():
self._mlist = create_list('test@example.com')
+ def test_create_domain(self):
+ """Create domain via REST"""
+ # TODO: Complete this
+ # Tests should be failing with improper REST API.
+
def test_bogus_endpoint_extension(self):
# /domains/<domain>/lists/<anything> is not a valid endpoint.
with self.assertRaises(HTTPError) as cm: