src/pyams_security/security.py
changeset 39 51a07039228f
parent 34 b84b491ea8bd
child 42 07229ac2497b
equal deleted inserted replaced
38:cadf156a926e 39:51a07039228f
    28 from pyams_utils.property import request_property
    28 from pyams_utils.property import request_property
    29 from pyams_utils.registry import query_utility
    29 from pyams_utils.registry import query_utility
    30 from pyams_utils.request import check_request
    30 from pyams_utils.request import check_request
    31 from pyramid.location import lineage
    31 from pyramid.location import lineage
    32 from pyramid.security import DENY_ALL, Everyone, Allow, ALL_PERMISSIONS, Authenticated
    32 from pyramid.security import DENY_ALL, Everyone, Allow, ALL_PERMISSIONS, Authenticated
       
    33 from pyramid.threadlocal import get_current_registry
       
    34 from zope.container.contained import Contained
    33 from zope.interface import implementer
    35 from zope.interface import implementer
    34 from zope.lifecycleevent import ObjectCreatedEvent
    36 from zope.lifecycleevent import ObjectCreatedEvent
    35 from zope.location.location import locate
    37 from zope.location.location import locate
    36 from zope.schema.fieldproperty import FieldProperty
    38 from zope.schema.fieldproperty import FieldProperty
    37 
    39 
    38 
    40 
    39 @implementer(IRoleProtectedObject)
    41 @implementer(IRoleProtectedObject)
    40 class RoleProtectedObject(Persistent):
    42 class RoleProtectedObject(Persistent, Contained):
    41     """Base class for object protected by roles"""
    43     """Base class for object protected by roles"""
    42 
    44 
    43     inherit_parent_security = FieldProperty(IRoleProtectedObject['inherit_parent_security'])
    45     inherit_parent_security = FieldProperty(IRoleProtectedObject['inherit_parent_security'])
    44     _everyone_permissions = FieldProperty(IRoleProtectedObject['everyone_permissions'])
    46     _everyone_permissions = FieldProperty(IRoleProtectedObject['everyone_permissions'])
    45     _authenticated_permissions = FieldProperty(IRoleProtectedObject['authenticated_permissions'])
    47     _authenticated_permissions = FieldProperty(IRoleProtectedObject['authenticated_permissions'])
   174     """Default protected object factory"""
   176     """Default protected object factory"""
   175     annotations = IAnnotations(context)
   177     annotations = IAnnotations(context)
   176     protection = annotations.get(ROLES_ANNOTATIONS_KEY)
   178     protection = annotations.get(ROLES_ANNOTATIONS_KEY)
   177     if protection is None:
   179     if protection is None:
   178         protection = annotations[ROLES_ANNOTATIONS_KEY] = RoleProtectedObject()
   180         protection = annotations[ROLES_ANNOTATIONS_KEY] = RoleProtectedObject()
   179         check_request().registry.notify(ObjectCreatedEvent(protection))
   181         get_current_registry().notify(ObjectCreatedEvent(protection))
   180         locate(protection, context)
   182         locate(protection, context)
   181     return protection
   183     return protection
   182 
   184 
   183 
   185 
   184 class ProtectedObject(object):
   186 class ProtectedObject(object):