Mark Sapiro pushed to branch master at GNU Mailman / Mailman Core


Commits:
740d50e6 by Mark Sapiro at 2022-03-24T04:46:09+00:00
Subscription workflow sanity checks both User and Address for existing

- - - - -
54d087b7 by Mark Sapiro at 2022-03-24T04:46:09+00:00
Merge branch 'member' into 'master'

Subscription workflow sanity checks both User and Address for existing

Closes #994

See merge request mailman/mailman!997
- - - - -


3 changed files:

- src/mailman/app/subscriptions.py
- src/mailman/app/tests/test_subscriptions.py
- src/mailman/docs/NEWS.rst


Changes:

=====================================
src/mailman/app/subscriptions.py
=====================================
@@ -235,17 +235,10 @@ class SubscriptionWorkflow(_SubscriptionWorkflowCommon):
         assert self.user is not None and self.address is not None, (
             'Insane sanity check results')
         # Is this subscriber already a member?
-        if (self.which is WhichSubscriber.user and
-                self.user.preferred_address is not None):
-            subscriber = self.user
-        else:
-            subscriber = self.address
-        if self.mlist.is_subscribed(subscriber):
-            # 2017-04-22 BAW: This branch actually *does* get covered, as I've
-            # verified by a full coverage run, but diffcov for some reason
-            # claims that the test added in the branch that added this code
-            # does not cover the change.  That seems like a bug in diffcov.
-            raise AlreadySubscribedError(           # pragma: nocover
+        if ((self.user.preferred_address is not None and
+                self.mlist.is_subscribed(self.user)) or
+                self.mlist.is_subscribed(self.address)):
+            raise AlreadySubscribedError(
                 self.mlist.fqdn_listname,
                 self.address.email,
                 MemberRole.member)


=====================================
src/mailman/app/tests/test_subscriptions.py
=====================================
@@ -30,13 +30,14 @@ from mailman.interfaces.address import 
InvalidEmailAddressError
 from mailman.interfaces.bans import IBanManager
 from mailman.interfaces.mailinglist import SubscriptionPolicy
 from mailman.interfaces.member import (
+    AlreadySubscribedError,
     DeliveryMode,
     DeliveryStatus,
     MemberRole,
     MembershipIsBannedError,
 )
 from mailman.interfaces.pending import IPendings
-from mailman.interfaces.subscriptions import TokenOwner
+from mailman.interfaces.subscriptions import ISubscriptionManager, TokenOwner
 from mailman.interfaces.usermanager import IUserManager
 from mailman.testing.helpers import (
     get_queue_messages,
@@ -204,6 +205,42 @@ class TestSubscriptionWorkflow(unittest.TestCase):
         workflow = SubscriptionWorkflow(self._mlist, user)
         self.assertRaises(AssertionError, workflow.run_thru, 'sanity_checks')
 
+    def test_sanity_checks_finds_address_for_user(self):
+        # Test raises AlreadySubscribedError for User when member is Address.
+        anne = self._user_manager.make_user(self._anne)
+        anne.addresses[0].verified_on = anne.created_on
+        anne.preferred_address = anne.addresses[0]
+        self._mlist.subscription_policy = SubscriptionPolicy.open
+        # Subscribe Address.
+        ISubscriptionManager(self._mlist).register(
+            anne.preferred_address,
+            pre_verified=True,
+            pre_confirmed=True,
+            pre_approved=True,
+            send_welcome_message=False
+            )
+        workflow = SubscriptionWorkflow(self._mlist, anne)
+        self.assertRaises(
+            AlreadySubscribedError, workflow.run_thru, 'sanity_checks')
+
+    def test_sanity_checks_finds_user_for_address(self):
+        # Test raises AlreadySubscribedError for Address when member is User.
+        anne = self._user_manager.make_user(self._anne)
+        anne.addresses[0].verified_on = anne.created_on
+        anne.preferred_address = anne.addresses[0]
+        self._mlist.subscription_policy = SubscriptionPolicy.open
+        # Subscribe User.
+        ISubscriptionManager(self._mlist).register(
+            anne,
+            pre_verified=True,
+            pre_confirmed=True,
+            pre_approved=True,
+            send_welcome_message=False
+            )
+        workflow = SubscriptionWorkflow(self._mlist, anne.preferred_address)
+        self.assertRaises(
+            AlreadySubscribedError, workflow.run_thru, 'sanity_checks')
+
     def test_sanity_checks_globally_banned_address(self):
         # An exception is raised if the address is globally banned.
         anne = self._user_manager.create_address(self._anne)


=====================================
src/mailman/docs/NEWS.rst
=====================================
@@ -52,6 +52,8 @@ Bugs fixed
   ``template`` table.  (Closes #988)
 * DMARC munge from mitigation will now find a nonmember poster's display name.
   (Closes #989)
+* Subscription workflow will now find an existing User when subscription is
+  for an Address and vice versa.  (Closes #994)
 
 REST
 ====



View it on GitLab: 
https://gitlab.com/mailman/mailman/-/compare/b39737eb90f41749cd7dfcec112d7b8043b46bd0...54d087b7e783c0cd026f5e0ad7cd9e33da56a290

-- 
View it on GitLab: 
https://gitlab.com/mailman/mailman/-/compare/b39737eb90f41749cd7dfcec112d7b8043b46bd0...54d087b7e783c0cd026f5e0ad7cd9e33da56a290
You're receiving this email because of your account on gitlab.com.


_______________________________________________
Mailman-checkins mailing list -- mailman-checkins@python.org
To unsubscribe send an email to mailman-checkins-le...@python.org
https://mail.python.org/mailman3/lists/mailman-checkins.python.org/
Member address: arch...@jab.org

Reply via email to