1
##############################################################################
3
# Copyright (c) 2004 Zope Corporation and Contributors.
6
# This software is subject to the provisions of the Zope Public License,
7
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
8
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11
# FOR A PARTICULAR PURPOSE.
13
##############################################################################
14
"""Evolve existing PAU group folders.
16
They should be used as contained plugins rather than registered plugins.
18
$Id: evolve3.py 85358 2008-04-14 20:30:57Z fdrake $
20
__docformat__ = "reStructuredText"
22
from zope import component
24
from zope.app.component.interfaces import ISite
25
from zope.app.zopeappgenerations import getRootFolder
27
from zope.app.generations.utility import findObjectsProviding
29
from zope.app.component import registration
30
import zope.app.authentication.interfaces
31
from zope.app.authentication import groupfolder
32
from zope.copypastemove.interfaces import IObjectMover
37
"""Evolve existing PAUs and group folders.
39
- Group folders should no longer be registered.
41
- PAUs that use group folders should use their contents name, not their
42
(formerly) registered name.
44
Group folders used by multiple PAUs were not supported, and are not
45
supported with this evolution.
47
root = getRootFolder(context)
49
for site in findObjectsProviding(root, ISite):
50
sm = site.getSiteManager()
51
for pau in findObjectsProviding(
52
sm, zope.app.authentication.interfaces.IPluggableAuthentication):
53
for nm, util in component.getUtilitiesFor(
54
zope.app.authentication.interfaces.IAuthenticatorPlugin,
56
if groupfolder.IGroupFolder.providedBy(util):
57
if util.__parent__ is not pau:
59
"I don't know how to migrate your database: "
60
"each group folder should only be within the "
61
"Pluggable Authentication utility that uses it")
62
# we need to remove this registration
63
regs = registration.Registered(util).registrations()
66
"I don't know how to migrate your database: "
67
"you should only have registered your group "
68
"folder as an IAuthenticatorPlugin, but it looks "
69
"like it's registered for something additional "
70
"that I don't expect")
72
r.registry.unregisterUtility(
74
zope.app.authentication.interfaces.IAuthenticatorPlugin,
76
if r.name in pau.authenticatorPlugins:
77
if util.__name__ != r.name: # else no-op
78
plugins = list(pau.authenticatorPlugins)
79
if util.__name__ in pau.authenticatorPlugins:
80
# argh! another active plugin's name is
81
# the same as this group folder's
82
# __name__. That means we need to choose
83
# a new name that is also not in
84
# authenticatorPlugins and not in
87
nm = '%s_%d' % (util.__name__, ct)
88
while (nm in pau.authenticatorPlugins or
91
nm = '%s_%d' % (util.__name__, ct)
92
IObjectMover(util).moveTo(pau, nm)
93
plugins[plugins.index(r.name)] = util.__name__
94
pau.authenticatorPlugins = tuple(plugins)
95
for k, r in pau.registrationManager.items():
96
if groupfolder.IGroupFolder.providedBy(r.component):
97
del pau.registrationManager[k]