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
...@@ -48,23 +48,6 @@ class DefaultGetter(Method): ...@@ -48,23 +48,6 @@ class DefaultGetter(Method):
self._key = key self._key = key
self._warning = warning self._warning = warning
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',()))
psyco.bind(__call__)
Getter = DefaultGetter
class RestrictedDefaultGetter(DefaultGetter):
"""
Gets a default reference object
"""
def __call__(self, instance, *args, **kw): def __call__(self, instance, *args, **kw):
if self._warning: if self._warning:
LOG("ERP5Type Deprecated Getter Id:",0, self._id) LOG("ERP5Type Deprecated Getter Id:",0, self._id)
...@@ -73,11 +56,11 @@ class RestrictedDefaultGetter(DefaultGetter): ...@@ -73,11 +56,11 @@ class RestrictedDefaultGetter(DefaultGetter):
spec=kw.get('spec',()), spec=kw.get('spec',()),
filter=kw.get('filter', None), filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()), portal_type=kw.get('portal_type',()),
query=instance.portal_catalog.getSecurityQuery(),) checked_permission=kw.get('checked_permission', None))
psyco.bind(__call__) psyco.bind(__call__)
RestrictedGetter = RestrictedDefaultGetter Getter = DefaultGetter
class ListGetter(Method): class ListGetter(Method):
""" """
...@@ -98,21 +81,6 @@ class ListGetter(Method): ...@@ -98,21 +81,6 @@ class ListGetter(Method):
self._key = key self._key = key
self._warning = warning self._warning = warning
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',()))
psyco.bind(__call__)
class RestrictedListGetter(ListGetter):
"""
Gets a list of reference objects
"""
def __call__(self, instance, *args, **kw): def __call__(self, instance, *args, **kw):
if self._warning: if self._warning:
LOG("ERP5Type Deprecated Getter Id:",0, self._id) LOG("ERP5Type Deprecated Getter Id:",0, self._id)
...@@ -121,7 +89,7 @@ class RestrictedListGetter(ListGetter): ...@@ -121,7 +89,7 @@ class RestrictedListGetter(ListGetter):
spec=kw.get('spec',()), spec=kw.get('spec',()),
filter=kw.get('filter', None), filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()), portal_type=kw.get('portal_type',()),
query=instance.portal_catalog.getSecurityQuery(),) checked_permission=kw.get('checked_permission', None))
psyco.bind(__call__) psyco.bind(__call__)
...@@ -133,12 +101,3 @@ class SetGetter(ListGetter): ...@@ -133,12 +101,3 @@ class SetGetter(ListGetter):
result_list = ListGetter.__call__(self, instance, *args, **kw) result_list = ListGetter.__call__(self, instance, *args, **kw)
result_set = dict([(x, 0) for x in result_list]).keys() result_set = dict([(x, 0) for x in result_list]).keys()
return result_set 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, ...@@ -1576,15 +1576,15 @@ class Base( CopyContainer,
security.declareProtected( Permissions.View, '_getDefaultRelatedValue' ) security.declareProtected( Permissions.View, '_getDefaultRelatedValue' )
def _getDefaultRelatedValue(self, id, spec=(), filter=None, portal_type=(), def _getDefaultRelatedValue(self, id, spec=(), filter=None, portal_type=(),
strict_membership=0, strict="deprecated", strict_membership=0, strict="deprecated",
query=None): checked_permission=None):
# backward compatibility to keep strict keyword working # backward compatibility to keep strict keyword working
if strict != "deprecated" : if strict != "deprecated" :
strict_membership = strict strict_membership = strict
value_list =self._getRelatedValueList( value_list = self._getRelatedValueList(
id, spec=spec, filter=filter, id, spec=spec, filter=filter,
portal_type=portal_type, portal_type=portal_type,
strict_membership=strict_membership, strict_membership=strict_membership,
query=query) checked_permission=checked_permission)
try: try:
return value_list[0] return value_list[0]
except IndexError: except IndexError:
...@@ -1596,7 +1596,7 @@ class Base( CopyContainer, ...@@ -1596,7 +1596,7 @@ class Base( CopyContainer,
security.declareProtected( Permissions.View, '_getRelatedValueList' ) security.declareProtected( Permissions.View, '_getRelatedValueList' )
def _getRelatedValueList(self, id, spec=(), filter=None, portal_type=(), def _getRelatedValueList(self, id, spec=(), filter=None, portal_type=(),
strict_membership=0, strict="deprecated", strict_membership=0, strict="deprecated",
query=None): checked_permission=None):
# backward compatibility to keep strict keyword working # backward compatibility to keep strict keyword working
if strict != "deprecated" : if strict != "deprecated" :
strict_membership = strict strict_membership = strict
...@@ -1604,7 +1604,7 @@ class Base( CopyContainer, ...@@ -1604,7 +1604,7 @@ class Base( CopyContainer,
self, id, self, id,
spec=spec, filter=filter, portal_type=portal_type, spec=spec, filter=filter, portal_type=portal_type,
strict_membership=strict_membership, strict_membership=strict_membership,
query=query) checked_permission=checked_permission)
security.declareProtected(Permissions.View, 'getRelatedValueList') security.declareProtected(Permissions.View, 'getRelatedValueList')
getRelatedValueList = _getRelatedValueList getRelatedValueList = _getRelatedValueList
...@@ -1613,13 +1613,13 @@ class Base( CopyContainer, ...@@ -1613,13 +1613,13 @@ class Base( CopyContainer,
'_getDefaultRelatedProperty') '_getDefaultRelatedProperty')
def _getDefaultRelatedProperty(self, id, property_name, spec=(), filter=None, def _getDefaultRelatedProperty(self, id, property_name, spec=(), filter=None,
portal_type=(), strict_membership=0, portal_type=(), strict_membership=0,
query=None): checked_permission=None):
property_list = self._getCategoryTool().getRelatedPropertyList(self, id, property_list = self._getCategoryTool().getRelatedPropertyList(self, id,
property_name=property_name, property_name=property_name,
spec=spec, filter=filter, spec=spec, filter=filter,
portal_type=portal_type, portal_type=portal_type,
strict_membership=strict_membership, strict_membership=strict_membership,
query=query) checked_permission=checked_permission)
try: try:
return property_list[0] return property_list[0]
except IndexError: except IndexError:
...@@ -1634,13 +1634,13 @@ class Base( CopyContainer, ...@@ -1634,13 +1634,13 @@ class Base( CopyContainer,
'_getRelatedPropertyList') '_getRelatedPropertyList')
def _getRelatedPropertyList(self, id, property_name, spec=(), filter=None, def _getRelatedPropertyList(self, id, property_name, spec=(), filter=None,
portal_type=(), strict_membership=0, portal_type=(), strict_membership=0,
query=None): checked_permission=None):
return self._getCategoryTool().getRelatedPropertyList(self, id, return self._getCategoryTool().getRelatedPropertyList(self, id,
property_name=property_name, property_name=property_name,
spec=spec, filter=filter, spec=spec, filter=filter,
portal_type=portal_type, portal_type=portal_type,
strict_membership=strict_membership, strict_membership=strict_membership,
query=query) checked_permission=checked_permission)
security.declareProtected( Permissions.AccessContentsInformation, security.declareProtected( Permissions.AccessContentsInformation,
'getRelatedPropertyList' ) '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