[Zope-dev] Owner Role and ZCatalog

Brian Lloyd Brian@digicool.com
Thu, 2 Sep 1999 15:30:52 -0400


> Thanks Brian!
> 
> This is terrific.  I tried yesterday to test to see if the owner role
> was working in Zope 2, and I wasn't having any luck.  I tried the: 
> <!--#with myobject-->
>    <!--#if "AUTHENTICATED_USER.has_role('Owner')"-->
>        foo
>    <!--#/if-->
> <!--#/with-->
> 
> And no matter who had created the object I got back foo for the Users
> with the manager role, and nothing for everyone else.
> 
> Jason

Yes - note that "local roles" are just that - local to a
particular object. The has_role method of the User objects
can take an optional second argument, which is the object
to be used as context for determining if the User has the
given role. If the second argument is passed, has_role will
take local roles into account - otherwise it will only look
through the roles actually assigned to the User itself.

If you try:

<!--#with myobject-->
   <!--#if "AUTHENTICATED_USER.has_role('Owner', this())"-->
       foo
   <!--#/if-->
<!--#/with-->

...then you should get the right answer. This is something that
needs to go into the API documentation for 2.0. Along these same
lines, if you ever use the getRoles method of User objects, note
that this will only give you the roles actually assigned to the
User. To get the list of the roles of a user taking into account
the local roles of an object, you can call:

AUTHENTICATED_USER.getRolesInContext(object)


Brian Lloyd        brian@digicool.com
Software Engineer  540.371.6909              
Digital Creations  http://www.digicool.com