[Zope3-checkins] CVS: Zope3/src/zope/products/securitypolicy - addrole.pt:1.1.2.1 browser.py:1.1.2.1 browser.zcml:1.1.2.1 role.gif:1.1.2.1 role.py:1.1.2.1 role_service.gif:1.1.2.1 roleregistry.py:1.1.2.1 configure.zcml:1.1.2.2 meta.zcml:1.1.2.2 metaconfigure.py:1.1.2.2 metadirectives.py:1.1.2.2

Chris McDonough chrism at plope.com
Tue Jan 13 20:32:08 EST 2004


Update of /cvs-repository/Zope3/src/zope/products/securitypolicy
In directory cvs.zope.org:/tmp/cvs-serv14028/src/zope/products/securitypolicy

Modified Files:
      Tag: steveachrismcd-securitypolicy-branch
	configure.zcml meta.zcml metaconfigure.py metadirectives.py 
Added Files:
      Tag: steveachrismcd-securitypolicy-branch
	addrole.pt browser.py browser.zcml role.gif role.py 
	role_service.gif roleregistry.py 
Log Message:
Move more role stuff out of Zope proper and into the securitypolicy product.


=== Added File Zope3/src/zope/products/securitypolicy/addrole.pt ===
<html metal:use-macro="views/standard_macros/page">
<head>
  <title metal:fill-slot="title" i18n:translate="add-role-form-title">
    Add Role
  </title>
</head>
<body>
<div metal:fill-slot="body">

  <div i18n:translate="">Enter the information about the role.</div>

  <form action="action.html" method="post">

    <div class="row">
      <div class="label" i18n:translate="">Id</div>
      <div class="field">
        <input type="text" name="id" size="40" value="" />
      </div>
    </div>

    <div class="row">
      <div class="label" i18n:translate="">Title</div>
      <div class="field">
        <input type="text" name="title" size="40" value="" />
      </div>
    </div>

    <div class="row">
      <div class="label" i18n:translate="">Description</div>
      <div class="field">
        <textarea name="description" rows="10" cols="60"></textarea>
      </div>
    </div>

    <div class="row">
      <div class="controls">
        <input type="submit" name="submit" value="Create Role"
               i18n:attributes="value create-role-button" />
      </div>
    </div>

  </form>

</div>
</body>
</html>


=== Added File Zope3/src/zope/products/securitypolicy/browser.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.
#
##############################################################################
""" Define view component for service manager contents.

$Id: browser.py,v 1.1.2.1 2004/01/14 01:31:37 chrism Exp $
"""
from zope.app.browser.container.contents import Contents
from zope.products.securitypolicy.role import Role, ILocalRoleService

class Add:
    "Provide a user interface for adding a role"
    __used_for__ = ILocalRoleService

    def action(self, id, title, description):
        "Add a contact"
        role = Role(id, title, description)
        self.context[id] = role
        self.request.response.redirect('.')


class Contents(Contents):
    # XXX: What the heck is that? I guess another dead chicken.
    pass


=== Added File Zope3/src/zope/products/securitypolicy/browser.zcml ===
<zope:configure 
   xmlns:zope="http://namespaces.zope.org/zope"
   xmlns="http://namespaces.zope.org/browser">

<!-- Role Service -->

  <menuItem
     menu="add_service"
     for="zope.app.interfaces.container.IAdding"
     action="RoleService"
     title="Role Service" />

  <icon
      name="zmi_icon" 
      for=".role.ILocalRoleService"
      file="role_service.gif" />

  <pages 
     permission="zope.ManageServices" 
     for=".role.IRoleService"
     class=".browser.Contents">

     <page name="index.html" attribute="contents"
           menu="zmi_views" title="Contents" />
     <page name="removeObjects.html" attribute="removeObjects" />

  </pages>

  <pages 
     permission="zope.ManageServices" 
     for=".role.IRoleService"
     class=".browser.Add">

    <page name="+" template="addrole.pt" 
          menu="zmi_actions" title="Add" />
    <page name="action.html" attribute="action" />

  </pages>

</zope:configure>


=== Added File Zope3/src/zope/products/securitypolicy/role.gif ===
  <Binary-ish file>

=== Added File Zope3/src/zope/products/securitypolicy/role.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.
#
##############################################################################
"""

Revision information:
$Id: role.py,v 1.1.2.1 2004/01/14 01:31:37 chrism Exp $
"""

from persistence import Persistent
from zope.products.securitypolicy.roleregistry import Role
from zope.app.container.btree import BTreeContainer
from zope.app.interfaces.security import IRoleService
from zope.app.interfaces.container import IContainer
from zope.app.component.nextservice import getNextService
from zope.app.interfaces.services.service import ISimpleService
from zope.interface import implements

class Role(Role, Persistent):
    "Persistent Role"

class ILocalRoleService(IRoleService, IContainer):
    """TTW manageable role service"""

class RoleService(BTreeContainer):

    implements(ILocalRoleService, ISimpleService)

    def getRole(wrapped_self, rid):
        '''See interface IRoleService'''
        try:
            return wrapped_self[rid]
        except KeyError:
            # We failed locally: delegate to a higher-level service.
            sv = getNextService(wrapped_self, 'Roles')
            if sv:
                return sv.getRole(rid)
            raise # will be original Key Error

    def getRoles(wrapped_self):
        '''See interface IRoleService'''
        roles = list(wrapped_self.values())
        roleserv = getNextService(wrapped_self, 'Roles')
        if roleserv:
            roles.extend(roleserv.getRoles())
        return roles


=== Added File Zope3/src/zope/products/securitypolicy/role_service.gif ===
  <Binary-ish file>

=== Added File Zope3/src/zope/products/securitypolicy/roleregistry.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.
#
##############################################################################
"""Global role registry."""

PREFIX = 'Global Role'

from zope.app.security.registries.registeredobject import RegisteredObject
from zope.app.security.registries.registry import Registry
from zope.app.interfaces.security import IRole
from zope.app.interfaces.security import IRoleService
from zope.app.interfaces.services.service import ISimpleService
from zope.interface import implements

class Role(RegisteredObject):
    implements(IRole)


class RoleRegistry(Registry):
    implements(IRoleService, ISimpleService)

    def __init__(self, prefix=PREFIX):
        Registry.__init__(self, Role)
        self._prefix = prefix

    def _make_global_id(self, suffix):
        return self._prefix + '.' + suffix

    def defineRole(self, role, title, description=None):
        """Define a new role object, register, and return it.

        role is the role name.

        title is the role title, human readable.

        description (optional) is human readable
        """
        if description is None:
            description = ''
        id = role
        return self.register(id, title, description)

    def definedRole(self, id):
        """Return true if named role is registered, otherwise return false
        """
        return self.is_registered(id)

    def getRole(self, id):
        """Return role object registered as name.

        If no named role is registered KeyError is raised.
        """
        return self.getRegisteredObject(id)

    def getRoles(self):
        """Return all registered role objects.
        """
        return self.getRegisteredObjects()

    def _clear(self):
        # Standard roles
        Registry._clear(self)
        self.register("zope.Anonymous", "Everybody",
                      "All users have this role implicitly")

roleRegistry = RoleRegistry()


# Register our cleanup with Testing.CleanUp to make writing unit tests simpler.
from zope.testing.cleanup import addCleanUp
addCleanUp(roleRegistry._clear)
del addCleanUp


=== Zope3/src/zope/products/securitypolicy/configure.zcml 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/products/securitypolicy/configure.zcml:1.1.2.1	Tue Jan 13 18:34:20 2004
+++ Zope3/src/zope/products/securitypolicy/configure.zcml	Tue Jan 13 20:31:37 2004
@@ -29,5 +29,45 @@
       provides="zope.app.interfaces.security.IPrincipalPermissionManager"
       for="zope.app.interfaces.annotation.IAnnotatable" />
 
+  <serviceType
+      id="Roles" 
+      interface="zope.app.interfaces.security.IRoleService" />
+
+  <service
+      serviceType="Roles" 
+      component=".roleregistry.roleRegistry" />
+
+  <!-- protect Roles and Permissions -->
+  <content class=".roleregistry.Role">
+    <allow interface="zope.app.interfaces.security.IRegisteredObject" />
+  </content>
+
+<!-- XXX (this came out of services/configure.zcml) Role Templates -->
+
+<content class=".role.RoleService">
+  <factory
+      id="RoleService"
+      permission="zope.ManageServices"
+      />
+  <require
+      permission="zope.Security"
+      interface="zope.app.interfaces.security.IRoleService"
+      />
+  <require
+      permission="zope.ManageServices"
+      interface="zope.app.interfaces.container.IContainer"
+      />
+</content>
+
+<content class=".role.Role">
+  <factory />
+  <require
+      permission="zope.Security"
+      interface="zope.app.interfaces.security.IRole"
+      />
+</content>
+
+
+
 </configure>
 


=== Zope3/src/zope/products/securitypolicy/meta.zcml 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/products/securitypolicy/meta.zcml:1.1.2.1	Tue Jan 13 18:34:20 2004
+++ Zope3/src/zope/products/securitypolicy/meta.zcml	Tue Jan 13 20:31:37 2004
@@ -8,4 +8,10 @@
       schema=".metadirectives.IGrantDirective"
       handler=".metaconfigure.grant" />
 
+  <meta:directive 
+      namespace="http://namespaces.zope.org/zope"
+      name="role"
+      schema=".metadirectives.IDefineRoleDirective"
+      handler=".metaconfigure.defineRole" />
+
 </configure>


=== Zope3/src/zope/products/securitypolicy/metaconfigure.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/products/securitypolicy/metaconfigure.py:1.1.2.1	Tue Jan 13 18:34:20 2004
+++ Zope3/src/zope/products/securitypolicy/metaconfigure.py	Tue Jan 13 20:31:37 2004
@@ -22,6 +22,7 @@
 from zope.products.securitypolicy.principalrole \
      import principalRoleManager as principal_role_mgr
 from zope.configuration.exceptions import ConfigurationError
+from zope.products.securitypolicy.roleregistry import roleRegistry as role_reg
 
 
 def grant(_context, principal=None, role=None, permission=None):
@@ -52,3 +53,10 @@
             discriminator = ('grantPermissionToRole', permission, role),
             callable = role_perm_mgr.grantPermissionToRole,
             args = (permission, role) )
+
+def defineRole(_context, id, title, description=''):
+    _context.action(
+            discriminator = ('defineRole', id),
+            callable = role_reg.defineRole,
+            args = (id, title, description) )
+


=== Zope3/src/zope/products/securitypolicy/metadirectives.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/products/securitypolicy/metadirectives.py:1.1.2.1	Tue Jan 13 18:34:20 2004
+++ Zope3/src/zope/products/securitypolicy/metadirectives.py	Tue Jan 13 20:31:37 2004
@@ -17,6 +17,7 @@
 """
 from zope.interface import Interface
 from zope.schema import Id 
+from zope.app.security.registries.metadirectives import IBaseDefineDirective
 
 class IGrantDirective(Interface):
     """Grant Permissions to roles and principals and roles to principals."""
@@ -35,3 +36,7 @@
         title=u"Role",
         description=u"Specifies the Role to be mapped.",
         required=False)
+
+class IDefineRoleDirective(IBaseDefineDirective):
+    """Define a new role."""
+




More information about the Zope3-Checkins mailing list