[Zope-dev] Owner Role and ZCatalog

Jason Spisak webmaster@mtear.com
Thu, 02 Sep 1999 08:04:49 -0800


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

Brian Lloyd wrote:
> 
> > Zopists,
> >
> > Does anyone know if the ZCatalog catalog's the Owner role of
> > an object.
> > This sounds strange, but I'd like someone to only search their own
> > stuff.  Is that possible?  Is Owner a searchable indexable
> > item?  Michel?
> >
> > Jason Spisak
> 
> Jason,
> 
> This is possible - currently you have to do a little bit of
> work to make it happen though. Ownership is basically a
> convention - when an object is created, the user who created
> the object is given the "Owner" local role on the object
> automatically. While there is currently no built-in API call
> to get the "owner" of an object (ownership is still kind of
> new, so we are letting it percolate before providing a formalized
> ownership api), here is an example external method that will
> give you the names of the users who have the "Owner" role on
> a given object. Note that there can be more than one, since
> site managers can go into an object and give multiple users
> the "Owner" local role on an object just as they could with
> any other local role.
> 
> def owner(self):
>     """Return a space-separated string of user names
>        who have the local Owner role on an object."""
>     parent=self.aq_parent
>     roles=parent.aq_acquire('__ac_local_roles__')
>     dict=roles or {}
>     items=[]
>     for key, val in dict.items():
>         if 'Owner' in val:
>             items.append(key)
>     return string.join(items, ' ')
> 
> You can either use this as an external method at the top of your
> site that objects can acquire, or add it to your ZClass definitions
> if you are indexing ZClass instances. That should effectively give
> your objects an "owner" method that the Catalog can use.
> 
> Next, you need to create an "owner" index in your Catalog (you
> probably want to make this a Text Index instead of a field index
> so that you can search for a single name and find it though there
> may be multiple owners).
> 
> Hope this helps!
> 
> Brian Lloyd        brian@digicool.com
> Software Engineer  540.371.6909
> Digital Creations  http://www.digicool.com