paula.testing: test for finding txt files + minor bugfix
[paula.git] / paula.pasplugins / src / paula / pasplugins / setuphandlers.py
blob3a80735890321bb939df2085a1351ec741617252
1 """
2 """
3 __author__ = "Florian Friesdorf <flo@chaoflow.net>"
4 __docformat__ = "plaintext"
6 from StringIO import StringIO
8 from Products.CMFCore.utils import getToolByName
9 from Products.PluggableAuthService.interfaces.plugins \
10 import IAuthenticationPlugin
11 from Products.PlonePAS.Extensions.Install import activatePluginInterfaces
13 from zope.app.security.interfaces import IAuthentication
14 from zope.component import getUtility
16 from paula.pasplugins.plugins.auth import paula_auth_ifs
17 from paula.pasplugins.plugins.groups import paula_groups_ifs
18 from paula.pasplugins.plugins.properties import paula_properties_ifs
20 # only for testing purposes
21 #from paula.pasplugins.tests.fake_pau_ap import AUTHPLUG_NAME
23 def _setupPlugins(portal, out):
24 """
25 Install and prioritize the Paula PAS plug-ins.
26 """
27 uf = getToolByName(portal, 'acl_users')
29 paula = uf.manage_addProduct['paula.pasplugins']
30 plugins = uf.plugins
32 def _move_to_top(interface, name):
33 while not plugins.listPlugins(
34 interface,
35 )[0][0] == name:
36 plugins.movePluginsUp(interface, [name])
38 existing = uf.objectIds()
40 if 'paula_auth' not in existing:
41 paula.addAuthenticationPlugin('paula_auth')
42 print >> out, "Added Paula PAS Authentication Plugin."
43 activatePluginInterfaces(portal, 'paula_auth', out)
44 for x in paula_auth_ifs:
45 _move_to_top(x, 'paula_auth')
47 if 'paula_properties' not in existing:
48 paula.addPropertiesPlugin('paula_properties')
49 print >> out, "Added Paula PAS Properties Plugin."
50 activatePluginInterfaces(portal, 'paula_properties', out)
51 for x in paula_properties_ifs:
52 _move_to_top(x, 'paula_properties')
54 if 'paula_groups' not in existing:
55 paula.addGroupsPlugin('paula_groups')
56 print >> out, "Added Paula PAS Groups Plugin."
57 activatePluginInterfaces(portal, 'paula_groups', out)
58 for x in paula_groups_ifs:
59 _move_to_top(x, 'paula_groups')
61 credplugname = 'Paula: PAU CredentialsFromMappingPlugin'
62 pau = getUtility(IAuthentication)
63 if credplugname not in pau.credentialsPlugins:
64 pau.credentialsPlugins = tuple(
65 list(pau.credentialsPlugins) + [credplugname]
67 # only for testing purposes
68 #pau.authenticatorPlugins = (AUTHPLUG_NAME,)
71 def setupPlugins(context):
72 """initialize paula plugins
73 """
74 if context.readDataFile('paula-pasplugins-setup-plugins.txt') is None:
75 return
77 portal = context.getSite()
78 out = StringIO()
79 _setupPlugins(portal, out)
80 logger = context.getLogger("plugins")
81 logger.info(out.getvalue())