Commit 37403619 authored by Julien Muchembled's avatar Julien Muchembled

Small optimizations in CatalogTool.wrapObject

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@30454 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 6972f666
...@@ -33,7 +33,6 @@ from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery ...@@ -33,7 +33,6 @@ from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from Products.ERP5Type.Cache import CachingMethod from Products.ERP5Type.Cache import CachingMethod
from AccessControl import ClassSecurityInfo, getSecurityManager from AccessControl import ClassSecurityInfo, getSecurityManager
from Products.CMFCore.CatalogTool import IndexableObjectWrapper as CMFCoreIndexableObjectWrapper
from Products.CMFCore.utils import UniqueObject, _checkPermission, _getAuthenticatedUser, getToolByName from Products.CMFCore.utils import UniqueObject, _checkPermission, _getAuthenticatedUser, getToolByName
from Products.ERP5Type.Globals import InitializeClass, DTMLFile, package_home from Products.ERP5Type.Globals import InitializeClass, DTMLFile, package_home
from Acquisition import aq_base, aq_inner, aq_parent, ImplicitAcquisitionWrapper from Acquisition import aq_base, aq_inner, aq_parent, ImplicitAcquisitionWrapper
...@@ -55,7 +54,6 @@ from Products.ERP5Type.Utils import sqlquote ...@@ -55,7 +54,6 @@ from Products.ERP5Type.Utils import sqlquote
import os, time, urllib, warnings import os, time, urllib, warnings
import sys import sys
from zLOG import LOG, PROBLEM, WARNING, INFO from zLOG import LOG, PROBLEM, WARNING, INFO
import sets
ACQUIRE_PERMISSION_VALUE = [] ACQUIRE_PERMISSION_VALUE = []
...@@ -63,41 +61,32 @@ from Persistence import Persistent ...@@ -63,41 +61,32 @@ from Persistence import Persistent
from Acquisition import Implicit from Acquisition import Implicit
class IndexableObjectWrapper(CMFCoreIndexableObjectWrapper): class IndexableObjectWrapper(object):
def __init__(self, vars, ob): def __init__(self, ob):
# sigh... CMFCoreIndexableObjectWrapper changed signature between
# CMF 1.5 and 2.x. The new signature is (self, ob, catalog), and the
# 'vars' calculation is done by __init__ itself
# FIXME, we should consider taking a page from the CMFCore parent and
# move the 'vars' logic here. We would be actually making use of the
# 'catalog' parameter, instead of just using it to fetch
# portal_workflow.
self.__vars = vars
self.__ob = ob self.__ob = ob
def __setattr__(self, name, value): def __getattr__(self, name):
# We need to update the uid during the cataloging process return getattr(self.__ob, name)
if name == 'uid':
setattr(self.__ob, name, value) # We need to update the uid during the cataloging process
else: uid = property(lambda self: self.__ob.uid,
self.__dict__[name] = value lambda self, value: setattr(self.__ob, 'uid', value))
def _getSecurityParameterList(self): def _getSecurityParameterList(self):
result_key = '_cache_result' result = self.__dict__.get('_cache_result', None)
if result_key not in self.__dict__: if result is None:
ob = self.__ob ob = self.__ob
localroles = mergedLocalRoles(ob)
# For each group or user, we have a list of roles, this list # For each group or user, we have a list of roles, this list
# give in this order : [roles on object, roles acquired on the parent, # give in this order : [roles on object, roles acquired on the parent,
# roles acquired on the parent of the parent....] # roles acquired on the parent of the parent....]
# So if we have ['-Author','Author'] we should remove the role 'Author' # So if we have ['-Author','Author'] we should remove the role 'Author'
# but if we have ['Author','-Author'] we have to keep the role 'Author' # but if we have ['Author','-Author'] we have to keep the role 'Author'
flat_localroles = {} localroles = {}
skip_role_set = sets.Set() skip_role_set = set()
skip_role = skip_role_set.add skip_role = skip_role_set.add
clear_skip_role = skip_role_set.clear clear_skip_role = skip_role_set.clear
for key, role_list in localroles.iteritems(): for key, role_list in mergedLocalRoles(ob).iteritems():
new_role_list = [] new_role_list = []
new_role = new_role_list.append new_role = new_role_list.append
clear_skip_role() clear_skip_role()
...@@ -107,10 +96,9 @@ class IndexableObjectWrapper(CMFCoreIndexableObjectWrapper): ...@@ -107,10 +96,9 @@ class IndexableObjectWrapper(CMFCoreIndexableObjectWrapper):
elif role not in skip_role_set: elif role not in skip_role_set:
new_role(role) new_role(role)
if len(new_role_list)>0: if len(new_role_list)>0:
flat_localroles[key] = new_role_list localroles[key] = new_role_list
localroles = flat_localroles
portal = self.getPortalObject() portal = ob.getPortalObject()
role_dict = dict(portal.portal_catalog.getSQLCatalog().\ role_dict = dict(portal.portal_catalog.getSQLCatalog().\
getSQLCatalogRoleKeysList()) getSQLCatalogRoleKeysList())
getUserById = portal.acl_users.getUserById getUserById = portal.acl_users.getUserById
...@@ -121,7 +109,7 @@ class IndexableObjectWrapper(CMFCoreIndexableObjectWrapper): ...@@ -121,7 +109,7 @@ class IndexableObjectWrapper(CMFCoreIndexableObjectWrapper):
# user:<user_id> # user:<user_id>
# user:<user_id>:<role_id> # user:<user_id>:<role_id>
# A line must not be present twice in final result. # A line must not be present twice in final result.
allowed = sets.Set(rolesForPermissionOn('View', ob)) allowed = set(rolesForPermissionOn('View', ob))
# XXX Owner is hardcoded, in order to prevent searching for user on the # XXX Owner is hardcoded, in order to prevent searching for user on the
# site root. # site root.
allowed.discard('Owner') allowed.discard('Owner')
...@@ -141,13 +129,9 @@ class IndexableObjectWrapper(CMFCoreIndexableObjectWrapper): ...@@ -141,13 +129,9 @@ class IndexableObjectWrapper(CMFCoreIndexableObjectWrapper):
add(prefix) add(prefix)
add(prefix + ':' + role) add(prefix + ':' + role)
# __setattr__ explicitely set the parameter on the wrapper self._cache_result = result = (sorted(allowed), user_role_dict,
setattr(self, result_key, user_view_permission_role_dict)
(list(allowed), user_role_dict, return result
user_view_permission_role_dict))
# Return expected value
return self.__dict__[result_key]
def allowedRolesAndUsers(self): def allowedRolesAndUsers(self):
""" """
...@@ -740,17 +724,15 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): ...@@ -740,17 +724,15 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
LOG('wrapObject', 0, 'Warning: catalog is not available') LOG('wrapObject', 0, 'Warning: catalog is not available')
return (None, None) return (None, None)
document_object = aq_inner(object)
w = IndexableObjectWrapper(document_object)
wf = getToolByName(self, 'portal_workflow') wf = getToolByName(self, 'portal_workflow')
if wf is not None: if wf is not None:
vars = wf.getCatalogVariablesFor(object) w.__dict__.update(wf.getCatalogVariablesFor(object))
else:
vars = {}
#LOG('catalog_object vars', 0, str(vars))
# Find the parent definition for security # Find the parent definition for security
document_object = aq_inner(object)
is_acquired = 0 is_acquired = 0
w = IndexableObjectWrapper(vars, document_object)
while getattr(document_object, 'isRADContent', 0): while getattr(document_object, 'isRADContent', 0):
# This condition tells which object should acquire # This condition tells which object should acquire
# from their parent. # from their parent.
...@@ -762,21 +744,18 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): ...@@ -762,21 +744,18 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
else: else:
break break
if is_acquired: if is_acquired:
document_w = IndexableObjectWrapper({}, document_object) document_w = IndexableObjectWrapper(document_object)
else: else:
document_w = w document_w = w
(security_uid, optimised_roles_and_users) = catalog.getSecurityUid(document_w) (security_uid, optimised_roles_and_users) = catalog.getSecurityUid(document_w)
#LOG('catalog_object optimised_roles_and_users', 0, str(optimised_roles_and_users)) #LOG('catalog_object optimised_roles_and_users', 0, str(optimised_roles_and_users))
# XXX we should build vars begore building the wrapper # XXX we should build vars begore building the wrapper
if optimised_roles_and_users is not None: w.optimised_roles_and_users = optimised_roles_and_users
vars['optimised_roles_and_users'] = optimised_roles_and_users
else:
vars['optimised_roles_and_users'] = None
predicate_property_dict = catalog.getPredicatePropertyDict(object) predicate_property_dict = catalog.getPredicatePropertyDict(object)
if predicate_property_dict is not None: if predicate_property_dict is not None:
vars['predicate_property_dict'] = predicate_property_dict w.predicate_property_dict = predicate_property_dict
vars['security_uid'] = security_uid w.security_uid = security_uid
return ImplicitAcquisitionWrapper(w, aq_parent(document_object)) return ImplicitAcquisitionWrapper(w, aq_parent(document_object))
......
...@@ -727,15 +727,11 @@ class Catalog(Folder, ...@@ -727,15 +727,11 @@ class Catalog(Folder,
and to assign security only to root document and to assign security only to root document
""" """
# Get security information # Get security information
allowed_roles_and_users = wrapped_object.allowedRolesAndUsers() allowed_roles_and_users = tuple(wrapped_object.allowedRolesAndUsers())
# Sort it
allowed_roles_and_users = list(allowed_roles_and_users)
allowed_roles_and_users.sort()
allowed_roles_and_users = tuple(allowed_roles_and_users)
# Make sure no duplicates # Make sure no duplicates
if getattr(aq_base(self), 'security_uid_dict', None) is None: if getattr(aq_base(self), 'security_uid_dict', None) is None:
self._clearSecurityCache() self._clearSecurityCache()
if self.security_uid_dict.has_key(allowed_roles_and_users): elif self.security_uid_dict.has_key(allowed_roles_and_users):
return (self.security_uid_dict[allowed_roles_and_users], None) return (self.security_uid_dict[allowed_roles_and_users], None)
# If the id_tool is there, it is better to use it, it allows # If the id_tool is there, it is better to use it, it allows
# to create many new security uids by the same time # to create many new security uids by the same time
......
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