[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security - IRolePermissionManager.py:1.1.2.1 IRolePermissionMap.py:1.1.2.1 RolePermissionManager.py:1.1.2.1 RolePermissionMap.py:NONE

Barry Warsaw barry@wooz.org
Thu, 13 Dec 2001 15:28:00 -0500


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

Added Files:
      Tag: Zope-3x-branch
	IRolePermissionManager.py IRolePermissionMap.py 
	RolePermissionManager.py 
Removed Files:
      Tag: Zope-3x-branch
	RolePermissionMap.py 
Log Message:
The wiki actually described two interfaces, a query interface and a
management interface for role/permission maps.  The IRolePermissionMap
is the query-only interface while IRolePermissionManager (and
implementation: RolePermissionManager) is the write/management
interface.

We can remove RolePermissionMap.py because we don't actually implement
the query-only interface separate from the management interface.


=== Added File Zope3/lib/python/Zope/App/Security/IRolePermissionManager.py ===
# RolePermissionMap.py
#
# Copyright (c) 2001 Zope Coporation and Contributors.  All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 1.1 (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.

"""Management interface for mappings between roles and permissions."""

from Zope.App.Security.IRolePermissionMap import IRolePermissionMap


class IRolePermissionManager(IRolePermissionMap):
    """Management interface for mappings between roles and permissions."""

    def grantPermissionToRole(permission, role):
        """Bind the permission to the role.

        permission must be an IPermission
        role must be an IRole
        """

    def setPermissionAcquired(permission, flag):
        """Set a flag indicating whether permission settings are acquired.

        Permission settings are acquired by default.
        """


=== Added File Zope3/lib/python/Zope/App/Security/IRolePermissionMap.py ===
# RolePermissionMap.py
#
# Copyright (c) 2001 Zope Coporation and Contributors.  All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 1.1 (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.

"""Query interface for mappings between roles and permissions."""


from Interface import Interface


class IRolePermissionMap(Interface):
    """Mappings between roles and permissions."""

    def getPermissionsForRole(role):
        """Return the list of permissions for the given role.

        role must be an IRole.  If no permissions have been granted to this
        role, then the empty list is returned.
        """

    def getPermissionAcquired(permission):
        """Return a flag indicating whether permission settings are acquired.
        """


=== Added File Zope3/lib/python/Zope/App/Security/RolePermissionManager.py ===
# RolePermissionManager.py
#
# Copyright (c) 2001 Zope Coporation and Contributors.  All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 1.1 (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.SecurityMap import SecurityMap
from Zope.App.Security.IRolePermissionManager import IRolePermissionManager


class RolePermissionManager(SecurityMap):
    """Mappings between roles and permissions."""

    __implements__ = IRolePermissionManager

    """Bind the permission to the role.

    permission must be an IPermission
    role must be an IRole
    """
    grantPermissionToRole = SecurityMap.addCell

    """Return the list of roles for the given permission.

    permission must be an IPermission.  If no roles have been granted this
    permission, then the empty list is returned.
    """
    getRolesForPermission = SecurityMap.getColumnsForRow

    """Return the list of permissions for the given role.

    role must be an IRole.  If no permissions have been granted to this
    role, then the empty list is returned.
    """
    getPermissionsForRole = SecurityMap.getRowsForColumn

    def setPermissionAcquired(self, permission, flag):
        """Set a flag indicating whether permission settings are acquired.

        Permission settings are acquired by default.
        """
        self._nonacquiredperms[permission] = flag

    def getPermissionAcquired(self, permission):
        """Return a flag indicating whether permission settings are acquired.
        """
        return self._nonacquiredperms.get(permission, 1)

    # Override _clear() so we can add the extra little acquired permission
    # mapping.
    def _clear(self):
        SecurityMap._clear(self)
        self._nonacquiredperms = {}

# Permissions are our rows, and roles are our columns
manager = RolePermissionManager()

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