backoffice: don't include endpoint status in "waiting" listings (#14384)

This commit is contained in:
Frédéric Péters 2016-12-19 17:26:05 +01:00 committed by Thomas NOEL
parent 1a2b4cb8e6
commit fdf9921f8e
2 changed files with 48 additions and 4 deletions

View File

@ -275,6 +275,7 @@ def test_backoffice_listing(pub):
workflow = Workflow.get_default_workflow()
workflow.id = '2'
st1 = workflow.add_status('Status1')
st1.id = 'plop'
jump = JumpWorkflowStatusItem()
jump.id = '_jump'
jump.timeout = 86400
@ -298,6 +299,47 @@ def test_backoffice_listing(pub):
resp = resp.forms[0].submit()
assert resp.body.count('data-link') == 17
# check status forced as endpoints are not part of the "actionable" list.
workflow = Workflow.get_default_workflow()
workflow.id = '3'
st1 = workflow.add_status('Status1')
st1.id = 'plop'
st1.forced_endpoint = False
again = ChoiceWorkflowStatusItem()
again.id = '_again'
again.label = 'Again'
again.by = ['_receiver']
again.status = st1.id
st1.items.append(again)
again.parent = st1
workflow.store()
formdef = FormDef.get_by_urlname('form-title')
formdef.workflow = workflow
formdef.store()
formdef.data_class().rebuild_security()
for i, formdata in enumerate(formdef.data_class().select(order_by='id')):
if formdata.status == 'wf-new' and i % 2:
formdata.status = 'wf-%s' % st1.id
formdata.store()
resp = app.get('/backoffice/management/form-title/')
assert resp.body.count('data-link') == 17
resp.forms[0]['filter'] = 'pending'
resp = resp.forms[0].submit()
assert resp.body.count('data-link') == 17
# mark status as an endpoint
st1.forced_endpoint = True
workflow.store()
formdef.data_class().rebuild_security()
resp = app.get('/backoffice/management/form-title/')
assert resp.body.count('data-link') == 9
resp.forms[0]['filter'] = 'pending'
resp = resp.forms[0].submit()
assert resp.body.count('data-link') == 9
def test_backoffice_listing_pagination(pub):
if not pub.is_using_postgresql():

View File

@ -152,12 +152,9 @@ class FormDefUI(object):
item_ids = formdata_class.keys()
drafts = formdata_class.get_ids_with_indexed_value('status', 'draft')
item_ids = [x for x in item_ids if x not in drafts]
elif selected_filter == 'waiting':
user_roles = [logged_users_role().id] + (user.roles or [])
item_ids = formdata_class.get_actionable_ids(user_roles)
else:
applied_filters = []
if selected_filter == 'pending':
if selected_filter in ('pending', 'waiting'):
applied_filters = ['wf-%s' % x.id for x in \
self.formdef.workflow.get_not_endpoint_status()]
elif selected_filter == 'done':
@ -170,6 +167,11 @@ class FormDefUI(object):
item_ids.extend(formdata_class.get_ids_with_indexed_value(
str('status'), status_id))
if selected_filter == 'waiting':
user_roles = [logged_users_role().id] + (user.roles or [])
item_ids = list(set(item_ids).intersection(
formdata_class.get_actionable_ids(user_roles)))
if query:
query_ids = formdata_class.get_ids_from_query(query)
item_ids = list(set(item_ids).intersection(query_ids))