Commit 50b28b01 authored by Barry Warsaw's avatar Barry Warsaw

Merge branch 'expose-max-message-size' into 'master'

Expose max_message_size through rest

Closes #417

See merge request !329
parents 0ff35504 2f230e87
Pipeline #12726751 failed with stage
in 60 minutes and 6 seconds
......@@ -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"
......
......@@ -62,6 +62,7 @@ All readable attributes for a list are available on a sub-resource.
leave_address: ant-leave@example.com
list_name: ant
mail_host: example.com
max_message_size: 40
moderator_password: None
next_digest_number: 1
no_reply_address: noreply@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
......
......@@ -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),
......
......@@ -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='bee@example.com',
......
......@@ -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)
......
......@@ -99,6 +99,15 @@ def list_of_strings_validator(values):
return 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."""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment