You are here: Home / Documentation / How To's / How to clean up directly-assigned Manager role

How to clean up directly-assigned Manager role

by nguyen — published Jul 29, 2009 01:14 PM, last modified Aug 16, 2016 10:50 AM
script that removes directly-assigned Manager role then adds that user to the Administrators group; iterates over all contained Plone sites
def listManagers(site):
  out = []
  users = site.acl_users
  prm = users.portal_role_manager
  pgm = users.source_groups
  who = prm.listAssignedPrincipals('Manager')
  #return [x[0] for x in who if x[0] <> 'Administrators']
  for x in who:
    principal = x[0]
    if principal <> 'Administrators':
      retval = prm.removeRoleFromPrincipal('Manager', principal)
      out.append( 'Removed Manager role from %s' % principal)
      if retval:
        retval2 = pgm.addPrincipalToGroup(principal, 'Administrators')
        if retval2:
          out.append( 'Added %s to Administrators group' % principal)
        else:
          out.append( 'FAILED to add %s to Administrators group' % principal)
  who2 = pgm.listAssignedPrincipals('Administrators')
  out.append('Final Admin membership: %s' % [x[0] for x in who2])
  out.append('.')
  return "; ".join(out)

uniqueDict = {}

for itemTuple in context.items():
 (item, itemType) = itemTuple
 if str(itemType).startswith('<PloneSite at '):
   site = getattr(context, item)
   print "Plone site <a href=\"%s\" target=\"_blank\">%s user prefs</a> or <a href=\"%s\" target=\"_blank\">%s Admin membership</a>: %s<br>" % (site.portal_url()+'/prefs_users_overview', site.id, site.portal_url()+'/prefs_group_members?groupname=Administrators', site.id, listManagers(site))
 elif str(itemType).startswith('<Folder at '):
   folder = getattr(context, item)
   print "<a href='%s/manage_main' target='_blank_'><h1>%s</h1></a>" % (folder.absolute_url(), item)
   for folderItemTuple in folder.items():
     (folderItem, folderItemType) = folderItemTuple
     if str(folderItemType).startswith('<PloneSite at '):
       site = getattr(folder, folderItem)
       print "Plone site <a href=\"%s\" target=\"_blank\">%s user prefs</a> or <a href=\"%s\" target=\"_blank\">%s Admin membership</a>: %s<br>" % (site.portal_url()+'/prefs_users_overview', site.id, site.portal_url()+'/prefs_group_members?groupname=Administrators', site.id, listManagers(site))
    
return printed
Navigation