[Zope3-dev] Re: How to get Principals Roles? Owner-Role?

Jim Fulton jim@zope.com
Thu, 19 Jun 2003 16:47:26 -0400


Administrator wrote:
> Hi Again!
> 
> How do I get the roles of a given principal?
> 
> This code, I have stolen from NewsSite doesnt work for me, because a
> Principal doesn't have any methode getRoles()::
> 
> 	authsvc = getService(self.context, Authentication)
>         authsvc.authenticate(self.request)
>         principal = getSecurityManager().getPrincipal()
>         return {'id' : principal.getId(),
>                 'title' : principal.getTitle(),
>                 'roles' : principal.getRoles()
>                }
> 
> I had a look through Zopes Sources, and found: only User has such a
> methode. How do I get Roles for a Principal, or how do I get a User
> instead of a Principal?

The fact that a user class has a getRoles method is a bug. :)

In Zope 3, all roles are local roles. Principals don't have
roles intrinsically.

To find the roles that a user has in a place, you have to find all
of the local role grants.  See the zope security policy implementation
to see how to do this, although I have no idea why you want this.

> Is there such a thing as a role Owner or Creator for an object, so that
> the creator may have some special rights, others don't have?

There should be, but we may not have implemented this yet.

Jim


-- 
Jim Fulton           mailto:jim@zope.com       Python Powered!
CTO                  (703) 361-1714            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org