Commit 9c47a1ad authored by Łukasz Nowak's avatar Łukasz Nowak

- implement selection deletion for given user with test


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@29934 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ac5b7154
......@@ -92,6 +92,17 @@ class SelectionTool( BaseTool, UniqueObject, SimpleItem ):
, 'manage_configure' )
manage_configure = DTMLFile( 'SelectionTool_configure', _dtmldir )
security.declareProtected( ERP5Permissions.ManagePortal
, 'manage_deleteSelectionForUser' )
def manage_deleteSelectionForUser(self, selection_name, user_id, REQUEST=None):
"""
Delete a specified selection
"""
self._deleteSelectionForUserFromContainer(selection_name, user_id)
if REQUEST is not None:
return REQUEST.RESPONSE.redirect('%s/%s' %
(self.absolute_url(), 'manage_viewSelections'))
security.declareProtected( ERP5Permissions.ManagePortal
, 'manage_deleteSelection' )
def manage_deleteSelection(self, selection_name, REQUEST=None):
......@@ -1376,14 +1387,17 @@ class SelectionTool( BaseTool, UniqueObject, SimpleItem ):
else:
self._getPersistentContainer(user_id)[selection_name] = aq_base(selection)
def _deleteSelectionFromContainer(self, selection_name):
user_id = self._getUserId()
def _deleteSelectionForUserFromContainer(self, selection_name, user_id):
if user_id is None: return None
if self.isMemcachedUsed():
del(self._getMemcachedContainer()['%s-%s' % (user_id, selection_name)])
else:
del(self._getPersistentContainer(user_id)[selection_name])
def _deleteSelectionFromContainer(self, selection_name):
user_id = self._getUserId()
self._deleteSelectionForUserFromContainer(selection_name, user_id)
def _deleteGlobalSelectionFromContainer(self, selection_name):
if not self.isMemcachedUsed():
if getattr(aq_base(self), 'selection_data', None) is not None:
......
......@@ -234,6 +234,16 @@ class TestSelectionTool(ERP5TypeTestCase):
selection = self.portal_selections.getSelectionFor('test_selection')
self.assertEqual(selection, None)
def testDeleteSelectionForUser(self):
# XXX: There is side effect, that manager, running user, is the same use
# and there is no way (for now) to get selections per user...
selection = self.portal_selections.getSelectionFor('test_selection')
self.assert_(isinstance(selection, Selection))
self.portal_selections.manage_deleteSelectionForUser('test_selection',
'manager')
selection = self.portal_selections.getSelectionFor('test_selection')
self.assertEqual(selection, None)
def testDeleteGlobalSelection(self):
selection = self.portal_selections.getSelectionFor('test_selection')
self.assert_(isinstance(selection, Selection))
......
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