Barry Warsaw pushed to branch master at mailman / Mailman
Commits: 3387791b by Barry Warsaw at 2016-07-14T10:01:27-04:00 Fix #207 A list's ``moderator_password`` can be set via the REST API. Given by Andrew Breksa. - - - - - 5 changed files: - src/mailman/docs/NEWS.rst - src/mailman/rest/docs/listconf.rst - src/mailman/rest/helpers.py - src/mailman/rest/listconf.py - src/mailman/rest/tests/test_listconf.py Changes: ===================================== src/mailman/docs/NEWS.rst ===================================== --- a/src/mailman/docs/NEWS.rst +++ b/src/mailman/docs/NEWS.rst @@ -209,6 +209,8 @@ REST * A member's ``moderation_action`` can be reset, allowing fallback to the list's ``default_member_action`` by setting the attribute to the empty string in the REST API. Given by Aurélien Bompard. + * A list's ``moderator_password`` can be set via the REST API. Given by + Andrew Breksa. (Closes #207) Other ----- ===================================== src/mailman/rest/docs/listconf.rst ===================================== --- a/src/mailman/rest/docs/listconf.rst +++ b/src/mailman/rest/docs/listconf.rst @@ -53,6 +53,7 @@ All readable attributes for a list are available on a sub-resource. leave_address: ant-le...@example.com list_name: ant mail_host: example.com + moderator_password: None next_digest_number: 1 no_reply_address: nore...@example.com owner_address: ant-ow...@example.com @@ -119,6 +120,7 @@ When using ``PUT``, all writable attributes must be included. ... welcome_message_uri='mailman:///welcome.txt', ... default_member_action='hold', ... default_nonmember_action='discard', + ... moderator_password='password', ... ), ... 'PUT') content-length: 0 @@ -165,6 +167,8 @@ These values are changed permanently. ... include_rfc2369_headers: False ... + moderator_password: {plaintext}password + ... posting_pipeline: virgin reply_goes_to_list: point_to_list reply_to_address: b...@example.com ===================================== src/mailman/rest/helpers.py ===================================== --- a/src/mailman/rest/helpers.py +++ b/src/mailman/rest/helpers.py @@ -21,6 +21,7 @@ import json import falcon import hashlib +from contextlib import suppress from datetime import datetime, timedelta from enum import Enum from lazr.config import as_boolean @@ -46,9 +47,20 @@ class ExtendedEncoder(json.JSONEncoder): # It's up to the decoding validator to associate this name with # the right Enum class. return obj.name + elif isinstance(obj, bytes): + return bytes_to_str(obj) return super().default(obj) +def bytes_to_str(value): + # Convert a string to unicode when the encoding is not declared. + if not isinstance(value, bytes): + return value + for encoding in ('ascii', 'utf-8', 'raw_unicode_escape'): + with suppress(UnicodeDecodeError): + return value.decode(encoding) + + @public def etag(resource): """Calculate the etag and return a JSON representation. ===================================== src/mailman/rest/listconf.py ===================================== --- a/src/mailman/rest/listconf.py +++ b/src/mailman/rest/listconf.py @@ -68,6 +68,12 @@ def pipeline_validator(pipeline_name): raise ValueError('Unknown pipeline: {}'.format(pipeline_name)) +def password_bytes_validator(value): + if value is None or isinstance(value, bytes): + return value + return config.password_context.encrypt(value).encode('utf-8') + + # This is the list of IMailingList attributes that are exposed through the # REST API. The values of the keys are the GetterSetter instance holding the # decoder used to convert the web request string to an internally valid value. @@ -120,6 +126,7 @@ ATTRIBUTES = dict( last_post_at=GetterSetter(None), leave_address=GetterSetter(None), list_name=GetterSetter(None), + moderator_password=GetterSetter(password_bytes_validator), next_digest_number=GetterSetter(None), no_reply_address=GetterSetter(None), owner_address=GetterSetter(None), ===================================== src/mailman/rest/tests/test_listconf.py ===================================== --- a/src/mailman/rest/tests/test_listconf.py +++ b/src/mailman/rest/tests/test_listconf.py @@ -28,7 +28,6 @@ from mailman.testing.helpers import call_api from mailman.testing.layers import RESTLayer from urllib.error import HTTPError - # The representation of the listconf resource as a dictionary. This is used # when PUTting to the list's configuration resource. RESOURCE = dict( @@ -65,6 +64,7 @@ RESOURCE = dict( first_strip_reply_to=True, goodbye_message_uri='mailman:///goodbye.txt', include_rfc2369_headers=False, + moderator_password='password', posting_pipeline='virgin', reply_goes_to_list='point_to_list', reply_to_address='b...@example.com', View it on GitLab: https://gitlab.com/mailman/mailman/commit/3387791beb7112dbe07664041f117fdcc20df53d
_______________________________________________ Mailman-checkins mailing list Mailman-checkins@python.org Unsubscribe: https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org