From 6e7a20bd542debae5b68a1e3bbfda314273ea341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sat, 24 Jun 2017 11:10:05 +0200 Subject: [PATCH] post: allow using submitted data in url substitution (#17172) --- combo/data/models.py | 19 ++++++++++++------- tests/test_public.py | 7 +++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/combo/data/models.py b/combo/data/models.py index 51cc83b..f1ccc67 100644 --- a/combo/data/models.py +++ b/combo/data/models.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import copy import feedparser import hashlib import json @@ -894,19 +895,23 @@ class JsonCellBase(CellBase): error_message = self.actions[action].get('error-message') logger = logging.getLogger(__name__) - context = RequestContext(request, {'request': request, 'synchronous': True}) - try: - url = utils.get_templated_url(self.actions[action]['url'], context) - except utils.UnknownTemplateVariableError: - logger.warning('unknown variable in URL (%s)', self.actions[action]['url']) - raise PostException(error_message) - content = {} for key, value in request.POST.items(): if key == 'action': continue content[key] = value + context_dict = copy.copy(content) + context_dict['request'] = request + context_dict['synchronous'] = True + + context = RequestContext(request, context_dict) + try: + url = utils.get_templated_url(self.actions[action]['url'], context) + except utils.UnknownTemplateVariableError: + logger.warning('unknown variable in URL (%s)', self.actions[action]['url']) + raise PostException(error_message) + json_response = utils.requests.post(url, headers={'Accept': 'application/json'}, remote_service='auto', diff --git a/tests/test_public.py b/tests/test_public.py index 39d9bc5..2870475 100644 --- a/tests/test_public.py +++ b/tests/test_public.py @@ -376,3 +376,10 @@ def test_post_cell(app): resp2 = resp.form.submit(headers={'x-requested-with': 'XMLHttpRequest'}) assert resp2.content.startswith('