workflows: add "role" suffix to roles sharing a name with a function (#50584) #971

Merged
fpeters merged 1 commits from wip/50584-suffix-role-with-function-name into main 2024-01-26 08:46:44 +01:00
2 changed files with 36 additions and 1 deletions

View File

@ -4212,3 +4212,32 @@ def test_workflows_edit_aggregationemail_action(pub):
app = login(get_app(pub))
resp = app.get(item.get_admin_url())
assert '_submitter' not in [x[0] for x in resp.form['to$element0'].options]
def test_workflows_function_and_role_with_same_name(pub):
create_superuser(pub)
pub.role_class.wipe()
role1 = pub.role_class(name='Foo')
role1.store()
role2 = pub.role_class(name='Foobar')
role2.store()
Workflow.wipe()
workflow = Workflow(name='foo')
workflow.roles = {'_receiver': 'Receiver', '_foobar': 'Foobar'}
st1 = workflow.add_status(name='baz')
commentable = st1.add_action('commentable', id='_commentable')
workflow.store()
app = login(get_app(pub))
resp = app.get(commentable.get_admin_url())
assert resp.form['by$element0'].options == [
('None', True, '---'),
('_submitter', False, 'User'),
('_receiver', False, 'Receiver'),
('_foobar', False, 'Foobar'),
('logged-users', False, 'Logged Users'),
('', False, '----'),
(str(role1.id), False, 'Foo'),
(str(role2.id), False, 'Foobar [role]'), # same name as function -> role suffix
]

View File

@ -1303,7 +1303,13 @@ class Workflow(StorableObject):
# use empty string instead of None so it's not automatically
# picked as default value by the browser
t.append(('', '----', ''))
t.extend(get_user_roles())
existing_labels = {str(x[1]) for x in t}
t.extend(
[
(x[0], x[1] if x[1] not in existing_labels else '%s [%s]' % (x[1], _('role')), x[2])
for x in get_user_roles()
]
)
return t
def get_add_role_label(self):