api: add triggerable jump actions to carddef api (#88875)

This commit is contained in:
Corentin Sechet 2024-04-05 11:23:16 +02:00 committed by Corentin Sechet
parent 8779eea796
commit ba7eb70024
2 changed files with 41 additions and 0 deletions

View File

@ -269,6 +269,40 @@ def test_carddef_schema_global_actions(pub):
assert resp.json['workflow']['actions'] == {}
def test_carddef_schema_jump_triggers(pub):
CardDef.wipe()
Workflow.wipe()
pub.role_class.wipe()
role = pub.role_class(name='test')
role.store()
workflow = Workflow(name='test-workflow')
source_status = workflow.add_status('source-status')
workflow.add_status('target-status')
jump = source_status.add_action('jump')
jump.trigger = 'test-trigger'
workflow.store()
carddef = CardDef()
carddef.name = 'test-actions'
carddef.workflow = workflow
carddef.store()
resp = get_app(pub).get(sign_uri('/api/cards/test-actions/@schema'), status=200)
assert resp.json['workflow']['actions'] == {
'jump:test-trigger': {'label': 'source-status (test-trigger)'}
}
jump.trigger = None
workflow.store()
resp = get_app(pub).get(sign_uri('/api/cards/test-actions/@schema'), status=200)
assert resp.json['workflow']['actions'] == {}
def test_carddef_schema_user_cards_datasource(pub):
CardDef.wipe()
carddef = CardDef()

View File

@ -1468,6 +1468,13 @@ class Workflow(StorableObject):
'label': f'{trigger.parent.name} ({trigger.identifier})'
}
for status in self.possible_status:
for item in status.items:
if item.key != 'jump' or not item.trigger:
continue
root['actions'][f'jump:{item.trigger}'] = {'label': f'{item.parent.name} ({item.trigger})'}
return root
@classmethod