[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security - AttributeRolePermissionManager.py:1.1.2.8
Casey Duncan
casey@zope.com
Thu, 28 Mar 2002 15:58:25 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Security
In directory cvs.zope.org:/tmp/cvs-serv31140/lib/python/Zope/App/Security
Modified Files:
Tag: Zope-3x-branch
AttributeRolePermissionManager.py
Log Message:
Refactored AttributeRolePermissionManager to use memento storage
=== Zope3/lib/python/Zope/App/Security/AttributeRolePermissionManager.py 1.1.2.7 => 1.1.2.8 ===
"""
-from Zope.ComponentArchitecture import getService
-
+from Zope.ComponentArchitecture import getService, getAdapter
+from Zope.App.OFS.Memento.IMementoBag import IMementoBag
from Zope.App.Security.IRolePermissionManager import IRolePermissionManager
from Zope.App.Security.LocalSecurityMap import LocalSecurityMap
from Zope.App.Security.Settings import Allow, Deny, Unset
+memo_key = 'Zope.App.Security.AttributeRolePermissionManager'
+
class AttributeRolePermissionManager:
"""
provide adaptor that manages role permission data in an object attribute
@@ -33,65 +35,65 @@
def grantPermissionToRole( self, permission_id, role_id ):
''' See the interface IRolePermissionManager '''
- pp = self._getRolePermissions(create=1)
- pp.addCell( permission_id, role_id, Allow )
+ rp = self._getRolePermissions(create=1)
+ rp.addCell( permission_id, role_id, Allow )
self._context._p_changed = 1
def denyPermissionToRole( self, permission_id, role_id ):
''' See the interface IRolePermissionManager '''
- pp = self._getRolePermissions(create=1)
- pp.addCell( permission_id, role_id, Deny )
+ rp = self._getRolePermissions(create=1)
+ rp.addCell( permission_id, role_id, Deny )
self._context._p_changed = 1
def unsetPermissionFromRole( self, permission_id, role_id ):
''' See the interface IRolePermissionManager '''
- pp = self._getRolePermissions()
+ rp = self._getRolePermissions()
# Only unset if there is a security map, otherwise, we're done
- if pp:
- pp.delCell( permission_id, role_id )
+ if rp:
+ rp.delCell( permission_id, role_id )
self._context._p_changed = 1
def getRolesForPermission( self, permission_id ):
'''See interface IRolePermissionMap'''
- pp = self._getRolePermissions()
- if pp:
- return pp.getRow( permission_id )
+ rp = self._getRolePermissions()
+ if rp:
+ return rp.getRow( permission_id )
else:
return []
def getPermissionsForRole( self, role_id ):
'''See interface IRolePermissionMap'''
- pp = self._getRolePermissions()
- if pp:
- return pp.getCol( role_id )
+ rp = self._getRolePermissions()
+ if rp:
+ return rp.getCol( role_id )
else:
return []
def getRolesAndPermissions( self ):
'''See interface IRolePermissionMap'''
- pp = self._getRolePermissions()
- if pp:
- return pp.getAllCells( role_id )
+ rp = self._getRolePermissions()
+ if rp:
+ return rp.getAllCells( role_id )
else:
return []
def getSetting( self, permission_id, role_id ):
'''See interface IRolePermissionMap'''
- pp = self._getRolePermissions()
- if pp:
- return pp.getCell( permission_id, role_id )
+ rp = self._getRolePermissions()
+ if rp:
+ return rp.getCell( permission_id, role_id )
else:
return Unset
def _getRolePermissions(self, create=0):
""" Get the role permission map stored in the context, optionally
creating one if necessary """
+ memo = getAdapter(self._context, IMementoBag)
try:
- return self._context.__role_permissions__
- except AttributeError:
+ return memo[memo_key]
+ except KeyError:
if create:
- pp = self._context.__role_permissions__ = \
- LocalSecurityMap()
- return pp
+ rp = memo[memo_key] = LocalSecurityMap()
+ return rp
return None