You are here: Home / Documentation / How To's / How to list the objects on which a user has been granted local roles, by user

How to list the objects on which a user has been granted local roles, by user

by nguyen — published Jan 13, 2011 04:52 PM, last modified Aug 16, 2016 10:50 AM
Sharing tab
## Script (Python) ".listObjectsWithLocalRolesByUser"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=Give info about local roles. 
##
# Example code:

# Import a standard function, and get the HTML request and response objects.
from Products.PythonScripts.standard import html_quote
request = container.REQUEST
RESPONSE =  request.RESPONSE

def do_one(obj, path): 
    localroles = obj.get_local_roles_for_userid(user)
    if len(localroles) > 0:
        msg = "User %s has local roles %r on %s" % ( 
            user, localroles, obj.absolute_url()) 
        messages.append(msg) 

messages = [] 
user = request.get('user') 
if not user: 
    return ("Please specify for example '?user=nguyen' to " 
            "report the objects on which the user has local roles.") 
else:
    messages.append("Checking objects on which local roles have been granted to %s" % user) 
    context.ZopeFindAndApply(context, apply_func=do_one, search_sub=True) 
    messages.append("Ready.") 

return '\n'.join(messages)
Navigation