admin: use new option style for workflow related options (#8049)

This commit is contained in:
Frédéric Péters 2015-08-06 14:29:59 +02:00
parent 2adfe9d67b
commit b656dada7c
2 changed files with 49 additions and 71 deletions

View File

@ -357,7 +357,7 @@ def test_form_workflow():
app = login(get_app(pub))
resp = app.get('/backoffice/forms/1/')
assert 'Workflow:' not in resp.body
assert_option_display(resp, 'Workflow', 'Default')
Workflow.wipe()
workflow = Workflow(name='Workflow One')
@ -366,7 +366,7 @@ def test_form_workflow():
workflow.store()
resp = app.get('/backoffice/forms/1/')
assert 'Workflow:' in resp.body
assert_option_display(resp, 'Workflow', 'Default')
def test_form_workflow_change():
create_superuser()
@ -387,12 +387,12 @@ def test_form_workflow_change():
app = login(get_app(pub))
resp = app.get('/backoffice/forms/1/')
resp = resp.click('change', href='workflow')
resp = resp.click(href='workflow', index=1)
resp = resp.forms[0].submit('cancel')
assert FormDef.get(formdef.id).workflow_id is None
resp = app.get('/backoffice/forms/1/')
resp = resp.click('change', href='workflow')
resp = resp.click(href='workflow', index=1)
assert 'Workflow One' not in resp.body # this workflow doesn't have any status
resp.forms[0]['workflow_id'] = workflow.id
resp = resp.forms[0].submit('submit')
@ -424,7 +424,7 @@ def test_form_workflow_remapping():
app = login(get_app(pub))
resp = app.get('/backoffice/forms/1/')
resp = resp.click('change', href='workflow')
resp = resp.click(href='workflow', index=1)
resp.forms[0]['workflow_id'] = workflow.id
resp = resp.forms[0].submit('submit')
assert resp.location == 'http://example.net/backoffice/forms/1/workflow-status-remapping?new=2'
@ -449,11 +449,11 @@ def test_form_workflow_role():
app = login(get_app(pub))
resp = app.get('/backoffice/forms/1/')
resp = resp.click('change', href='role/_receiver')
resp = resp.click(href='role/_receiver')
resp = resp.forms[0].submit('cancel')
resp = app.get('/backoffice/forms/1/')
resp = resp.click('change', href='role/_receiver')
resp = resp.click(href='role/_receiver')
resp.forms[0]['role_id'] = 'foobar'
resp = resp.forms[0].submit('submit')
assert FormDef.get(1).workflow_roles == {'_receiver': '1'}
@ -532,11 +532,11 @@ def test_form_acl_read():
app = login(get_app(pub))
resp = app.get('/backoffice/forms/1/')
resp = resp.click('change', href='acl-read')
resp = resp.click(href='acl-read')
resp = resp.forms[0].submit('cancel')
resp = app.get('/backoffice/forms/1/')
resp = resp.click('change', href='acl-read')
resp = resp.click(href='acl-read')
resp.forms[0]['acl_read'] = 'Everybody'
resp = resp.forms[0].submit('submit')
assert FormDef.get(1).acl_read == 'all'
@ -553,11 +553,12 @@ def test_form_roles():
app = login(get_app(pub))
resp = app.get('/backoffice/forms/1/')
resp = resp.click('change', href='roles', index=0)
resp = resp.click('User Roles')
resp = resp.forms[0].submit('cancel')
resp = app.get('/backoffice/forms/1/')
resp = resp.click('change', href='roles', index=0)
resp = resp.click('User Roles')
resp.forms[0]['roles$element0'].value = role.name
resp = resp.forms[0].submit('submit')
assert FormDef.get(1).roles == [role.id]
@ -917,16 +918,16 @@ def test_form_legacy_int_id():
assert resp.forms[0]['category_id'].value
resp = app.get('/backoffice/forms/1/')
resp = resp.click('change', href='workflow')
resp = resp.click(href='workflow', index=1)
assert resp.forms[0]['workflow_id'].value
resp = app.get('/backoffice/forms/1/')
resp = resp.click('change', href='roles', index=0)
resp = resp.click('User Roles')
assert resp.forms[0]['roles$element0'].value == 'Logged Users'
assert resp.forms[0]['roles$element1'].value == 'ZAB'
resp = app.get('/backoffice/forms/1/')
resp = resp.click('change', href='role/_receiver')
resp = resp.click('Recipient')
assert resp.forms[0]['role_id'].value == 'ZAB'
def test_form_anonymise():

View File

@ -367,67 +367,50 @@ class FormDefPage(Directory):
r += htmltext('<div class="splitcontent-left">')
r += htmltext('<div class="bo-block">')
r += htmltext('<h3>%s</h3>') % _('Access')
r += htmltext('<ul>')
r += htmltext('<h3>%s</h3>') % _('Workflow')
r += htmltext('<ul class="biglist optionslist">')
workflows = get_workflows()
if workflows:
r += htmltext('<li>%s ') % _('Workflow:')
if self.formdef.workflow:
r += self.formdef.workflow.name
else:
r += '-'
if self.formdef.workflow_id:
pristine_workflow = Workflow.get(self.formdef.workflow_id)
if pristine_workflow.variables_formdef:
r += htmltext(' (<a rel="popup" href="workflow-variables">%s</a>)') % _('options')
elif self.formdef.workflow_options:
# there are no variables defined but there are some values
# in workflow_options, this is probably the legacy stuff.
if any((x for x in self.formdef.workflow_options if '*' in x)):
r += htmltext(' (<a rel="popup" href="workflow-options">%s</a>)') % _('options')
r += add_option_line('workflow', _('Workflow'),
self.formdef.workflow and self.formdef.workflow.name or '-')
r += ' '
r += htmltext('(<a href="workflow" rel="popup">%s</a>)') % _('change')
r += htmltext('</li>')
if self.formdef.workflow_id:
pristine_workflow = Workflow.get(self.formdef.workflow_id)
if pristine_workflow.variables_formdef:
r += add_option_line('workflow-variables', _('Options'), '')
elif self.formdef.workflow_options:
# there are no variables defined but there are some values
# in workflow_options, this is probably the legacy stuff.
if any((x for x in self.formdef.workflow_options if '*' in x)):
r += add_option_line('workflow-options', _('Options'), '')
if self.formdef.workflow.roles:
r += htmltext('<li>%s ') % _('Workflow Roles:')
r += htmltext('<ul>')
if not self.formdef.workflow_roles:
self.formdef.workflow_roles = {}
for (wf_role_id, wf_role_label) in self.formdef.workflow.roles.items():
r += htmltext('<li>%s ') % _('%s:') % wf_role_label
role_id = self.formdef.workflow_roles.get(wf_role_id)
if role_id:
try:
role = Role.get(role_id)
r += htmltext('<a href="../../roles/%s/">%s</a>') % (role.id, role.name)
role_label = role.name
except KeyError:
# removed role ?
r += htmltext('<em>')
r += _('Unknown role (%s)') % role_id
r += htmltext('</em>')
role_label = _('Unknown role (%s)') % role_id
else:
r += '-'
r += htmltext(' ')
r += htmltext('(<a href="role/%s" rel="popup">%s</a>)') % (wf_role_id, _('change'))
r += htmltext('</li>')
r += htmltext('</ul>')
r += htmltext('</li>')
role_label = '-'
r += add_option_line('role/%s' % wf_role_id,
wf_role_label, role_label)
r += self._display_roles(_('User Roles:'), 'roles', 'roles')
r += self._display_roles(_('Backoffice Submission Roles:'),
'backoffice_submission_roles',
'backoffice-submission-roles')
r += add_option_line('roles', _('User Roles'),
self._get_roles_label('roles'))
r += add_option_line('backoffice-submission-roles',
_('Backoffice Submission Role'),
self._get_roles_label('backoffice_submission_roles'))
r += htmltext('<li>%s ') % _('Read Access:')
r += '%s' % {'none': _('None'),
'owner': _('Owner'),
'roles': _('Roles'),
'all': _('Everybody')}.get(self.formdef.acl_read, 'none')
r += ' '
r += htmltext('(<a href="acl-read" rel="popup">%s</a>)') % _('change')
r += add_option_line('acl-read', _('Read Access'),
{'none': _('None'),
'owner': _('Owner'),
'roles': _('Roles'),
'all': _('Everybody')}.get(self.formdef.acl_read, 'none'))
r += htmltext('</ul>')
r += htmltext('</div>')
r += htmltext('</div>')
@ -485,9 +468,7 @@ class FormDefPage(Directory):
r += htmltext('</div>')
return r.getvalue()
def _display_roles(self, title, attribute, change_url):
r = TemplateIO(html=True)
r += htmltext('<li>%s ') % title
def _get_roles_label(self, attribute):
if getattr(self.formdef, attribute):
roles = []
for x in getattr(self.formdef, attribute):
@ -495,18 +476,14 @@ class FormDefPage(Directory):
roles.append(logged_users_role().name)
else:
try:
roles.append(htmltext('<a href="../../roles/%s/">%s</a>') % (x, Role.get(x).name))
roles.append(Role.get(x).name)
except KeyError:
# removed role ?
roles.append(htmltext('<em>%s</em>') % _('Unknown role (%s)') % role_id)
r += htmltext(', ').join(roles)
roles.append(_('Unknown role (%s)') % role_id)
value = htmltext(', ').join(roles)
else:
r += '-'
r += ' '
r += htmltext('(<a href="%s" rel="popup">%s</a>)') % (
change_url, _('change'))
r += htmltext('</li>')
return r.getvalue()
value = _('None')
return value
def get_sidebar(self):
r = TemplateIO(html=True)