summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarry Warsaw2010-08-10 19:35:19 -0400
committerBarry Warsaw2010-08-10 19:35:19 -0400
commitde7f01e3836379e0902c2ac4b6b6691b955f2257 (patch)
tree159d27fadfdf642d823a6477d95fbfa7dbe11fcf
parent3426c60480b6cf3492c63e7cb5d115ae2d3d8930 (diff)
downloadmailman-de7f01e3836379e0902c2ac4b6b6691b955f2257.tar.gz
mailman-de7f01e3836379e0902c2ac4b6b6691b955f2257.tar.zst
mailman-de7f01e3836379e0902c2ac4b6b6691b955f2257.zip
Placeholder for PATCH implementation.
-rw-r--r--src/mailman/rest/docs/configuration.txt102
-rw-r--r--src/mailman/rest/lists.py14
2 files changed, 111 insertions, 5 deletions
diff --git a/src/mailman/rest/docs/configuration.txt b/src/mailman/rest/docs/configuration.txt
index e72e29f55..66502dd15 100644
--- a/src/mailman/rest/docs/configuration.txt
+++ b/src/mailman/rest/docs/configuration.txt
@@ -8,6 +8,10 @@ Mailing lists can be configured via the REST API.
<mailing list "test-one@example.com" at ...>
>>> transaction.commit()
+
+Reading a configuration
+=======================
+
All readable attributes for a list are available on a sub-resource.
>>> dump_json('http://localhost:8001/3.0/lists/'
@@ -41,8 +45,12 @@ All readable attributes for a list are available on a sub-resource.
volume: 1
web_host: lists.example.com
+
+Changing the full configuration
+===============================
+
Not all of the readable attributes can be set through the web interface. The
-once that can, can either be set via PUT or PATCH. PUT changes all the
+ones that can, can either be set via PUT or PATCH. PUT changes all the
writable attributes in one request.
>>> dump_json('http://localhost:8001/3.0/lists/'
@@ -80,3 +88,95 @@ These values are changed permanently.
...
real_name: Fnords
...
+
+If you use PUT to change a list's configuration, all writable attributes must
+be included. It is an error to leave one out (e.g. `pipeline`)...
+
+ >>> dump_json('http://localhost:8001/3.0/lists/'
+ ... 'test-one@example.com/config',
+ ... dict(real_name='Fnords',
+ ... include_rfc2369_headers=False,
+ ... include_list_post_header=False,
+ ... digest_size_threshold=10.5,
+ ... filter_content=True,
+ ... convert_html_to_plaintext=True,
+ ... collapse_alternatives=False,
+ ... ),
+ ... 'PUT')
+ Traceback (most recent call last):
+ ...
+ HTTPError: HTTP Error 400: Bad Request
+
+...or to add an unknown one.
+
+ >>> dump_json('http://localhost:8001/3.0/lists/'
+ ... 'test-one@example.com/config',
+ ... dict(real_name='Fnords',
+ ... include_rfc2369_headers=False,
+ ... include_list_post_header=False,
+ ... digest_size_threshold=10.5,
+ ... pipeline='virgin',
+ ... filter_content=True,
+ ... convert_html_to_plaintext=True,
+ ... collapse_alternatives=False,
+ ... whats_this=True,
+ ... ),
+ ... 'PUT')
+ Traceback (most recent call last):
+ ...
+ HTTPError: HTTP Error 400: Bad Request
+
+It is also an error to spell an attribute value incorrectly...
+
+ >>> dump_json('http://localhost:8001/3.0/lists/'
+ ... 'test-one@example.com/config',
+ ... dict(real_name='Fnords',
+ ... include_rfc2369_headers=False,
+ ... include_list_post_header=False,
+ ... digest_size_threshold=10.5,
+ ... pipeline='virgin',
+ ... filter_content=True,
+ ... convert_html_to_plaintext=True,
+ ... collapse_alternatives='Nope',
+ ... ),
+ ... 'PUT')
+ Traceback (most recent call last):
+ ...
+ HTTPError: HTTP Error 400: Bad Request
+
+...or to name a pipeline that doesn't exist.
+
+ >>> dump_json('http://localhost:8001/3.0/lists/'
+ ... 'test-one@example.com/config',
+ ... dict(real_name='Fnords',
+ ... include_rfc2369_headers=False,
+ ... include_list_post_header=False,
+ ... digest_size_threshold=10.5,
+ ... pipeline='dummy',
+ ... filter_content=True,
+ ... convert_html_to_plaintext=True,
+ ... collapse_alternatives=False,
+ ... ),
+ ... 'PUT')
+ Traceback (most recent call last):
+ ...
+ HTTPError: HTTP Error 400: Bad Request
+
+
+Changing a partial configuration
+================================
+
+Using PATCH, you can change just one attribute.
+
+ >>> dump_json('http://localhost:8001/3.0/lists/'
+ ... 'test-one@example.com/config',
+ ... dict(real_name='My List'),
+ ... 'PATCH')
+ content-length: 0
+ date: ...
+ server: WSGIServer/...
+ status: 200
+
+These values are changed permanently.
+
+XXX WebOb does not currently support PATCH, so neither does restish.
diff --git a/src/mailman/rest/lists.py b/src/mailman/rest/lists.py
index 9ed3f877e..6e297d0ed 100644
--- a/src/mailman/rest/lists.py
+++ b/src/mailman/rest/lists.py
@@ -264,14 +264,20 @@ class ListConfiguration(resource.Resource):
"""Set all of a mailing list's configuration."""
# Use PATCH to change just one or a few of the attributes.
validator = Validator(**VALIDATORS)
- for key, value in validator(request).items():
- setattr(self._mlist, key, value)
+ try:
+ for key, value in validator(request).items():
+ setattr(self._mlist, key, value)
+ except ValueError as error:
+ return http.bad_request([], str(error))
return http.ok([], '')
@PATCH()
def patch_configuration(self, request):
"""Set a subset of the mailing list's configuration."""
validator = Validator(_optional=VALIDATORS.keys(), **VALIDATORS)
- for key, value in validator(request).items():
- setattr(self._mlist, key, value)
+ try:
+ for key, value in validator(request).items():
+ setattr(self._mlist, key, value)
+ except ValueError as error:
+ return http.bad_request([], str(error))
return http.ok([], '')