From eaa1a2a763e633131073ebacf2e7dd2b9cb33b93 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Wed, 25 Nov 2009 16:34:04 +0000
Subject: [PATCH] return a copy of the selection params in
 selection.getParams() and selection_tool.getSelectionParamsFor, to prevent
 the callers to modify selection params without using the api

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@30862 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Form/Selection.py          |  7 ++-----
 product/ERP5Form/Tool/SelectionTool.py | 10 ++++------
 2 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/product/ERP5Form/Selection.py b/product/ERP5Form/Selection.py
index 2b13668760..029edaf1db 100644
--- a/product/ERP5Form/Selection.py
+++ b/product/ERP5Form/Selection.py
@@ -257,12 +257,9 @@ class Selection(Acquisition.Implicit, Traversable, Persistent):
         """
           Get a dictionary of parameters in this selection.
         """
-        #LOG('getParams',0,'params: %s' % str(self.params))
-        if self.params is None:
+        if not isinstance(self.params, dict):
           self.params = {}
-        if type(self.params) != type({}):
-          self.params = {}
-        return self.params
+        return self.params.copy()
 
     security.declarePublic('getSortOrder')
     def getSortOrder(self):
diff --git a/product/ERP5Form/Tool/SelectionTool.py b/product/ERP5Form/Tool/SelectionTool.py
index c10253389e..ecffd7fcdc 100644
--- a/product/ERP5Form/Tool/SelectionTool.py
+++ b/product/ERP5Form/Tool/SelectionTool.py
@@ -258,15 +258,13 @@ class SelectionTool( BaseTool, UniqueObject, SimpleItem ):
       """
         Returns the params in the selection
       """
-      if params is None: params = {}
+      if params is None:
+        params = {}
       selection = self.getSelectionFor(selection_name, REQUEST=REQUEST)
       if selection is not None:
-        if len(selection.params) > 0:
+        if selection.params:
           return selection.getParams()
-        else:
-          return params
-      else:
-        return params
+      return params
 
     # backward compatibility
     security.declareProtected(ERP5Permissions.View, 'getSelectionParams')
-- 
2.30.9