[Checkins] SVN: z3ext.ownership/ initial import
Nikolay Kim
fafhrd at datacom.kz
Fri Mar 21 02:28:54 EDT 2008
Log message for revision 84818:
initial import
Changed:
A z3ext.ownership/
A z3ext.ownership/branches/
A z3ext.ownership/tags/
A z3ext.ownership/trunk/
A z3ext.ownership/trunk/AUTHOR.txt
A z3ext.ownership/trunk/CHANGES.txt
A z3ext.ownership/trunk/LICENSE.txt
A z3ext.ownership/trunk/bootstrap.py
A z3ext.ownership/trunk/buildout.cfg
A z3ext.ownership/trunk/setup.py
A z3ext.ownership/trunk/src/
A z3ext.ownership/trunk/src/z3ext/
A z3ext.ownership/trunk/src/z3ext/__init__.py
A z3ext.ownership/trunk/src/z3ext/ownership/
A z3ext.ownership/trunk/src/z3ext/ownership/README.txt
A z3ext.ownership/trunk/src/z3ext/ownership/__init__.py
A z3ext.ownership/trunk/src/z3ext/ownership/configure.zcml
A z3ext.ownership/trunk/src/z3ext/ownership/interfaces.py
A z3ext.ownership/trunk/src/z3ext/ownership/localroles.py
A z3ext.ownership/trunk/src/z3ext/ownership/owner.py
A z3ext.ownership/trunk/src/z3ext/ownership/principalgroups.py
A z3ext.ownership/trunk/src/z3ext/ownership/tests.py
-=-
Property changes on: z3ext.ownership/trunk
___________________________________________________________________
Name: svn:ignore
+ bin
develop-eggs
eggs
parts
coverage
.installed.cfg
Added: z3ext.ownership/trunk/AUTHOR.txt
===================================================================
--- z3ext.ownership/trunk/AUTHOR.txt (rev 0)
+++ z3ext.ownership/trunk/AUTHOR.txt 2008-03-21 06:28:53 UTC (rev 84818)
@@ -0,0 +1 @@
+Nikolay Kim (fafhrd91 <at> gmail <dot> com)
Added: z3ext.ownership/trunk/CHANGES.txt
===================================================================
--- z3ext.ownership/trunk/CHANGES.txt (rev 0)
+++ z3ext.ownership/trunk/CHANGES.txt 2008-03-21 06:28:53 UTC (rev 84818)
@@ -0,0 +1,20 @@
+=======
+CHANGES
+=======
+
+1.0.0 (2008-03-21)
+------------------
+
+- Moved to svn.zope.org
+
+
+0.99 (2008-03-19)
+-----------------
+
+- Code cleanup
+
+
+0.9.0 (2008-02-01)
+------------------
+
+- Initial release
Added: z3ext.ownership/trunk/LICENSE.txt
===================================================================
--- z3ext.ownership/trunk/LICENSE.txt (rev 0)
+++ z3ext.ownership/trunk/LICENSE.txt 2008-03-21 06:28:53 UTC (rev 84818)
@@ -0,0 +1,54 @@
+Zope Public License (ZPL) Version 2.1
+-------------------------------------
+
+A copyright notice accompanies this license document that
+identifies the copyright holders.
+
+This license has been certified as open source. It has also
+been designated as GPL compatible by the Free Software
+Foundation (FSF).
+
+Redistribution and use in source and binary forms, with or
+without modification, are permitted provided that the
+following conditions are met:
+
+1. Redistributions in source code must retain the
+ accompanying copyright notice, this list of conditions,
+ and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the accompanying
+ copyright notice, this list of conditions, and the
+ following disclaimer in the documentation and/or other
+ materials provided with the distribution.
+
+3. Names of the copyright holders must not be used to
+ endorse or promote products derived from this software
+ without prior written permission from the copyright
+ holders.
+
+4. The right to distribute this software or to use it for
+ any purpose does not give you the right to use
+ Servicemarks (sm) or Trademarks (tm) of the copyright
+ holders. Use of them is covered by separate agreement
+ with the copyright holders.
+
+5. If any files are modified, you must cause the modified
+ files to carry prominent notices stating that you changed
+ the files and the date of any change.
+
+Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS''
+ AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ NO EVENT SHALL THE COPYRIGHT HOLDERS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ DAMAGE.
Added: z3ext.ownership/trunk/bootstrap.py
===================================================================
--- z3ext.ownership/trunk/bootstrap.py (rev 0)
+++ z3ext.ownership/trunk/bootstrap.py 2008-03-21 06:28:53 UTC (rev 84818)
@@ -0,0 +1,52 @@
+##############################################################################
+#
+# Copyright (c) 2006 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.
+#
+##############################################################################
+"""Bootstrap a buildout-based project
+
+Simply run this script in a directory containing a buildout.cfg.
+The script accepts buildout command-line options, so you can
+use the -c option to specify an alternate configuration file.
+
+$Id$
+"""
+
+import os, shutil, sys, tempfile, urllib2
+
+tmpeggs = tempfile.mkdtemp()
+
+ez = {}
+exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+ ).read() in ez
+ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+import pkg_resources
+
+cmd = 'from setuptools.command.easy_install import main; main()'
+if sys.platform == 'win32':
+ cmd = '"%s"' % cmd # work around spawn lamosity on windows
+
+ws = pkg_resources.working_set
+assert os.spawnle(
+ os.P_WAIT, sys.executable, sys.executable,
+ '-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout',
+ dict(os.environ,
+ PYTHONPATH=
+ ws.find(pkg_resources.Requirement.parse('setuptools')).location
+ ),
+ ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout')
+import zc.buildout.buildout
+zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
+shutil.rmtree(tmpeggs)
Property changes on: z3ext.ownership/trunk/bootstrap.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3ext.ownership/trunk/buildout.cfg
===================================================================
--- z3ext.ownership/trunk/buildout.cfg (rev 0)
+++ z3ext.ownership/trunk/buildout.cfg 2008-03-21 06:28:53 UTC (rev 84818)
@@ -0,0 +1,18 @@
+[buildout]
+develop = .
+parts = test coverage-test coverage-report
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = z3ext.ownership [test]
+
+[coverage-test]
+recipe = zc.recipe.testrunner
+eggs = z3ext.ownership [test]
+defaults = ['--coverage', '../../coverage']
+
+[coverage-report]
+recipe = zc.recipe.egg
+eggs = z3c.coverage
+scripts = coverage=coverage-report
+arguments = ('coverage', 'coverage/report')
Added: z3ext.ownership/trunk/setup.py
===================================================================
--- z3ext.ownership/trunk/setup.py (rev 0)
+++ z3ext.ownership/trunk/setup.py 2008-03-21 06:28:53 UTC (rev 84818)
@@ -0,0 +1,71 @@
+##############################################################################
+#
+# Copyright (c) 2008 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.
+#
+##############################################################################
+"""Setup for z3ext.ownership package
+
+$Id$
+"""
+import sys, os
+from setuptools import setup, find_packages
+
+def read(*rnames):
+ return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
+
+version='1.0.0'
+
+
+setup(name = 'z3ext.ownership',
+ version = version,
+ author = 'Nikolay Kim',
+ author_email = 'fafhrd91 at gmail.com',
+ description = "Content ownership.",
+ long_description = (
+ 'Detailed Documentation\n' +
+ '======================\n'
+ + '\n\n' +
+ read('src', 'z3ext', 'ownership', 'README.txt')
+ + '\n\n' +
+ read('CHANGES.txt')
+ ),
+ classifiers=[
+ 'Development Status :: 5 - Production/Stable',
+ 'Environment :: Web Environment',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: Zope Public License',
+ 'Programming Language :: Python',
+ 'Natural Language :: English',
+ 'Operating System :: OS Independent',
+ 'Topic :: Internet :: WWW/HTTP',
+ 'Framework :: Zope3'],
+ url='http://z3ext.net/',
+ license='ZPL 2.1',
+ packages=find_packages('src'),
+ package_dir = {'':'src'},
+ namespace_packages=['z3ext'],
+ install_requires = ['setuptools',
+ 'rwproperty',
+ 'zope.component',
+ 'zope.interface',
+ 'zope.security',
+ 'zope.annotation',
+ 'zope.lifecycleevent',
+ 'zope.app.security',
+ 'z3c.autoinclude',
+ 'z3ext.security',
+ ],
+ extras_require = dict(test=['zope.app.testing',
+ 'zope.testing',
+ ]),
+ include_package_data = True,
+ zip_safe = False
+ )
Property changes on: z3ext.ownership/trunk/setup.py
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Id
Added: z3ext.ownership/trunk/src/z3ext/__init__.py
===================================================================
--- z3ext.ownership/trunk/src/z3ext/__init__.py (rev 0)
+++ z3ext.ownership/trunk/src/z3ext/__init__.py 2008-03-21 06:28:53 UTC (rev 84818)
@@ -0,0 +1,6 @@
+# namespace package boilerplate
+try:
+ __import__('pkg_resources').declare_namespace(__name__)
+except ImportError, e:
+ from pkgutil import extend_path
+ __path__ = extend_path(__path__, __name__)
Property changes on: z3ext.ownership/trunk/src/z3ext/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3ext.ownership/trunk/src/z3ext/ownership/README.txt
===================================================================
--- z3ext.ownership/trunk/src/z3ext/ownership/README.txt (rev 0)
+++ z3ext.ownership/trunk/src/z3ext/ownership/README.txt 2008-03-21 06:28:53 UTC (rev 84818)
@@ -0,0 +1,155 @@
+=================
+Content ownership
+=================
+
+This package implement single ownership concept. Content owner has special
+role on content `content.Owner`.
+
+We need setup security interaction and principals
+
+ >>> from zope import interface, component, event
+ >>> import zope.security.management
+ >>> from z3ext.ownership import tests
+ >>> from z3ext.ownership.interfaces import IOwnership
+ >>> from z3ext.ownership.interfaces import IOwnerAware, IOwnerGroupAware
+
+ >>> from zope.app.security.interfaces import IAuthentication
+
+ >>> principal1 = tests.Principal('bob')
+ >>> principal2 = tests.Principal('meg')
+
+ >>> class Auth(object):
+ ... interface.implements(IAuthentication)
+ ...
+ ... def getPrincipal(self, id):
+ ... if id == 'bob':
+ ... return principal1
+ ... if id == 'meg':
+ ... return principal2
+
+ >>> auth = Auth()
+ >>> component.provideUtility(auth)
+
+ >>> participation = tests.Participation()
+ >>> participation.principal = principal1
+ >>> zope.security.management.endInteraction()
+ >>> zope.security.management.newInteraction(participation)
+ >>> interaction = zope.security.management.getInteraction()
+
+ >>> from zope.lifecycleevent import ObjectCreatedEvent
+ >>> from zope.annotation.interfaces import IAttributeAnnotatable
+
+ >>> class IMyObject(IOwnerAware):
+ ... pass
+
+ >>> class Content:
+ ... __parent__ = None
+ ... interface.implements(IAttributeAnnotatable, IMyObject)
+
+ >>> content = Content()
+ >>> event.notify(ObjectCreatedEvent(content))
+
+ >>> owner = IOwnership(content)
+
+ >>> owner.owner
+ <Principal 'bob'>
+
+ >>> owner.ownerId
+ 'bob'
+
+Now let's check owner roles
+
+ >>> from z3ext.security.interfaces import IExtendedGrantInfo
+
+ >>> grantinfo = IExtendedGrantInfo(content)
+ >>> grantinfo.getPrincipalsForRole('content.Owner')
+ [('bob', PermissionSetting: Allow)]
+
+ >>> grantinfo.getRolesForPrincipal('bob')
+ [('content.Owner', PermissionSetting: Allow)]
+
+ >>> grantinfo.getRolesForPrincipal('meg')
+ [('content.Owner', PermissionSetting: Deny)]
+
+We can change owner
+
+ >>> owner.owner = principal2
+
+ >>> owner = IOwnership(content)
+
+ >>> owner.owner
+ <Principal 'meg'>
+
+ >>> owner.ownerId
+ 'meg'
+
+Change ownerId
+
+ >>> owner.ownerId = 'bob'
+
+ >>> owner = IOwnership(content)
+ >>> owner.owner
+ <Principal 'bob'>
+
+ >>> owner.owner = principal2
+
+ >>> grantinfo = IExtendedGrantInfo(content)
+ >>> grantinfo.getRolesForPrincipal('meg')
+ [('content.Owner', PermissionSetting: Allow)]
+
+ >>> grantinfo.getRolesForPrincipal('bob')
+ [('content.Owner', PermissionSetting: Deny)]
+
+ >>> grantinfo.getPrincipalsForRole('unknown.Role')
+ []
+
+content.Owner and content.GroupOwner are disabled for principal bob
+so ownership is not inherited from parents. But we can change this, we should
+explicitly set marker interface for content
+
+ >>> from z3ext.ownership.interfaces import IInheritOwnership
+ >>> interface.directlyProvides(content, IInheritOwnership)
+
+ >>> grantinfo = IExtendedGrantInfo(content)
+ >>> grantinfo.getRolesForPrincipal('bob')
+ []
+
+
+We can assign only IPrincipal object
+
+ >>> owner.owner = object()
+ Traceback (most recent call last):
+ ...
+ ValueError: IPrincipal object is required.
+
+
+Group owner
+
+ >>> from zope.security.interfaces import IGroup
+ >>> interface.directlyProvides(principal1, IGroup)
+
+ >>> owner = IOwnership(content)
+ >>> owner.owner = principal1
+
+ >>> owner = IOwnership(content)
+ >>> owner.isGroup
+ True
+
+ >>> interface.directlyProvides(content, IOwnerGroupAware)
+
+ >>> grantinfo = IExtendedGrantInfo(content)
+ >>> grantinfo.getRolesForPrincipal('bob')
+ [('content.GroupOwner', PermissionSetting: Allow)]
+
+ >>> grantinfo.getPrincipalsForRole('content.GroupOwner')
+ [('bob', PermissionSetting: Allow)]
+
+ >>> grantinfo.getPrincipalsForRole('unknown.Role')
+ []
+
+ >>> grantinfo.getRolesForPrincipal('meg')
+ [('content.GroupOwner', PermissionSetting: Deny)]
+
+ >>> interface.alsoProvides(content, IInheritOwnership)
+ >>> grantinfo.getRolesForPrincipal('meg')
+ []
Added: z3ext.ownership/trunk/src/z3ext/ownership/__init__.py
===================================================================
--- z3ext.ownership/trunk/src/z3ext/ownership/__init__.py (rev 0)
+++ z3ext.ownership/trunk/src/z3ext/ownership/__init__.py 2008-03-21 06:28:53 UTC (rev 84818)
@@ -0,0 +1 @@
+# This file is necessary to make this directory a package.
Property changes on: z3ext.ownership/trunk/src/z3ext/ownership/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3ext.ownership/trunk/src/z3ext/ownership/configure.zcml
===================================================================
--- z3ext.ownership/trunk/src/z3ext/ownership/configure.zcml (rev 0)
+++ z3ext.ownership/trunk/src/z3ext/ownership/configure.zcml 2008-03-21 06:28:53 UTC (rev 84818)
@@ -0,0 +1,43 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ i18n_domain="z3ext">
+
+ <autoinclude package="z3ext.ownership" />
+
+ <role
+ id="content.Owner"
+ title="Content owner" />
+
+ <role
+ id="content.GroupOwner"
+ title="Content group owner" />
+
+ <permission
+ id="z3ext.changeOwnership"
+ title="Change ownership"
+ description="Change object ownership." />
+
+ <adapter factory=".owner.Ownership" />
+
+ <class class=".owner.Ownership">
+ <require
+ permission="zope.View"
+ interface=".interfaces.IOwnership" />
+ <require
+ permission="z3ext.changeOwnership"
+ set_schema=".interfaces.IOwnership" />
+ </class>
+
+ <adapter factory=".principalgroups.principalGroups" />
+
+ <adapter
+ name="z3ext.ownership-owner"
+ factory=".localroles.getLocalRoles" />
+
+ <adapter
+ name="z3ext.ownership-groupowner"
+ factory=".localroles.getGroupLocalRoles" />
+
+ <subscriber handler=".owner.initObjectOwnership" />
+
+</configure>
Added: z3ext.ownership/trunk/src/z3ext/ownership/interfaces.py
===================================================================
--- z3ext.ownership/trunk/src/z3ext/ownership/interfaces.py (rev 0)
+++ z3ext.ownership/trunk/src/z3ext/ownership/interfaces.py 2008-03-21 06:28:53 UTC (rev 84818)
@@ -0,0 +1,64 @@
+##############################################################################
+#
+# Copyright (c) 2008 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.ownership interfaces
+
+$Id$
+"""
+from zope import interface
+from zope.security.interfaces import IPrincipal
+from zope.component.interfaces import ObjectEvent, IObjectEvent
+
+
+class IOwnerAware(interface.Interface):
+ """ marker interface for objects that supports ownership """
+
+
+class IOwnerGroupAware(IOwnerAware):
+ """ marker interface for objects that supports group ownership """
+
+
+class IInheritOwnership(interface.Interface):
+ """ marker interface for object that can inherit
+ ownership information from parent """
+
+
+class IUnchangeableOwnership(interface.Interface):
+ """ marker interface """
+
+
+class IOwnership(interface.Interface):
+ """ ownership information """
+
+ owner = interface.Attribute(u'IPrincipal object')
+
+ ownerId = interface.Attribute(u'Principal id')
+
+ isGroup = interface.Attribute(u'Is owner group')
+
+
+class IOwnerChangedEvent(IObjectEvent):
+ """ owner of object changed """
+
+ newOwner = interface.Attribute('New owner')
+
+ oldOwner = interface.Attribute('Old owner')
+
+
+class OwnerChangedEvent(ObjectEvent):
+ interface.implements(IOwnerChangedEvent)
+
+ def __init__(self, object, newOwner, oldOwner):
+ self.object = object
+ self.newOwner = newOwner
+ self.oldOwner = oldOwner
Property changes on: z3ext.ownership/trunk/src/z3ext/ownership/interfaces.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3ext.ownership/trunk/src/z3ext/ownership/localroles.py
===================================================================
--- z3ext.ownership/trunk/src/z3ext/ownership/localroles.py (rev 0)
+++ z3ext.ownership/trunk/src/z3ext/ownership/localroles.py 2008-03-21 06:28:53 UTC (rev 84818)
@@ -0,0 +1,111 @@
+##############################################################################
+#
+# Copyright (c) 2008 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 import interface, component
+from zope.app.security.settings import Allow, Unset, Deny
+from zope.securitypolicy.interfaces import IPrincipalRoleMap
+
+from interfaces import \
+ IOwnership, IInheritOwnership, IOwnerAware, IOwnerGroupAware
+
+
+ at component.adapter(IOwnerAware)
+ at interface.implementer(IPrincipalRoleMap)
+def getLocalRoles(context):
+ owner = IOwnership(context)
+ if owner.isGroup and IOwnerGroupAware.providedBy(context):
+ return
+ return LocalRoles(context, owner)
+
+class LocalRoles(object):
+ interface.implements(IPrincipalRoleMap)
+
+ def __init__(self, context, owner):
+ self.owner = owner
+ self.ownerId = owner.ownerId
+ self.inherit = IInheritOwnership.providedBy(context)
+
+ def getPrincipalsForRole(self, role_id):
+ if (role_id == 'content.Owner'):
+ return ((self.ownerId, Allow),)
+ else:
+ return ()
+
+ def getRolesForPrincipal(self, principal_id,
+ deny = (('content.Owner', Deny),),
+ allow = (('content.Owner', Allow),)):
+ if principal_id == self.ownerId:
+ return allow
+ elif self.inherit:
+ return ()
+ else:
+ return deny
+
+ def getSetting(self, role_id, principal_id):
+ if (principal_id == self.ownerId) and (role_id == 'content.Owner'):
+ return Allow
+ if self.inherit:
+ return Unset
+ else:
+ return Deny
+
+ def getPrincipalsAndRoles(self):
+ return ()
+
+
+ at component.adapter(IOwnerGroupAware)
+ at interface.implementer(IPrincipalRoleMap)
+def getGroupLocalRoles(context):
+ owner = IOwnership(context)
+ if owner.isGroup:
+ return GroupLocalRoles(context, owner)
+
+class GroupLocalRoles(object):
+ interface.implements(IPrincipalRoleMap)
+
+ def __init__(self, context, owner):
+ self.owner = owner
+ self.ownerId = owner.ownerId
+ self.inherit = IInheritOwnership.providedBy(context)
+
+ def getPrincipalsForRole(self, role_id):
+ if role_id == 'content.GroupOwner':
+ return ((self.ownerId, Allow),)
+ else:
+ return ()
+
+ def getRolesForPrincipal(self, principal_id,
+ deny = (('content.GroupOwner', Deny),),
+ allow = (('content.GroupOwner', Allow),)):
+ if principal_id == self.ownerId:
+ return allow
+ elif self.inherit:
+ return ()
+ else:
+ return deny
+
+ def getSetting(self, role_id, principal_id):
+ if (principal_id == self.ownerId) and (role_id == 'content.GroupOwner'):
+ return Allow
+
+ if self.inherit:
+ return Unset
+ else:
+ return Deny
+
+ def getPrincipalsAndRoles(self):
+ return ()
Property changes on: z3ext.ownership/trunk/src/z3ext/ownership/localroles.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3ext.ownership/trunk/src/z3ext/ownership/owner.py
===================================================================
--- z3ext.ownership/trunk/src/z3ext/ownership/owner.py (rev 0)
+++ z3ext.ownership/trunk/src/z3ext/ownership/owner.py 2008-03-21 06:28:53 UTC (rev 84818)
@@ -0,0 +1,95 @@
+##############################################################################
+#
+# Copyright (c) 2008 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 rwproperty import getproperty, setproperty
+
+from zope import event, interface, component
+from zope.annotation.interfaces import IAnnotations
+from zope.lifecycleevent.interfaces import IObjectCreatedEvent
+
+from zope.security.proxy import removeSecurityProxy
+from zope.security.interfaces import IPrincipal, IGroup
+
+from z3ext.security.utils import getPrincipal
+
+from z3ext.ownership import interfaces
+from z3ext.ownership.interfaces import IInheritOwnership
+from z3ext.ownership.interfaces import IUnchangeableOwnership
+from z3ext.ownership.interfaces import OwnerChangedEvent
+
+ANNOTATION_KEY = 'z3ext.ownership.Owner'
+
+
+class Ownership(object):
+ component.adapts(interfaces.IOwnerAware)
+ interface.implements(interfaces.IOwnership)
+
+ _ownerId = ''
+ isGroup = False
+
+ def __init__(self, context):
+ annotations = IAnnotations(removeSecurityProxy(context))
+
+ self.context = context
+ self.annotations = annotations
+
+ ownerinfo = annotations.get(ANNOTATION_KEY)
+ if ownerinfo is None:
+ ownerinfo = {'ownerId': None, 'isGroup': False}
+ annotations[ANNOTATION_KEY] = ownerinfo
+
+ self._ownerId = ownerinfo['ownerId']
+ self.isGroup = ownerinfo['isGroup']
+
+ @setproperty
+ def owner(self, owner):
+ if IPrincipal.providedBy(owner):
+ oldOwner = self.owner
+
+ self._ownerId = owner.id
+ self.isGroup = IGroup.providedBy(owner)
+
+ self.annotations[ANNOTATION_KEY] = {'ownerId': self._ownerId,
+ 'isGroup': self.isGroup}
+
+ event.notify(OwnerChangedEvent(self.context, owner, oldOwner))
+ else:
+ raise ValueError('IPrincipal object is required.')
+
+ @getproperty
+ def owner(self):
+ if self._ownerId:
+ return getPrincipal(self._ownerId)
+ else:
+ return None
+
+ @getproperty
+ def ownerId(self):
+ return self._ownerId
+
+ @setproperty
+ def ownerId(self, pid):
+ self.owner = getPrincipal(pid)
+
+
+ at component.adapter(interfaces.IOwnerAware, IObjectCreatedEvent)
+def initObjectOwnership(object, event):
+ if interfaces.IUnchangeableOwnership.providedBy(object) or \
+ interfaces.IInheritOwnership.providedBy(object):
+ return
+
+ interfaces.IOwnership(removeSecurityProxy(object)).owner = getPrincipal()
Property changes on: z3ext.ownership/trunk/src/z3ext/ownership/owner.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3ext.ownership/trunk/src/z3ext/ownership/principalgroups.py
===================================================================
--- z3ext.ownership/trunk/src/z3ext/ownership/principalgroups.py (rev 0)
+++ z3ext.ownership/trunk/src/z3ext/ownership/principalgroups.py 2008-03-21 06:28:53 UTC (rev 84818)
@@ -0,0 +1,33 @@
+##############################################################################
+#
+# Copyright (c) 2008 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 import interface, component
+from zope.component import queryUtility
+from zope.app.security.interfaces import IUnauthenticatedPrincipal
+
+from z3ext.security.interfaces import IPrincipalGroups
+from z3ext.ownership.interfaces import IOwnerAware, IOwnership
+
+
+ at component.adapter(IOwnerAware)
+ at interface.implementer(IPrincipalGroups)
+def principalGroups(content):
+ owner = IOwnership(content).owner
+ if owner is None:
+ owner = queryUtility(IUnauthenticatedPrincipal)
+
+ return IPrincipalGroups(owner, None)
Property changes on: z3ext.ownership/trunk/src/z3ext/ownership/principalgroups.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3ext.ownership/trunk/src/z3ext/ownership/tests.py
===================================================================
--- z3ext.ownership/trunk/src/z3ext/ownership/tests.py (rev 0)
+++ z3ext.ownership/trunk/src/z3ext/ownership/tests.py 2008-03-21 06:28:53 UTC (rev 84818)
@@ -0,0 +1,66 @@
+##############################################################################
+#
+# Copyright (c) 2008 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$
+"""
+import unittest, doctest
+from zope import interface, component
+from zope.app.testing import placelesssetup
+from zope.annotation.attribute import AttributeAnnotations
+
+import zope.security.management
+from zope.security.interfaces import IPrincipal
+from z3ext.security import tests as sectests
+from z3ext.security.securitypolicy import SecurityPolicy
+
+from z3ext.ownership.owner import Ownership, initObjectOwnership
+from z3ext.ownership.localroles import getLocalRoles, getGroupLocalRoles
+
+
+class Principal:
+ interface.implements(IPrincipal)
+
+ def __init__(self, id):
+ self.id = id
+ self.title = id
+ self.groups = []
+
+ def __repr__(self):
+ return "<Principal '%s'>"%self.id
+
+class Participation:
+ interaction = None
+
+
+def setUp(test):
+ #placelesssetup.setUp(test)
+ sectests.setUp(test)
+ zope.security.management.setSecurityPolicy(SecurityPolicy)
+
+ sm = component.getSiteManager()
+ sm.registerAdapter(Ownership)
+ sm.registerAdapter(getLocalRoles, name="z3ext.ownership-owner")
+ sm.registerAdapter(getGroupLocalRoles, name="z3ext.ownership-group")
+ sm.registerAdapter(AttributeAnnotations)
+ sm.registerHandler(initObjectOwnership)
+
+
+def test_suite():
+ return unittest.TestSuite((
+ doctest.DocFileSuite(
+ 'README.txt',
+ setUp=setUp, tearDown=placelesssetup.tearDown,
+ optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS),
+ ))
Property changes on: z3ext.ownership/trunk/src/z3ext/ownership/tests.py
___________________________________________________________________
Name: svn:keywords
+ Id
More information about the Checkins
mailing list