From d01345ec725779aa60a8a3c2bc619929eb47c94e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 4 Sep 2018 09:42:35 +0200 Subject: [PATCH] general: give a custom error message on invalid action link (#25722) --- tests/test_form_pages.py | 3 ++- wcs/forms/actions.py | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/test_form_pages.py b/tests/test_form_pages.py index 2aa0c1c07..189397885 100644 --- a/tests/test_form_pages.py +++ b/tests/test_form_pages.py @@ -4964,7 +4964,8 @@ def test_email_actions(pub, emails): assert formdata.status == 'wf-accepted' # no longer on a correct status, action url will now return a 404 - app.get(action_url, status=404) + resp = app.get(action_url, status=404) + assert 'This action link has already been used or has expired.' in resp.body def test_manager_public_access(pub): user, manager = create_user_and_admin(pub) diff --git a/wcs/forms/actions.py b/wcs/forms/actions.py index c8f44e06f..0fcbf2fd2 100644 --- a/wcs/forms/actions.py +++ b/wcs/forms/actions.py @@ -28,12 +28,18 @@ from wcs.forms.common import FormTemplateMixin from wcs.wf.jump import jump_and_perform +class MissingOrExpiredToken(errors.PublishError): + status_code = 404 + title = N_('Error') + description = N_('This action link has already been used or has expired.') + + class ActionsDirectory(Directory): def _q_lookup(self, component): try: token = tokens.Token.get(component) except KeyError: - raise errors.TraversalError() + raise MissingOrExpiredToken() if token.type != 'action': raise errors.TraversalError() return ActionDirectory(token) -- 2.19.0.rc1