Commit 310e9c86 authored by Jérome Perrin's avatar Jérome Perrin

add unrestrictedSearchResults and unrestrictedCountResults



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@12636 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 5994e488
...@@ -183,7 +183,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): ...@@ -183,7 +183,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
def __init__(self): def __init__(self):
ZCatalog.__init__(self, self.getId()) ZCatalog.__init__(self, self.getId())
# Explicite Inheritance # Explicit Inheritance
__url = CMFCoreCatalogTool.__url __url = CMFCoreCatalogTool.__url
manage_catalogFind = CMFCoreCatalogTool.manage_catalogFind manage_catalogFind = CMFCoreCatalogTool.manage_catalogFind
...@@ -440,15 +440,18 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): ...@@ -440,15 +440,18 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
kw[ 'effective' ] = { 'query' : now, 'range' : 'max' } kw[ 'effective' ] = { 'query' : now, 'range' : 'max' }
kw[ 'expires' ] = { 'query' : now, 'range' : 'min' } kw[ 'expires' ] = { 'query' : now, 'range' : 'min' }
kw.setdefault('limit', 1000)
if not kw.has_key('limit'): return ZCatalog.searchResults(self, REQUEST, **kw)
kw['limit'] = 1000
#LOG("search allowedRolesAndUsers",0,str(kw[ 'allowedRolesAndUsers' ]))
return apply(ZCatalog.searchResults, (self, REQUEST), kw)
__call__ = searchResults __call__ = searchResults
security.declarePrivate('unrestrictedSearchResults')
def unrestrictedSearchResults(self, REQUEST=None, **kw):
"""Calls ZSQLCatalog.searchResults directly without restrictions.
"""
kw.setdefault('limit', 1000)
return ZCatalog.searchResults(self, REQUEST, **kw)
def countResults(self, REQUEST=None, **kw): def countResults(self, REQUEST=None, **kw):
""" """
Calls ZCatalog.countResults with extra arguments that Calls ZCatalog.countResults with extra arguments that
...@@ -468,7 +471,13 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): ...@@ -468,7 +471,13 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
# #kw[ 'effective' ] = { 'query' : now, 'range' : 'max' } # #kw[ 'effective' ] = { 'query' : now, 'range' : 'max' }
# #kw[ 'expires' ] = { 'query' : now, 'range' : 'min' } # #kw[ 'expires' ] = { 'query' : now, 'range' : 'min' }
return apply(ZCatalog.countResults, (self, REQUEST), kw) return ZCatalog.countResults(self, REQUEST, **kw)
security.declarePrivate('unrestrictedCountResults')
def unrestrictedCountResults(self, REQUEST=None, **kw):
"""Calls ZSQLCatalog.countResults directly without restrictions.
"""
return ZCatalog.countResults(self, REQUEST, **kw)
def wrapObject(self, object, sql_catalog_id=None, **kw): def wrapObject(self, object, sql_catalog_id=None, **kw):
""" """
......
...@@ -1328,4 +1328,38 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor): ...@@ -1328,4 +1328,38 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
self.assertEqual(1000,len(self.getCatalogTool()(portal_type='Organisation'))) self.assertEqual(1000,len(self.getCatalogTool()(portal_type='Organisation')))
self.assertEqual(1002,len(self.getCatalogTool()(portal_type='Organisation',limit=None))) self.assertEqual(1002,len(self.getCatalogTool()(portal_type='Organisation',limit=None)))
def test_47_Unrestricted(self, quiet=quiet, run=run_all_test):
"""test unrestricted search/count results.
"""
if not run: return
if not quiet:
message = 'Unrestricted queries'
ZopeTestCase._print('\n%s ' % message)
LOG('Testing... ',0,message)
login = PortalTestCase.login
uf = self.getPortal().acl_users
uf._doAddUser('alice', '', ['Member', 'Manager', 'Assignor'], [])
uf._doAddUser('bob', '', ['Member'], [])
# create a document that only alice can view
login(self, 'alice')
folder = self.getOrganisationModule()
ob = folder.newContent(title='Object Title')
ob.manage_permission('View', ['Manager'], 0)
get_transaction().commit()
self.tic()
# bob cannot see the document
login(self, 'bob')
ctool = self.getCatalogTool()
self.assertEquals(0, len(ctool.searchResults(title='Object Title')))
self.assertEquals(0, ctool.countResults(title='Object Title')[0][0])
# unless using unrestricted searches
self.assertEquals(1,
len(ctool.unrestrictedSearchResults(title='Object Title')))
self.assertEquals(1,
ctool.unrestrictedCountResults(title='Object Title')[0][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