Abhilash Raj pushed to branch master at GNU Mailman / Mailman Core
Commits:
61b323a4 by Abhilash Raj at 2020-12-16T12:14:59+00:00
Add support to specify rejection reason for subscription request.
Closes #767
- - - - -
b14f7290 by Abhilash Raj at 2020-12-16T12:14:59+00:00
Merge branch 'sub-mod-reason' into 'master'
Add support to specify rejection reason for subscription request.
Closes #767
See merge request mailman/mailman!747
- - - - -
4 changed files:
- src/mailman/docs/NEWS.rst
- src/mailman/rest/docs/sub-moderation.rst
- src/mailman/rest/sub_moderation.py
- src/mailman/rest/tests/test_moderation.py
Changes:
=====================================
src/mailman/docs/NEWS.rst
=====================================
@@ -42,6 +42,8 @@ REST
* List configuration option ``send_goodbye_message`` is now exposed through
the REST API. (See !737)
* Allow updating an Addresses' display_name attribute. (Closes #786)
+* Allow specifying a reason when rejecting a subscription request. (Closes
+ #767)
3.3.2
=====
=====================================
src/mailman/rest/docs/sub-moderation.rst
=====================================
@@ -110,3 +110,57 @@ There are no more membership change requests.
http_etag: "..."
start: 0
total_size: 0
+
+
+.. >>> # Clear the virgin queue.
+ >>> from mailman.testing.helpers import get_queue_messages
+ >>> items = get_queue_messages('virgin')
+
+When rejecting subscription requests, an optional reason can be specified. When
+Bart tries to subscribe to Ant mailing list, the request is held for moderator
+approval::
+
+ >>> dump_json('http://localhost:9001/3.0/members', {
+ ... 'list_id': 'ant.example.com',
+ ... 'subscriber': '[email protected]',
+ ... 'display_name': 'Bart Person',
+ ... 'pre_verified': True,
+ ... 'pre_confirmed': True,
+ ... })
+ http_etag: ...
+ token: 0000000000000000000000000000000000000002
+ token_owner: moderator
+
+
+The moderator can then reject the request stating the reason for rejection::
+
+ >>> dump_json('http://localhost:9001/3.0/lists/ant.example.com/requests'
+ ... '/0000000000000000000000000000000000000002',
+ ... {'action': 'reject', 'reason': 'This is a private list'})
+ date: ...
+ server: ...
+ status: 204
+
+This will send an email to Bart with the rejection reason::
+
+ >>> from mailman.testing.helpers import get_queue_messages
+ >>> items = get_queue_messages('virgin')
+ >>> message = items[0].msg
+ >>> print(message.as_string())
+ MIME-Version: 1.0
+ ...
+ <BLANKLINE>
+ Your request to the [email protected] mailing list
+ <BLANKLINE>
+ Subscription request
+ <BLANKLINE>
+ has been rejected by the list moderator. The moderator gave the
+ following reason for rejecting your request:
+ <BLANKLINE>
+ "This is a private list"
+ <BLANKLINE>
+ Any questions or comments should be directed to the list administrator
+ at:
+ <BLANKLINE>
+ [email protected]
+ <BLANKLINE>
=====================================
src/mailman/rest/sub_moderation.py
=====================================
@@ -70,7 +70,9 @@ class IndividualRequest(_ModerationBase):
def on_post(self, request, response):
try:
- validator = Validator(action=enum_validator(Action))
+ validator = Validator(action=enum_validator(Action),
+ reason=str,
+ _optional=('reason',))
arguments = validator(request)
except ValueError as error:
bad_request(response, str(error))
@@ -107,10 +109,10 @@ class IndividualRequest(_ModerationBase):
not_found(response)
else:
no_content(response)
+ reason = arguments.get('reason', _('[No reason given]'))
send_rejection(
self._mlist, _('Subscription request'),
- pendable['email'],
- _('[No reason given]'))
+ pendable['email'], reason)
class _SubscriptionRequestsFound(_ModerationBase, CollectionMixin):
=====================================
src/mailman/rest/tests/test_moderation.py
=====================================
@@ -502,6 +502,33 @@ class TestSubscriptionModeration(unittest.TestCase):
dict(action='reject'))
self.assertEqual(cm.exception.code, 404)
+ def test_reject_with_reason(self):
+ # Try to reject a request with an additional comment/reason.
+ # POST to the request to reject it. This leaves a bounce message in
+ # the virgin queue.
+ with transaction():
+ token, token_owner, member = self._registrar.register(self._anne)
+ # Anne's subscription request got held.
+ self.assertIsNone(member)
+ # Clear out the virgin queue, which currently contains the
+ # confirmation message sent to Anne.
+ get_queue_messages('virgin')
+ url = 'http://localhost:9001/3.0/lists/[email protected]/requests/{}'
+ reason = 'You are not authorized!'
+ json, response = call_api(url.format(token), dict(
+ action='reject',
+ reason=reason))
+ self.assertEqual(response.status_code, 204)
+ # And the rejection message to Anne is now in the virgin queue.
+ items = get_queue_messages('virgin')
+ self.assertEqual(len(items), 1)
+ message = items[0].msg
+ self.assertEqual(message['From'], '[email protected]')
+ self.assertEqual(message['To'], '[email protected]')
+ self.assertEqual(message['Subject'],
+ 'Request to mailing list "Ant" rejected')
+ self.assertTrue(reason in message.as_string())
+
def test_hold_keeps_holding(self):
# POST to the request to continue holding it.
with transaction():
View it on GitLab:
https://gitlab.com/mailman/mailman/-/compare/551f6facd65d99bdff3591b50442a889e92dee5e...b14f729023a7ed267cb54db68e5092dbaeab1d98
--
View it on GitLab:
https://gitlab.com/mailman/mailman/-/compare/551f6facd65d99bdff3591b50442a889e92dee5e...b14f729023a7ed267cb54db68e5092dbaeab1d98
You're receiving this email because of your account on gitlab.com.
_______________________________________________
Mailman-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/mailman-checkins.python.org/
Member address: [email protected]