misc: make identifier of status manual actions unique (#75321)
gitea/wcs/pipeline/head This commit looks good Details

This commit is contained in:
Benjamin Dauvergne 2023-03-16 10:04:29 +01:00
parent 7e4375e203
commit cb6fe33c70
2 changed files with 10 additions and 4 deletions

View File

@ -835,7 +835,7 @@ def test_backoffice_multi_actions_jump(pub):
ids.append(checkbox._value)
checkbox.checked = True
resp = resp.forms['multi-actions'].submit('button-action-st-new-accept')
resp = resp.forms['multi-actions'].submit('button-action-st-new-accept-_accept')
assert '?job=' in resp.location
resp = resp.follow()
assert 'Executing task "Accept" on forms' in resp.text
@ -905,7 +905,7 @@ def test_backoffice_multi_actions_jump_condition(pub):
}
workflow.store()
resp = resp.forms['multi-actions'].submit('button-action-st-new-accept')
resp = resp.forms['multi-actions'].submit('button-action-st-new-accept-_accept')
assert '?job=' in resp.location
resp = resp.follow()
assert 'Executing task "Accept" on forms' in resp.text

View File

@ -881,7 +881,7 @@ class Workflow(StorableObject):
class StatusAction:
def __init__(self, action):
self.status_id = action.parent.id
self.id = 'st-%s-%s' % (self.status_id, action.identifier)
self.id = 'st-%s-%s-%s' % (self.status_id, action.identifier, action.id)
self.name = action.get_label()
self.status_action = True
self.require_confirmation = action.require_confirmation
@ -897,14 +897,20 @@ class Workflow(StorableObject):
actions = []
choices = [x for x in get_actions(self) if x.key == 'choice' and x.identifier]
seen = set()
for action in choices:
roles = action.by or []
functions = [x for x in roles if x in (self.roles or [])]
roles = [x for x in roles if x not in (self.roles or [])]
if functions or roles:
status_action = StatusAction(action)
if status_action.id in seen:
# prevent multiple action with the same identifier to be shown
continue
seen.add(status_action.id)
actions.append(
{
'action': StatusAction(action),
'action': status_action,
'roles': roles,
'functions': functions,
'statuses': [action.parent.id],