diff options
| author | Barry Warsaw | 2016-09-13 19:43:34 +1200 |
|---|---|---|
| committer | Barry Warsaw | 2016-09-13 19:43:34 +1200 |
| commit | 74c7d6d1d089864fe01a3f2502314c31508a4781 (patch) | |
| tree | 13ebba81466850b64b4fb909018aa09694806d8f /src/mailman/app | |
| parent | e18e7ac34e8b4b2f88d5987ccb76a39c54c61c0c (diff) | |
| download | mailman-74c7d6d1d089864fe01a3f2502314c31508a4781.tar.gz mailman-74c7d6d1d089864fe01a3f2502314c31508a4781.tar.zst mailman-74c7d6d1d089864fe01a3f2502314c31508a4781.zip | |
Split registration (subscription) and unsubscription:
* events
* notices
* handlers
Also, be sure to do only one `leave` command per email.
Diffstat (limited to 'src/mailman/app')
| -rw-r--r-- | src/mailman/app/events.py | 3 | ||||
| -rw-r--r-- | src/mailman/app/subscriptions.py | 36 | ||||
| -rw-r--r-- | src/mailman/app/tests/test_subscriptions.py | 4 |
3 files changed, 25 insertions, 18 deletions
diff --git a/src/mailman/app/events.py b/src/mailman/app/events.py index d039a13d6..e29eee35c 100644 --- a/src/mailman/app/events.py +++ b/src/mailman/app/events.py @@ -38,6 +38,7 @@ def initialize(): passwords.handle_ConfigurationUpdatedEvent, style_manager.handle_ConfigurationUpdatedEvent, subscriptions.handle_ListDeletingEvent, - subscriptions.handle_ConfirmationNeededEvent, + subscriptions.handle_RegistrationConfirmationNeededEvent, + subscriptions.handle_UnsubscriptionConfirmationNeededEvent, switchboard.handle_ConfigurationUpdatedEvent, ]) diff --git a/src/mailman/app/subscriptions.py b/src/mailman/app/subscriptions.py index 49a83c293..2790a6751 100644 --- a/src/mailman/app/subscriptions.py +++ b/src/mailman/app/subscriptions.py @@ -36,8 +36,9 @@ from mailman.interfaces.mailinglist import SubscriptionPolicy from mailman.interfaces.member import MembershipIsBannedError, NotAMemberError from mailman.interfaces.pending import IPendable, IPendings from mailman.interfaces.subscriptions import ( - ConfirmationNeededEvent, ISubscriptionManager, ISubscriptionService, - SubscriptionPendingError, TokenOwner) + ISubscriptionManager, ISubscriptionService, + RegistrationConfirmationNeededEvent, SubscriptionPendingError, TokenOwner, + UnsubscriptionConfirmationNeededEvent) from mailman.interfaces.template import ITemplateLoader from mailman.interfaces.user import IUser from mailman.interfaces.usermanager import IUserManager @@ -303,7 +304,7 @@ class SubscriptionWorkflow(Workflow): self.push('do_confirm_verify') self.save() # Triggering this event causes the confirmation message to be sent. - notify(ConfirmationNeededEvent( + notify(RegistrationConfirmationNeededEvent( self.mlist, self.token, self.address.email)) # Now we wait for the confirmation. raise StopIteration @@ -463,7 +464,7 @@ class UnSubscriptionWorkflow(Workflow): self._set_token(TokenOwner.subscriber) self.push('do_confirm_verify') self.save() - notify(ConfirmationNeededEvent( + notify(UnsubscriptionConfirmationNeededEvent( self.mlist, self.token, self.address.email)) raise StopIteration @@ -618,21 +619,12 @@ class UnsubscriptionManager(BaseSubscriptionManager): return workflow.token, workflow.token_owner, workflow.member -@public -def handle_ConfirmationNeededEvent(event): - if not isinstance(event, ConfirmationNeededEvent): - return - # There are three ways for a user to confirm their subscription. They - # can reply to the original message and let the VERP'd return address - # encode the token, they can reply to the robot and keep the token in - # the Subject header, or they can click on the URL in the body of the - # message and confirm through the web. +def _handle_confirmation_needed_events(event, template_name): subject = 'confirm {}'.format(event.token) confirm_address = event.mlist.confirm_address(event.token) email_address = event.email # Send a verification email to the address. - template = getUtility(ITemplateLoader).get( - 'list:user:action:confirm', event.mlist) + template = getUtility(ITemplateLoader).get(template_name, event.mlist) text = expand(template, event.mlist, dict( token=event.token, subject=subject, @@ -649,6 +641,20 @@ def handle_ConfirmationNeededEvent(event): @public +def handle_RegistrationConfirmationNeededEvent(event): + if not isinstance(event, RegistrationConfirmationNeededEvent): + return + _handle_confirmation_needed_events(event, 'list:user:action:subscribe') + + +@public +def handle_UnsubscriptionConfirmationNeededEvent(event): + if not isinstance(event, UnsubscriptionConfirmationNeededEvent): + return + _handle_confirmation_needed_events(event, 'list:user:action:unsubscribe') + + +@public def handle_ListDeletingEvent(event): """Delete a mailing list's members when the list is being deleted.""" diff --git a/src/mailman/app/tests/test_subscriptions.py b/src/mailman/app/tests/test_subscriptions.py index 42b60b552..9f02593a9 100644 --- a/src/mailman/app/tests/test_subscriptions.py +++ b/src/mailman/app/tests/test_subscriptions.py @@ -286,8 +286,8 @@ class TestSubscriptionWorkflow(unittest.TestCase): def test_moderation_checks_approval_required(self): # The moderator must approve the subscription. self._mlist.subscription_policy = SubscriptionPolicy.moderate - anne = self._user_manager.create_address(self._anne, pre_verified=True) - workflow = SubscriptionWorkflow(self._mlist, anne) + anne = self._user_manager.create_address(self._anne) + workflow = SubscriptionWorkflow(self._mlist, anne, pre_verified=True) workflow.run_thru('moderation_checks') with patch.object(workflow, '_step_get_moderator_approval') as step: next(workflow) |
