[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security - AnnotationPrincipalPermissionManager.py:1.1.2.1 AnnotationPrincipalRoleManager.py:1.1.2.1 AnnotationRolePermissionManager.py:1.1.2.1 security.zcml:1.1.2.8 AttributePrincipalPermissionManager.py:NONE AttributePrincipalRoleManager.py:NONE AttributeRolePermissionManager.py:NONE

Steve Alexander steve@cat-box.net
Sun, 26 May 2002 14:21:20 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/Security
In directory cvs.zope.org:/tmp/cvs-serv6102/lib/python/Zope/App/Security

Modified Files:
      Tag: Zope-3x-branch
	security.zcml 
Added Files:
      Tag: Zope-3x-branch
	AnnotationPrincipalPermissionManager.py 
	AnnotationPrincipalRoleManager.py 
	AnnotationRolePermissionManager.py 
Removed Files:
      Tag: Zope-3x-branch
	AttributePrincipalPermissionManager.py 
	AttributePrincipalRoleManager.py 
	AttributeRolePermissionManager.py 
Log Message:
Security-related management screens now work!

I've had to change the way use of Annotations is declared in classes
a little bit. I'll explain more about that in an email to
zope3-dev shortly.


=== Added File Zope3/lib/python/Zope/App/Security/AnnotationPrincipalPermissionManager.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, stored in an object locally."""

from Zope.ComponentArchitecture import getAdapter
from Zope.App.OFS.Annotation.IAnnotations import IAnnotations
from Zope.App.Security.IPrincipalPermissionManager \
     import IPrincipalPermissionManager
from Zope.App.Security.LocalSecurityMap import LocalSecurityMap
from Zope.App.Security.Settings import Allow, Deny, Unset
from Zope.Proxy.ProxyIntrospection import removeAllProxies

annotation_key = 'Zope.App.Security.AnnotationPrincipalPermissionManager'

class AnnotationPrincipalPermissionManager:
    """Mappings between principals and permissions."""

    __implements__ = IPrincipalPermissionManager

    def __init__(self, context):
        self._context = removeAllProxies(context)

    def grantPermissionToPrincipal(self, permission_id, principal_id):
        ''' See the interface IPrincipalPermissionManager '''
        pp = self._getPrincipalPermissions(create=1)
        pp.addCell(permission_id, principal_id, Allow)
        self._context._p_changed = 1

    def denyPermissionToPrincipal(self, permission_id, principal_id):
        ''' See the interface IPrincipalPermissionManager '''
        pp = self._getPrincipalPermissions(create=1)
        pp.addCell(permission_id, principal_id, Deny)
        self._context._p_changed = 1

    def unsetPermissionForPrincipal(self, permission_id, principal_id):
        ''' See the interface IPrincipalPermissionManager '''
        pp = self._getPrincipalPermissions()
        # Only unset if there is a security map, otherwise, we're done
        if pp:
            pp.delCell(permission_id, principal_id)
            self._context._p_changed = 1

    def getPrincipalsForPermission(self, permission_id):
        ''' See the interface IPrincipalPermissionManager '''
        pp = self._getPrincipalPermissions()
        if pp: 
            return pp.getRow(permission_id)
        return []

    def getPermissionsForPrincipal(self, principal_id):
        ''' See the interface IPrincipalPermissionManager '''
        pp = self._getPrincipalPermissions()
        if pp: 
            return pp.getCol(principal_id)
        return []

    def getSetting(self, permission_id, principal_id):
        ''' See the interface IPrincipalPermissionManager '''
        pp = self._getPrincipalPermissions()
        if pp: 
            return pp.getCell(permission_id, principal_id, default=Unset)
        return []

    def getPrincipalsAndPermissions(self):
        ''' See the interface IPrincipalPermissionManager '''
        pp = self._getPrincipalPermissions()
        if pp: 
            return pp.getAllCells()
        return []

    # Implementation helpers

    def _getPrincipalPermissions(self, create=0):
        """ Get the principal permission map stored in the context, optionally
            creating one if necessary """
        annotations = getAdapter(self._context, IAnnotations)
        try:
            return annotations[annotation_key]
        except KeyError:
            if create:
                rp = annotations[annotation_key] = LocalSecurityMap()
                return rp
        return None


=== Added File Zope3/lib/python/Zope/App/Security/AnnotationPrincipalRoleManager.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, stored in an object locally."""

from Zope.ComponentArchitecture import getAdapter
from Zope.App.OFS.Annotation.IAnnotations import IAnnotations
from Zope.App.Security.IPrincipalRoleManager \
     import IPrincipalRoleManager
from Zope.App.Security.LocalSecurityMap import LocalSecurityMap
from Zope.App.Security.Settings import Assign, Remove, Unset
from Zope.Proxy.ProxyIntrospection import removeAllProxies

annotation_key = 'Zope.App.Security.AnnotationPrincipalRoleManager'

class AnnotationPrincipalRoleManager:
    """Mappings between principals and roles."""

    __implements__ = IPrincipalRoleManager

    def __init__(self, context):
        self._context = removeAllProxies(context)

    def assignRoleToPrincipal(self, role_id, principal_id):
        ''' See the interface IPrincipalRoleManager '''
        pp = self._getPrincipalRoles(create=1)
        pp.addCell(role_id, principal_id, Assign)
        self._context._p_changed = 1

    def removeRoleFromPrincipal(self, role_id, principal_id):
        ''' See the interface IPrincipalRoleManager '''
        pp = self._getPrincipalRoles(create=1)
        pp.addCell(role_id, principal_id, Remove)
        self._context._p_changed = 1

    def unsetRoleForPrincipal(self, role_id, principal_id):
        ''' See the interface IPrincipalRoleManager '''
        pp = self._getPrincipalRoles()
        # Only unset if there is a security map, otherwise, we're done
        if pp:
            pp.delCell(role_id, principal_id)
            self._context._p_changed = 1

    def getPrincipalsForRole(self, role_id):
        ''' See the interface IPrincipalRoleManager '''
        pp = self._getPrincipalRoles()
        if pp: 
            return pp.getRow(role_id)
        return []

    def getRolesForPrincipal(self, principal_id):
        ''' See the interface IPrincipalRoleManager '''
        pp = self._getPrincipalRoles()
        if pp: 
            return pp.getCol(principal_id)
        return []

    def getSetting(self, role_id, principal_id):
        ''' See the interface IPrincipalRoleManager '''
        pp = self._getPrincipalRoles()
        if pp: 
            return pp.getCell(role_id, principal_id, default=Unset)
        return Unset

    def getPrincipalsAndRoles(self):
        ''' See the interface IPrincipalRoleManager '''
        pp = self._getPrincipalRoles()
        if pp:
            return pp.getAllCells()
        return []

    # Implementation helpers

    def _getPrincipalRoles(self, create=0):
        """ Get the principal role map stored in the context, optionally
            creating one if necessary """
        annotations = getAdapter(self._context, IAnnotations)
        try:
            return annotations[annotation_key]
        except KeyError:
            if create:
                rp = annotations[annotation_key] = LocalSecurityMap()
                return rp
        return None


=== Added File Zope3/lib/python/Zope/App/Security/AnnotationRolePermissionManager.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.
# 
##############################################################################
"""

$Id: AnnotationRolePermissionManager.py,v 1.1.2.1 2002/05/26 18:20:49 stevea Exp $
"""

from Zope.ComponentArchitecture import getAdapter
from Zope.App.OFS.Annotation.IAnnotations import IAnnotations
from Zope.App.Security.IRolePermissionManager import IRolePermissionManager
from Zope.App.Security.LocalSecurityMap import LocalSecurityMap
from Zope.App.Security.Settings import Allow, Deny, Unset
from Zope.Proxy.ProxyIntrospection import removeAllProxies


annotation_key = 'Zope.App.Security.AnnotationRolePermissionManager'

class  AnnotationRolePermissionManager:
    """
    provide adaptor that manages role permission data in an object attribute
    """

    __implements__ = IRolePermissionManager

    def __init__(self, context):
        self._context = removeAllProxies(context)

    def grantPermissionToRole(self, permission_id, role_id):
        ''' See the interface IRolePermissionManager '''
        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 '''
        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 '''
        rp = self._getRolePermissions()
        # Only unset if there is a security map, otherwise, we're done
        if rp:
            rp.delCell(permission_id, role_id)
            #self._context._p_changed = 1

    def getRolesForPermission(self, permission_id):
        '''See interface IRolePermissionMap'''
        rp = self._getRolePermissions()
        if rp:
            return rp.getRow(permission_id)
        else:
            return []

    def getPermissionsForRole(self, role_id):
        '''See interface IRolePermissionMap'''
        rp = self._getRolePermissions()
        if rp:
            return rp.getCol(role_id)
        else:
            return []

    def getRolesAndPermissions(self):
        '''See interface IRolePermissionMap'''
        rp = self._getRolePermissions()
        if rp:
            return rp.getAllCells(role_id)
        else:
            return []

    def getSetting(self, permission_id, role_id):
        '''See interface IRolePermissionMap'''
        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 """
        annotations = getAdapter(self._context, IAnnotations)
        try:
            return annotations[annotation_key]
        except KeyError:
            if create:
                rp = annotations[annotation_key] = LocalSecurityMap()
                return rp
        return None



=== Zope3/lib/python/Zope/App/Security/security.zcml 1.1.2.7 => 1.1.2.8 ===
          for="Zope.Publisher.VFS.IVFSCredentials." />
 
+<adapter factory="Zope.App.Security.BasicVFSAuthAdapter."
+         provides="Zope.App.Security.ILoginPassword."
+         for="Zope.Publisher.VFS.IVFSCredentials." />
+
+
 <!-- Role-Permission management view -->
   
 <security:protectClass class="Zope.App.Security.RolePermissionView."
@@ -53,9 +58,14 @@
 
 
 <browser:view name="RolePermissionsManagement"
-              for="Zope.App.OFS.Annotation.IAttributeAnnotatable."
+              for="Zope.App.OFS.Annotation.IAnnotatable."
               factory="Zope.App.Security.RolePermissionView." />
 
+<adapter factory=".AnnotationRolePermissionManager."
+         provides=".IRolePermissionManager."
+         for="Zope.App.OFS.Annotation.IAnnotatable." />
+
+
 <!-- Principal-Permission management view -->
   
 <security:protectClass class="Zope.App.Security.PrincipalPermissionView."
@@ -66,15 +76,18 @@
 
 
 <browser:view name="PrincipalPermissionsManagement"
-              for="Zope.App.OFS.Annotation.IAttributeAnnotatable."
+              for="Zope.App.OFS.Annotation.IAnnotatable."
               factory="Zope.App.Security.PrincipalPermissionView." />
 
+<adapter factory=".AnnotationPrincipalPermissionManager."
+         provides=".IPrincipalPermissionManager."
+         for="Zope.App.OFS.Annotation.IAnnotatable." />
+
+
 <!-- protect Roles and Permissions -->
 <security:protectClass class="Zope.App.Security.RoleRegistry.Role"
                        interface="Zope.App.Security.IRegisteredObject."
                        permission_id="Zope.Public"/>
-
-
 
 </zopeConfigure>
 

=== Removed File Zope3/lib/python/Zope/App/Security/AttributePrincipalPermissionManager.py ===

=== Removed File Zope3/lib/python/Zope/App/Security/AttributePrincipalRoleManager.py ===

=== Removed File Zope3/lib/python/Zope/App/Security/AttributeRolePermissionManager.py ===