misc: display a proper error on action link to invalid formdata/status (#89067)
gitea/wcs/pipeline/head This commit looks good
Details
gitea/wcs/pipeline/head This commit looks good
Details
This commit is contained in:
parent
55897c68b3
commit
b42d0ae6b0
|
@ -3991,6 +3991,22 @@ def test_email_actions(pub, emails):
|
|||
formdata.remove_self()
|
||||
app = get_app(pub)
|
||||
resp = app.get(action_url, status=404)
|
||||
assert 'This action link is no longer valid as the attached form has been removed.' in resp.text
|
||||
|
||||
# check action link referencing a formdata with an invalid/unknown status
|
||||
emails.empty()
|
||||
formdef.data_class().wipe()
|
||||
app = login(get_app(pub), username='foo', password='foo')
|
||||
resp = app.get(formdef.get_url())
|
||||
resp = resp.form.submit('submit')
|
||||
resp = resp.form.submit('submit')
|
||||
email_data = emails.get('New form2 (test email action)')
|
||||
action_url = re.findall(r'http.* ', email_data['payload'])[0].strip()
|
||||
formdata = formdef.data_class().select()[0]
|
||||
formdata.status = 'wf-abc'
|
||||
formdata.store()
|
||||
app = get_app(pub)
|
||||
resp = app.get(action_url, status=404)
|
||||
assert 'This action link is no longer valid' in resp.text
|
||||
|
||||
# two buttons on the same line, two urls
|
||||
|
|
|
@ -31,15 +31,17 @@ from wcs.wf.jump import jump_and_perform
|
|||
from wcs.workflows import perform_items, push_perform_workflow
|
||||
|
||||
|
||||
class MissingOrExpiredToken(PublishError):
|
||||
class InvalidActionLink(PublishError):
|
||||
status_code = 404
|
||||
title = _('Error')
|
||||
description = _('This action link is no longer valid.')
|
||||
|
||||
|
||||
class MissingOrExpiredToken(InvalidActionLink):
|
||||
description = _('This action link has already been used or has expired.')
|
||||
|
||||
|
||||
class MissingFormdata(PublishError):
|
||||
status_code = 404
|
||||
title = _('Error')
|
||||
class MissingFormdata(InvalidActionLink):
|
||||
description = _('This action link is no longer valid as the attached form has been removed.')
|
||||
|
||||
|
||||
|
@ -78,6 +80,9 @@ class ActionDirectory(Directory, FormTemplateMixin):
|
|||
raise MissingFormdata()
|
||||
self.action = None
|
||||
status = self.formdata.get_status()
|
||||
if not status or not status.items:
|
||||
# unknown status or workflow change and no actions anymore
|
||||
raise InvalidActionLink()
|
||||
for item in status.items:
|
||||
if getattr(item, 'identifier', None) == self.token.context['action_id']:
|
||||
self.action = item
|
||||
|
|
Loading…
Reference in New Issue