[Zope] Enumerating owners

Paul Winkler pw_lists@slinkp.com
Wed, 28 Aug 2002 18:10:38 -0700


On Wed, Aug 28, 2002 at 05:30:43PM -0700, Michael S. Fischer wrote:
> On Wed, Aug 28, 2002 at 05:11:33PM -0700, Andy McKay wrote:
> 
> > Try owner_info rather than getOwner, the former needs View management screen
> > permission.
> > 
> > Something like:
> > 
> > obj = context.restrictedTraverse('/Test') # get the Test object
> > return obj.owner_info()
> 
> Thanks.  That works for the primary owner.  How about enumerating local
> ownership roles?

First thing that comes to mind is something like (untested):

owners = []
for owner in some_list_of_users:
    if owner.has_role(['Owner'], object):
        owners.append(owner)

return owners

But how to get the list of users?
You could just get context.acl_users.objectValues(),
but that won't be adequate if you have other user folders
higher up. Hmmm.... Well, the manage_ListLocalRoles
method does it, so let's look it up
in the source code.

(goes and looks for the relevant source)

... aha! it's in lib/python/AccessControl/dtml/listLocalRoles.dtml,
and it's a call like this:

   <dtml-in get_valid_userids>

which some grepping reveals is defined in lib/python/AccessControl/Role.py,
right next to this (in class RoleManager):

    def users_with_local_role(self, role):
        ...


so the answer is, do this:

   context.users_with_local_role('Owner')

And the real answer is, "Use the source, luke!" ;)

--PW


Paul Winkler
"Welcome to Muppet Labs, where the future is made - today!"