[Checkins] SVN: zope.

Dan Korostelev nadako at gmail.com
Wed Mar 11 12:08:01 EDT 2009


Log message for revision 97844:
  

Changed:
  U   zope.app.security/trunk/README.txt
  U   zope.app.security/trunk/src/zope/__init__.py
  A   zope.app.security/trunk/src/zope/localpermission/
  U   zope.app.security/trunk/src/zope/localpermission/__init__.py
  A   zope.app.security/trunk/src/zope/localpermission/configure.zcml
  A   zope.app.security/trunk/src/zope/localpermission/permission.py
  D   zope.app.security/trunk/src/zope/localpermission/security/
  A   zope.app.security/trunk/src/zope/localpermission/tests.py
  _U  zope.localpermission/trunk/

-=-
Modified: zope.app.security/trunk/README.txt
===================================================================
--- zope.app.security/trunk/README.txt	2009-03-11 16:07:11 UTC (rev 97843)
+++ zope.app.security/trunk/README.txt	2009-03-11 16:08:00 UTC (rev 97844)
@@ -1,2 +1,2 @@
-This package provides several components integrating the Zope security
-implementation into zope 3 applications.
+This package implements local persistent permissions for zope.security that
+can be added and registered per site.

Modified: zope.app.security/trunk/src/zope/__init__.py
===================================================================
--- zope.app.security/trunk/src/zope/__init__.py	2009-03-11 16:07:11 UTC (rev 97843)
+++ zope.app.security/trunk/src/zope/__init__.py	2009-03-11 16:08:00 UTC (rev 97844)
@@ -1,8 +1 @@
-# this is a namespace package
-try:
-    import pkg_resources
-    pkg_resources.declare_namespace(__name__)
-except ImportError:
-    import pkgutil
-    __path__ = pkgutil.extend_path(__path__, __name__)
-
+__import__('pkg_resources').declare_namespace(__name__)

Modified: zope.app.security/trunk/src/zope/localpermission/__init__.py
===================================================================
--- zope.app.security/trunk/src/zope/app/__init__.py	2009-03-11 15:13:37 UTC (rev 97840)
+++ zope.app.security/trunk/src/zope/localpermission/__init__.py	2009-03-11 16:08:00 UTC (rev 97844)
@@ -1,8 +1 @@
-# this is a namespace package
-try:
-    import pkg_resources
-    pkg_resources.declare_namespace(__name__)
-except ImportError:
-    import pkgutil
-    __path__ = pkgutil.extend_path(__path__, __name__)
-
+from zope.localpermission.permission import LocalPermission

Added: zope.app.security/trunk/src/zope/localpermission/configure.zcml
===================================================================
--- zope.app.security/trunk/src/zope/localpermission/configure.zcml	                        (rev 0)
+++ zope.app.security/trunk/src/zope/localpermission/configure.zcml	2009-03-11 16:08:00 UTC (rev 97844)
@@ -0,0 +1,42 @@
+<configure
+    xmlns="http://namespaces.zope.org/zope"
+    xmlns:zcml="http://namespaces.zope.org/zcml"
+    i18n_domain="zope"
+    >
+
+  <class class=".permission.LocalPermission">
+    <factory
+        id="zope.app.security.Permission"
+        />
+    <implements
+        zcml:condition="installed zope.annotation"
+        interface="zope.annotation.interfaces.IAttributeAnnotatable"
+        />
+    <allow
+        interface="zope.security.interfaces.IPermission"
+        />
+    <require
+        permission="zope.Security"
+        set_schema="zope.security.interfaces.IPermission"
+        />
+  </class>
+
+  <subscriber
+      for="zope.security.interfaces.IPermission
+           zope.component.interfaces.IRegistered"
+      handler=".permission.setIdOnActivation"
+      />
+
+  <subscriber
+      for="zope.security.interfaces.IPermission
+           zope.component.interfaces.IUnregistered"
+      handler=".permission.unsetIdOnDeactivation"
+      />
+
+  <!-- XXX: This should be moved elsewhere -->
+  <permission
+      id="zope.Security"
+      title="[change-security-settings-permission] Change security settings"
+      />
+
+</configure>


Property changes on: zope.app.security/trunk/src/zope/localpermission/configure.zcml
___________________________________________________________________
Added: svn:eol-style
   + native

Added: zope.app.security/trunk/src/zope/localpermission/permission.py
===================================================================
--- zope.app.security/trunk/src/zope/localpermission/permission.py	                        (rev 0)
+++ zope.app.security/trunk/src/zope/localpermission/permission.py	2009-03-11 16:08:00 UTC (rev 97844)
@@ -0,0 +1,98 @@
+##############################################################################
+#
+# Copyright (c) 2009 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.
+#
+##############################################################################
+"""Persistent Local Permissions
+
+$Id: permission.py 97714 2009-03-09 18:52:31Z nadako $
+"""
+__docformat__ = 'restructuredtext'
+
+from persistent import Persistent
+from zope.component import adapter
+from zope.component.interfaces import IRegistered, IUnregistered
+from zope.i18nmessageid import MessageFactory
+from zope.interface import implements
+from zope.location import Location
+from zope.security.interfaces import IPermission
+
+_ = MessageFactory('zope')
+
+NULL_ID = _(u'<permission not activated>')
+
+
+class LocalPermission(Persistent, Location):
+    implements(IPermission)
+
+    def __init__(self, title=u'', description=u''):
+        self.id = NULL_ID
+        self.title = title
+        self.description = description
+
+
+ at adapter(IPermission, IRegistered)
+def setIdOnActivation(permission, event):
+    """Set the permission id upon registration activation.
+
+    Let's see how this notifier can be used. First we need to create an event
+    using the permission instance and a registration stub:
+
+    >>> class Registration:
+    ...     def __init__(self, obj, name):
+    ...         self.component = obj
+    ...         self.name = name
+
+    >>> perm1 = LocalPermission('Permission 1', 'A first permission')
+    >>> perm1.id
+    u'<permission not activated>'
+
+    >>> import zope.component.interfaces
+    >>> event = zope.component.interfaces.Registered(
+    ...     Registration(perm1, 'perm1'))
+
+    Now we pass the event into this function, and the id of the permission
+    should be set to 'perm1'.
+
+    >>> setIdOnActivation(perm1, event)
+    >>> perm1.id
+    'perm1'
+    """
+    permission.id = event.object.name
+
+
+ at adapter(IPermission, IUnregistered)
+def unsetIdOnDeactivation(permission, event):
+    """Unset the permission id up registration deactivation.
+
+    Let's see how this notifier can be used. First we need to create an event
+    using the permission instance and a registration stub:
+
+    >>> class Registration:
+    ...     def __init__(self, obj, name):
+    ...         self.component = obj
+    ...         self.name = name
+
+    >>> perm1 = LocalPermission('Permission 1', 'A first permission')
+    >>> perm1.id = 'perm1'
+
+    >>> import zope.component.interfaces
+    >>> event = zope.component.interfaces.Unregistered(
+    ...     Registration(perm1, 'perm1'))
+
+    Now we pass the event into this function, and the id of the permission
+    should be set to NULL_ID.
+
+    >>> unsetIdOnDeactivation(perm1, event)
+    >>> perm1.id
+    u'<permission not activated>'
+    """
+    permission.id = NULL_ID


Property changes on: zope.app.security/trunk/src/zope/localpermission/permission.py
___________________________________________________________________
Added: svn:keywords
   + Id,svn:eol-style=native

Added: zope.app.security/trunk/src/zope/localpermission/tests.py
===================================================================
--- zope.app.security/trunk/src/zope/localpermission/tests.py	                        (rev 0)
+++ zope.app.security/trunk/src/zope/localpermission/tests.py	2009-03-11 16:08:00 UTC (rev 97844)
@@ -0,0 +1,24 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""Tests for zope.localpermission.
+
+$Id$
+"""
+import unittest
+import doctest
+
+def test_suite():
+    return unittest.TestSuite((
+        doctest.DocTestSuite('zope.localpermission.permission'),
+        ))


Property changes on: zope.app.security/trunk/src/zope/localpermission/tests.py
___________________________________________________________________
Added: svn:keywords
   + Id,svn:eol-style=native



More information about the Checkins mailing list