summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAurélien Bompard2015-03-26 08:47:25 +0100
committerAurélien Bompard2015-03-26 08:47:25 +0100
commitba4570b9a2db63ce4b448fe293677fdb808daca1 (patch)
treebcd9fa32a6419da20650fec5f91b0aa1a567c056
parent2066c8e5df17987be402c238aff46eb1328f6837 (diff)
downloadmailman-ba4570b9a2db63ce4b448fe293677fdb808daca1.tar.gz
mailman-ba4570b9a2db63ce4b448fe293677fdb808daca1.tar.zst
mailman-ba4570b9a2db63ce4b448fe293677fdb808daca1.zip
Save and restore attributes
-rw-r--r--src/mailman/app/subscriptions.py22
-rw-r--r--src/mailman/app/tests/test_subscriptions.py5
2 files changed, 20 insertions, 7 deletions
diff --git a/src/mailman/app/subscriptions.py b/src/mailman/app/subscriptions.py
index 04e0955cb..33f70241b 100644
--- a/src/mailman/app/subscriptions.py
+++ b/src/mailman/app/subscriptions.py
@@ -24,6 +24,7 @@ __all__ = [
]
+import json
from collections import deque
from operator import attrgetter
from sqlalchemy import and_, or_
@@ -75,7 +76,10 @@ class SubscriptionWorkflow:
self.pre_verified = pre_verified
self.pre_confirmed = pre_confirmed
self.pre_approved = pre_approved
+ # State saving
self._save_key = "{}:{}".format(self.mlist.list_id, self.address.email)
+ self._save_attributes = ("pre_verified", "pre_confirmed",
+ "pre_approved")
# Prepare the state machine.
self._next = deque()
self._next.append("verification_check")
@@ -98,18 +102,24 @@ class SubscriptionWorkflow:
raise
def save_state(self):
- manager = getUtility(IWorkflowStateManager)
+ state_manager = getUtility(IWorkflowStateManager)
+ data = {attr: getattr(self, attr) for attr in self._save_attributes}
# Note: only the next step is saved, not the whole stack. Not an issue
# since there's never more than a single step in the queue anyway.
- # Also: we don't save & restore the self.pre_* variables, but we could,
- # using the data argument.
- manager.save(self.__class__.__name__, self._save_key, self._next[0])
+ state_manager.save(
+ self.__class__.__name__,
+ self._save_key,
+ self._next[0],
+ json.dumps(data))
def restore_state(self):
- manager = getUtility(IWorkflowStateManager)
- state = manager.restore(self.__class__.__name__, self._save_key)
+ state_manager = getUtility(IWorkflowStateManager)
+ state = state_manager.restore(self.__class__.__name__, self._save_key)
if state is not None:
self._next[0] = state.step
+ if state.data is not None:
+ for attr, value in json.loads(state.data).items():
+ setattr(self, attr, value)
def _maybe_set_preferred_address(self):
if self.user is None:
diff --git a/src/mailman/app/tests/test_subscriptions.py b/src/mailman/app/tests/test_subscriptions.py
index 97dbd8382..fde33b91e 100644
--- a/src/mailman/app/tests/test_subscriptions.py
+++ b/src/mailman/app/tests/test_subscriptions.py
@@ -93,9 +93,12 @@ class TestSubscriptionWorkflow(unittest.TestCase):
# Now create a new instance and restore
workflow = SubscriptionWorkflow(
self._mlist, anne,
- pre_verified=True, pre_confirmed=False, pre_approved=False)
+ pre_verified=None, pre_confirmed=None, pre_approved=None)
workflow.restore_state()
self.assertEqual(next_step, workflow._next[0])
+ self.assertEqual(workflow.pre_verified, True)
+ self.assertEqual(workflow.pre_confirmed, False)
+ self.assertEqual(workflow.pre_approved, False)
def test_preverified_address_joins_open_list(self):
# The mailing list has an open subscription policy, so the subscriber