Abhilash Raj pushed to branch master at GNU Mailman / Mailman Core
Commits: 57847bfc by Abhilash Raj at 2020-05-12T15:52:13-07:00 Add an API endpoint to get a count of held messages for a ML. - - - - - ce337843 by Abhilash Raj at 2020-05-12T23:55:18+00:00 Merge branch 'held-count' into 'master' Add an API endpoint to get a count of held messages for a ML. See merge request mailman/mailman!639 - - - - - 4 changed files: - src/mailman/docs/NEWS.rst - src/mailman/rest/docs/post-moderation.rst - src/mailman/rest/post_moderation.py - src/mailman/rest/tests/test_moderation.py Changes: ===================================== src/mailman/docs/NEWS.rst ===================================== @@ -19,9 +19,6 @@ Bugs and footers. (Closes #701) * RFC 2369 headers are now added to notification messages. (Closes #710) * Bounce probes are now encoded in the correct charset. (Closes #712) -* Add ``subscription_mode`` to ``Member`` resource so API clients can - differentiate between subscription via address and via primary address of an - user. (Closes #707) REST @@ -30,6 +27,11 @@ REST number of pending requests. (Closes #713) * Subscription requests API now allows filtering requests with ``token_owner`` parameter. (Closes #714) +* Add ``subscription_mode`` to ``Member`` resource so API clients can + differentiate between subscription via address and via primary address of an + user. (Closes #707) +* Add ``/list/<listid>/held/count`` to get a count of total held + messages. (Closes #713) 3.3.1 ===================================== src/mailman/rest/docs/post-moderation.rst ===================================== @@ -60,6 +60,14 @@ When a message gets held for moderator approval, it shows up in this list. start: 0 total_size: 1 +A simple count of the held messages is also available: +:: + + >>> dump_json('http://localhost:9001/3.0/lists/a...@example.com/held/count') + count: 1 + http_etag: "..." + + You can get an individual held message by providing the *request id* for that message. This will include the text of the message. :: ===================================== src/mailman/rest/post_moderation.py ===================================== @@ -141,6 +141,17 @@ class HeldMessage(_HeldMessageBase): no_content(response) +class _HeldMessageCount: + + def __init__(self, mlist): + self._mlist = mlist + + def on_get(self, request, response): + requests = IListRequests(self._mlist) + count = requests.count_of(RequestType.held_message) + okay(response, etag(dict(count=count))) + + @public class HeldMessages(_HeldMessageBase, CollectionMixin): """Resource for messages held for moderation.""" @@ -163,6 +174,11 @@ class HeldMessages(_HeldMessageBase, CollectionMixin): resource = self._make_collection(request) okay(response, etag(resource)) + @child() + def count(self, context, segments): + """/lists/listname/held/count""" + return _HeldMessageCount(self._mlist) + @child(r'^(?P<id>[^/]+)') def message(self, context, segments, **kw): return HeldMessage(self._mlist, kw['id']) ===================================== src/mailman/rest/tests/test_moderation.py ===================================== @@ -97,6 +97,26 @@ Something else. 'Invalid Parameter "action": Accepted Values are:' ' hold, reject, discard, accept, defer.') + def test_held_message_count(self): + # Initially, the count should be zero. + url = 'http://localhost:9001/3.0/lists/a...@example.com/held/count' + json, resp = call_api(url) + self.assertEqual(resp.status_code, 200) + self.assertEqual(json['count'], 0) + # Now, verify that we get the number when a held message is added. + with transaction(): + hold_message(self._mlist, self._msg) + json, resp = call_api(url) + self.assertEqual(resp.status_code, 200) + self.assertEqual(json['count'], 1) + # Hold some more to see if we get the right numbers. + with transaction(): + hold_message(self._mlist, self._msg) + hold_message(self._mlist, self._msg) + json, resp = call_api(url) + self.assertEqual(resp.status_code, 200) + self.assertEqual(json['count'], 3) + def test_discard(self): # Discarding a message removes it from the moderation queue. with transaction(): View it on GitLab: https://gitlab.com/mailman/mailman/-/compare/87aed9bd24ca90d3da6149c74469ec56fd885d92...ce337843e608aa162398a3946e086a5b947e24ef -- View it on GitLab: https://gitlab.com/mailman/mailman/-/compare/87aed9bd24ca90d3da6149c74469ec56fd885d92...ce337843e608aa162398a3946e086a5b947e24ef You're receiving this email because of your account on gitlab.com.
_______________________________________________ Mailman-checkins mailing list -- mailman-checkins@python.org To unsubscribe send an email to mailman-checkins-le...@python.org https://mail.python.org/mailman3/lists/mailman-checkins.python.org/ Member address: arch...@jab.org