diff options
| author | Aurélien Bompard | 2016-01-14 16:16:32 +0100 |
|---|---|---|
| committer | Aurélien Bompard | 2016-01-14 16:41:32 +0100 |
| commit | 08d8cae4f79bdf0a0773efdd2f795411f280cd1e (patch) | |
| tree | feedf33bb16d9634cde36a1c288bfac4f927ce72 | |
| parent | 6f0b236ea33ffe2899e813dc9bcbc58da0cbefee (diff) | |
| download | mailman-08d8cae4f79bdf0a0773efdd2f795411f280cd1e.tar.gz mailman-08d8cae4f79bdf0a0773efdd2f795411f280cd1e.tar.zst mailman-08d8cae4f79bdf0a0773efdd2f795411f280cd1e.zip | |
| -rw-r--r-- | src/mailman/database/alembic/versions/bfda02ab3a9b_ban_indexes.py | 23 | ||||
| -rw-r--r-- | src/mailman/model/bans.py | 4 | ||||
| -rw-r--r-- | src/mailman/model/listmanager.py | 2 | ||||
| -rw-r--r-- | src/mailman/model/tests/test_bans.py | 46 |
4 files changed, 73 insertions, 2 deletions
diff --git a/src/mailman/database/alembic/versions/bfda02ab3a9b_ban_indexes.py b/src/mailman/database/alembic/versions/bfda02ab3a9b_ban_indexes.py new file mode 100644 index 000000000..952b9eeaf --- /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') diff --git a/src/mailman/model/bans.py b/src/mailman/model/bans.py index 0a3259167..5894c1aef 100644 --- 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__() diff --git a/src/mailman/model/listmanager.py b/src/mailman/model/listmanager.py index c4135a8c7..45f91bb6a 100644 --- 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)) diff --git a/src/mailman/model/tests/test_bans.py b/src/mailman/model/tests/test_bans.py new file mode 100644 index 000000000..a7ff8ed4f --- /dev/null +++ b/src/mailman/model/tests/test_bans.py @@ -0,0 +1,46 @@ +# Copyright (C) 2013-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('ant@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("anne@example.com") + getUtility(IListManager).delete(self._mlist) + self.assertEqual(len(list(self._manager)), 0) |
