[damned-lies] Allow archiving if state has at least one action in it



commit 6170d1d08c40e3da63e64640c2aaf50cd68b8eaf
Author: Claude Paroz <claude 2xlibre net>
Date:   Fri Aug 26 16:48:07 2016 +0200

    Allow archiving if state has at least one action in it

 vertimus/models.py      |    4 ++--
 vertimus/tests/tests.py |    4 +++-
 2 files changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/vertimus/models.py b/vertimus/models.py
index 5b0271f..6afa539 100644
--- a/vertimus/models.py
+++ b/vertimus/models.py
@@ -105,7 +105,7 @@ class State(models.Model):
     def _get_available_actions(self, person, action_names):
         # For archived modules, the only possible action is to archive the state (by the coordinator only)
         if self.branch.module.archived:
-            if self.name != 'None' and person.is_coordinator(self.language.team):
+            if self.action_set.count() > 0 and person.is_coordinator(self.language.team):
                 return [ActionAA()]
             else:
                 return []
@@ -464,7 +464,7 @@ class Action(ActionAbstract):
 
     def apply_on(self, state, form_data):
         if not self.name in [a.name for a in state.get_available_actions(self.person)]:
-            raise Exception('Not allowed')
+            raise Exception('Action not allowed')
         self.state_db = state
         if self.file:
             self.file.save(self.file.name, self.file, save=False)
diff --git a/vertimus/tests/tests.py b/vertimus/tests/tests.py
index c20ae47..c329e63 100644
--- a/vertimus/tests/tests.py
+++ b/vertimus/tests/tests.py
@@ -517,7 +517,9 @@ class VertimusTest(TeamsAndRolesTests):
         self.assertEqual(state.name, 'Translated')
 
     def test_action_on_archived_module(self):
-        state = StateTranslated.objects.create(branch=self.b, domain=self.d, language=self.l)
+        state = StateNone.objects.create(branch=self.b, domain=self.d, language=self.l)
+        action = Action.new_by_name('WC', person=self.pt)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml, 'comment': "Hi!"})
         self.m.archived = True
         self.m.save()
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]