Barry Warsaw pushed to branch release-3.0 at mailman / Mailman
Commits: 4cc192fa by Anirudh Dahiya at 2016-03-05T12:10:40-05:00 Add AlreadySubscribedError Exception for better error message - - - - - 3df0f01a by Barry Warsaw at 2016-03-05T12:12:42-05:00 Fix #198 - duplicate owner subscription error Trying to subscribe an address as a list owner (or moderator or nonmember) which is already subscribed with that role produces a server error. - - - - - d2517223 by Barry Warsaw at 2016-03-05T13:06:58-05:00 Fix for release-3.0 branch. - - - - - 3 changed files: - src/mailman/docs/NEWS.rst - src/mailman/rest/members.py - src/mailman/rest/tests/test_membership.py Changes: ===================================== src/mailman/docs/NEWS.rst ===================================== --- a/src/mailman/docs/NEWS.rst +++ b/src/mailman/docs/NEWS.rst @@ -17,6 +17,9 @@ Bugs * When approving a subscription request via the REST API, for a user who is already a member, return an HTTP 409 Conflict code instead of the previous server traceback (and resulting HTTP 500 code). (Closes: #193) + * Trying to subscribe an address as a list owner (or moderator or nonmember) + which is already subscribed with that role produces a server error. + Originally given by Anirudh Dahiya. (Closes #198) 3.0.2 -- "Show Don't Tell" ===================================== src/mailman/rest/members.py ===================================== --- a/src/mailman/rest/members.py +++ b/src/mailman/rest/members.py @@ -324,6 +324,11 @@ class AllMembers(_MemberBase): except MembershipIsBannedError: bad_request(response, b'Membership is banned') return + except AlreadySubscribedError: + bad_request(response, + '{} is already an {} of {}'.format( + email, role.name, mlist.fqdn_listname)) + return # The subscription completed. Let's get the resulting member # and return the location to the new member. Member ids are # UUIDs and need to be converted to URLs because JSON doesn't ===================================== src/mailman/rest/tests/test_membership.py ===================================== --- a/src/mailman/rest/tests/test_membership.py +++ b/src/mailman/rest/tests/test_membership.py @@ -28,6 +28,7 @@ import unittest from mailman.app.lifecycle import create_list from mailman.config import config from mailman.database.transaction import transaction +from mailman.interfaces.member import MemberRole from mailman.interfaces.usermanager import IUserManager from mailman.testing.helpers import ( TestableMaster, call_api, get_lmtp_client, make_testable_runner, @@ -372,3 +373,19 @@ Some text. # previously been linked to a user record. self.assertEqual(nonmember['user'], 'http://localhost:9001/3.0/users/1') + + def test_duplicate_owner(self): + # Server failure when someone is already an owner. + with transaction(): + anne = getUtility(IUserManager).create_address('a...@example.com') + self._mlist.subscribe(anne, MemberRole.owner) + with self.assertRaises(HTTPError) as cm: + call_api('http://localhost:9001/3.0/members', { + 'list_id': 'test.example.com', + 'subscriber': anne.email, + 'role': 'owner', + }) + self.assertEqual(cm.exception.code, 400) + self.assertEqual( + cm.exception.reason, + b'a...@example.com is already an owner of t...@example.com') View it on GitLab: https://gitlab.com/mailman/mailman/compare/0f2c7888c4360d677cd0887d7ca01037f42ed0f8...d251722399a5470fa5c4ea6b9325129d8895b135
_______________________________________________ Mailman-checkins mailing list Mailman-checkins@python.org Unsubscribe: https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org