From 0be4a9c149ce29b76a6badc7db2b613f03456d66 Mon Sep 17 00:00:00 2001
From: Nicolas ROCHE <nroche@entrouvert.com>
Date: Thu, 13 Aug 2020 14:44:14 +0200
Subject: [PATCH] admin: detail target status on choice action (#39207)

---
 tests/test_admin_pages.py | 57 +++++++++++++++++++++++++++++++++++++++
 wcs/workflows.py          | 24 ++++++++++-------
 2 files changed, 72 insertions(+), 9 deletions(-)

diff --git a/tests/test_admin_pages.py b/tests/test_admin_pages.py
index 43d41efe..1db181c4 100644
--- a/tests/test_admin_pages.py
+++ b/tests/test_admin_pages.py
@@ -997,16 +997,73 @@ def test_workflows_edit_choice_action_functions_only(pub):
 
     resp = app.get('/backoffice/workflows/1/')
     resp = resp.click('baz')
     resp = resp.click(href='items/1/', index=0)
     assert 'foobar' not in [x[2] for x in resp.form['by$element0'].options]
     assert '_receiver' in [x[0] for x in resp.form['by$element0'].options]
 
 
+def test_workflows_edit_choice_action_line_details(pub):
+    create_superuser(pub)
+    create_role()
+
+    Workflow.wipe()
+    wf = Workflow(name='foo')
+    st1 = wf.add_status('New')
+    st2 = wf.add_status('Resubmit')
+
+    jump = ChoiceWorkflowStatusItem()
+    jump.id = '1'
+    jump.parent = st1
+    st1.items.append(jump)
+    wf.store()
+
+    app = login(get_app(pub))
+    resp = app.get('/backoffice/workflows/%s/status/%s/' % (wf.id, st1.id))
+    assert resp.html.find('a', {'href': 'items/1/'}).text == 'Manual Jump (not completed)'
+
+    jump.label = 'Resubmit'
+    wf.store()
+    resp = app.get('/backoffice/workflows/%s/status/%s/' % (wf.id, st1.id))
+    assert resp.html.find('a', {'href': 'items/1/'}).text == \
+        'Manual Jump ("Resubmit", to New)'
+
+    jump.status = st2.id
+    wf.store()
+    resp = app.get('/backoffice/workflows/%s/status/%s/' % (wf.id, st1.id))
+    assert resp.html.find('a', {'href': 'items/1/'}).text == \
+        'Manual Jump ("Resubmit", to Resubmit)'
+
+    jump.label = 'Resubmit'
+    wf.store()
+    resp = app.get('/backoffice/workflows/%s/status/%s/' % (wf.id, st1.id))
+    assert resp.html.find('a', {'href': 'items/1/'}).text == \
+        'Manual Jump ("Resubmit", to Resubmit)'
+
+    jump.set_marker_on_status = True
+    wf.store()
+    resp = app.get('/backoffice/workflows/%s/status/%s/' % (wf.id, st1.id))
+    assert resp.html.find('a', {'href': 'items/1/'}).text == \
+        'Manual Jump ("Resubmit", to Resubmit (and set marker))'
+
+    jump.set_marker_on_status = False
+    jump.by = ['_submitter']
+    wf.store()
+    resp = app.get('/backoffice/workflows/%s/status/%s/' % (wf.id, st1.id))
+    assert resp.html.find('a', {'href': 'items/1/'}).text == \
+        'Manual Jump ("Resubmit", to Resubmit, by User)'
+
+    jump.set_marker_on_status = True
+    wf.store()
+    resp = app.get('/backoffice/workflows/%s/status/%s/' % (wf.id, st1.id))
+    assert resp.html.find('a', {'href': 'items/1/'}).text == \
+        'Manual Jump ("Resubmit", to Resubmit, by User (and set marker))'
+
+
 def test_workflows_action_subpath(pub):
     create_superuser(pub)
     role = create_role()
     Workflow.wipe()
     workflow = Workflow(name='foo')
     baz_status = workflow.add_status(name='baz')
     display_message = DisplayMessageWorkflowStatusItem()
     display_message.parent = baz_status
diff --git a/wcs/workflows.py b/wcs/workflows.py
index da6e1856..a7e53744 100644
--- a/wcs/workflows.py
+++ b/wcs/workflows.py
@@ -2408,27 +2408,33 @@ class ChoiceWorkflowStatusItem(WorkflowStatusJumpItem):
             return expression['value']
         return _('computed label')
 
     def get_line_details(self):
         if self.label:
             more = ''
             if self.set_marker_on_status:
                 more += ' ' + _('(and set marker)')
+            if self.status:
+                to_status = self.parent.parent.get_status(self.status)
+            else:
+                to_status = self.parent
             if self.by:
-                return  _('"%(label)s" by %(by)s%(more)s') % {
-                        'label' : self.get_label(),
-                        'by' : self.render_list_of_roles(self.by),
-                        'more': more
-                    }
+                return  _('"%(label)s", to %(to)s, by %(by)s%(more)s') % {
+                    'label' : self.get_label(),
+                    'to' : to_status.name,
+                    'by' : self.render_list_of_roles(self.by),
+                    'more': more
+                }
             else:
-                return _('"%(label)s"%(more)s') % {
-                        'label': self.get_label(),
-                        'more': more
-                    }
+                return  _('"%(label)s", to %(to)s%(more)s') % {
+                    'label' : self.get_label(),
+                    'to' : to_status.name,
+                    'more': more
+                }
         else:
             return _('not completed')
 
     def fill_form(self, form, formdata, user, **kwargs):
         label = self.compute(self.label)
         if not label:
             return
         widget = form.add_submit('button%s' % self.id, label)
-- 
2.28.0

