[Zope3-checkins] SVN: Zope3/branches/jim-adapter/src/zope/ Move Permission field to zope.security.zcml.

Philipp von Weitershausen philikon at philikon.de
Wed Apr 12 19:06:04 EDT 2006


Log message for revision 66920:
  Move Permission field to zope.security.zcml.
  

Changed:
  U   Zope3/branches/jim-adapter/src/zope/app/component/metadirectives.py
  U   Zope3/branches/jim-adapter/src/zope/app/container/browser/metaconfigure.py
  U   Zope3/branches/jim-adapter/src/zope/app/form/browser/metadirectives.py
  U   Zope3/branches/jim-adapter/src/zope/app/mail/metadirectives.py
  U   Zope3/branches/jim-adapter/src/zope/app/publisher/browser/metadirectives.py
  U   Zope3/branches/jim-adapter/src/zope/app/publisher/xmlrpc/metadirectives.py
  D   Zope3/branches/jim-adapter/src/zope/app/security/fields.py
  U   Zope3/branches/jim-adapter/src/zope/app/security/metadirectives.py
  U   Zope3/branches/jim-adapter/src/zope/app/security/tests/test_directives.py
  D   Zope3/branches/jim-adapter/src/zope/app/security/tests/test_fields.py
  U   Zope3/branches/jim-adapter/src/zope/app/securitypolicy/metadirectives.py
  U   Zope3/branches/jim-adapter/src/zope/component/zcml.py
  A   Zope3/branches/jim-adapter/src/zope/security/zcml.py

-=-
Modified: Zope3/branches/jim-adapter/src/zope/app/component/metadirectives.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/component/metadirectives.py	2006-04-12 22:24:15 UTC (rev 66919)
+++ Zope3/branches/jim-adapter/src/zope/app/component/metadirectives.py	2006-04-12 23:06:03 UTC (rev 66920)
@@ -18,13 +18,12 @@
 __docformat__ = 'restructuredtext'
 
 import zope.configuration.fields
+import zope.security.zcml
 import zope.interface
 import zope.schema
 from zope.component.zcml import IBasicComponentInformation
 
-import zope.app.security.fields
 import zope.app.component.fields
-
 from zope.app.i18n import ZopeMessageFactory as _
 
 class IDefaultViewName(zope.interface.Interface):
@@ -47,7 +46,7 @@
           ),
         )
 
-    permission = zope.app.security.fields.Permission(
+    permission = zope.security.zcml.Permission(
         title=_("Permission"),
         description=_("The permission needed to use the view."),
         required=False,
@@ -232,7 +231,7 @@
     given Interface require a given permission for access.
     """
 
-    permission = zope.app.security.fields.Permission(
+    permission = zope.security.zcml.Permission(
         title=_("Permission"),
         description=_("""
         Specifies the permission by id that will be required to

Modified: Zope3/branches/jim-adapter/src/zope/app/container/browser/metaconfigure.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/container/browser/metaconfigure.py	2006-04-12 22:24:15 UTC (rev 66919)
+++ Zope3/branches/jim-adapter/src/zope/app/container/browser/metaconfigure.py	2006-04-12 23:06:03 UTC (rev 66920)
@@ -18,16 +18,16 @@
 
 __docformat__ = 'restructuredtext'
 
-from zope.app.component.fields import LayerField
 from zope.interface import Interface
 from zope.configuration.fields import GlobalObject
 from zope.publisher.interfaces.browser import IDefaultBrowserLayer
 from zope.schema import Id
+from zope.security.zcml import Permission
 from zope.app.publisher.browser.viewmeta import page, view
 from zope.app.container.browser.contents import Contents
 from zope.app.container.browser.adding import Adding
+from zope.app.component.fields import LayerField
 from zope.app.i18n import ZopeMessageFactory as _
-from zope.app.security.fields import Permission
 
 
 class IContainerViews(Interface):

Modified: Zope3/branches/jim-adapter/src/zope/app/form/browser/metadirectives.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/form/browser/metadirectives.py	2006-04-12 22:24:15 UTC (rev 66919)
+++ Zope3/branches/jim-adapter/src/zope/app/form/browser/metadirectives.py	2006-04-12 23:06:03 UTC (rev 66920)
@@ -22,8 +22,8 @@
 from zope.configuration.fields import Tokens, Path, Bool, PythonIdentifier
 from zope.configuration.fields import MessageID
 from zope.schema import Text, TextLine, Id
+from zope.security.zcml import Permission
 from zope.app.component.fields import LayerField
-from zope.app.security.fields import Permission
 from zope.app.publisher.browser.fields import MenuField
 
 class ICommonInformation(Interface):

Modified: Zope3/branches/jim-adapter/src/zope/app/mail/metadirectives.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/mail/metadirectives.py	2006-04-12 22:24:15 UTC (rev 66919)
+++ Zope3/branches/jim-adapter/src/zope/app/mail/metadirectives.py	2006-04-12 23:06:03 UTC (rev 66920)
@@ -20,7 +20,7 @@
 from zope.configuration.fields import Path
 from zope.interface import Interface
 from zope.schema import TextLine, ASCII, BytesLine, Int
-from zope.app.security.fields import Permission
+from zope.security.zcml import Permission
 
 class IDeliveryDirective(Interface):
     """This abstract directive describes a generic mail delivery utility

Modified: Zope3/branches/jim-adapter/src/zope/app/publisher/browser/metadirectives.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/publisher/browser/metadirectives.py	2006-04-12 22:24:15 UTC (rev 66919)
+++ Zope3/branches/jim-adapter/src/zope/app/publisher/browser/metadirectives.py	2006-04-12 23:06:03 UTC (rev 66920)
@@ -21,11 +21,11 @@
 from zope.configuration.fields import GlobalObject, GlobalInterface
 from zope.configuration.fields import Tokens, Path, PythonIdentifier, MessageID
 from zope.schema import TextLine, Text, Id, Int, Bool
+from zope.security.zcml import Permission
 
 from zope.app.component.metadirectives import IBasicViewInformation
 from zope.app.component.fields import LayerField
 from zope.app.publisher.browser.fields import MenuField
-from zope.app.security.fields import Permission
 
 #
 # browser views

Modified: Zope3/branches/jim-adapter/src/zope/app/publisher/xmlrpc/metadirectives.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/publisher/xmlrpc/metadirectives.py	2006-04-12 22:24:15 UTC (rev 66919)
+++ Zope3/branches/jim-adapter/src/zope/app/publisher/xmlrpc/metadirectives.py	2006-04-12 23:06:03 UTC (rev 66920)
@@ -18,9 +18,8 @@
 import zope.configuration.fields
 import zope.interface
 import zope.schema
+import zope.security.zcml
 
-import zope.app.security.fields
-
 class IViewDirective(zope.interface.Interface):
     """View Directive for XML-RPC methods."""
 
@@ -51,7 +50,7 @@
         required=False
         )
 
-    permission = zope.app.security.fields.Permission(
+    permission = zope.security.zcml.Permission(
         title=u"Permission",
         description=u"""The permission needed to use the view.
 

Deleted: Zope3/branches/jim-adapter/src/zope/app/security/fields.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/security/fields.py	2006-04-12 22:24:15 UTC (rev 66919)
+++ Zope3/branches/jim-adapter/src/zope/app/security/fields.py	2006-04-12 23:06:03 UTC (rev 66920)
@@ -1,82 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004 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.
-#
-##############################################################################
-"""Security related configuration fields.
-
-$Id$
-"""
-__docformat__ = 'restructuredtext'
-from zope import schema
-from zope.interface import implements
-from zope.schema.interfaces import IFromUnicode
-from zope.security.permission import checkPermission
-
-class Permission(schema.Id):
-    r"""This field describes a permission.
-
-    Let's look at an example:
-
-    >>> class FauxContext(object):
-    ...     permission_mapping = {'zope.ManageCode':'zope.private'}
-    ...     _actions = []
-    ...     def action(self, **kws):
-    ...        self._actions.append(kws)
-    >>> context = FauxContext()
-    >>> field = Permission().bind(context)
-
-    Let's test the fromUnicode method:
-
-    >>> field.fromUnicode(u'zope.foo')
-    'zope.foo'
-    >>> field.fromUnicode(u'zope.ManageCode')
-    'zope.private'
-
-    Now let's see whether validation works alright
-
-    >>> field._validate('zope.ManageCode')
-    >>> context._actions[0]['args']
-    (None, 'zope.foo')
-    >>> field._validate('3 foo')
-    Traceback (most recent call last):
-    ...
-    InvalidId: 3 foo
-
-    zope.Public is always valid
-    >>> field._validate('zope.Public')
-    """
-    implements(IFromUnicode)
-
-    def fromUnicode(self, u):
-        u = super(Permission, self).fromUnicode(u)
-
-        map = getattr(self.context, 'permission_mapping', {})
-        return map.get(u, u)
-
-    def _validate(self, value):
-        super(Permission, self)._validate(value)
-
-        if value != 'zope.Public':
-            self.context.action(
-                discriminator = None,
-                callable = checkPermission,
-                args = (None, value),
-
-                # Delay execution till end. This is an
-                # optimization. We don't want to intersperse utility
-                # lookup, done when checking permissions, with utility
-                # definitions. Utility lookup is expensive after
-                # utility definition, as extensive caches have to be
-                # rebuilt.                
-                order=9999999, 
-                )
-        

Modified: Zope3/branches/jim-adapter/src/zope/app/security/metadirectives.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/security/metadirectives.py	2006-04-12 22:24:15 UTC (rev 66919)
+++ Zope3/branches/jim-adapter/src/zope/app/security/metadirectives.py	2006-04-12 23:06:03 UTC (rev 66920)
@@ -19,7 +19,7 @@
 from zope.configuration.fields import GlobalObject, GlobalInterface
 from zope.configuration.fields import Tokens, PythonIdentifier, MessageID
 from zope.schema import InterfaceField, Id, TextLine
-from fields import Permission
+from zope.security.zcml import Permission
 
 
 class ISecurityPolicyDirective(Interface):

Modified: Zope3/branches/jim-adapter/src/zope/app/security/tests/test_directives.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/security/tests/test_directives.py	2006-04-12 22:24:15 UTC (rev 66919)
+++ Zope3/branches/jim-adapter/src/zope/app/security/tests/test_directives.py	2006-04-12 23:06:03 UTC (rev 66920)
@@ -17,18 +17,18 @@
 """
 import unittest
 from pprint import PrettyPrinter
+
+import zope.security.zcml
 from zope.interface import Interface, Attribute
 from zope.testing import doctest
+from zope.component import provideUtility
+from zope.component.testing import setUp, tearDown, PlacelessSetup
 from zope.configuration import xmlconfig
 from zope.security.checker import moduleChecker
 from zope.security.permission import Permission
+from zope.security.interfaces import IPermission
 
-import zope.app.security
-from zope.app.testing import ztapi
-from zope.app.testing.placelesssetup import setUp, tearDown, PlacelessSetup
 from zope.app.security import metaconfigure
-from zope.app.security.interfaces import IPermission
-from zope.app.security import fields
 
 def pprint(ob, width=70):
     PrettyPrinter(width=width).pprint(ob)
@@ -53,7 +53,7 @@
     >>> moduleChecker(test_directives)
         
     >>> perm = Permission(test_perm, '')
-    >>> ztapi.provideUtility(IPermission, perm, test_perm)
+    >>> provideUtility(perm, IPermission, test_perm)
     >>> metaconfigure.protectModule(test_directives, 'foo', test_perm)
 
     Now, the checker should exist and have an access dictionary with the
@@ -193,7 +193,7 @@
 
 class IDummy(Interface):
 
-    perm = fields.Permission(title=u'')
+    perm = zope.security.zcml.Permission(title=u'')
 
 perms = []
 
@@ -217,22 +217,28 @@
     def testRedefinePermission(self):
         self.assertEqual(perms, ['zope.Security'])
 
+def setUpAuth(test=None):
+    setUp(test)
+    from zope.app.authentication.placelesssetup import PlacelessSetup
+    PlacelessSetup().setUp()
+
 def zcml(s):
     context = xmlconfig.file('meta.zcml', package=zope.app.security)
     xmlconfig.string(s, context)
 
 def reset():
     tearDown()
-    setUp()
+    setUpAuth()
 
 def test_suite():
     return unittest.TestSuite((
         doctest.DocTestSuite(setUp=setUp, tearDown=tearDown),
+        doctest.DocTestSuite('zope.security.zcml'),
         unittest.makeSuite(DirectivesTest),
         doctest.DocFileSuite(
             '../globalprincipals.txt',
             globs={'zcml': zcml, 'reset': reset},
-            setUp=setUp, tearDown=tearDown,
+            setUp=setUpAuth, tearDown=tearDown,
             )
         ))
 

Deleted: Zope3/branches/jim-adapter/src/zope/app/security/tests/test_fields.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/security/tests/test_fields.py	2006-04-12 22:24:15 UTC (rev 66919)
+++ Zope3/branches/jim-adapter/src/zope/app/security/tests/test_fields.py	2006-04-12 23:06:03 UTC (rev 66920)
@@ -1,27 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2003 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.
-#
-##############################################################################
-"""Configuration field doc tests.
-
-$Id$
-"""
-import unittest
-from zope.testing.doctestunit import DocTestSuite
-
-def test_suite():
-    return unittest.TestSuite((
-        DocTestSuite('zope.app.security.fields'),
-        ))
-
-if __name__ == '__main__':
-    unittest.main(defaultTest='test_suite')

Modified: Zope3/branches/jim-adapter/src/zope/app/securitypolicy/metadirectives.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/securitypolicy/metadirectives.py	2006-04-12 22:24:15 UTC (rev 66919)
+++ Zope3/branches/jim-adapter/src/zope/app/securitypolicy/metadirectives.py	2006-04-12 23:06:03 UTC (rev 66920)
@@ -17,8 +17,8 @@
 """
 from zope.interface import Interface
 from zope.schema import Id 
+from zope.security.zcml import Permission
 from zope.app.security.metadirectives import IBaseDefineDirective
-from zope.app.security.fields import Permission
 
 class IGrantAllDirective(Interface):
     """Grant Permissions to roles and principals and roles to principals."""

Modified: Zope3/branches/jim-adapter/src/zope/component/zcml.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/component/zcml.py	2006-04-12 22:24:15 UTC (rev 66919)
+++ Zope3/branches/jim-adapter/src/zope/component/zcml.py	2006-04-12 23:06:03 UTC (rev 66920)
@@ -20,6 +20,7 @@
 import zope.component
 import zope.interface
 import zope.configuration.fields
+import zope.security.zcml
 from zope.component.interface import provideInterface
 from zope.proxy import ProxyBase, getProxiedObject
 from zope.security.proxy import Proxy
@@ -30,8 +31,6 @@
 from zope.i18nmessageid import MessageFactory
 _ = MessageFactory('zope')
 
-import zope.app.security.fields
-
 PublicPermission = 'zope.Public'
 
 def handler(methodName, *args, **kwargs):
@@ -49,7 +48,7 @@
         required=False,
         )
 
-    permission = zope.app.security.fields.Permission(
+    permission = zope.security.zcml.Permission(
         title=_("Permission"),
         description=_("Permission required to use this component."),
         required=False,
@@ -94,7 +93,7 @@
           ),
         )
 
-    permission = zope.app.security.fields.Permission(
+    permission = zope.security.zcml.Permission(
         title=_("Permission"),
         description=_("This adapter is only available, if the principal"
                       " has this permission."),
@@ -261,7 +260,7 @@
           ),
         )
 
-    permission = zope.app.security.fields.Permission(
+    permission = zope.security.zcml.Permission(
         title=_("Permission"),
         description=_("This subscriber is only available, if the"
                       " principal has this permission."),

Copied: Zope3/branches/jim-adapter/src/zope/security/zcml.py (from rev 66918, Zope3/branches/jim-adapter/src/zope/app/security/fields.py)



More information about the Zope3-Checkins mailing list