From: Maurits v. R. <m.v...@ze...> - 2010-12-31 08:00:03
|
Op 31-12-10 05:24, Jim Biggs schreef: > > I'm trying to figure out the best way to list all content for which a > specific user has been given a local sharing role -- e.g. view, edit... > > It seems the solution rests with > site/portal_catalog/Indexes/allowedRolesAndUsers. Looking in the ZMI, one > can see the allowedRolesAndUsers index has an entry for each user, e.g. > user:member1 -- where the "user:member1" entry has a list of content the > user has the "view" permission -- both globally and locally, via sharing. > > A new content share will immediately become visible for the target user in > the allowedRolesAndUsers index. Removing the share immediately removes the > content entry from the allowedRolesAndUsers index for the user. > > Per the API, allowedRolesAndUsers(obj, portal, **kwargs) returns a list of > roles and users with View permission -- which is a list from the content > object perspective. My question is: > > How does one list the content objects and roles related to a specific user > -- i.e. return a list from the user perspective? > > Any direction is appreciated. > > Regards... Jim This is not possible with the standard catalog indexes. I also do not know an add-on product that does this, though you could try your luck by searching. So you will have to write your own python code in an extra package. You can get the local roles of a user in a context like this: context.get_local_roles_for_userid('joe') I did something slightly similar just yesterday, so I will post that code here as an example. At least it deals with local roles too. For each item in the site it shows which users have a specific local role, and optionally which other local roles they have there. (The goal for me was to figure out if the custom 'Áuthor' role that was defined in a client site was actually used anywhere.) The zcml: ============================================================ <configure xmlns="http://namespaces.zope.org/zope" xmlns:browser="http://namespaces.zope.org/browser"> <browser:page name="my-role-info" for="Products.CMFPlone.interfaces.IPloneSiteRoot" permission="zope2.ViewManagementScreens" class=".roles.LocalRoleInfo" /> </configure> ============================================================ The python code in roles.py: ============================================================ import logging from Products.Five import BrowserView from Acquisition import aq_inner logger = logging.getLogger('roles') class LocalRoleInfo(BrowserView): def __call__(self): """Give info about local roles. """ context = aq_inner(self.context) self.found = 0 self.messages = [] self.role = self.request.get('role') if not self.role: return ("Please specify for example '?role=Manager&more=1' to " "report local Managers and their other local roles.") try: self.more = bool(int(self.request.get('more', ''))) except Exception: self.more = False def do_one(obj, path): try: users = obj.users_with_local_role(self.role) except AttributeError: return if not users: return self.found += 1 msg = "Users with local role %s on %s = %r" % ( self.role, obj.absolute_url(), users) logger.info(msg) self.messages.append(msg) # Maybe specify extra info. if not self.more: return for user in users: msg = "User %s has local roles %r" % ( user, obj.get_local_roles_for_userid(user)) logger.info(msg) self.messages.append(msg) logger.info("Checking for users with local role %s", self.role) context.ZopeFindAndApply(context, apply_func=do_one, search_sub=True) msg = "Found %d objects." % self.found logger.info(msg) self.messages.insert(0, msg) logger.info("Ready.") return '\n'.join(self.messages) ============================================================ Cheers, -- Maurits van Rees Programmer, Zest Software |