Commit 1a801662 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

rename SelectionTool._isAnonymous to SelectionTool.isAnonymous.

so that we can call it from restricted environment.
parent 5fcc42c2
...@@ -2466,7 +2466,7 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine): ...@@ -2466,7 +2466,7 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine):
'selection_index=%s' % self.index, 'selection_index=%s' % self.index,
'reset:int=1')) 'reset:int=1'))
selection_tool = self.getObject().getPortalObject().portal_selections selection_tool = self.getObject().getPortalObject().portal_selections
if selection_tool._isAnonymous(): if selection_tool.isAnonymous():
params.append('selection_key=%s' % selection.getAnonymousSelectionKey()) params.append('selection_key=%s' % selection.getAnonymousSelectionKey())
if params: if params:
url = '%s?%s' % (url, '&'.join(params)) url = '%s?%s' % (url, '&'.join(params))
......
...@@ -291,7 +291,7 @@ class SelectionTool( BaseTool, SimpleItem ): ...@@ -291,7 +291,7 @@ class SelectionTool( BaseTool, SimpleItem ):
if not selection_name: if not selection_name:
return None return None
selection = self._getSelectionFromContainer(selection_name) selection = self._getSelectionFromContainer(selection_name)
if selection is None and self._isAnonymous(): if selection is None and self.isAnonymous():
selection_key = self._getSelectionKeyFromRequest(selection_name, REQUEST) selection_key = self._getSelectionKeyFromRequest(selection_name, REQUEST)
if selection_key is not None: if selection_key is not None:
selection = self.getAnonymousSelection(selection_key, selection_name) selection = self.getAnonymousSelection(selection_key, selection_name)
...@@ -317,7 +317,7 @@ class SelectionTool( BaseTool, SimpleItem ): ...@@ -317,7 +317,7 @@ class SelectionTool( BaseTool, SimpleItem ):
selection_object.name)) selection_object.name))
elif self.getSelectionFor(selection_name, REQUEST=REQUEST) != selection_object: elif self.getSelectionFor(selection_name, REQUEST=REQUEST) != selection_object:
self._setSelectionToContainer(selection_name, selection_object) self._setSelectionToContainer(selection_name, selection_object)
if selection_object is None and self._isAnonymous(): if selection_object is None and self.isAnonymous():
REQUEST = self._getRequest(REQUEST=REQUEST) REQUEST = self._getRequest(REQUEST=REQUEST)
for key in ('%s_selection_key' % selection_name, 'selection_key'): for key in ('%s_selection_key' % selection_name, 'selection_key'):
try: try:
...@@ -463,7 +463,7 @@ class SelectionTool( BaseTool, SimpleItem ): ...@@ -463,7 +463,7 @@ class SelectionTool( BaseTool, SimpleItem ):
selection = self.getSelectionFor(selection_name, REQUEST=REQUEST) selection = self.getSelectionFor(selection_name, REQUEST=REQUEST)
if selection: if selection:
url = selection.getListUrl() url = selection.getListUrl()
if self._isAnonymous() and '?' in url: if self.isAnonymous() and '?' in url:
url += '&selection_key=%s' % self._getSelectionKeyFromRequest(selection_name, REQUEST) url += '&selection_key=%s' % self._getSelectionKeyFromRequest(selection_name, REQUEST)
return url return url
else: else:
...@@ -733,7 +733,7 @@ class SelectionTool( BaseTool, SimpleItem ): ...@@ -733,7 +733,7 @@ class SelectionTool( BaseTool, SimpleItem ):
url += '?selection_index=%s&selection_name=%s' % (selection_index, selection_name) url += '?selection_index=%s&selection_name=%s' % (selection_index, selection_name)
if ignore_layout: if ignore_layout:
url += '&ignore_layout:int=1' url += '&ignore_layout:int=1'
if self._isAnonymous(): if self.isAnonymous():
url += '&selection_key=%s' % self.getAnonymousSelectionKey(selection_name, REQUEST=REQUEST) url += '&selection_key=%s' % self.getAnonymousSelectionKey(selection_name, REQUEST=REQUEST)
REQUEST.RESPONSE.redirect(url) REQUEST.RESPONSE.redirect(url)
...@@ -1461,7 +1461,7 @@ class SelectionTool( BaseTool, SimpleItem ): ...@@ -1461,7 +1461,7 @@ class SelectionTool( BaseTool, SimpleItem ):
return container.getSelection(key, selection_name) return container.getSelection(key, selection_name)
def getAnonymousSelectionKey(self, selection_name, REQUEST=None): def getAnonymousSelectionKey(self, selection_name, REQUEST=None):
if not self._isAnonymous(): if not self.isAnonymous():
return '' return ''
selection = self.getSelectionFor(selection_name, REQUEST=REQUEST) selection = self.getSelectionFor(selection_name, REQUEST=REQUEST)
if selection is None: if selection is None:
...@@ -1514,11 +1514,11 @@ class SelectionTool( BaseTool, SimpleItem ): ...@@ -1514,11 +1514,11 @@ class SelectionTool( BaseTool, SimpleItem ):
return list(set(self._getContainer().getSelectionNameList(user_id) + \ return list(set(self._getContainer().getSelectionNameList(user_id) + \
self.getTemporarySelectionDict().keys())) self.getTemporarySelectionDict().keys()))
def _isAnonymous(self): def isAnonymous(self):
return self._getUserId() == 'Anonymous User' return self._getUserId() == 'Anonymous User'
def _getContainer(self): def _getContainer(self):
if self._isAnonymous(): if self.isAnonymous():
tv = getTransactionalVariable() tv = getTransactionalVariable()
storage = tv.setdefault('_transactional_selection_container', {}) storage = tv.setdefault('_transactional_selection_container', {})
container = TransactionalCacheContainer(storage) container = TransactionalCacheContainer(storage)
......
...@@ -247,7 +247,7 @@ class TestSelectionPersistence(unittest.TestCase): ...@@ -247,7 +247,7 @@ class TestSelectionPersistence(unittest.TestCase):
# find the current user name # find the current user name
SelectionTool._getUserId_saved = SelectionTool._getUserId SelectionTool._getUserId_saved = SelectionTool._getUserId
SelectionTool._getUserId = lambda self: 'user' SelectionTool._getUserId = lambda self: 'user'
SelectionTool._isAnonymous = lambda self: 0 SelectionTool.isAnonymous = lambda self: 0
self.db = ZODB.DB(ZODB.DemoStorage.DemoStorage()) self.db = ZODB.DB(ZODB.DemoStorage.DemoStorage())
self.cnx = self.db.open() self.cnx = self.db.open()
......
...@@ -30,9 +30,9 @@ import unittest ...@@ -30,9 +30,9 @@ import unittest
from Products.ERP5Type.tests.testFunctionalCore import \ from Products.ERP5Type.tests.testFunctionalCore import \
TestZeleniumCore TestZeleniumCore
# monkey patch SelectionTool._isAnonymous to render as anonymous selection. # monkey patch SelectionTool.isAnonymous to render as anonymous selection.
from Products.ERP5Form.Tool.SelectionTool import SelectionTool from Products.ERP5Form.Tool.SelectionTool import SelectionTool
SelectionTool._isAnonymous = lambda *args, **kw:True SelectionTool.isAnonymous = lambda *args, **kw:True
class TestAnonymousSelection(TestZeleniumCore): class TestAnonymousSelection(TestZeleniumCore):
foreground = 0 foreground = 0
......
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