Commit 9c9d0f01 authored by Aurélien Bompard's avatar Aurélien Bompard Committed by Barry Warsaw

Allow a Member's moderation_action to be changed by the REST API.

Cleanups by Barry.  Closes !67
parent 054b412a
Pipeline #436384 failed with stage
......@@ -113,6 +113,8 @@ REST
* JSON representations for held message now include a ``self_link``.
* When ``[devmode]enabled`` is set, the JSON output is sorted. Given by
Aurélien Bompard.
* A member's moderation action can be changed via the REST API. Given by
Aurélien Bompard.
Other
-----
......
......@@ -379,6 +379,7 @@ Elle can get her memberships for each of her email addresses.
http_etag: "..."
list_id: ant.example.com
member_id: 1
moderation_action: defer
role: member
self_link: http://localhost:9001/3.0/members/1
user: http://localhost:9001/3.0/users/4
......@@ -389,6 +390,7 @@ Elle can get her memberships for each of her email addresses.
http_etag: "..."
list_id: bee.example.com
member_id: 2
moderation_action: defer
role: member
self_link: http://localhost:9001/3.0/members/2
user: http://localhost:9001/3.0/users/4
......@@ -420,6 +422,7 @@ does not show up in the list of memberships for his other address.
http_etag: "..."
list_id: ant.example.com
member_id: 1
moderation_action: defer
role: member
self_link: http://localhost:9001/3.0/members/1
user: http://localhost:9001/3.0/users/4
......@@ -430,6 +433,7 @@ does not show up in the list of memberships for his other address.
http_etag: "..."
list_id: bee.example.com
member_id: 2
moderation_action: defer
role: member
self_link: http://localhost:9001/3.0/members/2
user: http://localhost:9001/3.0/users/4
......@@ -446,6 +450,7 @@ does not show up in the list of memberships for his other address.
http_etag: "..."
list_id: bee.example.com
member_id: 3
moderation_action: defer
role: member
self_link: http://localhost:9001/3.0/members/3
user: http://localhost:9001/3.0/users/4
......
This diff is collapsed.
......@@ -26,6 +26,7 @@ __all__ = [
from mailman.app.membership import add_member, delete_member
from mailman.interfaces.action import Action
from mailman.interfaces.address import IAddress, InvalidEmailAddressError
from mailman.interfaces.listmanager import IListManager
from mailman.interfaces.member import (
......@@ -62,13 +63,14 @@ class _MemberBase(CollectionMixin):
# URL.
member_id = member.member_id.int
response = dict(
list_id=member.list_id,
email=member.address.email,
role=role,
address=self.path_to('addresses/{}'.format(member.address.email)),
self_link=self.path_to('members/{}'.format(member_id)),
delivery_mode=member.delivery_mode,
email=member.address.email,
list_id=member.list_id,
member_id=member_id,
moderation_action=member.moderation_action,
role=role,
self_link=self.path_to('members/{}'.format(member_id)),
)
# Add the user link if there is one.
user = member.user
......@@ -178,7 +180,9 @@ class AMember(_MemberBase):
values = Validator(
address=str,
delivery_mode=enum_validator(DeliveryMode),
_optional=('address', 'delivery_mode'))(request)
moderation_action=enum_validator(Action),
_optional=('address', 'delivery_mode', 'moderation_action'),
)(request)
except ValueError as error:
bad_request(response, str(error))
return
......@@ -195,6 +199,8 @@ class AMember(_MemberBase):
return
if 'delivery_mode' in values:
self._member.preferences.delivery_mode = values['delivery_mode']
if 'moderation_action' in values:
self._member.moderation_action = values['moderation_action']
no_content(response)
......
......@@ -253,6 +253,19 @@ class TestMembership(unittest.TestCase):
call_api('http://localhost:9001/3.0/members/1/all')
self.assertEqual(cm.exception.code, 404)
def test_patch_member_invalid_moderation_action(self):
# /members/<id> PATCH with invalid 'moderation_action' returns 400.
with transaction():
anne = self._usermanager.create_address('[email protected]')
self._mlist.subscribe(anne)
with self.assertRaises(HTTPError) as cm:
call_api('http://localhost:9001/3.0/members/1', {
'moderation_action': 'invalid',
}, method='PATCH')
self.assertEqual(cm.exception.code, 400)
self.assertEqual(cm.exception.reason,
b'Cannot convert parameters: moderation_action')
class CustomLayer(ConfigLayer):
......
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