[Zope3-checkins] CVS: Zope3/src/zope/app/security/grants/global - __init__.py:1.1.2.1 meta.zcml:1.1.2.1 metaconfigure.py:1.1.2.1 principalpermissionmanager.py:1.1.2.1 principalrolemanager.py:1.1.2.1 rolepermissionmanager.py:1.1.2.1
Jim Fulton
jim@zope.com
Mon, 23 Dec 2002 14:32:19 -0500
Update of /cvs-repository/Zope3/src/zope/app/security/grants/global
In directory cvs.zope.org:/tmp/cvs-serv19908/zope/app/security/grants/global
Added Files:
Tag: NameGeddon-branch
__init__.py meta.zcml metaconfigure.py
principalpermissionmanager.py principalrolemanager.py
rolepermissionmanager.py
Log Message:
Initial renaming before debugging
=== Added File Zope3/src/zope/app/security/grants/global/__init__.py ===
#
# This file is necessary to make this directory a package.
=== Added File Zope3/src/zope/app/security/grants/global/meta.zcml ===
<zopeConfigure xmlns='http://namespaces.zope.org/zope'>
<directives namespace="http://namespaces.zope.org/zope">
<directive name="grant" attributes="principal permission role"
handler="zope.app.security.grants.global.metaconfigure.grant" />
</directives>
</zopeConfigure>
=== Added File Zope3/src/zope/app/security/grants/global/metaconfigure.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
""" Register security related configuration directives.
$Id: metaconfigure.py,v 1.1.2.1 2002/12/23 19:32:18 jim Exp $
"""
from zope.app.security.grants.global.rolepermissionmanager import rolePermissionManager as role_perm_mgr
from zope.app.security.grants.global.principalpermissionmanager import principalPermissionManager \
as principal_perm_mgr
from zope.app.security.grants.global.principalrolemanager import principalRoleManager as principal_role_mgr
from zope.configuration.action import Action
from zope.configuration.exceptions import ConfigurationError
def grant(_context, principal=None, role=None, permission=None):
if ( (principal is not None)
+ (role is not None)
+ (permission is not None)
) != 2:
raise ConfigurationError(
"Exactly two of the principal, role, and permission attributes "
"must be specified")
if principal:
if role:
return [
Action(
discriminator = ('grantRoleToPrincipal', role, principal),
callable = principal_role_mgr.assignRoleToPrincipal,
args = (role, principal),
)
]
if permission:
return [
Action(
discriminator = ('grantPermissionToPrincipal',
permission,
principal),
callable = principal_perm_mgr.grantPermissionToPrincipal,
args = (permission, principal),
)
]
else:
return [
Action(
discriminator = ('grantPermissionToRole', permission, role),
callable = role_perm_mgr.grantPermissionToRole,
args = (permission, role),
)
]
=== Added File Zope3/src/zope/app/security/grants/global/principalpermissionmanager.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Mappings between principals and permissions."""
from zope.app.interfaces.security \
import IPrincipalPermissionManager
from zope.app.security.grants.localsecuritymap import LocalSecurityMap
from zope.app.security.settings import Allow, Deny, Unset
class PrincipalPermissionManager(LocalSecurityMap):
"""Mappings between principals and permissions."""
__implements__ = IPrincipalPermissionManager
def grantPermissionToPrincipal( self, permission_id, principal_id ):
''' See the interface IPrincipalPermissionManager '''
self.addCell( permission_id, principal_id, Allow )
def denyPermissionToPrincipal( self, permission_id, principal_id ):
''' See the interface IPrincipalPermissionManager '''
self.addCell( permission_id, principal_id, Deny )
def unsetPermissionForPrincipal( self, permission_id, principal_id ):
''' See the interface IPrincipalPermissionManager '''
self.delCell( permission_id, principal_id )
def getPrincipalsForPermission( self, permission_id ):
''' See the interface IPrincipalPermissionManager '''
return self.getRow( permission_id )
def getPermissionsForPrincipal( self, principal_id ):
''' See the interface IPrincipalPermissionManager '''
return self.getCol( principal_id )
def getSetting( self, permission_id, principal_id ):
''' See the interface IPrincipalPermissionManager '''
return self.getCell( permission_id, principal_id, default=Unset )
def getPrincipalsAndPermissions( self ):
''' See the interface IPrincipalPermissionManager '''
return self.getAllCells()
# Permissions are our rows, and principals are our columns
principalPermissionManager = PrincipalPermissionManager()
# Register our cleanup with Testing.CleanUp to make writing unit tests simpler.
from zope.testing.cleanup import addCleanUp
addCleanUp(principalPermissionManager._clear)
del addCleanUp
=== Added File Zope3/src/zope/app/security/grants/global/principalrolemanager.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Mappings between principals and roles."""
from zope.app.security.grants.localsecuritymap import LocalSecurityMap
from zope.app.security.settings import Allow, Deny, Unset
from zope.app.interfaces.security import IPrincipalRoleManager
from zope.app.interfaces.security import IPrincipalRoleMap
class PrincipalRoleManager(LocalSecurityMap):
"""Mappings between principals and roles."""
__implements__ = ( IPrincipalRoleManager, IPrincipalRoleMap )
def assignRoleToPrincipal( self, role_id, principal_id ):
''' See the interface IPrincipalRoleManager '''
self.addCell( role_id, principal_id, Allow )
def removeRoleFromPrincipal( self, role_id, principal_id ):
''' See the interface IPrincipalRoleManager '''
self.addCell( role_id, principal_id, Deny )
def unsetRoleForPrincipal( self, role_id, principal_id ):
''' See the interface IPrincipalRoleManager '''
self.delCell( role_id, principal_id )
def getPrincipalsForRole( self, role_id ):
''' See the interface IPrincipalRoleMap '''
return self.getRow( role_id )
def getRolesForPrincipal( self, principal_id ):
''' See the interface IPrincipalRoleMap '''
return self.getCol( principal_id )
def getSetting( self, role_id, principal_id ):
''' See the interface IPrincipalRoleMap '''
return self.getCell( role_id, principal_id, default=Unset )
def getPrincipalsAndRoles( self ):
''' See the interface IPrincipalRoleMap '''
return self.getAllCells()
# Roles are our rows, and principals are our columns
principalRoleManager = PrincipalRoleManager()
# Register our cleanup with Testing.CleanUp to make writing unit tests simpler.
from zope.testing.cleanup import addCleanUp
addCleanUp(principalRoleManager._clear)
del addCleanUp
=== Added File Zope3/src/zope/app/security/grants/global/rolepermissionmanager.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Mappings between roles and permissions."""
from zope.app.security.grants.localsecuritymap import LocalSecurityMap
from zope.app.security.settings import Allow, Deny
from zope.app.interfaces.security import IRolePermissionManager
class RolePermissionManager(LocalSecurityMap):
"""Mappings between roles and permissions."""
__implements__ = IRolePermissionManager
# Implementation methods for interface
# Zope.App.Security.IRolePermissionManager
def grantPermissionToRole( self, permission_id, role_id ):
'''See interface IRolePermissionMap'''
self.addCell( permission_id, role_id, Allow )
def denyPermissionToRole( self, permission_id, role_id ):
'''See interface IRolePermissionMap'''
self.addCell( permission_id, role_id, Deny )
def unsetPermissionFromRole( self, permission_id, role_id ):
'''See interface IRolePermissionMap'''
self.delCell( permission_id, role_id )
def getRolesForPermission( self, permission_id ):
'''See interface IRolePermissionMap'''
return self.getRow( permission_id )
def getPermissionsForRole( self, role_id ):
'''See interface IRolePermissionMap'''
return self.getCol( role_id )
def getSetting( self, permission_id, role_id ):
'''See interface IRolePermissionMap'''
return self.getCell( permission_id, role_id )
def getRolesAndPermissions( self ):
'''See interface IRolePermissionMap'''
return self.getAllCells()
# Permissions are our rows, and roles are our columns
rolePermissionManager = RolePermissionManager()
# Register our cleanup with Testing.CleanUp to make writing unit tests simpler.
from zope.testing.cleanup import addCleanUp
addCleanUp(rolePermissionManager._clear)
del addCleanUp