--- a/src/pyams_content/shared/common/security.py Fri May 25 08:05:13 2018 +0200
+++ b/src/pyams_content/shared/common/security.py Fri May 25 15:48:59 2018 +0200
@@ -23,14 +23,12 @@
# import packages
from persistent import Persistent
from pyams_security.interfaces import IPrincipalInfo, IRevokedRoleEvent, IGrantedRoleEvent
-from pyams_utils.adapter import adapter_config, ContextAdapter
+from pyams_utils.adapter import adapter_config, ContextAdapter, get_annotation_adapter
from pyams_utils.request import check_request
from pyams_utils.traversing import get_parent
from pyramid.events import subscriber
-from zope.annotation.interfaces import IAnnotations
from zope.container.folder import Folder
from zope.interface import implementer
-from zope.location import locate
from zope.schema.fieldproperty import FieldProperty
@@ -64,28 +62,19 @@
"""Shared tool manager restrictions"""
def get_restrictions(self, principal):
- annotations = IAnnotations(self.context)
- restrictions_folder = annotations.get(MANAGER_RESTRICTIONS_KEY)
- if restrictions_folder is None:
- restrictions_folder = annotations[MANAGER_RESTRICTIONS_KEY] = Folder()
- locate(restrictions_folder, self.context)
+ restrictions_folder = get_annotation_adapter(self.context, MANAGER_RESTRICTIONS_KEY, Folder)
if IPrincipalInfo.providedBy(principal):
principal = principal.id
return restrictions_folder.get(principal)
def set_restrictions(self, principal, restrictions):
- annotations = IAnnotations(self.context)
- restrictions_folder = annotations.get(MANAGER_RESTRICTIONS_KEY)
- if restrictions_folder is None:
- restrictions_folder = annotations[MANAGER_RESTRICTIONS_KEY] = Folder()
- locate(restrictions_folder, self.context)
+ restrictions_folder = get_annotation_adapter(self.context, MANAGER_RESTRICTIONS_KEY, Folder)
if IPrincipalInfo.providedBy(principal):
principal = principal.id
restrictions_folder[principal] = restrictions
def drop_restrictions(self, principal):
- annotations = IAnnotations(self.context)
- restrictions_folder = annotations.get(MANAGER_RESTRICTIONS_KEY)
+ restrictions_folder = get_annotation_adapter(self.context, MANAGER_RESTRICTIONS_KEY)
if restrictions_folder is None:
return
if IPrincipalInfo.providedBy(principal):