Back to index

plone3  3.1.7
setuphandlers.py
Go to the documentation of this file.
00001 from zope.component import getUtility
00002 from zope.component import getMultiAdapter
00003 from StringIO import StringIO
00004 from plone.portlets.interfaces import IPortletAssignmentMapping
00005 from plone.portlets.interfaces import IPortletManager
00006 from plone.app.openid.portlets.login import Assignment as LoginAssignment
00007 from Products.CMFCore.utils import getToolByName
00008 from Products.PlonePAS.browser.info import PASInfoView
00009 
00010 
00011 def hasOpenIdPlugin(portal):
00012     pas_info=PASInfoView(portal, None)
00013     return pas_info.hasOpenIDdExtractor()
00014 
00015 
00016 def createOpenIdPlugin(portal, out):
00017     print >>out, "Adding an OpenId plugin"
00018     acl=getToolByName(portal, "acl_users")
00019     acl.manage_addProduct["plone.openid"].addOpenIdPlugin(
00020             id="openid", title="OpenId authentication plugin")
00021 
00022 
00023 def activatePlugin(portal, out, plugin):
00024     acl=getToolByName(portal, "acl_users")
00025     plugin=getattr(acl, plugin)
00026     interfaces=plugin.listInterfaces()
00027 
00028     activate=[]
00029 
00030     for info in acl.plugins.listPluginTypeInfo():
00031         interface=info["interface"]
00032         interface_name=info["id"]
00033         if plugin.testImplements(interface):
00034             activate.append(interface_name)
00035             print >>out, "Activating interface %s for plugin %s" % \
00036                     (interface_name, info["title"])
00037 
00038     plugin.manage_activateInterfaces(activate)
00039 
00040 
00041 def addLoginPortlet(portal, out):
00042     leftColumn = getUtility(IPortletManager, name=u'plone.leftcolumn', context=portal)
00043     left = getMultiAdapter((portal, leftColumn,), IPortletAssignmentMapping, context=portal)
00044     if u'openid-login' not in left:
00045         print >>out, "Adding OpenID login portlet to the left column"
00046         left[u'openid-login'] = LoginAssignment()
00047 
00048 
00049 def importVarious(context):
00050     # Only run step if a flag file is present (e.g. not an extension profile)
00051     if context.readDataFile('openid-pas.txt') is None:
00052         return
00053 
00054     site = context.getSite()
00055     out = StringIO()
00056     if not hasOpenIdPlugin(site):
00057         createOpenIdPlugin(site, out)
00058         activatePlugin(site, out, "openid")
00059 
00060     addLoginPortlet(site, out)
00061