Barry Warsaw pushed to branch master at mailman / Mailman
Commits:
cecb66d2 by Aurélien Bompard at 2016-11-25T11:22:07-05:00
Transmit the moderation reason to hold_message()
The `reason` attribute of `hold_message()` was always None. Serialize
the moderation reasons list and pass it to the function.
This allows the `reason` attribute in REST to actually contain the
moderation reason. It was always blank before.
- - - - -
7142a0ea by Barry Warsaw at 2016-11-25T11:36:35-05:00
Minor cleanup and test added.
- - - - -
055082f2 by Barry Warsaw at 2016-11-25T11:37:27-05:00
Merge branch 'master' of gitlab.com:mailman/mailman
- - - - -
3 changed files:
- src/mailman/chains/hold.py
- src/mailman/chains/tests/test_hold.py
- src/mailman/docs/NEWS.rst
Changes:
=====================================
src/mailman/chains/hold.py
=====================================
--- a/src/mailman/chains/hold.py
+++ b/src/mailman/chains/hold.py
@@ -142,8 +142,9 @@ class HoldChain(TerminalChainBase):
rule_misses = msgdata.get('rule_misses')
if rule_misses:
msg['X-Mailman-Rule-Misses'] = SEMISPACE.join(rule_misses)
+ reasons = msgdata.get('moderation_reasons', ['n/a'])
# Hold the message by adding it to the list's request database.
- request_id = hold_message(mlist, msg, msgdata, None)
+ request_id = hold_message(mlist, msg, msgdata, SEMISPACE.join(reasons))
# Calculate a confirmation token to send to the author of the
# message.
pendable = HeldMessagePendable(id=request_id)
=====================================
src/mailman/chains/tests/test_hold.py
=====================================
--- a/src/mailman/chains/tests/test_hold.py
+++ b/src/mailman/chains/tests/test_hold.py
@@ -26,6 +26,7 @@ from mailman.core.chains import process as process_chain
from mailman.interfaces.autorespond import IAutoResponseSet, Response
from mailman.interfaces.member import MemberRole
from mailman.interfaces.messages import IMessageStore
+from mailman.interfaces.requests import IListRequests, RequestType
from mailman.interfaces.usermanager import IUserManager
from mailman.testing.helpers import (
LogFileMark, configuration, get_queue_messages, set_preferred,
@@ -130,6 +131,31 @@ A message body.
logged = logfile.read()
self.assertIn('TEST-REASON-1', logged)
self.assertIn('TEST-REASON-2', logged)
+ # Check the reason passed to hold_message().
+ requests = IListRequests(self._mlist)
+ self.assertEqual(requests.count_of(RequestType.held_message), 1)
+ request = requests.of_type(RequestType.held_message)[0]
+ key, data = requests.get_request(request.id)
+ self.assertEqual(
+ data.get('_mod_reason'), 'TEST-REASON-1; TEST-REASON-2')
+
+ def test_hold_chain_no_reasons_given(self):
+ msg = mfs("""\
+From: [email protected]
+To: [email protected]
+Subject: A message
+Message-ID: <ant>
+MIME-Version: 1.0
+
+A message body.
+""")
+ process_chain(self._mlist, msg, {}, start_chain='hold')
+ # No reason was given, so a default is used.
+ requests = IListRequests(self._mlist)
+ self.assertEqual(requests.count_of(RequestType.held_message), 1)
+ request = requests.of_type(RequestType.held_message)[0]
+ key, data = requests.get_request(request.id)
+ self.assertEqual(data.get('_mod_reason'), 'n/a')
def test_hold_chain_charset(self):
# Issue #144 - UnicodeEncodeError in the hold chain.
=====================================
src/mailman/docs/NEWS.rst
=====================================
--- a/src/mailman/docs/NEWS.rst
+++ b/src/mailman/docs/NEWS.rst
@@ -99,6 +99,8 @@ Bugs
Bompard. (Closes: #259)
* Messages sent to the list's moderators now include the actual recipient
addresses. Given by Tom Briles. (Closes: #68)
+ * Transmit the moderation reason and expose it in the REST API as the
+ ``reason`` attribute. Given by Aurélien Bompard.
Configuration
-------------
View it on GitLab:
https://gitlab.com/mailman/mailman/compare/1677387fae8d62fc930c2c4f481c502e287cc743...055082f2694c84d5dd46ba194224b1b9f51f835f
_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe:
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org