from BTrees.OOBTree import OOBTree import persistent from zope.interface import implements from zope.component import adapter from zope.event import notify from zope.app.container.interfaces import IObjectAddedEvent from zope.app.component.site import SiteManagerContainer, LocalSiteManager from zope.app.folder import Folder import interfaces # Site registration class class NewKrihvelSiteEvent(object): implements(interfaces.INewKrihvelSiteEvent) def __init__(self, site): self.object = site # Main site containing all the rest class Krihvel(Folder): # Here we're saying that this class implements # the IKrihvel interface, see interfaces.py for # more info. implements(interfaces.IKrihvel) # Initializer def __init__(self, title='Default krihvel title', description='Default krihvel description'): self.data = OOBTree() self.title = title self.description = description # Creates Site Manager out of Krihvel root folder def setSiteManager(self, sm): super(Krihvel, self).setSiteManager(sm) notify(NewKrihvelSiteEvent(self)) # all attributes and getters are covered by the interface # IKrihvel located in interfaces.py def getTitle(self): return self.title def getDescription(self): return self.description # Example to display how permissions can be defined for # object attributes, see the require directive for the # attribute test to see how it works. # XXX This one should be gone soon. Just keeping it here as and example. def test(self): return "test" # Make Krihvel root folder a Site Manager upon creation @adapter(interfaces.IKrihvel, IObjectAddedEvent) def setSiteManagerWhenAdded(site, event): site.setSiteManager(LocalSiteManager(site)) # Setup all the additional components needed by the Krihvel Portal @adapter(interfaces.IKrihvel, IObjectAddedEvent) def setUpAllNeededParts(site, event): from zope.app.security.interfaces import IAuthentication from zope.app.authentication.authentication import PluggableAuthentication from cookiecredentials import CookieCredentialsPlugin from signup import SignupPrincipalFolder from zope.app.authentication.groupfolder import GroupFolder, GroupInformation from zope.app.principalannotation.interfaces import IPrincipalAnnotationUtility from zope.app.principalannotation import PrincipalAnnotationUtility # Add and register PAU sm = site.getSiteManager() pau = sm['krihvel_auth'] = PluggableAuthentication() sm.registerUtility(pau, IAuthentication) # Add, configure and register cookie credentils plug-in cookies = pau['krihvel_cookies'] = CookieCredentialsPlugin() cookies.loginpagename = 'wclogin.html' pau.credentialsPlugins = ('krihvel_cookies',) # Add, configure and register sign-up authentication plug-in signups = pau['signups'] = SignupPrincipalFolder('krihvel.signup.') signups.signup_roles = ['krihvel.Anyone', 'krihvel.Member'] pau.authenticatorPlugins = ('signups',) # Add and register groups plug-in groups = pau['groups'] = GroupFolder('groups') kadm = GroupInformation('Krihvel admins') groups['admins'] = kadm pau.authenticatorPlugins = pau.authenticatorPlugins + ('groups',) # Add and register PrincipalAnnotation panot = sm['PrincipalAnnotation'] = PrincipalAnnotationUtility() sm.registerUtility(panot, IPrincipalAnnotationUtility) # Creare a members folder from MembersFolder import MembersFolder mfolders = site['members'] = MembersFolder() sm.registerUtility(mfolders, interfaces.IMembersFolder) # Create a management folder from ManagementFolder import ManagementFolder manage_krihvel = site['manage_krihvel'] = ManagementFolder() sm.registerUtility(manage_krihvel, interfaces.IManagementFolder)