You are here: Home / Documentation / How To's / How to remove a user ID from the Administrators group of all your Plone sites

How to remove a user ID from the Administrators group of all your Plone sites

by nguyen — published Oct 06, 2010 12:50 PM, last modified Aug 16, 2016 10:50 AM
.removeSiteAdmin, a script that iterates over all the Plone sites in your Zope

Beware: if you run this script and the user you specify owns customized views or skin items, your site may start giving you Unauthorized errors when you try to create new content items (such as News Items) or want to edit an item (can't see the Edit tab).  See the related how-tos at the bottom of this page.

This script takes one argument:


The body of the script follows:

# Script to place in Zope root that removes the given ID from the Administrators
# group in all the contained Plone sites.

outln = []

def doIt(site):
   outln.append("Plone site '%s':" %
   groups = site.portal_groups
   adminGroup = groups.getGroupById('Administrators')
   if groups.removePrincipalFromGroup(useridToRemove,
     outln.append("    removed %s from group %s" % (useridToRemove, adminGroup))
     outln.append("    %s was not in group %s" % (useridToRemove, adminGroup))

for itemTuple in context.items():
 (item, itemType) = itemTuple
 if str(itemType).startswith('<PloneSite at '):
   site = getattr(context, item)
 elif str(itemType).startswith('<Folder at '):
   folder = getattr(context, item)
   for folderItemTuple in folder.items():
     (folderItem, folderItemType) = folderItemTuple
     if str(folderItemType).startswith('<PloneSite at '):
       site = getattr(folder, folderItem)
return '\n'.join(outln)