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): ...@@ -52,33 +52,16 @@ class DefaultGetter(Method):
if self._warning: if self._warning:
LOG("ERP5Type Deprecated Getter Id:",0, self._id) LOG("ERP5Type Deprecated Getter Id:",0, self._id)
return instance._getDefaultRelatedProperty( return instance._getDefaultRelatedProperty(
self._key, 'relative_url', self._key, 'relative_url',
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',()),
checked_permission=kw.get('checked_permission', None))
psyco.bind(__call__) psyco.bind(__call__)
Getter = DefaultGetter 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): class ListGetter(Method):
""" """
Gets a list of reference objects Gets a list of reference objects
...@@ -102,26 +85,11 @@ class ListGetter(Method): ...@@ -102,26 +85,11 @@ class ListGetter(Method):
if self._warning: if self._warning:
LOG("ERP5Type Deprecated Getter Id:",0, self._id) LOG("ERP5Type Deprecated Getter Id:",0, self._id)
return instance._getRelatedPropertyList( return instance._getRelatedPropertyList(
self._key, 'relative_url', self._key, 'relative_url',
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',()),
checked_permission=kw.get('checked_permission', None))
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(),)
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
...@@ -62,32 +62,14 @@ class DefaultGetter(Method): ...@@ -62,32 +62,14 @@ class DefaultGetter(Method):
filter=kw.get('filter', None), filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()), portal_type=kw.get('portal_type',()),
strict_membership=kw.get('strict_membership', strict_membership=kw.get('strict_membership',
kw.get('strict', None))) # 'strict' is deprecated # 'strict' is deprecated
kw.get('strict', None)),
checked_permission=kw.get('checked_permission', None))
psyco.bind(__call__) psyco.bind(__call__)
Getter = DefaultGetter 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._getDefaultRelatedValue(
self._key,
spec=kw.get('spec',()),
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
strict_membership=kw.get('strict_membership',
kw.get('strict', None)), # 'strict' is deprecated
query=instance.portal_catalog.getSecurityQuery(),)
psyco.bind(__call__)
RestrictedGetter = RestrictedDefaultGetter
class ListGetter(Method): class ListGetter(Method):
""" """
Gets a list of reference objects Gets a list of reference objects
...@@ -119,26 +101,10 @@ class ListGetter(Method): ...@@ -119,26 +101,10 @@ class ListGetter(Method):
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',()),
strict_membership=kw.get('strict_membership', strict_membership=kw.get('strict_membership',
kw.get('strict', None))) # 'strict' is deprecated # 'strict' is deprecated
kw.get('strict', None)),
psyco.bind(__call__) checked_permission=kw.get('checked_permission', None))
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._getRelatedValueList(
self._key,
spec=kw.get('spec',()),
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
strict_membership=kw.get('strict_membership',
kw.get('strict', None)), # 'strict' is deprecated
query=instance.portal_catalog.getSecurityQuery(),)
psyco.bind(__call__) psyco.bind(__call__)
...@@ -151,15 +117,6 @@ class SetGetter(ListGetter): ...@@ -151,15 +117,6 @@ class SetGetter(ListGetter):
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
class DefaultIdGetter(Method): class DefaultIdGetter(Method):
""" """
Gets a default reference object Gets a default reference object
...@@ -187,35 +144,15 @@ class DefaultIdGetter(Method): ...@@ -187,35 +144,15 @@ class DefaultIdGetter(Method):
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',()),
strict_membership=kw.get('strict_membership', strict_membership=kw.get('strict_membership',
kw.get('strict', None))) # 'strict' is deprecated # 'strict' is deprecated
kw.get('strict', None)),
checked_permission=kw.get('checked_permission', None))
psyco.bind(__call__) psyco.bind(__call__)
IdGetter = DefaultIdGetter IdGetter = DefaultIdGetter
class RestrictedDefaultIdGetter(DefaultIdGetter):
"""
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, 'id',
spec=kw.get('spec',()),
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
strict_membership=kw.get('strict_membership',
kw.get('strict', None)), # 'strict' is deprecated
query=instance.portal_catalog.getSecurityQuery(),)
psyco.bind(__call__)
RestrictedIdGetter = RestrictedDefaultIdGetter
class IdListGetter(Method): class IdListGetter(Method):
""" """
Gets a list of reference objects Gets a list of reference objects
...@@ -243,26 +180,10 @@ class IdListGetter(Method): ...@@ -243,26 +180,10 @@ class IdListGetter(Method):
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',()),
strict_membership=kw.get('strict_membership', strict_membership=kw.get('strict_membership',
kw.get('strict', None))) # 'strict' is deprecated # 'strict' is deprecated
kw.get('strict', None)),
psyco.bind(__call__) checked_permission=kw.get('checked_permission', None))
class RestrictedIdListGetter(IdListGetter):
"""
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, 'id',
spec=kw.get('spec',()),
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
strict_membership=kw.get('strict_membership',
kw.get('strict', None)), # 'strict' is deprecated
query=instance.portal_catalog.getSecurityQuery(),)
psyco.bind(__call__) psyco.bind(__call__)
...@@ -275,15 +196,6 @@ class IdSetGetter(IdListGetter): ...@@ -275,15 +196,6 @@ class IdSetGetter(IdListGetter):
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 RestrictedIdSetGetter(RestrictedIdListGetter):
"""
Gets a category value set
"""
def __call__(self, instance, *args, **kw):
result_list = RestrictedIdListGetter.__call__(self, instance, *args, **kw)
result_set = dict([(x, 0) for x in result_list]).keys()
return result_set
class DefaultTitleGetter(Method): class DefaultTitleGetter(Method):
""" """
Gets a default reference object Gets a default reference object
...@@ -311,33 +223,15 @@ class DefaultTitleGetter(Method): ...@@ -311,33 +223,15 @@ class DefaultTitleGetter(Method):
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',()),
strict_membership=kw.get('strict_membership', strict_membership=kw.get('strict_membership',
kw.get('strict', None))) # 'strict' is deprecated # 'strict' is deprecated
kw.get('strict', None)),
checked_permission=kw.get('checked_permission', None))
psyco.bind(__call__) psyco.bind(__call__)
TitleGetter = DefaultTitleGetter TitleGetter = DefaultTitleGetter
class RestrictedDefaultTitleGetter(DefaultTitleGetter):
"""
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, 'title',
spec=kw.get('spec',()),
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
strict_membership=kw.get('strict_membership',
kw.get('strict', None)), # 'strict' is deprecated
query=instance.portal_catalog.getSecurityQuery(),)
psyco.bind(__call__)
RestrictedTitleGetter = RestrictedDefaultTitleGetter
class TitleListGetter(Method): class TitleListGetter(Method):
""" """
Gets a list of reference objects Gets a list of reference objects
...@@ -365,25 +259,10 @@ class TitleListGetter(Method): ...@@ -365,25 +259,10 @@ class TitleListGetter(Method):
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',()),
strict_membership=kw.get('strict_membership', strict_membership=kw.get('strict_membership',
kw.get('strict', None))) # 'strict' is deprecated # 'strict' is deprecated
psyco.bind(__call__) kw.get('strict', None)),
checked_permission=kw.get('checked_permission', None))
class RestrictedTitleListGetter(TitleListGetter):
"""
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, 'title',
spec=kw.get('spec',()),
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
strict_membership=kw.get('strict_membership',
kw.get('strict', None)), # 'strict' is deprecated
query=instance.portal_catalog.getSecurityQuery(),)
psyco.bind(__call__) psyco.bind(__call__)
...@@ -396,16 +275,6 @@ class TitleSetGetter(TitleListGetter): ...@@ -396,16 +275,6 @@ class TitleSetGetter(TitleListGetter):
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 RestrictedTitleSetGetter(RestrictedTitleListGetter):
"""
Gets a category value set
"""
def __call__(self, instance, *args, **kw):
result_list = RestrictedTitleListGetter.__call__(self, instance,
*args, **kw)
result_set = dict([(x, 0) for x in result_list]).keys()
return result_set
class DefaultPropertyGetter(Method): class DefaultPropertyGetter(Method):
""" """
Gets a default reference object Gets a default reference object
...@@ -433,32 +302,14 @@ class DefaultPropertyGetter(Method): ...@@ -433,32 +302,14 @@ class DefaultPropertyGetter(Method):
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',()),
strict_membership=kw.get('strict_membership', strict_membership=kw.get('strict_membership',
kw.get('strict', None))) # 'strict' is deprecated # 'strict' is deprecated
kw.get('strict', None)),
checked_permission=kw.get('checked_permission', None))
psyco.bind(__call__) psyco.bind(__call__)
PropertyGetter = DefaultPropertyGetter PropertyGetter = DefaultPropertyGetter
class RestrictedDefaultPropertyGetter(DefaultPropertyGetter):
"""
Gets a default reference object
"""
def __call__(self, instance, key, *args, **kw):
if self._warning:
LOG("ERP5Type Deprecated Getter Id:",0, self._id)
return instance._getDefaultRelatedProperty(
self._key, key,
spec=kw.get('spec',()),
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
strict_membership=kw.get('strict_membership',
kw.get('strict', None)), # 'strict' is deprecated
query=instance.portal_catalog.getSecurityQuery(),)
psyco.bind(__call__)
RestrictedPropertyGetter = RestrictedDefaultPropertyGetter
class PropertyListGetter(Method): class PropertyListGetter(Method):
""" """
Gets a list of reference objects Gets a list of reference objects
...@@ -486,26 +337,10 @@ class PropertyListGetter(Method): ...@@ -486,26 +337,10 @@ class PropertyListGetter(Method):
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',()),
strict_membership=kw.get('strict_membership', strict_membership=kw.get('strict_membership',
kw.get('strict', None))) # 'strict' is deprecated # 'strict' is deprecated
psyco.bind(__call__) kw.get('strict', None)),
checked_permission=kw.get('checked_permission', None))
class RestrictedPropertyListGetter(PropertyListGetter):
"""
Gets a list of reference objects
"""
def __call__(self, instance, key, *args, **kw):
if self._warning:
LOG("ERP5Type Deprecated Getter Id:",0, self._id)
return instance._getRelatedPropertyList(
self._key, key,
spec=kw.get('spec',()),
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
strict_membership=kw.get('strict_membership',
kw.get('strict', None)), # 'strict' is deprecated
query=instance.portal_catalog.getSecurityQuery(),)
psyco.bind(__call__) psyco.bind(__call__)
class PropertySetGetter(PropertyListGetter): class PropertySetGetter(PropertyListGetter):
...@@ -516,14 +351,3 @@ class PropertySetGetter(PropertyListGetter): ...@@ -516,14 +351,3 @@ class PropertySetGetter(PropertyListGetter):
result_list = PropertyListGetter.__call__(self, instance, *args, **kw) result_list = PropertyListGetter.__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 RestrictedPropertySetGetter(RestrictedPropertyListGetter):
"""
Gets a category value set
"""
def __call__(self, instance, *args, **kw):
result_list = RestrictedPropertyListGetter.__call__(self, instance,
*args, **kw)
result_set = dict([(x, 0) for x in result_list]).keys()
return result_set
...@@ -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