From 391f8d968484947855a06fb6e3a9d5e724e35c3f Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Mon, 13 Jul 2015 21:00:31 -0400 Subject: [PATCH] Fixes #136 on the 3.0 maintenance branch. * The REST API incorrectly parsed `is_server_owner` values when given explicitly in the POST that creates a user. (Closes #136) --- src/mailman/docs/NEWS.rst | 2 ++ src/mailman/rest/tests/test_users.py | 27 +++++++++++++++++++++++++++ src/mailman/rest/users.py | 2 +- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst index 2f35d3df6..49dd61581 100644 --- a/src/mailman/docs/NEWS.rst +++ b/src/mailman/docs/NEWS.rst @@ -26,6 +26,8 @@ Bugs * Confirmation messages should not be `Precedence: bulk`. (Closes #75) * The ``prototype`` archiver is not web accessible so it does not have a ``list_url`` or permalink. Given by Aurélien Bompard. + * The REST API incorrectly parsed `is_server_owner` values when given + explicitly in the POST that creates a user. (Closes #136) 3.0.0 -- "Show Don't Tell" diff --git a/src/mailman/rest/tests/test_users.py b/src/mailman/rest/tests/test_users.py index ac8d018e8..3c4a549d7 100644 --- a/src/mailman/rest/tests/test_users.py +++ b/src/mailman/rest/tests/test_users.py @@ -212,6 +212,33 @@ class TestUsers(unittest.TestCase): content, response = call_api('http://localhost:9001/3.0/users') self.assertEqual(content['total_size'], 1) + def test_create_server_owner_false(self): + # Issue #136: Creating a user with is_server_owner=no should create + # user who is not a server owner. + content, response = call_api('http://localhost:9001/3.0/users', dict( + email='anne@example.com', + is_server_owner='no')) + anne = getUtility(IUserManager).get_user('anne@example.com') + self.assertFalse(anne.is_server_owner) + + def test_create_server_owner_true(self): + # Issue #136: Creating a user with is_server_owner=yes should create a + # new server owner user. + content, response = call_api('http://localhost:9001/3.0/users', dict( + email='anne@example.com', + is_server_owner='yes')) + anne = getUtility(IUserManager).get_user('anne@example.com') + self.assertTrue(anne.is_server_owner) + + def test_create_server_owner_bogus(self): + # Issue #136: Creating a user with is_server_owner=bogus should throw + # an exception. + with self.assertRaises(HTTPError) as cm: + call_api('http://localhost:9001/3.0/users', dict( + email='anne@example.com', + is_server_owner='bogus')) + self.assertEqual(cm.exception.code, 400) + def test_preferences_deletion_on_user_deletion(self): # LP: #1418276 - deleting a user did not delete their preferences. with transaction(): diff --git a/src/mailman/rest/users.py b/src/mailman/rest/users.py index 7b1ec8040..f25756349 100644 --- a/src/mailman/rest/users.py +++ b/src/mailman/rest/users.py @@ -82,7 +82,7 @@ ATTRIBUTES = dict( CREATION_FIELDS = dict( display_name=str, email=str, - is_server_owner=bool, + is_server_owner=as_boolean, password=str, _optional=('display_name', 'password', 'is_server_owner'), ) -- 2.11.4.GIT