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):
self._key = key
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):
if self._warning:
LOG("ERP5Type Deprecated Getter Id:",0, self._id)
......@@ -73,11 +56,11 @@ class RestrictedDefaultGetter(DefaultGetter):
spec=kw.get('spec',()),
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
query=instance.portal_catalog.getSecurityQuery(),)
checked_permission=kw.get('checked_permission', None))
psyco.bind(__call__)
RestrictedGetter = RestrictedDefaultGetter
Getter = DefaultGetter
class ListGetter(Method):
"""
......@@ -98,21 +81,6 @@ class ListGetter(Method):
self._key = key
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):
if self._warning:
LOG("ERP5Type Deprecated Getter Id:",0, self._id)
......@@ -121,7 +89,7 @@ class RestrictedListGetter(ListGetter):
spec=kw.get('spec',()),
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
query=instance.portal_catalog.getSecurityQuery(),)
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
......@@ -62,32 +62,14 @@ class DefaultGetter(Method):
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
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__)
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):
"""
Gets a list of reference objects
......@@ -120,25 +102,9 @@ class ListGetter(Method):
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
strict_membership=kw.get('strict_membership',
kw.get('strict', None))) # 'strict' is deprecated
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._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(),)
# 'strict' is deprecated
kw.get('strict', None)),
checked_permission=kw.get('checked_permission', None))
psyco.bind(__call__)
......@@ -151,15 +117,6 @@ class SetGetter(ListGetter):
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
class DefaultIdGetter(Method):
"""
Gets a default reference object
......@@ -188,34 +145,14 @@ class DefaultIdGetter(Method):
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
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__)
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):
"""
Gets a list of reference objects
......@@ -244,25 +181,9 @@ class IdListGetter(Method):
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
strict_membership=kw.get('strict_membership',
kw.get('strict', None))) # 'strict' is deprecated
psyco.bind(__call__)
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(),)
# 'strict' is deprecated
kw.get('strict', None)),
checked_permission=kw.get('checked_permission', None))
psyco.bind(__call__)
......@@ -275,15 +196,6 @@ class IdSetGetter(IdListGetter):
result_set = dict([(x, 0) for x in result_list]).keys()
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):
"""
Gets a default reference object
......@@ -312,32 +224,14 @@ class DefaultTitleGetter(Method):
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
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__)
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):
"""
Gets a list of reference objects
......@@ -366,24 +260,9 @@ class TitleListGetter(Method):
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
strict_membership=kw.get('strict_membership',
kw.get('strict', None))) # 'strict' is deprecated
psyco.bind(__call__)
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(),)
# 'strict' is deprecated
kw.get('strict', None)),
checked_permission=kw.get('checked_permission', None))
psyco.bind(__call__)
......@@ -396,16 +275,6 @@ class TitleSetGetter(TitleListGetter):
result_set = dict([(x, 0) for x in result_list]).keys()
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):
"""
Gets a default reference object
......@@ -434,31 +303,13 @@ class DefaultPropertyGetter(Method):
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
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__)
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):
"""
Gets a list of reference objects
......@@ -487,25 +338,9 @@ class PropertyListGetter(Method):
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
strict_membership=kw.get('strict_membership',
kw.get('strict', None))) # 'strict' is deprecated
psyco.bind(__call__)
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(),)
# 'strict' is deprecated
kw.get('strict', None)),
checked_permission=kw.get('checked_permission', None))
psyco.bind(__call__)
class PropertySetGetter(PropertyListGetter):
......@@ -516,14 +351,3 @@ class PropertySetGetter(PropertyListGetter):
result_list = PropertyListGetter.__call__(self, instance, *args, **kw)
result_set = dict([(x, 0) for x in result_list]).keys()
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,
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