summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBarry Warsaw2015-03-24 22:43:42 -0400
committerBarry Warsaw2015-03-24 22:43:42 -0400
commit4372f2b9e56fac9c433c26470c444d4f29722de2 (patch)
treec276e8740f3f55aac309dfc4f6631967e041e793 /src
parent18b7980823d2f9d5b7b0f50596cc05e8efb845e8 (diff)
parent3f0b367751acf7ab5201c3961f2b75c2acb730dc (diff)
downloadmailman-4372f2b9e56fac9c433c26470c444d4f29722de2.tar.gz
mailman-4372f2b9e56fac9c433c26470c444d4f29722de2.tar.zst
mailman-4372f2b9e56fac9c433c26470c444d4f29722de2.zip
Diffstat (limited to 'src')
-rw-r--r--src/mailman/docs/NEWS.rst2
-rw-r--r--src/mailman/model/listmanager.py4
-rw-r--r--src/mailman/model/mailinglist.py3
-rw-r--r--src/mailman/model/tests/test_mailinglist.py24
-rw-r--r--src/mailman/rest/tests/test_lists.py16
5 files changed, 46 insertions, 3 deletions
diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst
index 1fda90a89..77c45375d 100644
--- a/src/mailman/docs/NEWS.rst
+++ b/src/mailman/docs/NEWS.rst
@@ -28,6 +28,8 @@ Bugs
by Manish Gill. (LP: #1166911)
* When deleting a user object, make sure their preferences are also deleted.
Given by Abhishek. (LP: #1418276)
+ * Be sure a mailing list's acceptable aliases are deleted when the mailing
+ list itself is deleted. (LP: #1432239)
Configuration
-------------
diff --git a/src/mailman/model/listmanager.py b/src/mailman/model/listmanager.py
index be0e153a3..8fc739543 100644
--- a/src/mailman/model/listmanager.py
+++ b/src/mailman/model/listmanager.py
@@ -27,7 +27,7 @@ from mailman.interfaces.address import InvalidEmailAddressError
from mailman.interfaces.listmanager import (
IListManager, ListAlreadyExistsError, ListCreatedEvent, ListCreatingEvent,
ListDeletedEvent, ListDeletingEvent)
-from mailman.model.mailinglist import MailingList
+from mailman.model.mailinglist import IAcceptableAliasSet, MailingList
from mailman.model.mime import ContentFilter
from mailman.utilities.datetime import now
from zope.event import notify
@@ -74,6 +74,8 @@ class ListManager:
"""See `IListManager`."""
fqdn_listname = mlist.fqdn_listname
notify(ListDeletingEvent(mlist))
+ # First delete information associated with the mailing list.
+ IAcceptableAliasSet(mlist).clear()
store.query(ContentFilter).filter_by(mailing_list=mlist).delete()
store.delete(mlist)
notify(ListDeletedEvent(fqdn_listname))
diff --git a/src/mailman/model/mailinglist.py b/src/mailman/model/mailinglist.py
index a204d54cd..f7ef04314 100644
--- a/src/mailman/model/mailinglist.py
+++ b/src/mailman/model/mailinglist.py
@@ -504,10 +504,11 @@ class AcceptableAlias(Model):
mailing_list_id = Column(
Integer, ForeignKey('mailinglist.id'),
index=True, nullable=False)
- mailing_list = relationship('MailingList', backref='acceptable_alias')
+ mailing_list = relationship('MailingList', backref='acceptablealias')
alias = Column(Unicode, index=True, nullable=False)
def __init__(self, mailing_list, alias):
+ super(AcceptableAlias, self).__init__()
self.mailing_list = mailing_list
self.alias = alias
diff --git a/src/mailman/model/tests/test_mailinglist.py b/src/mailman/model/tests/test_mailinglist.py
index 843918e5e..745096b4b 100644
--- a/src/mailman/model/tests/test_mailinglist.py
+++ b/src/mailman/model/tests/test_mailinglist.py
@@ -18,6 +18,7 @@
"""Test MailingLists and related model objects.."""
__all__ = [
+ 'TestAcceptableAliases',
'TestDisabledListArchiver',
'TestListArchiver',
'TestMailingList',
@@ -28,7 +29,10 @@ import unittest
from mailman.app.lifecycle import create_list
from mailman.config import config
-from mailman.interfaces.mailinglist import IListArchiverSet
+from mailman.database.transaction import transaction
+from mailman.interfaces.listmanager import IListManager
+from mailman.interfaces.mailinglist import (
+ IAcceptableAliasSet, IListArchiverSet)
from mailman.interfaces.member import (
AlreadySubscribedError, MemberRole, MissingPreferredAddressError)
from mailman.interfaces.usermanager import IUserManager
@@ -141,3 +145,21 @@ class TestDisabledListArchiver(unittest.TestCase):
archiver = archiver_set.get('prototype')
self.assertTrue(archiver.is_enabled)
config.pop('enable prototype')
+
+
+
+class TestAcceptableAliases(unittest.TestCase):
+ layer = ConfigLayer
+
+ def setUp(self):
+ self._mlist = create_list('ant@example.com')
+
+ def test_delete_list_with_acceptable_aliases(self):
+ # LP: #1432239 - deleting a mailing list with acceptable aliases
+ # causes a SQLAlchemy error. The aliases must be deleted first.
+ with transaction():
+ alias_set = IAcceptableAliasSet(self._mlist)
+ alias_set.add('bee@example.com')
+ self.assertEqual(['bee@example.com'], list(alias_set.aliases))
+ getUtility(IListManager).delete(self._mlist)
+ self.assertEqual(len(list(alias_set.aliases)), 0)
diff --git a/src/mailman/rest/tests/test_lists.py b/src/mailman/rest/tests/test_lists.py
index a365db969..8e89f423c 100644
--- a/src/mailman/rest/tests/test_lists.py
+++ b/src/mailman/rest/tests/test_lists.py
@@ -28,8 +28,12 @@ __all__ = [
import unittest
from mailman.app.lifecycle import create_list
+from mailman.config import config
from mailman.database.transaction import transaction
+from mailman.interfaces.listmanager import IListManager
+from mailman.interfaces.mailinglist import IAcceptableAliasSet
from mailman.interfaces.usermanager import IUserManager
+from mailman.model.mailinglist import AcceptableAlias
from mailman.testing.helpers import call_api
from mailman.testing.layers import RESTLayer
from urllib.error import HTTPError
@@ -176,6 +180,18 @@ class TestLists(unittest.TestCase):
self.assertEqual(member['email'], 'bart@example.com')
self.assertEqual(member['role'], 'member')
+ def test_delete_list_with_acceptable_aliases(self):
+ # LP: #1432239 - deleting a mailing list with acceptable aliases
+ # causes a SQLAlchemy error. The aliases must be deleted first.
+ with transaction():
+ alias_set = IAcceptableAliasSet(self._mlist)
+ alias_set.add('bee@example.com')
+ call_api('http://localhost:9001/3.0/lists/test.example.com',
+ method='DELETE')
+ # Neither the mailing list, nor the aliases are present.
+ self.assertIsNone(getUtility(IListManager).get('test@example.com'))
+ self.assertEqual(config.db.store.query(AcceptableAlias).count(), 0)
+
class TestListArchivers(unittest.TestCase):