From 47b5ea3a4038f653b64678f8b472a60eb78adaa6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= <fpeters@entrouvert.com>
Date: Mon, 10 Aug 2020 15:25:49 +0200
Subject: [PATCH] misc: always use lazy evaluation for URL templates (#45806)

---
 wcs/data_sources.py     | 2 +-
 wcs/forms/root.py       | 4 ++--
 wcs/qommon/form.py      | 4 ++--
 wcs/qommon/ident/idp.py | 2 +-
 wcs/wscalls.py          | 2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/wcs/data_sources.py b/wcs/data_sources.py
index 1eacbad60..46295f28d 100644
--- a/wcs/data_sources.py
+++ b/wcs/data_sources.py
@@ -241,7 +241,7 @@ def get_structured_items(data_source, mode=None):
             return []
         url = url.strip()
         if Template.is_template_string(url):
-            vars = get_publisher().substitutions.get_context_variables(mode=mode)
+            vars = get_publisher().substitutions.get_context_variables(mode='lazy')
             url = get_variadic_url(url, vars)
 
         request = get_request()
diff --git a/wcs/forms/root.py b/wcs/forms/root.py
index 9c3046bee..46b0652fe 100644
--- a/wcs/forms/root.py
+++ b/wcs/forms/root.py
@@ -568,7 +568,7 @@ class FormPage(Directory, FormTemplateMixin):
         if self.formdef.is_disabled():
             if self.formdef.disabled_redirection:
                 return misc.get_variadic_url(self.formdef.disabled_redirection,
-                        get_publisher().substitutions.get_context_variables())
+                        get_publisher().substitutions.get_context_variables(mode='lazy'))
             else:
                 raise errors.AccessForbiddenError()
         return False
@@ -1420,7 +1420,7 @@ class RootDirectory(AccessControlled, Directory):
 
         if redirect_url:
             return redirect(misc.get_variadic_url(redirect_url,
-                get_publisher().substitutions.get_context_variables()))
+                get_publisher().substitutions.get_context_variables(mode='lazy')))
 
         template.html_top(default_org = _('Forms'))
         r = TemplateIO(html=True)
diff --git a/wcs/qommon/form.py b/wcs/qommon/form.py
index 30e85d871..59fa983b0 100644
--- a/wcs/qommon/form.py
+++ b/wcs/qommon/form.py
@@ -2118,7 +2118,7 @@ class JsonpSingleSelectWidget(Widget):
 
     def get_select2_url(self):
         if Template.is_template_string(self.url):
-            vars = get_publisher().substitutions.get_context_variables()
+            vars = get_publisher().substitutions.get_context_variables(mode='lazy')
             # skip variables that were not set (None)
             vars = dict((x, y) for x, y in vars.items() if y is not None)
             url = misc.get_variadic_url(self.url, vars, encode_query=False)
@@ -2150,7 +2150,7 @@ class AutocompleteStringWidget(WcsExtraStringWidget):
 
     def render_content(self):
         if Template.is_template_string(self.url):
-            vars = get_publisher().substitutions.get_context_variables()
+            vars = get_publisher().substitutions.get_context_variables(mode='lazy')
             # skip variables that were not set (None)
             vars = dict((x, y) for x, y in vars.items() if y is not None)
             url = misc.get_variadic_url(self.url, vars, encode_query=False)
diff --git a/wcs/qommon/ident/idp.py b/wcs/qommon/ident/idp.py
index 58c2f7a0d..088e83c1d 100644
--- a/wcs/qommon/ident/idp.py
+++ b/wcs/qommon/ident/idp.py
@@ -146,7 +146,7 @@ class MethodDirectory(Directory):
 
         if not get_request().user or not get_session().name_identifier:
             if get_cfg('saml_identities', {}).get('registration-url'):
-                vars = get_publisher().substitutions.get_context_variables()
+                vars = get_publisher().substitutions.get_context_variables(mode='lazy')
                 vars['next_url'] = get_request().get_frontoffice_url()
                 registration_url = misc.get_variadic_url(
                                 get_cfg('saml_identities', {}).get('registration-url'),
diff --git a/wcs/wscalls.py b/wcs/wscalls.py
index 9389a04b5..506f9af6b 100644
--- a/wcs/wscalls.py
+++ b/wcs/wscalls.py
@@ -43,7 +43,7 @@ def call_webservice(url, qs_data=None, request_signature_key=None,
 
     url = url.strip()
     if Template.is_template_string(url):
-        variables = get_publisher().substitutions.get_context_variables()
+        variables = get_publisher().substitutions.get_context_variables(mode='lazy')
         url = get_variadic_url(url, variables)
 
     if not request_signature_key:
-- 
2.28.0

