misc: allow trailing slash in trigger calls (#51257)
This commit is contained in:
parent
c0a2648a39
commit
a614759d78
|
@ -47,7 +47,7 @@ l’exemple qui suit).
|
|||
|
||||
<screen>
|
||||
<output style="prompt">$ </output><input>curl -H "Accept: application/json" -X POST \
|
||||
https://www.example.net/inscriptions/newsletter/14/jump/trigger/validate<var>?signature…</var></input>
|
||||
https://www.example.net/inscriptions/newsletter/14/jump/trigger/validate/<var>?signature…</var></input>
|
||||
<output>{"url": null, "err": 0}</output>
|
||||
</screen>
|
||||
|
||||
|
@ -60,7 +60,7 @@ workflow du formulaire.
|
|||
<screen>
|
||||
<output style="prompt">$ </output><input>curl -H "Content-type: application/json" -H "Accept: application/json" \
|
||||
-X POST -d@donnes.json \
|
||||
https://www.example.net/inscriptions/newsletter/14/jump/trigger/validate<var>?signature…</var></input>
|
||||
https://www.example.net/inscriptions/newsletter/14/jump/trigger/validate/<var>?signature…</var></input>
|
||||
<output>{"url": null, "err": 0}</output>
|
||||
</screen>
|
||||
|
||||
|
|
|
@ -3133,6 +3133,11 @@ def test_workflow_trigger(pub, local_user):
|
|||
resp = get_app(pub).post(sign_uri(formdata.get_url() + 'jump/trigger/XXX'), status=200)
|
||||
assert formdef.data_class().get(formdata.id).status == 'wf-st2'
|
||||
|
||||
# check with trailing slash
|
||||
formdata.store() # reset
|
||||
resp = get_app(pub).post(sign_uri(formdata.get_url() + 'jump/trigger/XXX/'), status=200)
|
||||
assert formdef.data_class().get(formdata.id).status == 'wf-st2'
|
||||
|
||||
Role.wipe()
|
||||
role = Role(name='xxx')
|
||||
role.store()
|
||||
|
@ -3313,6 +3318,44 @@ def test_workflow_global_webservice_trigger(pub, local_user):
|
|||
assert formdef.data_class().get(formdata.id).workflow_data == {'plop': {'test': 'BAR'}}
|
||||
|
||||
|
||||
def test_workflow_global_webservice_trigger_no_trailing_slash(pub, local_user):
|
||||
workflow = Workflow(name='test')
|
||||
st1 = workflow.add_status('Status1', 'st1')
|
||||
|
||||
ac1 = workflow.add_global_action('Action', 'ac1')
|
||||
trigger = ac1.append_trigger('webservice')
|
||||
trigger.identifier = 'plop'
|
||||
|
||||
add_to_journal = RegisterCommenterWorkflowStatusItem()
|
||||
add_to_journal.id = '_add_to_journal'
|
||||
add_to_journal.comment = 'HELLO WORLD'
|
||||
ac1.items.append(add_to_journal)
|
||||
add_to_journal.parent = ac1
|
||||
|
||||
workflow.store()
|
||||
|
||||
FormDef.wipe()
|
||||
formdef = FormDef()
|
||||
formdef.name = 'test'
|
||||
formdef.fields = []
|
||||
formdef.workflow_id = workflow.id
|
||||
formdef.store()
|
||||
|
||||
formdef.data_class().wipe()
|
||||
formdata = formdef.data_class()()
|
||||
formdata.just_created()
|
||||
formdata.store()
|
||||
assert formdef.data_class().get(formdata.id).status == 'wf-st1'
|
||||
|
||||
# call to undefined hook
|
||||
resp = get_app(pub).post(sign_uri(formdata.get_url() + 'hooks/XXX'), status=404)
|
||||
resp = get_app(pub).post(sign_uri(formdata.get_api_url() + 'hooks/XXX'), status=404)
|
||||
|
||||
# anonymous call
|
||||
resp = get_app(pub).post(formdata.get_url() + 'hooks/plop', status=200)
|
||||
assert formdef.data_class().get(formdata.id).evolution[-1].parts[-1].content == 'HELLO WORLD'
|
||||
|
||||
|
||||
def test_tracking_code(pub):
|
||||
FormDef.wipe()
|
||||
formdef = FormDef()
|
||||
|
|
|
@ -73,3 +73,9 @@ class WorkflowGlobalActionWebserviceHooksDirectory(Directory):
|
|||
if trigger.identifier == component:
|
||||
return HookDirectory(self.formdata, action, trigger)
|
||||
raise errors.TraversalError()
|
||||
|
||||
def _q_traverse(self, path):
|
||||
if len(path) == 1:
|
||||
# add fake trailing slash into path
|
||||
path = path + ['']
|
||||
return super()._q_traverse(path)
|
||||
|
|
|
@ -104,6 +104,12 @@ class TriggerDirectory(Directory):
|
|||
# no trigger found
|
||||
raise errors.TraversalError()
|
||||
|
||||
def _q_traverse(self, path):
|
||||
# remove trailing slash from path
|
||||
if path[-1] == '':
|
||||
path = path[:-1]
|
||||
return super()._q_traverse(path)
|
||||
|
||||
|
||||
class JumpWorkflowStatusItem(WorkflowStatusJumpItem):
|
||||
description = N_('Automatic Jump')
|
||||
|
@ -183,7 +189,7 @@ class JumpWorkflowStatusItem(WorkflowStatusJumpItem):
|
|||
title=_('Identifier for webservice'),
|
||||
hint=_(
|
||||
'This jump will be triggered by an authorized call '
|
||||
'to <form_url>/jump/trigger/<identifier>.'
|
||||
'to <form_url>/jump/trigger/<identifier>/.'
|
||||
),
|
||||
value=self.trigger,
|
||||
size=40,
|
||||
|
|
Loading…
Reference in New Issue