[Zope3-Users] Run starup code with zope 3.

Sebastian Bartos seth.kriticos at googlemail.com
Thu Feb 12 13:28:23 EST 2009


Was playing with the event system a bit, and ended up with the
following, which works fine:

import zope.event
class MyEvent:
    pass
event = MyEvent()
def f(event):
    if isinstance(event, zope.app.appsetup.interfaces.ProcessStarting):
        """Put stuff you want to execute after server startup here. """
        principalPermissionManager.grantAllPermissionsToPrincipal("use")
zope.event.subscribers.append(f)

...

Is this a good zopey way?

- Seth


On Thu, 2009-02-12 at 20:32 +0300, Dan Korostelev wrote:
> 2009/2/12 Thierry Florac <thierry.florac at onf.fr>:
> > Le jeudi 12 février 2009 à 17:50 +0100, Sebastian Bartos a écrit :
> >> I'm struggling with some Zope 3 startup code. I registered a user like
> >> this for the Session Credentials plugin and login form stuff:
> >>
> >> ...
> >>
> >>     def create(self, data):
> >>         site = getSite()
> >>         sm = site.getSiteManager()
> >>
> >>         if sm.has_key('auth'):
> >>             return "Site is already set up"
> >>
> >>         pau = Pluggableauth()
> >>         sm['auth'] = pau
> >>         sm.registerUtility(pau, Iauth)
> >>         users = PrincipalFolder()
> >>         sm['auth']['Users'] = users
> >>         sm.registerUtility(users, IAuthenticatorPlugin, name="Users")
> >>         pau.authenticatorPlugins = (users.__name__, )
> >>         pau.credentialsPlugins = ("No Challenge if Authenticated",
> >>                                   "Session Credentials")
> >>
> >>         user = InternalPrincipal("user", "foo", "user",
> >>                                  passwordManagerName="SHA1")
> >>         users["user"] = user
> >>        principalPermissionManager.grantAllPermissionsToPrincipal("user")
> >
> >
> > To run code automatically at application startup, I think that you
> > should have a look at the IDatabaseOpenedWithRootEvent (defined in
> > zope.app.appsetup.interfaces).
> > I use this event to check a set of persistent database utilities at
> > application startup, and it works fine.
> 
> Also, zope.securitypolicy provides a way to store location-based
> grants. Just adapt your site object to IPrincipalRoleManager or to
> IPrincipalPermissionManager (defined in zope.security.interfaces) and
> use its methods to allow/deny roles/permissions to some principal ID.
> It will handle the actual storing work. Child objects will inherit
> parent's settings until they have their own local settings.
> 
-- 
Sebastian Bartos, <seth.kriticos at googlemail.com>
keyserevr: pgp.mit.edu
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
Url : http://mail.zope.org/pipermail/zope3-users/attachments/20090212/cf32da4b/attachment.bin 


More information about the Zope3-users mailing list