diff options
| author | Barry Warsaw | 2015-04-13 18:28:59 -0400 |
|---|---|---|
| committer | Barry Warsaw | 2015-04-13 18:28:59 -0400 |
| commit | 24c01dbd8e93acdc61884b3b9783a0e71fd6df23 (patch) | |
| tree | 18d2503ae488efa403f9606b9fbdf67298fec7ff | |
| parent | f7a4e76d24898ec942a0f3a9a932916d9d0662bc (diff) | |
| download | mailman-24c01dbd8e93acdc61884b3b9783a0e71fd6df23.tar.gz mailman-24c01dbd8e93acdc61884b3b9783a0e71fd6df23.tar.zst mailman-24c01dbd8e93acdc61884b3b9783a0e71fd6df23.zip | |
The SubscriptionWorkflow class doesn't need to include the expiry date in its
pendable data since that gets added automatically by the IPendings utility.
After the user is subscribed, clean up the saved workflows and reset the token
to None.
Give the SubscriptionWorkflow a name property for convenience.
| -rw-r--r-- | src/mailman/app/subscriptions.py | 5 | ||||
| -rw-r--r-- | src/mailman/app/tests/test_subscriptions.py | 28 | ||||
| -rw-r--r-- | src/mailman/app/workflow.py | 4 |
3 files changed, 36 insertions, 1 deletions
diff --git a/src/mailman/app/subscriptions.py b/src/mailman/app/subscriptions.py index 6c60a71a4..999b04270 100644 --- a/src/mailman/app/subscriptions.py +++ b/src/mailman/app/subscriptions.py @@ -50,6 +50,7 @@ from mailman.interfaces.subscriptions import ( ISubscriptionService, MissingUserError, RequestRecord) from mailman.interfaces.user import IUser from mailman.interfaces.usermanager import IUserManager +from mailman.interfaces.workflow import IWorkflowStateManager from mailman.model.member import Member from mailman.utilities.datetime import now from mailman.utilities.i18n import make @@ -176,7 +177,6 @@ class SubscriptionWorkflow(Workflow): # Create a pending record. This will give us the hash token we can use # to uniquely name this workflow. pendable = Pendable( - when=now().isoformat(), list_id=self.mlist.list_id, address=self.address.email, ) @@ -268,6 +268,9 @@ class SubscriptionWorkflow(Workflow): def _step_do_subscription(self): # We can immediately subscribe the user to the mailing list. self.mlist.subscribe(self.subscriber) + # This workflow is done so throw away any associated state. + getUtility(IWorkflowStateManager).restore(self.name, self.token) + self.token = None def _step_send_confirmation(self): self.push('do_confirm_verify') diff --git a/src/mailman/app/tests/test_subscriptions.py b/src/mailman/app/tests/test_subscriptions.py index bdfa72e29..7bb635a16 100644 --- a/src/mailman/app/tests/test_subscriptions.py +++ b/src/mailman/app/tests/test_subscriptions.py @@ -32,12 +32,14 @@ from mailman.interfaces.address import InvalidEmailAddressError from mailman.interfaces.bans import IBanManager from mailman.interfaces.member import ( MemberRole, MembershipIsBannedError, MissingPreferredAddressError) +from mailman.interfaces.pending import IPendings from mailman.interfaces.subscriptions import ( MissingUserError, ISubscriptionService) from mailman.testing.helpers import LogFileMark, get_queue_messages from mailman.testing.layers import ConfigLayer from mailman.interfaces.mailinglist import SubscriptionPolicy from mailman.interfaces.usermanager import IUserManager +from mailman.interfaces.workflow import IWorkflowStateManager from mailman.utilities.datetime import now from unittest.mock import patch from zope.component import getUtility @@ -343,6 +345,32 @@ class TestSubscriptionWorkflow(unittest.TestCase): member = self._mlist.regular_members.get_member(self._anne) self.assertEqual(member.address, anne) + def test_do_subscription_cleanups(self): + # Once the user is subscribed, the token, and its associated pending + # database record will be removed from the database. + self._mlist.subscription_policy = SubscriptionPolicy.open + anne = self._user_manager.create_address(self._anne) + workflow = SubscriptionWorkflow(self._mlist, anne, + pre_verified=True, + pre_confirmed=True, + pre_approved=True) + # Cache the token. + token = workflow.token + # Consume the entire state machine. + list(workflow) + # Anne is now a member of the mailing list. + member = self._mlist.regular_members.get_member(self._anne) + self.assertEqual(member.address, anne) + # The workflow is done, so it has no token. + self.assertIsNone(workflow.token) + # The pendable associated with the token has been evicted. + self.assertIsNone(getUtility(IPendings).confirm(token, expunge=False)) + # There is no saved workflow associated with the token. + new_workflow = SubscriptionWorkflow(self._mlist) + new_workflow.token = token + new_workflow.restore() + self.assertIsNone(new_workflow.which) + def test_moderator_approves(self): # The workflow runs until moderator approval is required, at which # point the workflow is saved. Once the moderator approves, the diff --git a/src/mailman/app/workflow.py b/src/mailman/app/workflow.py index 9395dc7b7..8006f8e51 100644 --- a/src/mailman/app/workflow.py +++ b/src/mailman/app/workflow.py @@ -49,6 +49,10 @@ class Workflow: self.debug = False self._count = 0 + @property + def name(self): + return self.__class__.__name__ + def __iter__(self): return self |
