Commit 3cb786cc authored by Jérome Perrin's avatar Jérome Perrin

Listbox,SelectionTool: use make_query instead of crafting URL manually

Using make_query makes sure that the query parameters are properly
encoded and also change selection_index to become an int, because
it keeps the type of parameters.

As a consequence, we had to adjust a few place in the code where
selection_index was tested for truthiness: because "0" as a string is
true, but 0 as an int is not. For that, we changed to test the presence
of selection_name instead of testing selection_index, as they are always
used together.

This fixes a problem that & in URL was encoded twice for listbox
anchor links ( bug_module/1137 )
parent 2bd1d4ed
...@@ -26,9 +26,13 @@ if dialog_id not in ('', None): ...@@ -26,9 +26,13 @@ if dialog_id not in ('', None):
# editing it by calling the Base_edit script with correct # editing it by calling the Base_edit script with correct
# parameters directly. # parameters directly.
if not silent_mode and not request.AUTHENTICATED_USER.has_permission('Modify portal content', context) : if not silent_mode and not request.AUTHENTICATED_USER.has_permission('Modify portal content', context) :
msg = Base_translateString("You do not have the permissions to edit the object.") redirect_kw = {
redirect_url = '%s/%s?selection_index=%s&selection_name=%s&%s' % (context.absolute_url(), form_id, selection_index, selection_name, 'portal_status_message=%s' % msg) 'portal_status_message': Base_translateString("You do not have the permissions to edit the object.")
return request['RESPONSE'].redirect(redirect_url) }
if selection_name:
redirect_kw['selection_name'] = selection_name
redirect_kw['selection_index'] = selection_index
return request['RESPONSE'].redirect('%s/%s?%s' % (context.absolute_url(), form_id, make_query(redirect_kw)))
# Get the form # Get the form
form = getattr(context,form_id) form = getattr(context,form_id)
...@@ -262,7 +266,7 @@ redirect_url_kw = dict( ...@@ -262,7 +266,7 @@ redirect_url_kw = dict(
editable_mode=editable_mode, editable_mode=editable_mode,
portal_status_message=message portal_status_message=message
) )
if selection_index: if selection_name:
redirect_url_kw.update( redirect_url_kw.update(
selection_index=selection_index, selection_index=selection_index,
selection_name=selection_name selection_name=selection_name
......
...@@ -159,7 +159,7 @@ ...@@ -159,7 +159,7 @@
<span class="description" i18n:translate="" i18n:domain="ui">Delete</span> <span class="description" i18n:translate="" i18n:domain="ui">Delete</span>
</button> </button>
<tal:block tal:condition="not: list_mode"> <tal:block tal:condition="not: list_mode">
<tal:block tal:condition="request/selection_index | nothing"> <tal:block tal:condition="request/selection_name | nothing">
<span class="separator"><!--separator--></span> <span class="separator"><!--separator--></span>
<a class="jump_first" title="First" <a class="jump_first" title="First"
tal:attributes="href string:portal_selections/viewFirst?$http_parameters" tal:attributes="href string:portal_selections/viewFirst?$http_parameters"
......
...@@ -49,6 +49,7 @@ from Acquisition import aq_base, aq_self, aq_inner ...@@ -49,6 +49,7 @@ from Acquisition import aq_base, aq_self, aq_inner
import Acquisition import Acquisition
from zLOG import LOG, WARNING from zLOG import LOG, WARNING
from ZODB.POSException import ConflictError from ZODB.POSException import ConflictError
from ZTUtils import make_query
from Products.ERP5Type.Globals import InitializeClass, get_request from Products.ERP5Type.Globals import InitializeClass, get_request
from Products.PythonScripts.Utility import allow_class from Products.PythonScripts.Utility import allow_class
...@@ -2149,22 +2150,24 @@ class ListBoxRendererLine: ...@@ -2149,22 +2150,24 @@ class ListBoxRendererLine:
except AttributeError: except AttributeError:
return None return None
params = [] params = {}
selection_name = renderer.getSelectionName() selection_name = renderer.getSelectionName()
if int(request.get( if int(request.get(
'ignore_layout', 'ignore_layout',
0 if request.get('is_web_mode') else 1)): 0 if request.get('is_web_mode') else 1)):
params.append('ignore_layout:int=1') params['ignore_layout'] = 1
if int(request.get('editable_mode', 0)): if int(request.get('editable_mode', 0)):
params.append('editable_mode:int=1') params['editable_mode'] = 1
if selection_name: if selection_name:
params.extend(('selection_name=%s' % selection_name, params.update({
'selection_index=%s' % self.index, 'selection_name': selection_name,
'reset:int=1')) 'selection_index': self.index,
'reset': 1,
})
if renderer.getSelectionTool().isAnonymous(): if renderer.getSelectionTool().isAnonymous():
params.append('selection_key=%s' % renderer.getSelection().getAnonymousSelectionKey()) params['selection_key'] = renderer.getSelection().getAnonymousSelectionKey()
if params: if params:
url = '%s?%s' % (url, '&amp;'.join(params)) url = '%s?%s' % (url, make_query(params))
return url return url
def isSummary(self): def isSummary(self):
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
from OFS.SimpleItem import SimpleItem from OFS.SimpleItem import SimpleItem
from Products.ERP5Type.Globals import InitializeClass, DTMLFile, PersistentMapping, get_request from Products.ERP5Type.Globals import InitializeClass, DTMLFile, PersistentMapping, get_request
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from ZTUtils import make_query
from Products.ERP5Type.Tool.BaseTool import BaseTool from Products.ERP5Type.Tool.BaseTool import BaseTool
from Products.ERP5Type import Permissions as ERP5Permissions from Products.ERP5Type import Permissions as ERP5Permissions
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
...@@ -730,15 +731,17 @@ class SelectionTool( BaseTool, SimpleItem ): ...@@ -730,15 +731,17 @@ class SelectionTool( BaseTool, SimpleItem ):
url = REQUEST.getURL() url = REQUEST.getURL()
else: else:
url = REQUEST.getURL() url = REQUEST.getURL()
ignore_layout = int(REQUEST.get('ignore_layout', 0))
if form_id != 'view': if form_id != 'view':
url += '/%s' % form_id url += '/%s' % form_id
url += '?selection_index=%s&selection_name=%s' % (selection_index, selection_name) query_kw = {
if ignore_layout: 'selection_index': selection_index,
url += '&ignore_layout:int=1' 'selection_name': selection_name,
}
if int(REQUEST.get('ignore_layout', 0)):
query_kw['ignore_layout'] = 1
if self.isAnonymous(): if self.isAnonymous():
url += '&selection_key=%s' % self.getAnonymousSelectionKey(selection_name, REQUEST=REQUEST) query_kw['selection_key'] = self.getAnonymousSelectionKey(selection_name, REQUEST=REQUEST)
REQUEST.RESPONSE.redirect(url) REQUEST.RESPONSE.redirect('%s?%s' % (url, make_query(query_kw)))
# ListBox related methods # ListBox related methods
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment