forms: display messages from visible status (#55409)

This commit is contained in:
Frédéric Péters 2021-07-05 17:51:02 +02:00
parent 1627285621
commit 01809d67f7
4 changed files with 16 additions and 4 deletions

View File

@ -5597,7 +5597,7 @@ def test_backoffice_display_message(pub):
formdef.store()
formdata = formdef.data_class().select()[0]
formdata.status = 'wf-st1'
formdata.jump_status('st1')
formdata.store()
app = login(get_app(pub))

View File

@ -4916,6 +4916,12 @@ def test_display_message(pub):
formdef.store()
workflow = Workflow(name='test')
st0 = workflow.add_status('Status0', 'st0')
jump = JumpWorkflowStatusItem()
jump.status = 'st1'
st0.items.append(jump)
jump.parent = st0
st1 = workflow.add_status('Status1', 'st1')
display1 = DisplayMessageWorkflowStatusItem()
@ -5011,6 +5017,12 @@ def test_display_message(pub):
page = app.get(formdata.get_url())
assert 'warningnotice' in page.text
# check message is not displayed if status is not visible to user
st1.visibility = ['_receiver']
workflow.store()
page = app.get(formdata.get_url())
assert 'warningnotice' not in page.text
def test_workflow_condition_on_message(pub):
create_user(pub)

View File

@ -535,8 +535,8 @@ class FormData(StorableObject):
perform_items(action.items, self)
break
def get_workflow_messages(self, position='top'):
wf_status = self.get_status()
def get_workflow_messages(self, position='top', user=None):
wf_status = self.get_visible_status(user=user)
if not wf_status:
return []
messages = []

View File

@ -183,7 +183,7 @@ class FormStatusPage(Directory, FormTemplateMixin):
def workflow_messages(self, position='top'):
if self.formdef.workflow:
workflow_messages = self.filled.get_workflow_messages(position=position)
workflow_messages = self.filled.get_workflow_messages(position=position, user=get_request().user)
if workflow_messages:
r = TemplateIO(html=True)
if position == 'top':