[Checkins] SVN: z3ext.security/tags/1.3.0/ release tag

Nikolay Kim fafhrd91 at gmail.com
Fri May 29 08:49:56 EDT 2009


Log message for revision 100533:
  release tag

Changed:
  A   z3ext.security/tags/1.3.0/
  D   z3ext.security/tags/1.3.0/CHANGES.txt
  A   z3ext.security/tags/1.3.0/CHANGES.txt
  U   z3ext.security/tags/1.3.0/setup.py
  D   z3ext.security/tags/1.3.0/src/z3ext/security/configure.zcml
  A   z3ext.security/tags/1.3.0/src/z3ext/security/configure.zcml
  D   z3ext.security/tags/1.3.0/src/z3ext/security/interfaces.py
  A   z3ext.security/tags/1.3.0/src/z3ext/security/interfaces.py
  A   z3ext.security/tags/1.3.0/src/z3ext/security/meta.zcml
  D   z3ext.security/tags/1.3.0/src/z3ext/security/tests.py
  A   z3ext.security/tags/1.3.0/src/z3ext/security/tests.py
  D   z3ext.security/tags/1.3.0/src/z3ext/security/utils.py
  A   z3ext.security/tags/1.3.0/src/z3ext/security/utils.py
  A   z3ext.security/tags/1.3.0/src/z3ext/security/vocabulary.py
  A   z3ext.security/tags/1.3.0/src/z3ext/security/zcml.py
  A   z3ext.security/tags/1.3.0/src/z3ext/security/zcml.txt

-=-
Deleted: z3ext.security/tags/1.3.0/CHANGES.txt
===================================================================
--- z3ext.security/trunk/CHANGES.txt	2009-05-29 00:36:13 UTC (rev 100525)
+++ z3ext.security/tags/1.3.0/CHANGES.txt	2009-05-29 12:49:56 UTC (rev 100533)
@@ -1,66 +0,0 @@
-=======
-CHANGES
-=======
-
-1.2.6 (2009-03-25)
-------------------
-
-- Added 'checkPermissionForPrincipal' helper function
-
-
-1.2.5 (2009-03-15)
-------------------
-
-- Check IPrincipalRoleMap adapter last 
-
-
-1.2.4 (2009-03-12)
-------------------
-
-- Fixed permissions/roles calculation in IExtendedGrantInfo
-
-
-1.2.3 (2009-01-19)
-------------------
-
-- Added 'getPrincipalsForPermission' to IExtendedGrantInfo interface
-
-
-1.2.2 (2009-01-09)
-------------------
-
-- Query all IPrincipalPermissionMap adapter for context
-
-
-1.2.1 (2008-09-02)
-------------------
-
-- Fixed bug in extended grant info
-
-
-1.2.0 (2008-03-21)
-------------------
-
-- Code cleanup
-
-- Move code to svn.zope.org
-
-
-1.1.1 (2008-02-16)
-------------------
-
-- Performance (Profiling)
-
-
-1.1.0 (2008-02-01)
-------------------
-
-- Code cleanup
-
-- Removed unused code
-
-
-1.0.0 (2007-12-08)
-------------------
-
-- Initial release.

Copied: z3ext.security/tags/1.3.0/CHANGES.txt (from rev 100532, z3ext.security/trunk/CHANGES.txt)
===================================================================
--- z3ext.security/tags/1.3.0/CHANGES.txt	                        (rev 0)
+++ z3ext.security/tags/1.3.0/CHANGES.txt	2009-05-29 12:49:56 UTC (rev 100533)
@@ -0,0 +1,72 @@
+=======
+CHANGES
+=======
+
+1.3.0 (2009-05-29)
+------------------
+
+- Added 'z3ext:role' and 'z3ext:permission' directives
+
+
+1.2.6 (2009-03-25)
+------------------
+
+- Added 'checkPermissionForPrincipal' helper function
+
+
+1.2.5 (2009-03-15)
+------------------
+
+- Check IPrincipalRoleMap adapter last 
+
+
+1.2.4 (2009-03-12)
+------------------
+
+- Fixed permissions/roles calculation in IExtendedGrantInfo
+
+
+1.2.3 (2009-01-19)
+------------------
+
+- Added 'getPrincipalsForPermission' to IExtendedGrantInfo interface
+
+
+1.2.2 (2009-01-09)
+------------------
+
+- Query all IPrincipalPermissionMap adapter for context
+
+
+1.2.1 (2008-09-02)
+------------------
+
+- Fixed bug in extended grant info
+
+
+1.2.0 (2008-03-21)
+------------------
+
+- Code cleanup
+
+- Move code to svn.zope.org
+
+
+1.1.1 (2008-02-16)
+------------------
+
+- Performance (Profiling)
+
+
+1.1.0 (2008-02-01)
+------------------
+
+- Code cleanup
+
+- Removed unused code
+
+
+1.0.0 (2007-12-08)
+------------------
+
+- Initial release.

Modified: z3ext.security/tags/1.3.0/setup.py
===================================================================
--- z3ext.security/trunk/setup.py	2009-05-29 00:36:13 UTC (rev 100525)
+++ z3ext.security/tags/1.3.0/setup.py	2009-05-29 12:49:56 UTC (rev 100533)
@@ -21,7 +21,7 @@
 def read(*rnames):
     return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
 
-version = '1.2.7dev'
+version = '1.3.0'
 
 
 setup(name='z3ext.security',

Deleted: z3ext.security/tags/1.3.0/src/z3ext/security/configure.zcml
===================================================================
--- z3ext.security/trunk/src/z3ext/security/configure.zcml	2009-05-29 00:36:13 UTC (rev 100525)
+++ z3ext.security/tags/1.3.0/src/z3ext/security/configure.zcml	2009-05-29 12:49:56 UTC (rev 100533)
@@ -1,35 +0,0 @@
-<configure xmlns="http://namespaces.zope.org/zope">
-
-  <!-- IPrincipalGroups adapter -->
-  <adapter
-     for="zope.security.interfaces.IPrincipal"
-     provides=".interfaces.IPrincipalGroups"
-     factory=".groups.PrincipalGroups" />
-
-  <!-- extended grant info -->
-  <adapter factory="z3ext.security.grantinfo.ExtendedGrantInfo" />
-
-  <class class=".grantinfo.ExtendedGrantInfo">
-    <allow interface=".interfaces.IExtendedGrantInfo" />
-  </class>
-
-  <!-- add security declaration for anonymous -->
-  <class class="zope.app.security.principalregistry.UnauthenticatedPrincipal">
-    <require
-       permission="zope.Public"
-       interface="zope.security.interfaces.IPrincipal" />
-  </class>
-
-  <!-- Registering documentation with API doc -->
-  <configure
-     xmlns:apidoc="http://namespaces.zope.org/apidoc"
-     xmlns:zcml="http://namespaces.zope.org/zcml"
-     zcml:condition="have apidoc">
-
-    <apidoc:bookchapter
-       id="z3ext"
-       title="z3ext packages" />
-
-  </configure>
-
-</configure>

Copied: z3ext.security/tags/1.3.0/src/z3ext/security/configure.zcml (from rev 100532, z3ext.security/trunk/src/z3ext/security/configure.zcml)
===================================================================
--- z3ext.security/tags/1.3.0/src/z3ext/security/configure.zcml	                        (rev 0)
+++ z3ext.security/tags/1.3.0/src/z3ext/security/configure.zcml	2009-05-29 12:49:56 UTC (rev 100533)
@@ -0,0 +1,44 @@
+<configure xmlns="http://namespaces.zope.org/zope">
+
+  <!-- IPrincipalGroups adapter -->
+  <adapter
+     for="zope.security.interfaces.IPrincipal"
+     provides=".interfaces.IPrincipalGroups"
+     factory=".groups.PrincipalGroups" />
+
+  <!-- extended grant info -->
+  <adapter factory="z3ext.security.grantinfo.ExtendedGrantInfo" />
+
+  <class class=".grantinfo.ExtendedGrantInfo">
+    <allow interface=".interfaces.IExtendedGrantInfo" />
+  </class>
+
+  <!-- add security declaration for anonymous -->
+  <class class="zope.app.security.principalregistry.UnauthenticatedPrincipal">
+    <require
+       permission="zope.Public"
+       interface="zope.security.interfaces.IPrincipal" />
+  </class>
+
+  <!-- Public Roles/Permissions vocabulary -->
+  <utility
+     name="z3ext.roles"
+     factory=".vocabulary.RolesVocabulary" />
+
+  <utility
+     name="z3ext.permissions"
+     factory=".vocabulary.PermissionsVocabulary" />
+
+  <!-- Registering documentation with API doc -->
+  <configure
+     xmlns:apidoc="http://namespaces.zope.org/apidoc"
+     xmlns:zcml="http://namespaces.zope.org/zcml"
+     zcml:condition="have apidoc">
+
+    <apidoc:bookchapter
+       id="z3ext"
+       title="z3ext packages" />
+
+  </configure>
+
+</configure>

Deleted: z3ext.security/tags/1.3.0/src/z3ext/security/interfaces.py
===================================================================
--- z3ext.security/trunk/src/z3ext/security/interfaces.py	2009-05-29 00:36:13 UTC (rev 100525)
+++ z3ext.security/tags/1.3.0/src/z3ext/security/interfaces.py	2009-05-29 12:49:56 UTC (rev 100533)
@@ -1,47 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2007 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.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.
-#
-##############################################################################
-""" z3ext.security interfaces
-
-$Id$
-"""
-from zope import interface
-
-
-class IZ3extSecurityPolicy(interface.Interface):
-    """ z3ext security policy """
-
-
-class IPrincipalGroups(interface.Interface):
-    """ principal groups """
-
-    principal = interface.Attribute('Principal')
-
-    def getGroups(type=None):
-        """ get principal groups """
-
-
-class IExtendedGrantInfo(interface.Interface):
-    """ similar to IGrantInfo but recursive """
-
-    def getRolesForPermission(permission):
-        """ roles with permission """
-
-    def getRolesForPrincipal(principal):
-        """ principal roles """
-
-    def getPrincipalsForRole(role_id):
-        """ Get the principals that have been granted a role. """
-
-    def getPrincipalsForPermission(permission):
-        """ Get principals for permission """

Copied: z3ext.security/tags/1.3.0/src/z3ext/security/interfaces.py (from rev 100532, z3ext.security/trunk/src/z3ext/security/interfaces.py)
===================================================================
--- z3ext.security/tags/1.3.0/src/z3ext/security/interfaces.py	                        (rev 0)
+++ z3ext.security/tags/1.3.0/src/z3ext/security/interfaces.py	2009-05-29 12:49:56 UTC (rev 100533)
@@ -0,0 +1,67 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.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.
+#
+##############################################################################
+""" z3ext.security interfaces
+
+$Id$
+"""
+from zope import interface
+
+
+class IZ3extSecurityPolicy(interface.Interface):
+    """ z3ext security policy """
+
+
+class IPrincipalGroups(interface.Interface):
+    """ principal groups """
+
+    principal = interface.Attribute('Principal')
+
+    def getGroups(type=None):
+        """ get principal groups """
+
+
+class IExtendedGrantInfo(interface.Interface):
+    """ similar to IGrantInfo but recursive """
+
+    def getRolesForPermission(permission):
+        """ roles with permission """
+
+    def getRolesForPrincipal(principal):
+        """ principal roles """
+
+    def getPrincipalsForRole(role_id):
+        """ Get the principals that have been granted a role. """
+
+    def getPrincipalsForPermission(permission):
+        """ Get principals for permission """
+
+
+class IPublicRole(interface.Interface):
+    """ public role """
+
+
+class IManagerRole(interface.Interface):
+    """ marker interface for manager role """
+
+
+class IPublicPermission(interface.Interface):
+    """ marker interface for allowed permissins """
+
+
+class IPermissionCategory(interface.Interface):
+    """ permissions category """
+
+
+class IPermissionCategoryType(interface.interfaces.IInterface):
+    """Permission category type"""

Copied: z3ext.security/tags/1.3.0/src/z3ext/security/meta.zcml (from rev 100532, z3ext.security/trunk/src/z3ext/security/meta.zcml)
===================================================================
--- z3ext.security/tags/1.3.0/src/z3ext/security/meta.zcml	                        (rev 0)
+++ z3ext.security/tags/1.3.0/src/z3ext/security/meta.zcml	2009-05-29 12:49:56 UTC (rev 100533)
@@ -0,0 +1,25 @@
+<configure
+   xmlns="http://namespaces.zope.org/zope"
+   xmlns:meta="http://namespaces.zope.org/meta">
+
+  <meta:directives namespace="http://namespaces.zope.org/z3ext">
+
+    <meta:directive
+       name="role"
+       schema=".zcml.IPublicRoleDirective"
+       handler=".zcml.publicRoleHandler" />
+
+    <meta:directive
+       name="permission"
+       schema=".zcml.IPublicPermissionDirective"
+       handler=".zcml.publicPermissionHandler" />
+
+    <!-- deprecated -->
+    <meta:directive
+       name="publicrole"
+       schema=".zcml.IPublicRoleDirective"
+       handler=".zcml.publicRoleHandler" />
+
+  </meta:directives>
+
+</configure>

Deleted: z3ext.security/tags/1.3.0/src/z3ext/security/tests.py
===================================================================
--- z3ext.security/trunk/src/z3ext/security/tests.py	2009-05-29 00:36:13 UTC (rev 100525)
+++ z3ext.security/tags/1.3.0/src/z3ext/security/tests.py	2009-05-29 12:49:56 UTC (rev 100533)
@@ -1,43 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2007 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.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.
-#
-##############################################################################
-""" z3ext.security tests
-
-$Id$
-"""
-__docformat__ = "reStructuredText"
-
-import unittest, doctest
-from zope import interface, schema
-from zope.app.testing import setup, ztapi
-from zope.security.management import endInteraction
-from zope.securitypolicy.tests import test_zopepolicy
-from z3ext.security.grantinfo import ExtendedGrantInfo
-from z3ext.security.interfaces import IExtendedGrantInfo
-
-
-def setUp(test):
-    test_zopepolicy.setUp(test)
-    ztapi.provideAdapter(interface.Interface, IExtendedGrantInfo, ExtendedGrantInfo)
-
-def tearDown(test):
-    setup.placelessTearDown()
-
-
-def test_suite():
-    return unittest.TestSuite((
-            doctest.DocFileSuite(
-                'grantinfo.txt',setUp=setUp, tearDown=tearDown),
-            doctest.DocFileSuite(
-                'securitypolicy.txt',setUp=setUp, tearDown=tearDown),
-            ))

Copied: z3ext.security/tags/1.3.0/src/z3ext/security/tests.py (from rev 100532, z3ext.security/trunk/src/z3ext/security/tests.py)
===================================================================
--- z3ext.security/tags/1.3.0/src/z3ext/security/tests.py	                        (rev 0)
+++ z3ext.security/tags/1.3.0/src/z3ext/security/tests.py	2009-05-29 12:49:56 UTC (rev 100533)
@@ -0,0 +1,51 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.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.
+#
+##############################################################################
+""" z3ext.security tests
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+import unittest, doctest
+from zope import interface, schema
+from zope.app.testing import setup, ztapi
+from zope.security.management import endInteraction
+from zope.securitypolicy.tests import test_zopepolicy
+from z3ext.security.grantinfo import ExtendedGrantInfo
+from z3ext.security.interfaces import IExtendedGrantInfo
+
+
+def setUp(test):
+    test_zopepolicy.setUp(test)
+    ztapi.provideAdapter(
+        interface.Interface, IExtendedGrantInfo, ExtendedGrantInfo)
+
+def tearDown(test):
+    setup.placelessTearDown()
+
+
+def test_suite():
+    return unittest.TestSuite((
+            doctest.DocFileSuite(
+                'grantinfo.txt', setUp=setUp, tearDown=tearDown),
+            doctest.DocFileSuite(
+                'securitypolicy.txt',setUp=setUp, tearDown=tearDown),
+            doctest.DocFileSuite(
+                'zcml.txt', setUp=setUp, tearDown=tearDown,
+                optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS),
+            doctest.DocTestSuite(
+                'z3ext.security.vocabulary',
+                setUp=setup.placelessSetUp, tearDown=setup.placelessTearDown, 
+                optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS),
+            ))

Deleted: z3ext.security/tags/1.3.0/src/z3ext/security/utils.py
===================================================================
--- z3ext.security/trunk/src/z3ext/security/utils.py	2009-05-29 00:36:13 UTC (rev 100525)
+++ z3ext.security/tags/1.3.0/src/z3ext/security/utils.py	2009-05-29 12:49:56 UTC (rev 100533)
@@ -1,50 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2007 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.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.
-#
-##############################################################################
-"""
-
-$Id$
-"""
-from zope.component import getUtility
-from zope.security.proxy import removeSecurityProxy
-from zope.security.management import queryInteraction
-from zope.app.security.interfaces import IAuthentication, PrincipalLookupError
-
-from interfaces import IZ3extSecurityPolicy
-
-
-def getPrincipal(id=None):
-    """ get current interaction principal """
-    if id is None:
-        interaction = queryInteraction()
-
-        if interaction is not None:
-            for participation in interaction.participations:
-                if participation.principal is not None:
-                    return participation.principal
-    else:
-        try:
-            return getUtility(IAuthentication).getPrincipal(id)
-        except PrincipalLookupError:
-            return None
-
-
-def checkPermissionForPrincipal(principal, permission, object):
-    interaction = queryInteraction()
-
-    if IZ3extSecurityPolicy.providedBy(interaction):
-        return interaction.cached_decision(
-            removeSecurityProxy(object), principal.id,
-            interaction._groupsFor(principal), permission)
-
-    return False

Copied: z3ext.security/tags/1.3.0/src/z3ext/security/utils.py (from rev 100532, z3ext.security/trunk/src/z3ext/security/utils.py)
===================================================================
--- z3ext.security/tags/1.3.0/src/z3ext/security/utils.py	                        (rev 0)
+++ z3ext.security/tags/1.3.0/src/z3ext/security/utils.py	2009-05-29 12:49:56 UTC (rev 100533)
@@ -0,0 +1,62 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.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.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+from zope.component import getUtility
+from zope.security.proxy import removeSecurityProxy
+from zope.security.management import queryInteraction
+from zope.app.security.interfaces import IAuthentication, PrincipalLookupError
+
+from interfaces import IZ3extSecurityPolicy
+
+
+def getPrincipal(id=None):
+    """ get current interaction principal """
+    if id is None:
+        interaction = queryInteraction()
+
+        if interaction is not None:
+            for participation in interaction.participations:
+                if participation.principal is not None:
+                    return participation.principal
+    else:
+        try:
+            return getUtility(IAuthentication).getPrincipal(id)
+        except PrincipalLookupError:
+            return None
+
+
+def getPrincipals(ids):
+    auth = getUtility(IAuthentication)
+
+    for pid in ids:
+        try:
+            principal = auth.getPrincipal(pid)
+        except PrincipalLookupError:
+            continue
+
+        yield principal
+
+
+def checkPermissionForPrincipal(principal, permission, object):
+    interaction = queryInteraction()
+
+    if IZ3extSecurityPolicy.providedBy(interaction):
+        return interaction.cached_decision(
+            removeSecurityProxy(object), principal.id,
+            interaction._groupsFor(principal), permission)
+
+    return False

Copied: z3ext.security/tags/1.3.0/src/z3ext/security/vocabulary.py (from rev 100532, z3ext.security/trunk/src/z3ext/security/vocabulary.py)
===================================================================
--- z3ext.security/tags/1.3.0/src/z3ext/security/vocabulary.py	                        (rev 0)
+++ z3ext.security/tags/1.3.0/src/z3ext/security/vocabulary.py	2009-05-29 12:49:56 UTC (rev 100533)
@@ -0,0 +1,99 @@
+##############################################################################
+#
+# Copyright (c) 2009 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.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.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+from zope import interface
+from zope.component import getUtilitiesFor
+from zope.schema.interfaces import IVocabularyFactory
+from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
+
+from interfaces import IPublicRole, IPublicPermission
+
+
+class Vocabulary(SimpleVocabulary):
+
+    def getTerm(self, value):
+        try:
+            return self.by_value[value]
+        except KeyError:
+            return self.by_value[self.by_value.keys()[0]]
+
+
+class RolesVocabulary(object):
+    """
+    >>> from zope import interface, component
+    >>> from z3ext.security.vocabulary import RolesVocabulary
+    >>> factory = RolesVocabulary()
+
+    >>> list(factory(None))
+    []
+
+    >>> from z3ext.security.interfaces import IPublicRole
+    >>> class Role(object):
+    ...     interface.implements(IPublicRole)
+    >>> r = Role()
+    >>> r.id = 'portal.Member'
+    >>> r.title = 'Portal member'
+
+    >>> component.provideUtility(r, name='portla.Member')
+
+    >>> for term in factory(None):
+    ...     print term.value, term.title
+    portal.Member Portal member
+    
+    """
+    interface.implements(IVocabularyFactory)
+
+    def __call__(self, context, **kw):
+        roles = []
+        for name, role in getUtilitiesFor(IPublicRole):
+            term = SimpleTerm(role.id, role.id, role.title)
+            term.description = getattr(role, 'description', u'')
+            roles.append((role.title, term))
+        roles.sort()
+        return Vocabulary([term for title, term in roles])
+
+
+class PermissionsVocabulary(object):
+    """
+    >>> from zope import interface, component
+
+    >>> factory = PermissionsVocabulary()
+    >>> list(factory(None))
+    []
+
+    >>> from z3ext.security.interfaces import IPublicPermission
+    >>> class Permission(object):
+    ...     interface.implements(IPublicPermission)
+    >>> r = Permission()
+    >>> r.id = 'permission1'
+    >>> r.title = 'Permission1'
+
+    >>> component.provideUtility(r, name='permission1')
+
+    >>> for term in factory(None):
+    ...     print term.value, term.title
+    permission1 Permission1
+    
+    """
+    interface.implements(IVocabularyFactory)
+
+    def __call__(self, context, **kw):
+        perms = []
+        for name, perm in getUtilitiesFor(IPublicPermission):
+            perms.append((perm.title, SimpleTerm(perm.id, perm.id, perm.title)))
+        perms.sort()
+        return Vocabulary([term for title, term in perms])

Copied: z3ext.security/tags/1.3.0/src/z3ext/security/zcml.py (from rev 100532, z3ext.security/trunk/src/z3ext/security/zcml.py)
===================================================================
--- z3ext.security/tags/1.3.0/src/z3ext/security/zcml.py	                        (rev 0)
+++ z3ext.security/tags/1.3.0/src/z3ext/security/zcml.py	2009-05-29 12:49:56 UTC (rev 100533)
@@ -0,0 +1,93 @@
+##############################################################################
+#
+# Copyright (c) 2009 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.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.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+from zope import schema, interface, component
+from zope.security.zcml import Permission
+from zope.security.interfaces import IPermission
+from zope.securitypolicy.interfaces import IRole
+from zope.configuration.fields import GlobalInterface
+
+from interfaces import IPublicRole, IManagerRole, IPublicPermission
+
+
+class IPublicRoleDirective(interface.Interface):
+
+    role = schema.Id(
+        title=u"Role",
+        description=u"Specifies the Role to be manageable.",
+        required=True)
+
+    manager = schema.Bool(
+        title=u"Manager",
+        description=u"Specifies the manager roles.",
+        default=False,
+        required=False)
+
+
+class IPublicPermissionDirective(interface.Interface):
+
+    permission = Permission(
+        title = u'Permission',
+        required = True)
+
+    category = GlobalInterface(
+        title = u'Category',
+        description = u'Permission category',
+        required = False)
+
+
+def publicRoleHandler(_context, role, manager=False):
+    _context.action(
+	discriminator = ('z3ext:role', role),
+	callable = publicRole,
+	args = (role, manager))
+
+
+def publicRole(roleId, manager):
+    sm = component.getSiteManager()
+
+    role = sm.getUtility(IRole, roleId)
+    
+    if not manager:
+        interface.directlyProvides(role, IPublicRole)
+    else:
+        interface.directlyProvides(role, IPublicRole, IManagerRole)
+
+    sm.registerUtility(role, IPublicRole, roleId)
+
+
+def publicPermissionHandler(_context, permission, category=None):
+    if permission == 'zope.Public':
+        raise TypeError('zope.Public permission is not allowed.')
+
+    _context.action(
+	discriminator = ('z3ext:permission', permission),
+	callable = publicPermission,
+	args = (permission, category))
+
+
+def publicPermission(name, category):
+    sm = component.getSiteManager()
+
+    permission = sm.getUtility(IPermission, name)
+
+    interface.alsoProvides(permission, IPublicPermission)
+
+    if category is not None:
+        interface.alsoProvides(permission, category)
+
+    sm.registerUtility(permission, IPublicPermission, name)

Copied: z3ext.security/tags/1.3.0/src/z3ext/security/zcml.txt (from rev 100532, z3ext.security/trunk/src/z3ext/security/zcml.txt)
===================================================================
--- z3ext.security/tags/1.3.0/src/z3ext/security/zcml.txt	                        (rev 0)
+++ z3ext.security/tags/1.3.0/src/z3ext/security/zcml.txt	2009-05-29 12:49:56 UTC (rev 100533)
@@ -0,0 +1,87 @@
+====================
+z3ext:role directive
+====================
+
+PublicRole - это роль которая доступна для UI
+
+   >>> from zope import component
+
+   >>> sm = component.getSiteManager()
+
+Let's create role
+
+   >>> from zope.securitypolicy.role import Role
+   >>> from zope.securitypolicy.interfaces import IRole
+
+   >>> role = Role('zope.Member', 'Member')
+   >>> sm.registerUtility(role, name='zope.Member')
+
+   >>> manager = Role('zope.Manager', 'Manager')
+   >>> sm.registerUtility(manager, name='zope.Manager')
+
+Now load zcml directive and set portal.Member as public role
+
+   >>> from zope.configuration import xmlconfig
+   >>> context = xmlconfig.string("""
+   ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+   ...    <include package="z3ext.security" file="meta.zcml" />
+   ... 
+   ...    <z3ext:role role="zope.Member" />
+   ...    <z3ext:role role="zope.Manager" manager="true" />
+   ... </configure>""")
+
+   >>> from z3ext.security.interfaces import IPublicRole, IManagerRole
+
+   >>> prole = sm.getUtility(IPublicRole, name='zope.Member')
+   >>> prole.id == 'zope.Member'
+   True
+   >>> IPublicRole.providedBy(prole)
+   True
+   >>> role is prole
+   True
+
+   >>> prole = sm.getUtility(IPublicRole, name='zope.Manager')
+   >>> IManagerRole.providedBy(prole)
+   True
+   >>> manager is prole
+   True
+
+
+==========================
+z3ext:permission directive
+==========================
+
+Let's create permission
+
+   >>> from zope.security.permission import Permission
+   >>> from zope.security.interfaces import IPermission
+
+   >>> permission = Permission('portal.Permission', 'Permission')
+   >>> sm.registerUtility(permission, name='portal.Permission')
+
+Now load zcml directive and set portal.Member as public pemrission
+
+   >>> context = xmlconfig.string("""
+   ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+   ...    <z3ext:permission permission="zope.Public" />
+   ... </configure>""", context)
+   Traceback (most recent call last):
+   ...
+   ZopeXMLConfigurationError:...
+
+   >>> context = xmlconfig.string("""
+   ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+   ...    <z3ext:permission
+   ...         permission="portal.Permission"
+   ...         category="z3ext.security.interfaces.IPermissionCategory" />
+   ... </configure>""", context)
+
+   >>> from z3ext.security.interfaces import IPublicPermission
+
+   >>> p = sm.getUtility(IPublicPermission, name='portal.Permission')
+   >>> p.id == 'portal.Permission'
+   True
+   >>> IPublicPermission.providedBy(p)
+   True
+   >>> permission is p
+   True



More information about the Checkins mailing list