Barry Warsaw pushed to branch master at mailman / Mailman

Commits:
10570a3d by Anirudh Dahiya at 2016-03-05T10:24:40-05:00
Add AlreadySubscribedError Exception for better error message

- - - - -
47b4d1f9 by Barry Warsaw at 2016-03-05T11:55:18-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.

- - - - -


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
@@ -65,6 +65,9 @@ Bugs
  * In decoration URIs (e.g. ``IMailingList.header_uri`` and ``.footer_uri``)
    you should now use the mailing list's List-ID instead of the
    fqdn-listname.  The latter is deprecated.  (Closes #196)
+ * 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)
 
 Configuration
 -------------


=====================================
src/mailman/rest/members.py
=====================================
--- a/src/mailman/rest/members.py
+++ b/src/mailman/rest/members.py
@@ -328,6 +328,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
@@ -633,3 +633,19 @@ class TestAPI31Members(unittest.TestCase):
         # that's known to the system, in API 3.1.  It's not technically a 404
         # because that's reserved for URL lookups.
         self.assertEqual(cm.exception.code, 400)
+
+    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.1/members', {
+                'list_id': 'ant.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 a...@example.com')



View it on GitLab: 
https://gitlab.com/mailman/mailman/compare/b4f45c4128b20d9519126ff464cafd22c1a58a03...47b4d1f987a91e1a2ce9b1e533c166ca21c2477e
_______________________________________________
Mailman-checkins mailing list
Mailman-checkins@python.org
Unsubscribe: 
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to