diff options
| -rw-r--r-- | src/mailman/app/subscriptions.py | 19 | ||||
| -rw-r--r-- | src/mailman/app/tests/test_subscriptions.py | 15 | ||||
| -rw-r--r-- | src/mailman/database/alembic/versions/2bb9b382198_workflow_state_table.py | 2 | ||||
| -rw-r--r-- | src/mailman/model/workflowstate.py | 4 |
4 files changed, 33 insertions, 7 deletions
diff --git a/src/mailman/app/subscriptions.py b/src/mailman/app/subscriptions.py index 507f8bf28..375fe159d 100644 --- a/src/mailman/app/subscriptions.py +++ b/src/mailman/app/subscriptions.py @@ -93,19 +93,30 @@ class Workflow: # 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. # If we want to support more than a single step in the queue AND want - # to support state saving/restoring, change this method and - # restore_state(). + # to support state saving/restoring, change this method and the + # restore_state() method. + if len(self._next) == 0: + step = None + elif len(self._next) == 1: + step = self._next[0] + else: + raise AssertionError( + "Can't save a workflow state with more than one step " + "in the queue") state_manager.save( self.__class__.__name__, self._save_key, - self._next[0], + step, json.dumps(data)) def restore_state(self): 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 not state.step: + self._next.clear() + else: + self._next[0] = state.step if state.data is not None: for attr, value in json.loads(state.data).items(): setattr(self, attr, value) diff --git a/src/mailman/app/tests/test_subscriptions.py b/src/mailman/app/tests/test_subscriptions.py index fde33b91e..05646c929 100644 --- a/src/mailman/app/tests/test_subscriptions.py +++ b/src/mailman/app/tests/test_subscriptions.py @@ -100,6 +100,21 @@ class TestSubscriptionWorkflow(unittest.TestCase): self.assertEqual(workflow.pre_confirmed, False) self.assertEqual(workflow.pre_approved, False) + def test_save_restore_no_next_step(self): + anne = self._user_manager.create_address(self._anne, 'Anne Person') + workflow = SubscriptionWorkflow( + self._mlist, anne, + pre_verified=True, pre_confirmed=False, pre_approved=False) + workflow._next.pop() + self.assertEqual(len(workflow._next), 0) + workflow.save_state() + # Now create a new instance and restore + workflow = SubscriptionWorkflow( + self._mlist, anne, + pre_verified=None, pre_confirmed=None, pre_approved=None) + workflow.restore_state() + self.assertEqual(len(workflow._next), 0) + def test_preverified_address_joins_open_list(self): # The mailing list has an open subscription policy, so the subscriber # becomes a member with no human intervention. diff --git a/src/mailman/database/alembic/versions/2bb9b382198_workflow_state_table.py b/src/mailman/database/alembic/versions/2bb9b382198_workflow_state_table.py index 23b3adebb..e6608b6ce 100644 --- a/src/mailman/database/alembic/versions/2bb9b382198_workflow_state_table.py +++ b/src/mailman/database/alembic/versions/2bb9b382198_workflow_state_table.py @@ -18,7 +18,7 @@ def upgrade(): op.create_table('workflowstate', sa.Column('name', sa.Unicode(), nullable=False), sa.Column('key', sa.Unicode(), nullable=False), - sa.Column('step', sa.Unicode(), nullable=False), + sa.Column('step', sa.Unicode(), nullable=True), sa.Column('data', sa.Unicode(), nullable=True), sa.PrimaryKeyConstraint('name', 'key') ) diff --git a/src/mailman/model/workflowstate.py b/src/mailman/model/workflowstate.py index ee0226d61..229a2240b 100644 --- a/src/mailman/model/workflowstate.py +++ b/src/mailman/model/workflowstate.py @@ -40,7 +40,7 @@ class WorkflowState(Model): name = Column(Unicode, primary_key=True) key = Column(Unicode, primary_key=True) - step = Column(Unicode, nullable=False) + step = Column(Unicode) data = Column(Unicode) @@ -50,7 +50,7 @@ class WorkflowStateManager: """See `IWorkflowStateManager`.""" @dbconnection - def save(self, store, name, key, step, data=None): + def save(self, store, name, key, step=None, data=None): """See `IWorkflowStateManager`.""" state = store.query(WorkflowState).get((name, key)) if state is None: |
