You are here: Home / Documentation / How To's / How to list the objects on which someone has been granted certain local roles, by role(s)

How to list the objects on which someone has been granted certain local roles, by role(s)

by nguyen — published Jan 13, 2011 04:30 PM, last modified Aug 16, 2016 10:50 AM
ie. the Sharing tab

This is based on http://plone.org/documentation/manual/plone-community-developer-documentation/security-1/local-roles and http://groups.google.com/group/plone-users/browse_thread/thread/b2283cc511837c7e

## Script (Python) ".listObjectsWithLocalRolesByRoles"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=Give info about local roles. 
##

# 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
 
messages = [] 
role = request.get('role') 
if not role: 
    return ("Please specify for example '?role=Manager&more=1' to " 
            "report local Managers and their other local roles.") 
try: 
    more = bool(int(request.get('more', ''))) 
except Exception: 
    more = False 
def do_one(obj, path): 
    try: 
        users = obj.users_with_local_role(role) 
    except AttributeError: 
        return 
    if not users: 
        return 
    msg = "Users with local role %s on %s = %r" % ( 
        role, obj.absolute_url(), users) 
    messages.append(msg) 
    # Maybe specify extra info. 
    if not more: 
        return 
    for user in users: 
        msg = "User %s has local roles %r" % ( 
            user, obj.get_local_roles_for_userid(user)) 
        messages.append(msg) 
messages.append("Checking for users with local role %s" % role) 
context.ZopeFindAndApply(context, apply_func=do_one, 
search_sub=True) 
messages.append("Ready.") 
return '\n'.join(messages)
Navigation