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

This commit is contained in:
Corentin Sechet 2024-03-29 15:21:33 +01:00 committed by Corentin Sechet
parent bb78703d7e
commit ab9adecf55
2 changed files with 40 additions and 0 deletions

View File

@ -237,6 +237,38 @@ def test_carddef_schema(pub):
resp = get_app(pub).get('/api/cards/test/@schema', status=403)
def test_carddef_schema_global_actions(pub):
CardDef.wipe()
Workflow.wipe()
pub.role_class.wipe()
role = pub.role_class(name='test')
role.store()
workflow = Workflow(name='test-workflow')
workflow.add_status('dummy-status')
action = workflow.add_global_action('Test Global Action')
trigger = action.append_trigger('webservice')
trigger.identifier = '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'] == {
'global-action:test-trigger': {'label': 'Test Global Action (test-trigger)'}
}
trigger.identifier = 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

@ -1459,6 +1459,14 @@ class Workflow(StorableObject):
root['fields'] = []
for field in self.get_backoffice_fields():
root['fields'].append(field.export_to_json(include_id=include_id))
root['actions'] = {}
for trigger in self.get_all_global_action_triggers():
if trigger.key == 'webservice' and trigger.identifier:
root['actions'][f'global-action:{trigger.identifier}'] = {
'label': f'{trigger.parent.name} ({trigger.identifier})'
}
return root
@classmethod