diff options
| author | Abhilash Raj | 2015-04-06 03:58:22 +0530 |
|---|---|---|
| committer | Abhilash Raj | 2015-04-06 03:58:22 +0530 |
| commit | 17fa7ac10ddd6ca0916cdcdd3a5e8c1414e9bcbc (patch) | |
| tree | 8d69d19d1c47ef4ba76d75140ef5706223f6cc6b /src/mailman/model | |
| parent | fe12351e6f0e11f48bd714357f05aa7a34ec7e90 (diff) | |
| download | mailman-17fa7ac10ddd6ca0916cdcdd3a5e8c1414e9bcbc.tar.gz mailman-17fa7ac10ddd6ca0916cdcdd3a5e8c1414e9bcbc.tar.zst mailman-17fa7ac10ddd6ca0916cdcdd3a5e8c1414e9bcbc.zip | |
* implement left over methods
* add and remove owners using the address
Diffstat (limited to 'src/mailman/model')
| -rw-r--r-- | src/mailman/model/docs/domains.rst | 10 | ||||
| -rw-r--r-- | src/mailman/model/domain.py | 32 | ||||
| -rw-r--r-- | src/mailman/model/tests/test_domain.py | 25 | ||||
| -rw-r--r-- | src/mailman/model/user.py | 1 |
4 files changed, 36 insertions, 32 deletions
diff --git a/src/mailman/model/docs/domains.rst b/src/mailman/model/docs/domains.rst index dd0904f2b..ded52f817 100644 --- a/src/mailman/model/docs/domains.rst +++ b/src/mailman/model/docs/domains.rst @@ -58,7 +58,7 @@ Domains can have explicit descriptions. ... 'example.net', ... base_url='http://lists.example.net', ... description='The example domain', - ... owner=user) + ... owners=['user@domain.com']) <Domain example.net, The example domain, base_url: http://lists.example.net> @@ -67,13 +67,13 @@ Domains can have explicit descriptions. <Domain example.net, The example domain, base_url: http://lists.example.net> -Domains can have multiple number of owners, ideally one of the owners -should have a verified preferred address. However this is not checked -right now and contact_address from config is used as a fallback. +Domains can have multiple owners, ideally one of the owners should have a +verified preferred address. However this is not checked right now and +contact_address from config can be used as a fallback. :: >>> net_domain = manager['example.net'] - >>> net_domain.add_owner(user_manager.get_user('test@example.org')) + >>> net_domain.add_owner('test@example.org') Domains can list all associated mailing lists with the mailing_lists property. diff --git a/src/mailman/model/domain.py b/src/mailman/model/domain.py index 6809688d6..32ea7db9b 100644 --- a/src/mailman/model/domain.py +++ b/src/mailman/model/domain.py @@ -28,6 +28,7 @@ from mailman.database.transaction import dbconnection from mailman.interfaces.domain import ( BadDomainSpecificationError, DomainCreatedEvent, DomainCreatingEvent, DomainDeletedEvent, DomainDeletingEvent, IDomain, IDomainManager) +from mailman.interfaces.usermanager import IUserManager from mailman.model.mailinglist import MailingList from mailman.model.user import User, DomainOwner from urllib.parse import urljoin, urlparse @@ -35,6 +36,7 @@ from sqlalchemy import Column, Integer, Unicode from sqlalchemy.orm import relationship, backref from zope.event import notify from zope.interface import implementer +from zope.component import getUtility @@ -46,7 +48,7 @@ class Domain(Model): id = Column(Integer, primary_key=True) - mail_host = Column(Unicode) # TODO: add index? + mail_host = Column(Unicode) base_url = Column(Unicode) description = Column(Unicode) owners = relationship("User", @@ -56,7 +58,7 @@ class Domain(Model): def __init__(self, mail_host, description=None, base_url=None, - owner=None): + owners=[]): """Create and register a domain. :param mail_host: The host name for the email interface. @@ -67,16 +69,16 @@ class Domain(Model): scheme. If not given, it will be constructed from the `mail_host` using the http protocol. :type base_url: string - :param owner: The `User` who is the owner of this domain - :type owner: `IUser` + :param owners: List of `User` who are the owners of this domain + :type owners: list """ self.mail_host = mail_host self.base_url = (base_url if base_url is not None else 'http://' + mail_host) self.description = description - if owner is not None: - self.owners.append(owner) + if len(owners): + self.add_owners(owners) @property def url_host(self): @@ -112,16 +114,22 @@ class Domain(Model): def add_owner(self, owner): """Add a domain owner""" - self.owners.append(owner) + user_manager = getUtility(IUserManager) + user = user_manager.get_user(owner) + if user is None: + user = user_manager.create_user(owner) + self.owners.append(user) def add_owners(self, owners): """Add multiple owners""" - for each in owners: - self.owners.append(each) + assert(isinstance(owners, list)) + for owner in owners: + self.add_owner(owner) def remove_owner(self, owner): """ Remove a domain owner""" - self.owners.remove(owner) + user_manager = getUtility(IUserManager) + self.owners.remove(user_manager.get_user(owner)) @implementer(IDomainManager) @@ -133,7 +141,7 @@ class DomainManager: mail_host, description=None, base_url=None, - owner=None): + owners=[]): """See `IDomainManager`.""" # Be sure the mail_host is not already registered. This is probably # a constraint that should (also) be maintained in the database. @@ -142,7 +150,7 @@ class DomainManager: 'Duplicate email host: %s' % mail_host) notify(DomainCreatingEvent(mail_host)) - domain = Domain(mail_host, description, base_url, owner) + domain = Domain(mail_host, description, base_url, owners) store.add(domain) notify(DomainCreatedEvent(domain)) return domain diff --git a/src/mailman/model/tests/test_domain.py b/src/mailman/model/tests/test_domain.py index 950c34969..8223aa00b 100644 --- a/src/mailman/model/tests/test_domain.py +++ b/src/mailman/model/tests/test_domain.py @@ -81,25 +81,23 @@ 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@example.org') - config.db.commit() - domain = self._manager.add('example.org', owner=user) + domain = self._manager.add('example.org', + owners=['someuser@example.org']) self.assertEqual(len(domain.owners), 1) - self.assertEqual(domain.owners[0].id, user.id) + self.assertEqual(domain.owners[0].addresses[0].email, + 'someuser@example.org') def test_add_domain_owner(self): - user = getUtility(IUserManager).create_user('someuser@example.org') - config.db.commit() domain = self._manager.add('example.org') - domain.add_owner(user) + domain.add_owner('someuser@example.org') self.assertEqual(len(domain.owners), 1) - self.assertEqual(domain.owners[0].id, user.id) + self.assertEqual(domain.owners[0].addresses[0].email, + 'someuser@example.org') def test_remove_domain_owner(self): - user = getUtility(IUserManager).create_user('someuser@somedomain.org') - config.db.commit() - domain = self._manager.add('example.org', owner=user) - domain.remove_owner(user) + domain = self._manager.add('example.org', + owners=['someuser@example.org']) + domain.remove_owner('someuser@example.org') self.assertEqual(len(domain.owners), 0) @@ -134,6 +132,3 @@ class TestDomainLifecycleEvents(unittest.TestCase): self.assertEqual(listmanager.get('dog@example.org'), None) self.assertEqual(listmanager.get('ewe@example.com'), ewe) self.assertEqual(listmanager.get('fly@example.com'), fly) - - def test_owners_are_deleted_when_domain_is(self): - self._domainmanager.remove('example.net') diff --git a/src/mailman/model/user.py b/src/mailman/model/user.py index a8bc556cd..5fecc1836 100644 --- a/src/mailman/model/user.py +++ b/src/mailman/model/user.py @@ -19,6 +19,7 @@ __all__ = [ 'User', + 'DomainOwner' ] |
