Commit 21363a4e authored by Romain Courteaud's avatar Romain Courteaud

Add checked_permission to related accessors.

It may be used for example to check if user has the View permission on objects.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13559 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0f40836d
......@@ -52,33 +52,16 @@ class DefaultGetter(Method):
if self._warning:
LOG("ERP5Type Deprecated Getter Id:",0, self._id)
return instance._getDefaultRelatedProperty(
self._key, 'relative_url',
spec=kw.get('spec',()),
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()))
self._key, 'relative_url',
spec=kw.get('spec',()),
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
checked_permission=kw.get('checked_permission', None))
psyco.bind(__call__)
Getter = DefaultGetter
class RestrictedDefaultGetter(DefaultGetter):
"""
Gets a default reference object
"""
def __call__(self, instance, *args, **kw):
if self._warning:
LOG("ERP5Type Deprecated Getter Id:",0, self._id)
return instance._getDefaultRelatedProperty(
self._key, 'relative_url',
spec=kw.get('spec',()),
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
query=instance.portal_catalog.getSecurityQuery(),)
psyco.bind(__call__)
RestrictedGetter = RestrictedDefaultGetter
class ListGetter(Method):
"""
Gets a list of reference objects
......@@ -102,26 +85,11 @@ class ListGetter(Method):
if self._warning:
LOG("ERP5Type Deprecated Getter Id:",0, self._id)
return instance._getRelatedPropertyList(
self._key, 'relative_url',
spec=kw.get('spec',()),
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()))
psyco.bind(__call__)
class RestrictedListGetter(ListGetter):
"""
Gets a list of reference objects
"""
def __call__(self, instance, *args, **kw):
if self._warning:
LOG("ERP5Type Deprecated Getter Id:",0, self._id)
return instance._getRelatedPropertyList(
self._key, 'relative_url',
spec=kw.get('spec',()),
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
query=instance.portal_catalog.getSecurityQuery(),)
self._key, 'relative_url',
spec=kw.get('spec',()),
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
checked_permission=kw.get('checked_permission', None))
psyco.bind(__call__)
......@@ -133,12 +101,3 @@ class SetGetter(ListGetter):
result_list = ListGetter.__call__(self, instance, *args, **kw)
result_set = dict([(x, 0) for x in result_list]).keys()
return result_set
class RestrictedSetGetter(RestrictedListGetter):
"""
Gets a category value set
"""
def __call__(self, instance, *args, **kw):
result_list = RestrictedListGetter.__call__(self, instance, *args, **kw)
result_set = dict([(x, 0) for x in result_list]).keys()
return result_set
This diff is collapsed.
......@@ -1576,15 +1576,15 @@ class Base( CopyContainer,
security.declareProtected( Permissions.View, '_getDefaultRelatedValue' )
def _getDefaultRelatedValue(self, id, spec=(), filter=None, portal_type=(),
strict_membership=0, strict="deprecated",
query=None):
checked_permission=None):
# backward compatibility to keep strict keyword working
if strict != "deprecated" :
strict_membership = strict
value_list =self._getRelatedValueList(
value_list = self._getRelatedValueList(
id, spec=spec, filter=filter,
portal_type=portal_type,
strict_membership=strict_membership,
query=query)
checked_permission=checked_permission)
try:
return value_list[0]
except IndexError:
......@@ -1596,7 +1596,7 @@ class Base( CopyContainer,
security.declareProtected( Permissions.View, '_getRelatedValueList' )
def _getRelatedValueList(self, id, spec=(), filter=None, portal_type=(),
strict_membership=0, strict="deprecated",
query=None):
checked_permission=None):
# backward compatibility to keep strict keyword working
if strict != "deprecated" :
strict_membership = strict
......@@ -1604,7 +1604,7 @@ class Base( CopyContainer,
self, id,
spec=spec, filter=filter, portal_type=portal_type,
strict_membership=strict_membership,
query=query)
checked_permission=checked_permission)
security.declareProtected(Permissions.View, 'getRelatedValueList')
getRelatedValueList = _getRelatedValueList
......@@ -1613,13 +1613,13 @@ class Base( CopyContainer,
'_getDefaultRelatedProperty')
def _getDefaultRelatedProperty(self, id, property_name, spec=(), filter=None,
portal_type=(), strict_membership=0,
query=None):
checked_permission=None):
property_list = self._getCategoryTool().getRelatedPropertyList(self, id,
property_name=property_name,
spec=spec, filter=filter,
portal_type=portal_type,
strict_membership=strict_membership,
query=query)
checked_permission=checked_permission)
try:
return property_list[0]
except IndexError:
......@@ -1634,13 +1634,13 @@ class Base( CopyContainer,
'_getRelatedPropertyList')
def _getRelatedPropertyList(self, id, property_name, spec=(), filter=None,
portal_type=(), strict_membership=0,
query=None):
checked_permission=None):
return self._getCategoryTool().getRelatedPropertyList(self, id,
property_name=property_name,
spec=spec, filter=filter,
portal_type=portal_type,
strict_membership=strict_membership,
query=query)
checked_permission=checked_permission)
security.declareProtected( Permissions.AccessContentsInformation,
'getRelatedPropertyList' )
......
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