Skip to content

Commit

Permalink
Deactivted all BBB to ensure that we use only the latest code in zope…
Browse files Browse the repository at this point in the history
….app

Made almost all tests pass again, except the few that heavily depended on
the old way of doing things: apidoc, module, presentation
  • Loading branch information
strichter committed Jan 9, 2005
1 parent bbf4e59 commit 03e77c1
Show file tree
Hide file tree
Showing 10 changed files with 753 additions and 11 deletions.
2 changes: 1 addition & 1 deletion browser/principalterms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ create an authentication utility to demonstrate how this works:

Now we need to install the authentication utility:

>>> from zope.app.tests import ztapi
>>> from zope.app.testing import ztapi
>>> ztapi.provideUtility(IAuthenticationUtility, AuthUtility())

We need a principal source so that we can create a view from it.
Expand Down
2 changes: 1 addition & 1 deletion browser/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
__docformat__ = "reStructuredText"
import unittest
from zope.testing import doctest
from zope.app.tests import placelesssetup
from zope.app.testing import placelesssetup

def test_suite():
return unittest.TestSuite((
Expand Down
6 changes: 3 additions & 3 deletions configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<vocabulary
name="Permissions"
factory="zope.app.utility.vocabulary.UtilityVocabulary"
factory="zope.app.component.vocabulary.UtilityVocabulary"
interface="zope.security.interfaces.IPermission" />

<vocabulary
Expand Down Expand Up @@ -40,12 +40,12 @@
</localUtility>

<subscriber
for="..registration.interfaces.IRegistrationActivatedEvent"
for="..component.interfaces.registration.IRegistrationActivatedEvent"
factory=".permission.setIdOnActivation"
/>

<subscriber
for="..registration.interfaces.IRegistrationDeactivatedEvent"
for="..component.interfaces.registration.IRegistrationDeactivatedEvent"
factory=".permission.unsetIdOnDeactivation"
/>

Expand Down
173 changes: 173 additions & 0 deletions permission.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
##############################################################################
#
# Copyright (c) 2002 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.
#
##############################################################################
"""Permissions
$Id$
"""
from persistent import Persistent
from zope.interface import implements
from zope.schema.interfaces import ValidationError
from zope.security.checker import CheckerPublic
from zope.app import zapi
from zope.app.location import Location
from zope.app.security.interfaces import IPermission

from zope.app.i18n import ZopeMessageIDFactory as _
NULL_ID = _('<permission not activated>')

class Permission(object):
implements(IPermission)

def __init__(self, id, title="", description=""):
self.id = id
self.title = title
self.description = description


class LocalPermission(Persistent, Location):
implements(IPermission)

def __init__(self, title="", description=""):
self.id = NULL_ID
self.title = title
self.description = description


def setIdOnActivation(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>'
>>> from zope.app.component import registration
>>> event = registration.RegistrationActivatedEvent(
... Registration(perm1, 'perm1'))
Now we pass the event into this function, and the id of the permission
should be set to 'perm1'.
>>> setIdOnActivation(event)
>>> perm1.id
'perm1'
If the function is called and the component is not a local permission,
nothing is done:
>>> class Foo:
... id = 'no id'
>>> foo = Foo()
>>> event = registration.RegistrationActivatedEvent(
... Registration(foo, 'foo'))
>>> setIdOnActivation(event)
>>> foo.id
'no id'
"""
perm = event.object.component
if isinstance(perm, LocalPermission):
perm.id = event.object.name


def unsetIdOnDeactivation(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'
>>> from zope.app.component import registration
>>> event = registration.RegistrationDeactivatedEvent(
... Registration(perm1, 'perm1'))
Now we pass the event into this function, and the id of the permission
should be set to NULL_ID.
>>> unsetIdOnDeactivation(event)
>>> perm1.id
u'<permission not activated>'
If the function is called and the component is not a local permission,
nothing is done:
>>> class Foo:
... id = 'foo'
>>> foo = Foo()
>>> event = registration.RegistrationDeactivatedEvent(
... Registration(foo, 'foo'))
>>> unsetIdOnDeactivation(event)
>>> foo.id
'foo'
"""
perm = event.object.component
if isinstance(perm, LocalPermission):
perm.id = NULL_ID


def checkPermission(context, permission_id):
"""Check whether a given permission exists in the provided context.
>>> from zope.app.testing.placelesssetup import setUp, tearDown
>>> setUp()
>>> from zope.app.testing.ztapi import provideUtility
>>> provideUtility(IPermission, Permission('x'), 'x')
>>> checkPermission(None, 'x')
>>> checkPermission(None, 'y')
Traceback (most recent call last):
...
ValueError: ('Undefined permission id', 'y')
>>> tearDown()
"""
if permission_id is CheckerPublic:
return
if not zapi.queryUtility(IPermission, permission_id, context=context):
raise ValueError("Undefined permission id", permission_id)

def allPermissions(context=None):
"""Get the ids of all defined permissions
>>> from zope.app.testing.placelesssetup import setUp, tearDown
>>> setUp()
>>> from zope.app.testing.ztapi import provideUtility
>>> provideUtility(IPermission, Permission('x'), 'x')
>>> provideUtility(IPermission, Permission('y'), 'y')
>>> ids = list(allPermissions(None))
>>> ids.sort()
>>> ids
[u'x', u'y']
>>> tearDown()
"""
for id, permission in zapi.getUtilitiesFor(IPermission, context):
if id != u'zope.Public':
yield id
Loading

0 comments on commit 03e77c1

Please sign in to comment.