This Python script uses XML-RPC to automate the addition of new Confluence users, give them their own personal space, and more.
This script does the following:
- Adds a new user to Confluence (if not already there)
- Adds the user to the "confluence-users" group
- Creates a personal space for the user
- Gives the user full admin rights to their own space
- Gives the "confluence-users" group limited rights to the user's personal space
Without automation, performing these tasks takes an excessive amount of mouse-clicking for each new user (especially the admin rights). This script makes it very easy and quick.
|
The script is generic and requires you to first set the specifics for your server. See the code for details. |
Download
Download the script here: AddUser.py
Code
This code is written in Python (www.python.org). If you aren't familiar with it, it is a free language you can be up and running with very quickly. To get started quickly, a good one-step Python distribution to start with can be grabbed from here: ActivePython.
#!/usr/bin/python # # File Name: AddUser.py # Purpose: Sets up a user login and gives the user a personal space # # Notes: # All rights management is also done # User added to confluence-users # No command-line or gui as of yet - just edit top parameters and run # # To use this file you first need to change some things like the # address format, the URL to the wiki, and the space key used for # the user's page. # # This should really just be a starting point for people to work with. # # File History: # 06-03-01 russ Created file import xmlrpclib # ****** EDIT THESE NEXT PARAMETERS ****** userName = "jblow" fullName = "Joe Blow" # ****** END OF PARAMETERS TO EDIT!! ***** wikiURL = "http://yourwikiaddress:8080" s = xmlrpclib.ServerProxy(wikiURL + "/rpc/xmlrpc") #log in as admin... print "Logging in..." token = s.confluence1.login("admin", "adminpassword") #add the user... if not s.confluence1.hasUser(token, userName): print "Adding user '%s'..." % userName userDef = dict(email = "%s@yourcompany.com" % (userName,), fullname = fullName, name = userName, url = wikiURL + "/display/~%s" % (userName,) ) password = userName s.confluence1.addUser(token, userDef, password) else: print "User '%s' already exists!" % userName #add user to the standard user group... print "Adding user to the 'confluence-users' group..." s.confluence1.addUserToGroup(token, userName, "confluence-users") #create the personal space for the user... spaceKey = "U" + userName[:2].upper() print "Creating personal space ('%s') for user..." % spaceKey spaceDef = dict(description = "This is the personal space for %s." % fullName, homePage = "", key = spaceKey, name = "User_%s" % userName, url = wikiURL + "/display/%s" % spaceKey ) try: s.confluence1.addSpace(token, spaceDef) except Exception, E: #space probably already exists print "User space already exists!" #make user an admin of their personal space... print "Assigning full permissions on personal space to user..." adminPermissions = s.confluence1.getSpaceLevelPermissions(token) s.confluence1.addPermissionsToSpace(token, adminPermissions, userName, spaceKey) #Assign general user permissions to the space... print "Assigning permissions to general users for personal space..." userPermissions = ["VIEWSPACE", "COMMENT", "EDITSPACE", "CREATEATTACHMENT", "REMOVEATTACHMENT", ] s.confluence1.addPermissionsToSpace(token, userPermissions, "confluence-users", spaceKey) print "User management complete!"

Comments (7)
Jun 13, 2006
Peter R. says:
Could this script be used when a new user logs in? I'm trying to figure out a wa...Could this script be used when a new user logs in? I'm trying to figure out a way that a user authenticated via LDAP will be automatically added to the confluence-users group the first time they log into the system.
Jun 13, 2006
Russell Warren says:
I don't know. There would need to be some way in Confluence to trigger an extern...I don't know. There would need to be some way in Confluence to trigger an external action (eg: a variant of this script) when a new user logs in, and I have no clue if such a thing exists. That would be a good question for the general or dev mailing lists.
As an aside — the personal space creation aspect of this script is probably irrelevant with Confluence 2.2 anyway, since users now get their own space automatically... we haven't upgraded yet, so I'm not sure, though.
May 29, 2007
Lehky, Miro says:
Russell I recently deployed Confluence and did some rework of this scr...Russell
I recently deployed Confluence and did some rework of this script to bring it inline with the new personal space feature and to make use of some of the new functions Confluence provides.
If you have no objections I'd like to rework this page abit to reflect my updated version of the script.
Miro
May 30, 2007
Russell Warren says:
No problem... this is a wiki after all!No problem... this is a wiki after all!
Aug 22, 2007
David Dembo says:
Forgive me, I'm not really a software developer but could this script be modifie...Forgive me, I'm not really a software developer - but could this script be modified slightly to assign limited permissions to the user rather than full admin rights?
An example to elaborate:
This isn't possible using the Space Admin page (it simply doesn't allow you to do it), but I'm wondering if you could circumvent this by changing this...
#make user an admin of their personal space... print "Assigning full permissions on personal space to user..." adminPermissions = s.confluence1.getSpaceLevelPermissions(token) s.confluence1.addPermissionsToSpace(token, adminPermissions, userName, spaceKey)... to this:
This would allow you to do things like restricting the Home page of a personal space so that it can be used as a standard & more advanced user profile, but still allowing the user to have free reign over most other aspects of the space.
Aug 22, 2007
Russell Warren says:
Is that even necessary? Doesn't the "confluenceadministrators" group already hav...Is that even necessary? Doesn't the "confluence-administrators" group already have full admin access to every space for you? If so, just ditch those lines.
If it is necessary, it seems reasonable at first glance, but I'd have to look up the valid arguments to "addPermissionsToSpace" again... I haven't looked at this in a while. The easiest thing to do is just try it. ie: Make a bogus user and see what happens.
Also, keep in mind that this macro is a tad out of date now that all Confluence users now get their own personal space... not sure since we're still on Confluence 2.1.5a at my location (which doesn't have that feature).
Aug 22, 2007
David Dembo says:
Sorry that probably wasn't the best example. :) You're right, confluenceadminist...Sorry that probably wasn't the best example.
You're right, confluence-administrators has full admin access to personal spaces, my example should've been something more along the lines of changing...
...to this...
... and then changing the section below that for confluence-users so that they only have "VIEWSPACE" and "COMMENT" permissions.
Regarding all users having personal spaces, they still have to create them (there is a permission to allow/disallow this) otherwise by default they just have a basic user profile page. It looks like there have been some API changes to permissions methods and what-not over time though, so this script might be out of date as you say.