How to import users into a group
by
kimadmin
—
last modified
Nov 18, 2010 01:15 PM
a script that takes a list of users and adds them to a group
Via ZMI add a Script (Python), call it .importGroupMembers:
# takes list of email addresses and populates the group with those members
targetGroupTitle = 'Fair Trade Intranet Viewers'
groupMembers = [ 'abc123@uwosh.edu', 'xyz432@uwosh.edu', ]
pg = container.portal_groups
group = pg.getGroupById(targetGroupTitle)
if group:
print "found group %s" % group
currentMembers = [m.getId() for m in group.getGroupMembers()]
for m in groupMembers:
mId = m.replace('@uwosh.edu', '').replace(' ', '')
print "checking %s..." % mId
if mId in currentMembers:
print " already a member"
else:
print " adding %s to group" % mId
group.addMember(mId)
else:
print "no such group exists"
return printed
Change the values of the targetGroupTitle and of the list of group members. Here we listed their full email addresses, so in the for loop we strip out the "@uwosh.edu" portion of their email address to get their LDAP user account ID.











