[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mailman-cvs
Subject:    [Mailman-checkins] [Git][mailman/mailman][master] 2 commits: Delete bans when their associated list 
From:       Barry Warsaw <gitlab () mg ! gitlab ! com>
Date:       2016-01-14 22:28:35
Message-ID: 569821138a01f_afe32028cb0980da () worker2 ! cluster ! gitlab ! com ! mail
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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('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(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('bart@example.com')
+        getUtility(IListManager).delete(self._mlist)
+        self.assertEqual([ban.email for ban in global_ban_manager],
+                         ['bart@example.com'])



View it on GitLab: https://gitlab.com/mailman/mailman/compare/6f0b236ea33ffe2899e813dc9bcbc58da0cbefee...29ad7d4a658081a442c6cb120943f7014d36dade



[Attachment #5 (text/html)]

<html lang='en'>
<head>
<meta content='text/html; charset=utf-8' http-equiv='Content-Type'>
<title>
GitLab
</title>
</meta>
</head>
<style>
  img {
    max-width: 100%;
    height: auto;
  }
  p.details {
    font-style:italic;
    color:#777
  }
  .footer p {
    font-size:small;
    color:#777
  }
  pre.commit-message {
    white-space: pre-wrap;
  }
  .file-stats a {
    text-decoration: none;
  }
  .file-stats .new-file {
    color: #090;
  }
  .file-stats .deleted-file {
    color: #B00;
  }
</style>
<body>
<div class='content'>
<h3>
Barry Warsaw pushed to branch master
at <a href="https://gitlab.com/mailman/mailman">mailman / Mailman</a>
</h3>
<h4>
Commits:
</h4>
<ul>
<li>
<strong><a href="https://gitlab.com/mailman/mailman/commit/08d8cae4f79bdf0a0773efdd2f795411f280cd1e">08d8cae4</a></strong>
 <div>
<span>by Aurélien Bompard</span>
<i>at 2016-01-14T16:41:32+01:00</i>
</div>
<pre class='commit-message'>Delete bans when their associated list is deleted

Also add indexes on the Ban fields that are filtered on.</pre>
</li>
<li>
<strong><a href="https://gitlab.com/mailman/mailman/commit/29ad7d4a658081a442c6cb120943f7014d36dade">29ad7d4a</a></strong>
 <div>
<span>by Barry Warsaw</span>
<i>at 2016-01-14T17:27:11-05:00</i>
</div>
<pre class='commit-message'>Branch tweaks:

- Fix an interface description.
- Fix a copyright year.
- Fix quote styles.
- Tweak a test.
- Add a test.</pre>
</li>
</ul>
<h4>5 changed files:</h4>
<ul>
<li class='file-stats'>
<a href='#diff-0'>
<span class='new-file'>
&#43;
src/mailman/database/alembic/versions/bfda02ab3a9b_ban_indexes.py
</span>
</a>
</li>
<li class='file-stats'>
<a href='#diff-1'>
src/mailman/interfaces/bans.py
</a>
</li>
<li class='file-stats'>
<a href='#diff-2'>
src/mailman/model/bans.py
</a>
</li>
<li class='file-stats'>
<a href='#diff-3'>
src/mailman/model/listmanager.py
</a>
</li>
<li class='file-stats'>
<a href='#diff-4'>
<span class='new-file'>
&#43;
src/mailman/model/tests/test_bans.py
</span>
</a>
</li>
</ul>
<h4>Changes:</h4>
<li id='diff-0'>
<a href='https://gitlab.com/mailman/mailman/compare/6f0b236ea33ffe2899e813dc9bcbc58da0cbefee...29ad7d4a658081a442c6cb120943f7014d36dade#diff-0'>
 <strong>
src/mailman/database/alembic/versions/bfda02ab3a9b_ban_indexes.py
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: \
#ffdddd">--- /dev/null </span><span style="color: #000000;background-color: \
#ddffdd">+++ b/src/mailman/database/alembic/versions/bfda02ab3a9b_ban_indexes.py \
</span><span style="color: #aaaaaa">@@ -0,0 +1,23 @@ </span><span style="color: \
#000000;background-color: #ddffdd">+"""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')
</span></code></pre>

<br>
</li>
<li id='diff-1'>
<a href='https://gitlab.com/mailman/mailman/compare/6f0b236ea33ffe2899e813dc9bcbc58da0cbefee...29ad7d4a658081a442c6cb120943f7014d36dade#diff-1'>
 <strong>
src/mailman/interfaces/bans.py
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: \
#ffdddd">--- a/src/mailman/interfaces/bans.py </span><span style="color: \
#000000;background-color: #ddffdd">+++ b/src/mailman/interfaces/bans.py </span><span \
style="color: #aaaaaa">@@ -102,5 +102,5 @@ class IBanManager(Interface): </span>      \
"""Iterate over all banned addresses.  
         :return: The list of all banned addresses.
<span style="color: #000000;background-color: #ffdddd">-        :rtype: list of `str`
</span><span style="color: #000000;background-color: #ddffdd">+        :rtype: list \
of `IBan` </span>         """
</code></pre>

<br>
</li>
<li id='diff-2'>
<a href='https://gitlab.com/mailman/mailman/compare/6f0b236ea33ffe2899e813dc9bcbc58da0cbefee...29ad7d4a658081a442c6cb120943f7014d36dade#diff-2'>
 <strong>
src/mailman/model/bans.py
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: \
#ffdddd">--- a/src/mailman/model/bans.py </span><span style="color: \
#000000;background-color: #ddffdd">+++ b/src/mailman/model/bans.py </span><span \
style="color: #aaaaaa">@@ -39,8 +39,8 @@ class Ban(Model): </span>     __tablename__ \
= 'ban'  
     id = Column(Integer, primary_key=True)
<span style="color: #000000;background-color: #ffdddd">-    email = Column(Unicode)
-    list_id = Column(Unicode)
</span><span style="color: #000000;background-color: #ddffdd">+    email = \
Column(Unicode, index=True) +    list_id = Column(Unicode, index=True)
</span> 
     def __init__(self, email, list_id):
         super(Ban, self).__init__()
</code></pre>

<br>
</li>
<li id='diff-3'>
<a href='https://gitlab.com/mailman/mailman/compare/6f0b236ea33ffe2899e813dc9bcbc58da0cbefee...29ad7d4a658081a442c6cb120943f7014d36dade#diff-3'>
 <strong>
src/mailman/model/listmanager.py
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: \
#ffdddd">--- a/src/mailman/model/listmanager.py </span><span style="color: \
#000000;background-color: #ddffdd">+++ b/src/mailman/model/listmanager.py \
</span><span style="color: #aaaaaa">@@ -28,6 +28,7 @@ from \
mailman.interfaces.listmanager import ( </span>     IListManager, \
ListAlreadyExistsError, ListCreatedEvent, ListCreatingEvent,  ListDeletedEvent, \
ListDeletingEvent)  from mailman.model.autorespond import AutoResponseRecord
<span style="color: #000000;background-color: #ddffdd">+from mailman.model.bans \
import Ban </span> from mailman.model.mailinglist import (
     IAcceptableAliasSet, ListArchiver, MailingList)
 from mailman.model.mime import ContentFilter
<span style="color: #aaaaaa">@@ -81,6 +82,7 @@ class ListManager:
</span>         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()
<span style="color: #000000;background-color: #ddffdd">+        \
store.query(Ban).filter_by(list_id=mlist.list_id).delete() </span>         \
store.delete(mlist)  notify(ListDeletedEvent(fqdn_listname))
 
</code></pre>

<br>
</li>
<li id='diff-4'>
<a href='https://gitlab.com/mailman/mailman/compare/6f0b236ea33ffe2899e813dc9bcbc58da0cbefee...29ad7d4a658081a442c6cb120943f7014d36dade#diff-4'>
 <strong>
src/mailman/model/tests/test_bans.py
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: \
#ffdddd">--- /dev/null </span><span style="color: #000000;background-color: \
#ddffdd">+++ b/src/mailman/model/tests/test_bans.py </span><span style="color: \
#aaaaaa">@@ -0,0 +1,54 @@ </span><span style="color: #000000;background-color: \
#ddffdd">+# 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 &lt;http://www.gnu.org/licenses/&gt;.
+
+"""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(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('bart@example.com')
+        getUtility(IListManager).delete(self._mlist)
+        self.assertEqual([ban.email for ban in global_ban_manager],
+                         ['bart@example.com'])
</span></code></pre>

<br>
</li>

</div>
<div class='footer' style='margin-top: 10px;'>
<p>
&mdash;
<br>
<a href="https://gitlab.com/mailman/mailman/compare/6f0b236ea33ffe2899e813dc9bcbc58da0cbefee...29ad7d4a658081a442c6cb120943f7014d36dade">View \
it on GitLab</a>. <br>
You're receiving this email because of your account on gitlab.com.
If you'd like to receive fewer emails, you can adjust your notification settings.

</p>
</div>
</body>
</html>



_______________________________________________
Mailman-checkins mailing list
Mailman-checkins@python.org
Unsubscribe: https://mail.python.org/mailman/options/mailman-checkins/mailman-cvs%40progressive-comp.com



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic