Barry Warsaw pushed to branch master at mailman / Mailman

Commits:
08d8cae4 by Aurélien Bompard at 2016-01-14T16:41:32+01:00
Delete bans when their associated list is deleted

Also add indexes on the Ban fields that are filtered on.

- - - - -
29ad7d4a by Barry Warsaw at 2016-01-14T17:27:11-05:00
Branch tweaks:

- Fix an interface description.
- Fix a copyright year.
- Fix quote styles.
- Tweak a test.
- Add a test.

- - - - -


5 changed files:

- + src/mailman/database/alembic/versions/bfda02ab3a9b_ban_indexes.py
- src/mailman/interfaces/bans.py
- src/mailman/model/bans.py
- src/mailman/model/listmanager.py
- + src/mailman/model/tests/test_bans.py


Changes:

=====================================
src/mailman/database/alembic/versions/bfda02ab3a9b_ban_indexes.py
=====================================
--- /dev/null
+++ b/src/mailman/database/alembic/versions/bfda02ab3a9b_ban_indexes.py
@@ -0,0 +1,23 @@
+"""Ban indexes
+
+Revision ID: bfda02ab3a9b
+Revises: 70af5a4e5790
+Create Date: 2016-01-14 16:15:44.059688
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = 'bfda02ab3a9b'
+down_revision = '781a38e146bf'
+
+from alembic import op
+
+
+def upgrade():
+    op.create_index(op.f('ix_ban_email'), 'ban', ['email'], unique=False)
+    op.create_index(op.f('ix_ban_list_id'), 'ban', ['list_id'], unique=False)
+
+
+def downgrade():
+    op.drop_index(op.f('ix_ban_list_id'), table_name='ban')
+    op.drop_index(op.f('ix_ban_email'), table_name='ban')


=====================================
src/mailman/interfaces/bans.py
=====================================
--- a/src/mailman/interfaces/bans.py
+++ b/src/mailman/interfaces/bans.py
@@ -102,5 +102,5 @@ class IBanManager(Interface):
         """Iterate over all banned addresses.
 
         :return: The list of all banned addresses.
-        :rtype: list of `str`
+        :rtype: list of `IBan`
         """


=====================================
src/mailman/model/bans.py
=====================================
--- a/src/mailman/model/bans.py
+++ b/src/mailman/model/bans.py
@@ -39,8 +39,8 @@ class Ban(Model):
     __tablename__ = 'ban'
 
     id = Column(Integer, primary_key=True)
-    email = Column(Unicode)
-    list_id = Column(Unicode)
+    email = Column(Unicode, index=True)
+    list_id = Column(Unicode, index=True)
 
     def __init__(self, email, list_id):
         super(Ban, self).__init__()


=====================================
src/mailman/model/listmanager.py
=====================================
--- a/src/mailman/model/listmanager.py
+++ b/src/mailman/model/listmanager.py
@@ -28,6 +28,7 @@ from mailman.interfaces.listmanager import (
     IListManager, ListAlreadyExistsError, ListCreatedEvent, ListCreatingEvent,
     ListDeletedEvent, ListDeletingEvent)
 from mailman.model.autorespond import AutoResponseRecord
+from mailman.model.bans import Ban
 from mailman.model.mailinglist import (
     IAcceptableAliasSet, ListArchiver, MailingList)
 from mailman.model.mime import ContentFilter
@@ -81,6 +82,7 @@ class ListManager:
         store.query(AutoResponseRecord).filter_by(mailing_list=mlist).delete()
         store.query(ContentFilter).filter_by(mailing_list=mlist).delete()
         store.query(ListArchiver).filter_by(mailing_list=mlist).delete()
+        store.query(Ban).filter_by(list_id=mlist.list_id).delete()
         store.delete(mlist)
         notify(ListDeletedEvent(fqdn_listname))
 


=====================================
src/mailman/model/tests/test_bans.py
=====================================
--- /dev/null
+++ b/src/mailman/model/tests/test_bans.py
@@ -0,0 +1,54 @@
+# Copyright (C) 2016 by the Free Software Foundation, Inc.
+#
+# This file is part of GNU Mailman.
+#
+# GNU Mailman is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+#
+# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# GNU Mailman.  If not, see <http://www.gnu.org/licenses/>.
+
+"""Test Bans and the ban manager."""
+
+__all__ = [
+    'TestMailingListBans',
+    ]
+
+
+import unittest
+
+from mailman.app.lifecycle import create_list
+from mailman.interfaces.bans import IBanManager
+from mailman.interfaces.listmanager import IListManager
+from mailman.testing.layers import ConfigLayer
+from zope.component import getUtility
+
+
+
+class TestMailingListBans(unittest.TestCase):
+    layer = ConfigLayer
+
+    def setUp(self):
+        self._mlist = create_list('a...@example.com')
+        self._manager = IBanManager(self._mlist)
+
+    def test_delete_list(self):
+        # All list bans must be deleted when the list is deleted.
+        self._manager.ban('a...@example.com')
+        getUtility(IListManager).delete(self._mlist)
+        self.assertEqual(list(self._manager), [])
+
+    def test_delete_list_does_not_delete_global_bans(self):
+        # Global bans are not deleted when the list is deleted.
+        global_ban_manager = IBanManager(None)
+        global_ban_manager.ban('b...@example.com')
+        getUtility(IListManager).delete(self._mlist)
+        self.assertEqual([ban.email for ban in global_ban_manager],
+                         ['b...@example.com'])



View it on GitLab: 
https://gitlab.com/mailman/mailman/compare/6f0b236ea33ffe2899e813dc9bcbc58da0cbefee...29ad7d4a658081a442c6cb120943f7014d36dade
_______________________________________________
Mailman-checkins mailing list
Mailman-checkins@python.org
Unsubscribe: 
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to