src/pyams_security/security.py
changeset 126 18711a1f3140
parent 119 ccf5a7b0bbe4
child 155 326ee1e62dcb
--- a/src/pyams_security/security.py	Wed May 23 15:09:56 2018 +0200
+++ b/src/pyams_security/security.py	Mon May 28 14:05:40 2018 +0200
@@ -20,12 +20,11 @@
 from pyams_security.interfaces import IProtectedObject, IRole, IPrincipalInfo, GrantedRoleEvent, RevokedRoleEvent, \
     IDefaultProtectionPolicy, IRoleProtectedObject, ADMIN_USER_ID
 from pyams_utils.interfaces import PUBLIC_PERMISSION
-from zope.annotation.interfaces import IAnnotations
 
 # import packages
 from persistent import Persistent
 from persistent.dict import PersistentDict
-from pyams_utils.adapter import adapter_config
+from pyams_utils.adapter import adapter_config, get_annotation_adapter
 from pyams_utils.registry import query_utility
 from pyams_utils.request import request_property
 from pyramid.location import lineage
@@ -33,8 +32,6 @@
 from pyramid.threadlocal import get_current_registry
 from zope.container.contained import Contained
 from zope.interface import implementer
-from zope.lifecycleevent import ObjectCreatedEvent
-from zope.location.location import locate
 from zope.schema.fieldproperty import FieldProperty
 
 
@@ -205,13 +202,7 @@
 @adapter_config(context=IDefaultProtectionPolicy, provides=IRoleProtectedObject)
 def protected_object_factory(context):
     """Default protected object factory"""
-    annotations = IAnnotations(context)
-    protection = annotations.get(ROLES_ANNOTATIONS_KEY)
-    if protection is None:
-        protection = annotations[ROLES_ANNOTATIONS_KEY] = RoleProtectedObject()
-        get_current_registry().notify(ObjectCreatedEvent(protection))
-        locate(protection, context)
-    return protection
+    return get_annotation_adapter(context, ROLES_ANNOTATIONS_KEY, RoleProtectedObject)
 
 
 class ProtectedObject(object):