summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mailman/rest/docs/lists.rst30
-rw-r--r--src/mailman/rest/lists.py14
2 files changed, 39 insertions, 5 deletions
diff --git a/src/mailman/rest/docs/lists.rst b/src/mailman/rest/docs/lists.rst
index 6554b04c2..eb8314704 100644
--- a/src/mailman/rest/docs/lists.rst
+++ b/src/mailman/rest/docs/lists.rst
@@ -49,6 +49,33 @@ You can also query for lists from a particular domain.
start: 0
total_size: 1
+Advertised lists can be filtered using the ``only_advertised`` query parameter.
+::
+
+ >>> mlist = create_list('bird@example.com')
+ >>> mlist.advertised = False
+ >>> transaction.commit()
+
+ >>> dump_json('http://localhost:9001/3.0/lists?only_advertised=true')
+ entry 0:
+ ...
+ list_id: ant.example.com
+ ...
+ http_etag: "..."
+ start: 0
+ total_size: 1
+
+The same applies to lists from a particular domain.
+
+ >>> dump_json('http://localhost:9001/3.0/domains/example.com/lists?only_advertised=true')
+ entry 0:
+ ...
+ list_id: ant.example.com
+ ...
+ http_etag: "..."
+ start: 0
+ total_size: 1
+
Paginating over list records
----------------------------
@@ -59,9 +86,6 @@ request URI. Page 1 is the first page and ``count`` defines the size of the
page.
::
- >>> mlist = create_list('bird@example.com')
- >>> transaction.commit()
-
>>> dump_json('http://localhost:9001/3.0/domains/example.com/lists'
... '?count=1&page=1')
entry 0:
diff --git a/src/mailman/rest/lists.py b/src/mailman/rest/lists.py
index c3919c001..3d2ed072c 100644
--- a/src/mailman/rest/lists.py
+++ b/src/mailman/rest/lists.py
@@ -107,7 +107,16 @@ class _ListBase(CollectionMixin):
def _get_collection(self, request):
"""See `CollectionMixin`."""
- return list(getUtility(IListManager))
+ return self._filter_lists(
+ request, list(getUtility(IListManager)))
+
+ def _filter_lists(self, request, lists):
+ """Filter a collection using query parameters."""
+ only_advertised = request.get_param_as_bool('only_advertised')
+ if only_advertised:
+ return [l for l in lists if l.advertised]
+ else:
+ return lists
@public
@@ -299,7 +308,8 @@ class ListsForDomain(_ListBase):
def _get_collection(self, request):
"""See `CollectionMixin`."""
- return list(self._domain.mailing_lists)
+ return self._filter_lists(
+ request, list(self._domain.mailing_lists))
@public