summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mailman/docs/NEWS.rst2
-rw-r--r--src/mailman/interfaces/pending.py18
-rw-r--r--src/mailman/model/pending.py7
-rw-r--r--src/mailman/model/requests.py4
-rw-r--r--src/mailman/model/tests/test_listmanager.py16
5 files changed, 30 insertions, 17 deletions
diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst
index d8b8bb75f..0259d967d 100644
--- a/src/mailman/docs/NEWS.rst
+++ b/src/mailman/docs/NEWS.rst
@@ -101,6 +101,8 @@ Bugs
``reason`` attribute. Given by Aurélien Bompard.
* Don't return a 500 error from the REST API when trying to handle a held
message with defective content. Given by Abhilash Raj. (Closes: #256)
+ * Delete subscription requests when a mailing list is deleted. Given by
+ Abhilash Raj. (Closes: #214)
Configuration
-------------
diff --git a/src/mailman/interfaces/pending.py b/src/mailman/interfaces/pending.py
index 841d195f5..aef18bcb4 100644
--- a/src/mailman/interfaces/pending.py
+++ b/src/mailman/interfaces/pending.py
@@ -96,14 +96,20 @@ class IPendings(Interface):
def evict():
"""Remove all pended items whose lifetime has expired."""
- def find(mlist=None, pend_type=None):
+ def find(mlist=None, pend_type=None, confirm=True):
"""Search for the pendables matching the given criteria.
- :param mlist: The MailingList object that the pendables must be
- related to.
- :param pend_type: The type of the pendables that are looked for, this
- corresponds to the `PEND_TYPE` attribute.
- :return: An iterator over 2-tuples of the form (token, dict).
+ :param mlist: The mailing list object that the pendables must be
+ related to, or None. The default returns all pendables regardless
+ of which mailing list they are related to.
+ :type mlist: IMailingList or None.
+ :param pend_type: The type of the pendables that are looked for, or
+ None. This corresponds to the `PEND_TYPE` attribute. The default
+ returns all pending types.
+ :param confirm: A flag indicating whether the found pendings should be
+ "confirmed" or not. See ``confirm()`` for details.
+ :return: An iterator over 2-tuples of the form (token, pendable).
+ When ``confirm`` is False, ``pendable`` is None.
"""
def __iter__():
diff --git a/src/mailman/model/pending.py b/src/mailman/model/pending.py
index 023baf8de..5e5a2af83 100644
--- a/src/mailman/model/pending.py
+++ b/src/mailman/model/pending.py
@@ -166,10 +166,9 @@ class Pendings:
pkv_alias_type.value == pend_type
))
for pending in query:
- if confirm:
- yield pending.token, self.confirm(pending.token, expunge=False)
- else:
- yield pending.token
+ pendable = (self.confirm(pending.token, expunge=False)
+ if confirm else None)
+ yield pending.token, pendable
@dbconnection
def __iter__(self, store):
diff --git a/src/mailman/model/requests.py b/src/mailman/model/requests.py
index 0c164172d..90d1c686c 100644
--- a/src/mailman/model/requests.py
+++ b/src/mailman/model/requests.py
@@ -142,10 +142,10 @@ class ListRequests:
@dbconnection
def clear(self, store):
- for pended_token in getUtility(IPendings).find(
+ for token, pendable in getUtility(IPendings).find(
mlist=self.mailing_list,
confirm=False):
- pended = store.query(Pended).filter_by(token=pended_token).first()
+ pended = store.query(Pended).filter_by(token=token).first()
store.query(PendedKeyValue).filter_by(pended_id=pended.id).delete()
store.delete(pended)
diff --git a/src/mailman/model/tests/test_listmanager.py b/src/mailman/model/tests/test_listmanager.py
index cdd13ced3..da65f88ce 100644
--- a/src/mailman/model/tests/test_listmanager.py
+++ b/src/mailman/model/tests/test_listmanager.py
@@ -199,13 +199,19 @@ Message-ID: <argon>
def test_pendings_are_deleted_when_mailing_list_is_deleted(self):
pendingdb = getUtility(IPendings)
- test1_list = create_list('test@example.com')
- subscription_1 = SimplePendable(
+ pendable_1 = SimplePendable(
type='subscription',
- list_id='test.example.com')
- pendingdb.add(subscription_1)
+ list_id='ant.example.com')
+ pendingdb.add(pendable_1)
+ pendable_2 = SimplePendable(
+ type='subscription',
+ list_id='bee.example.com')
+ pendingdb.add(pendable_2)
+ self.assertEqual(pendingdb.count, 2)
+ list_manager = getUtility(IListManager)
+ list_manager.delete(self._ant)
self.assertEqual(pendingdb.count, 1)
- getUtility(IListManager).delete(test1_list)
+ list_manager.delete(self._bee)
self.assertEqual(pendingdb.count, 0)