[Zope-dev] Membership and Local Roles

Michael Bernstein mbernstein@profitscape.com
Mon, 18 Sep 2000 09:19:29 -0500


I posted this to the PTK list on Friday, but didn't get any responses
over the weekend, so I'm reposting here.

I feel that a barrier to Loginmanager and Membership becoming more
generally usable for site builders is it's current lack of support for
local roles. Specifically, members do not show up in the local roles
screen (manage_listLocalRoles) user list.

Through the magic of grep and find, I think I've identified the relevant
sections of code in Zope that need to be duplicated in Membership (or
maybe in LoginManager).

First I tracked down what seems to be the relevant section in
/lib/python/AccessControl/Role.py, in the section labeled 'Local roles
support':


    def get_valid_userids(self):
        item=self
        dict={}
        while 1:
            if hasattr(aq_base(item), 'acl_users') and \
               hasattr(item.acl_users, 'user_names'):
                for name in item.acl_users.user_names():
                    dict[name]=1
            if not hasattr(item, 'aq_parent'):
                break
            item=item.aq_parent
        keys=dict.keys()
        keys.sort()
        return keys


Then I tracked down the user_names attribute to
/lib/python/AccessControl/User.py, in the section labeled 'Private
UserFolder
object interface':


    def user_names(self):
        return self.getUserNames()


Well, that wasn't very helpful. searching a bit more and I find:


    def getUserNames(self):
        """Return a list of usernames"""
        names=self.data.keys()
        names.sort()
        return names


Experimenting a bit, I find that a normal user folder object responds to
an /acl_users/user_names URL with an error, but does respond to an
/acl_users/getUserNames URL with a list of user names.

And now I'm stuck. I *think* that LoginManager needs a getUserNames
method that cycles through the available User Sources and grabs a list
of
names from each, concatenating them into one big list to return. I'll
settle for some code that has the User Source name hard-wired in,
though.

However, IANAC (I Am Not A Coder), and I don't know how to do this. If
anyone can offer a cut-and-paste set of instructions to add this into
LoginManager or Membership, it would be greatly appreciated.

If I've missed something obvious or misunderstood the problem, please
tell me that too.

Thanks,

Michael Bernstein.