Barry Warsaw pushed to branch master at mailman / Mailman Core

Commits:
2f230e87 by Simon Hanna at 2017-10-12T01:11:21+02:00
Expose max_message_size through rest

- - - - -
50b28b01 by Barry Warsaw at 2017-10-12T13:25:17+00:00
Merge branch 'expose-max-message-size' into 'master'

Expose max_message_size through rest

Closes #417

See merge request mailman/mailman!329
- - - - -


6 changed files:

- src/mailman/docs/NEWS.rst
- src/mailman/rest/docs/listconf.rst
- src/mailman/rest/listconf.py
- src/mailman/rest/tests/test_listconf.py
- src/mailman/rest/tests/test_validator.py
- src/mailman/rest/validator.py


Changes:

=====================================
src/mailman/docs/NEWS.rst
=====================================
--- a/src/mailman/docs/NEWS.rst
+++ b/src/mailman/docs/NEWS.rst
@@ -80,6 +80,7 @@ REST
 * Allow a mailing list's acceptable aliases to be cleared by calling
   ``DELETE`` on the list's ``config/acceptable_aliases`` resource.
   (Closes #394)
+* Allow setting max_message_size for a mailing list. (Closes #417)
 
 
 3.1.0 -- "Between The Wheels"


=====================================
src/mailman/rest/docs/listconf.rst
=====================================
--- a/src/mailman/rest/docs/listconf.rst
+++ b/src/mailman/rest/docs/listconf.rst
@@ -62,6 +62,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
+    max_message_size: 40
     moderator_password: None
     next_digest_number: 1
     no_reply_address: nore...@example.com
@@ -131,6 +132,7 @@ When using ``PUT``, all writable attributes must be 
included.
     ...             default_member_action='hold',
     ...             default_nonmember_action='discard',
     ...             moderator_password='password',
+    ...             max_message_size='500',
     ...             ),
     ...           'PUT')
     content-length: 0


=====================================
src/mailman/rest/listconf.py
=====================================
--- a/src/mailman/rest/listconf.py
+++ b/src/mailman/rest/listconf.py
@@ -31,7 +31,9 @@ from mailman.rest.helpers import (
     GetterSetter, bad_request, etag, no_content, not_found, okay)
 from mailman.rest.validator import (
     PatchValidator, ReadOnlyPATCHRequestError, UnknownPATCHRequestError,
-    Validator, enum_validator, list_of_strings_validator)
+    Validator, enum_validator, integer_ge_zero_validator,
+    list_of_strings_validator
+    )
 from public import public
 from zope.component import getUtility
 
@@ -168,6 +170,7 @@ ATTRIBUTES = dict(
     list_name=GetterSetter(None),
     mail_host=GetterSetter(None),
     moderator_password=GetterSetter(password_bytes_validator),
+    max_message_size=GetterSetter(integer_ge_zero_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
@@ -72,6 +72,7 @@ RESOURCE = dict(
     include_rfc2369_headers=False,
     info='This is the mailing list info',
     moderator_password='password',
+    max_message_size='150',
     posting_pipeline='virgin',
     reply_goes_to_list='point_to_list',
     reply_to_address='b...@example.com',


=====================================
src/mailman/rest/tests/test_validator.py
=====================================
--- a/src/mailman/rest/tests/test_validator.py
+++ b/src/mailman/rest/tests/test_validator.py
@@ -23,7 +23,8 @@ from mailman.core.api import API30, API31
 from mailman.interfaces.action import Action
 from mailman.interfaces.usermanager import IUserManager
 from mailman.rest.validator import (
-    enum_validator, list_of_strings_validator, subscriber_validator)
+    enum_validator, integer_ge_zero_validator, list_of_strings_validator,
+    subscriber_validator)
 from mailman.testing.layers import RESTLayer
 from zope.component import getUtility
 
@@ -41,6 +42,14 @@ class TestValidators(unittest.TestCase):
             list_of_strings_validator(['ant', 'bee', 'cat']),
             ['ant', 'bee', 'cat'])
 
+    def test_integer_ge_zero_validator_invalid(self):
+        self.assertRaises(ValueError, integer_ge_zero_validator, 'foo')
+        self.assertRaises(ValueError, integer_ge_zero_validator, '-1')
+
+    def test_integer_ge_zero_validator_valid(self):
+        self.assertEquals(integer_ge_zero_validator('0'), 0)
+        self.assertEquals(integer_ge_zero_validator('100'), 100)
+
     def test_list_of_strings_validator_invalid(self):
         # Strings are required.
         self.assertRaises(ValueError, list_of_strings_validator, 7)


=====================================
src/mailman/rest/validator.py
=====================================
--- a/src/mailman/rest/validator.py
+++ b/src/mailman/rest/validator.py
@@ -100,6 +100,15 @@ def list_of_strings_validator(values):
 
 
 @public
+def integer_ge_zero_validator(value):
+    """Validate that the value is a non-negative integer."""
+    value = int(value)
+    if value < 0:
+        raise ValueError('Expected a non-negative integer: {}'.format(value))
+    return value
+
+
+@public
 class Validator:
     """A validator of parameter input."""
 



View it on GitLab: 
https://gitlab.com/mailman/mailman/compare/0ff35504ece1c2e06bd9aa0ff0e85f029d4d1dd3...50b28b014835d22786001a36919ef841849513f3

---
View it on GitLab: 
https://gitlab.com/mailman/mailman/compare/0ff35504ece1c2e06bd9aa0ff0e85f029d4d1dd3...50b28b014835d22786001a36919ef841849513f3
You're receiving this email because of your account on gitlab.com.
_______________________________________________
Mailman-checkins mailing list
Mailman-checkins@python.org
Unsubscribe: 
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to