Wednesday, May 15, 2013

Bulk adding of users to a Plone site (TTW)

This is a quick way to add new users to a Plone site, very useful in a pinch but probably not very robust (so I make no guarantees). It might possibly serve as the pattern for a "user importer", assuming someone hasn't invented one already.

Everything is done through the web (TTW) using the Zope Management Interface (ZMI), so you'll need to be an administrator.


Add the following script to your Plone instance and give the script a name, I called mine 'addusers'.

out = []
acl_users = context.acl_users
for item in container.temp:
    person = item.split(',') username = person[0]
    password = person[1]
    try:
         acl_users.userFolderAddUser(username,password,['trainee'],'')
    except ValueError, msg:
        out.append("Skipped %s, reason: %s" % (username, msg))
    else:
        out.append("Success with %s" % username)
return out

Note: the use of the role 'trainee' in my example, the role MUST exist for this to work. Also for the Python purists, that "hanging" return statement is perfectly fine, TTW Python scripts run inside Zope and return the output to your browser. If it absolutely bothers you, you can leave it out.

Under the ZMI > properties' add a 'lines' field called 'temp' it should include the usernames and passwords of the newusers (no spaces after the commas)

The 'temp' lines field should look like this:
Maurice,dttrrrsffd
Natalie,55542yylrw
Herman,d5rrrrr6tfdsa
Ryan,r4rffd243faz
Patrick,e443rereew
Sean,erserwrew
Michael,4343243qw
Running the 'addusers' script will now create the users with the passwords that you defined.

Update: July 1, 2013

There are a couple other tools mentioned in the comments of this post which you may also want to look at.
https://pypi.python.org/pypi/atreal.usersinout/

http://plone.org/products/collective.mass_subscriptions - can send out initial passwords in bulk

https://pypi.python.org/pypi/collective.loremipsum - generates fake content and fake users

5 comments:

christian said...

https://pypi.python.org/pypi/atreal.usersinout/ ?

David Bain said...

:) thanks Christian. Will look into that addon.

Luca Fabbri said...

If you need to send e-mail after creation or auto-generate starting password: http://plone.org/products/collective.mass_subscriptions

Unknown said...

Or you can just use collective.loremipsum to create 500 users with data generated from http://fakenamegenerator.com :)

Tiberiu Ichim said...

Might also be useful: http://play.pixelblaster.ro/blog/archive/2011/03/09/export-import-users-in-and-out-of-plone

Sign up for my upcoming Plone 5 Book & Video tutorials

plone 5 for newbies book and videos