Commit 27df6c95 authored by Jean-Paul Smets's avatar Jean-Paul Smets

getTypeBasedMethod added

additional security methods added


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@3523 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a37c0829
...@@ -60,9 +60,9 @@ from Products.ERP5Type.Accessor.Accessor import Accessor as Method ...@@ -60,9 +60,9 @@ from Products.ERP5Type.Accessor.Accessor import Accessor as Method
from string import join from string import join
import sys import sys
import psyco
import pickle import pickle
import copy import copy
import psyco
from cStringIO import StringIO from cStringIO import StringIO
from email.MIMEBase import MIMEBase from email.MIMEBase import MIMEBase
...@@ -255,6 +255,8 @@ def initializePortalTypeDynamicProperties(self, klass, ptype): ...@@ -255,6 +255,8 @@ def initializePortalTypeDynamicProperties(self, klass, ptype):
# We can now associate it after initialising security # We can now associate it after initialising security
InitializeClass(prop_holder) InitializeClass(prop_holder)
prop_holder.__propholder__ = prop_holder
klass.__ac_permissions__ = prop_holder.__ac_permissions__
Base.aq_portal_type[ptype] = prop_holder Base.aq_portal_type[ptype] = prop_holder
...@@ -331,6 +333,16 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -331,6 +333,16 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
list(getattr(self, '_local_properties', ()))) list(getattr(self, '_local_properties', ())))
return ERP5PropertyManager._propertyMap(self) return ERP5PropertyManager._propertyMap(self)
def _aq_dynamic_pmethod(self, id):
ptype = self.portal_type
#LOG("In _aq_dynamic_pmethod", 0, str((id, ptype, self)))
if Base.aq_portal_type.has_key(ptype):
return getattr(Base.aq_portal_type[ptype], id, None).__of__(self)
return None
def _aq_dynamic(self, id): def _aq_dynamic(self, id):
ptype = self.portal_type ptype = self.portal_type
...@@ -339,7 +351,10 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -339,7 +351,10 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
# If this is a portal_type property and everything is already defined # If this is a portal_type property and everything is already defined
# for that portal_type, try to return a value ASAP # for that portal_type, try to return a value ASAP
if Base.aq_portal_type.has_key(ptype): if Base.aq_portal_type.has_key(ptype):
return getattr(Base.aq_portal_type[ptype], id, None) accessor = getattr(Base.aq_portal_type[ptype], id, None)
if accessor is not None:
return accessor.__of__(self) # XXX - JPS: I has no idea if we should __of__ before returning
return None
elif id in ('portal_types', 'portal_url', 'portal_workflow'): elif id in ('portal_types', 'portal_url', 'portal_workflow'):
# This is required to precent infinite loop (we need to access portal_types tool) # This is required to precent infinite loop (we need to access portal_types tool)
return None return None
...@@ -1798,13 +1813,41 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -1798,13 +1813,41 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
""" """
return getattr(self,'guid',None) return getattr(self,'guid',None)
# Type Casting
security.declarePrivate( '_getTypeBasedMethod' )
def _getTypeBasedMethod(self, method_id):
"""
Looks up for
"""
category_tool = getToolByName(self,'portal_categories')
# Look at local and acquired categories and make it criterion membership
script_name = ''
script = None
script_name_end = '_%s' % method_id
# Look at a local script which
# can return a new predicate.
if script_id is not None:
script = getattr(self, script_id)
else:
for script_name_begin in [self.getPortalType(), self.getMetaType(), self.__class__.__name__]:
script_name = join( [ replace(script_name_begin, ' ','') , script_name_end ], '')
if hasattr(self, script_name):
script = getattr(self, script_name)
break
return script
# Predicate handling
security.declareProtected(Permissions.AccessContentsInformation, 'asPredicate') security.declareProtected(Permissions.AccessContentsInformation, 'asPredicate')
def asPredicate(self): def asPredicate(self,script_id=None):
""" """
Returns a temporary Predicate based on the document properties This method tries to convert the current Document into a predicate
looking up methods named Class_asPredictae, MetaType_asPredicate, PortalType_asPredicate
""" """
script = self._getTypeBasedMethod('asPredicate')
if script is not None:
return = script()
return None return None
security.declareProtected(Permissions.View, 'get_local_permissions') security.declareProtected(Permissions.View, 'get_local_permissions')
def get_local_permissions(self): def get_local_permissions(self):
""" """
......
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