0

I've been working on an app that uses url dispatch. I setup my root factory based on some great info found here: https://github.com/mmerickel/pyramid_auth_demo (thanks Michael!)

Now I'm trying to use pyramid_formalchemy as well. It seems pyramid_formalchemy uses traversal for determining authorization. That's ok, but I'm stuck on one point...

For traversal objects need to be location-aware which means they need to have a name and parent. So I have a User object.

class User(Base):
    __name__ = 'user'
    __parent__ = ...

I've defined my desired ACLs in my RootFactory. This all gets setup when the RootFactory's constructor gets called. I'd like to set all my classes' parents to the RootFactory, but create a RootFactory instance you need to pass in a request to the constructor (particularly because my RootFactory subclasses pyramid_formalchemy.resources.Models)

But when setting up my classes I don't have a request.

How can I correctly set parent on my classes to RootFactory?

Thanks.

lostdorje
  • 6,150
  • 9
  • 44
  • 86

1 Answers1

0

I've answered some similar questions on handling ACLs within pyramid_formalchemy here:

Pyramid and FormAlchemy admin interface

Basically pyramid_formalchemy defines it's own root factory for all of the admin URLs. You can override it and define an __acl__ there (see ModelsWithACL) which will probably solve most of your problems. From that root, pyramid_formalchemy will automatically setup the __parent__ references. So if you define some special __acl__ on your object, that will be tested first, then the ACLAuthorizationPolicy will look at the __parent__ which would be the Models or ModelsWithACL object.

See also:

http://docs.formalchemy.org/pyramid_formalchemy/#setting-permissions

Community
  • 1
  • 1
Michael Merickel
  • 23,153
  • 3
  • 54
  • 70
  • Yeah I saw this answer before. The problem I'm still facing is that the pyramid_formalchemy machinery is not setting the __parent__ property on my models. So when a model becomes the context and the authorization policy moves up the lineage, ACLAuthorizationPolicy.permits() bottoms out on the model itself and never makes it to my custom RootFactory. Where does pyramid_formalchemy set the __parent__ on the models? – lostdorje Nov 02 '11 at 07:03
  • I see the code now in Models.__getitem__() You're right this does setup __parent__ on the model. Viewing pages like .../admin/User works and users are listed. What's broken is the .../admin page itself. It should be listing all the models I configured in the call to formalchemy_admin(). But when the /admin page is called __getitem__() is never called and so the __parent__ for the models is not set correclty and I don't see the models listed. – lostdorje Nov 02 '11 at 07:13