Bulk User Upload Macro

Name Bulk User Upload
Vendor Brendan Patterson
Authors Brendan Patterson, Jeremy Plichta, Dan Hardiker
Homepage http://confluence.atlassian.com/display/CONFEXT/Bulk+User+Upload+Macro
Issue Management
Continuous Integration n/a
Categories Admin Macros
Most Recent Version 2.0
Availability Confluence v2.3-dr1 to v3.0.0_01
State Stable
Support Unsupported Plugins
License Freeware / Open Source (BSD)
Price Free
Release Docs http://confluence.atlassian.com/display/CONFEXT/Bulk+User+Upload+Macro
Java API Docs n/a
Download Source n/a
Download JAR bulkuserupload-2.0.jar

Here is my first cut at a bulk user upload macro. This macro lets you easily add multiple users from a CSV file.

Plugin has been updated to work with Confluence v2.3 - please use the plugin repository to get it
Backup before using!

Please do a complete backup of your server before using this.
Its been only minimally tested at this point.

Usage
Usage: {bulk-user-upload}
The macro is only available to members of the group 'confluence-administrators'.
Copy and paste the CSV file contents into the form.
The formatting of the CSV is indicated in the window.
Also use the form buttons to bring up a sample, directions, or clear the form.

A screen shot:

Known issues:
  • If some of the users in the list already exist (but not all) an internal error is thrown. I'm not sure yet whether I can do anything to handle this. This only seems to occur when attempting to add the users to groups.
  • If groups are included in the CSV but the groups don't already exist errors are thrown in some cases. I'm pursuing work arounds for this.
Source code:

The source code is at a free Subversion repository hosting service.
svn co http://opensvn.csie.org/artemistech/confluence-plugins-open/bulk-user-upload/

Let me know if you want to add back updates and I'll give you access to the repository brendan.patterson@gmail.com

Planned features:
  • The ability to add existing users to groups in bulk (should be easy).
  • The ability to deactivate users in bulk (also trivial, but I'd like to solicit feedback on this one).
  • Better error handling and resolving the above issues.
  • Upload a csv text file instead of needing to copy / paste the contents.
  • I wrote this as a precursor to solving the issue where LDAP users still have to create an account to get familiar with the system and specifically the user management system. Atlassian is rewriting their user management so I may hold off to see how that looks.
  • Suggestions?
Screen shots:


Download history of the multi-excerpt plugin for the last year


Date 2008-Jul 2008-Aug 2008-Sep 2008-Oct 2008-Nov 2008-Dec 2009-Jan 2009-Feb 2009-Mar 2009-Apr 2009-May 2009-Jun 2009-Jul
Hits 28 54 55 50 40 33 64 27 51 37 41 38 4

Total:

class com.thoughtworks.xstream.alias.CannotResolveClassException: org.jfree.data.time.DateRange : org.jfree.data.time.DateRange

Labels

plugin plugin Delete
user user Delete
macro macro Delete
repository_current repository_current Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Nov 09, 2005

    Mark Michaelis says:

    Hello, I had not been able to add users with this Macro (Confluence v1.4.4, JDK...

    Hello,

    I had not been able to add users with this Macro (Confluence v1.4.4, JDK1.5.0_04, Tomcat). The users simply did not appear in "Manage Users" although adding them again either with the User Manager or with this macro always revealed that the users already exist. To work around the problem I finally wrote my own small macro which might be handy to use:

    ## Creates a user with default-groups as used here at
    ## CoreMedia. Put this on your page and render it.
    ## Mind that any exception-handling e. g. for duplicate
    ## users is missing.
    ##
    ## Usage: 
    ##  {admin-create-user:loginname|passwd|email|fullname}
    ##
    #set($username=$param0)
    #set($userpasswd=$param1)
    #set($useremail=$param2)
    #set($userfullname=$param3)
    ##
    #set($defaultGroups=["confluence-users", "common"])
    ##
    #set($currentUser=$action.getRemoteUser())
    #set($userManager=$currentUser.getUserManager())
    #if(!$currentUser.inGroup("confluence-administrators"))
    <p style="color:red;">
    Macro can only be rendered by administrators.
    </p>
    #else
    $userManager.flushCaches()
    ##
    <hr/>
    <div>
    Going to create user ${username}...
    </div>
    #set($userObject=$userManager.createUser($username))
    <div>
    Created user ${username}.
    </div>
    $userObject.setPassword($userpasswd)
    $userObject.setFullName($userfullname)
    $userObject.setEmail($useremail)
    <div>
    Set password, etc. of user ${username}.
    </div>
    ##
    #foreach($group in $defaultGroups)
    #set($groupObject=$userManager.getGroup($group))
    #set($addResult=$userObject.addToGroup($groupObject))
    <div>
    Add user ${username} to group ${group}
    </div>
    #end
    <hr/>
    $userManager.flushCaches()
    #end
    

    And to remove users which did not get created correctly (or even for normal users) I created a macro to remove users:

    ## Removes a user from confluence
    ##
    ## Usage: 
    ##  {admin-remove-user:loginname}
    ##
    #set($username=$param0)
    ##
    #set($currentUser=$action.getRemoteUser())
    #set($userManager=$currentUser.getUserManager())
    #if(!$currentUser.inGroup("confluence-administrators"))
    <p style="color:red;">
    Macro can only be rendered by administrators.
    </p>
    #else
    $userManager.flushCaches()
    ##
    <hr/>
    <div>
    Going to delete user ${username}...
    </div>
    #set($userObject=$userManager.getUser($username))
    #if($userObject)
    #set($result=$userObject.remove())
    <div>
    Removed user ${username}
    </div>
    #end
    <hr/>
    $userManager.flushCaches()
    #end
    
  2. Dec 18, 2005

    randall zapata says:

    This code is finicky because it takes a couple attempts to get some your users e...

    This code is finicky because it takes a couple attempts to get some your users entered.  The major issue with the program is that is says that it can not add users because the user already exist, but they are not in the "list users."    
    Things that I found that may help:

    1. Delete all quotes and comma-space

    2. Make sure none of the fields are null

  3. Feb 16, 2006

    Ben Coleman says:

    It's not working for me, I've installed the plugin and created a page with {bu...

    It's not working for me, I've installed the plugin and created a page with

    {bulk-user-upload}

    All I get is the following error...
    Error rendering macro: java.lang.NoSuchMethodError: com.atlassian.confluence.user.UserAccessor.getGroup(Ljava/lang/String;)Lcom/opensymphony/user/Group;

    Any ideas what I'm doing wrong? (I'm using version 2.1.3)

    1. Feb 16, 2006

      Brendan Patterson says:

      Sorry the hassel. This has not yet been updated for version 2.1.3 of Confluence ...

      Sorry the hassel. This has not yet been updated for version 2.1.3 of Confluence and the API has changed. I'll put a note up about it not being ready for 2.1.2. Feel free to check out the source code and fix it up if you're able

  4. Feb 25, 2006

    Giles Lewis says:

    The Perl XML-RPC client page illustrates the use of Perl to upload users via...

    The Perl XML-RPC client page illustrates the use of Perl to upload users via the remote API. This has been tested with 2.1.3, but not with prior versions.

  5. May 04, 2006

    Chris Dant says:

    I desperately needed a way to add users so I tinkered with Mark Michaelis' contr...

    I desperately needed a way to add users so I tinkered with Mark Michaelis' contribution above to get this. I made two changes:

    • removed the check for admin rights, since I was sure that only I would use it
    • added the ability to specify up to three groups for each user
    • added a check for existing user

    If anyone happens across this and can suggest how to pass a list as a param, then the group processing could be done with an iterator. I couldn't figure that out. Also, if I have time I'd like to get a list of users from an attached CSV file; seems like it might be possible? Don't know.

    The best solution would be for the Bulk User Upload Macro to actually work!

    Another Add-User Macro
    ## Usage:
    ##  {admin-create-user:loginname|passwd|email|fullname[|group1[|group2[|group3]]]}
    ##
    #set($username=$param0)
    #set($userpasswd=$param1)
    #set($useremail=$param2)
    #set($userfullname=$param3)
    #set($group1=$param4)
    #set($group2=$param5)
    #set($group3=$param6)
    ##
    ${username} ${userpasswd} ${useremail} ${userfullname} ${group1} ${group2} ${group3}
    ##
    #set($myuseraccessor=$content.getUserAccessor())
    ##
    #set($userObj=$myuseraccessor.getUser($username))
    #if($userObj)
    <span style="color:red">Already exists!</span>
    #else
    #set($userObj=$myuseraccessor.addUser($username,$userpasswd,$useremail,$userfullname))
    #if($group1)
    #set($addResult=$myuseraccessor.addMembership($group1,$username))
    #end
    #if($group2)
    #set($addResult=$myuseraccessor.addMembership($group2,$username))
    #end
    #if($group3)
    #set($addResult=$myuseraccessor.addMembership($group3,$username))
    #end
    <span style="color:green">Done!</span>
    #end
    <br />
    
  6. May 15, 2006

    Bob Swift says:

    [Confluence SOAP Client in Java] can also be used for bulk add (and remo...

    [Confluence SOAP Client in Java] can also be used for bulk add (and remove) of users and of users to groups using csv files.

  7. Jun 14, 2007

    Andy Brook says:

    I would really love to use this plugin but it keeps stacking on me.  I've w...

    I would really love to use this plugin but it keeps stacking on me.  I've written an app to parse a bunch of LDAP filter matches for confluence groups 'Users' which gives me 450 AD users in nice-and-neat CSV just as described, my problem is it bales with hiberate issues such as 'Failed to lazily initialize a collection'. I'm lucky if its get to #3,

    Also, if I add a user, it bales if I try to add it again, (it not just ignoring and carrying on with the next user).  As you can imagine this is a bit of a problem for 450 users.  I really need an automated upload route.

    Perhaps related is that the system I'm trying to create users in already has content? dunno.

    I hear the SOAP client reference, Ill try that next, heck I may even have to write something! 

  8. Sep 14, 2007

    François Nonnenmacher says:

    Warning, this macro will silently fail (you get a blank page) if you have any ac...

    Warning, this macro will silently fail (you get a blank page) if you have any accentuated (diacritical) character in a user full name. Just one such char and your whole list gets rejected.

  9. Nov 23, 2007

    richard buchan says:

    hi, just testing this add-in on conf v2.6 and get a strange error that you might...

    hi, just testing this add-in on conf v2.6 and get a strange error that you might be able to point me in the right direction... when we create users with a group of confluence-users, the plugin creates its own group and uses that instead of using the confluence-users group that already exists in the system, even though the spelling is exactly the same - this causes issues when the user , created by the bulk upload, tries to login as the system errors with a message saying that permission is not allowed to the whole system.

    i have run the bulk upload as an admin user and also as admin itself with the same results.

    is there a configuration soemwhere that i have not assigned correctly ?

    thanks

     richard buchan

    1. Nov 26, 2007

      richard buchan says:

      i think i have just figured it out... there cannot be a space between the comma ...

      i think i have just figured it out... there cannot be a space between the comma and the group name !

      the sample input has this space - it needs to be taken out !

      richard buchan 

  10. Aug 15, 2008

    Rich Kucera says:

    The white space needs to be removed from the sample input: testUser1,testPass...

    The white space needs to be removed from the sample input:

    testUser1,testPassword1,testEmail1,testFullName1,confluence-users
    testUser2,testPassword2,testEmail2,testFullName2,confluence-users
    testUser3,testPassword3,testEmail3,testFullName3,confluence-users
    
    


  11. Aug 15, 2008

    Rich Kucera says:

    See also: you might also be interested in [Confluence Command Line Interface...

    See also:

    you might also be interested in [Confluence Command Line Interface|http://confluence.atlassian.com/display/CONFEXT/Confluence+Command+Line+Interface] which provides a set of functions implemented from available APIs.



    and Python snippet using remote API: http://confluence.atlassian.com/display/CONFEXT/Add+a+new+user+with+a+personal+space

    but I'd prefer to get this function working within the wiki (with this macro) rather than command line.

  12. Jan 14

    Sally says:

    Works for me, thank you!  You've saved me having to add 100 users manua...

    Works for me, thank you!  You've saved me having to add 100 users manually!

  13. Apr 02

    Royce Wong says:

    Sweet! Works for me on Confluence 2.7.1, added 500 dummy users for performan...

    Sweet! Works for me on Confluence 2.7.1, added 500 dummy users for performance testing with no problem. Thanks & great job. Now, only if there is a tool like this for JIRA...

    1. Apr 02

      Brendan Patterson says:

      Thanks for the positive feedback!! It's no longer even April Fools day so must b...

      Thanks for the positive feedback!! It's no longer even April Fools day so must be genuine

      I think the vast majority of people use tools that they are generally pleased with but rarely give positive feedback (myself included). Developers mostly only hear about the problems. But the effect of a positive comment or two are bigger than you can guess.

      We need a simple thumbs up widget for 'Confluence extensions' and 'JIRA ext.' which someone could just press and/or leave a couple words like 'worked' or 'worthy' or 'good enough'.

      1. Apr 16

        Boots Wang [atlassian] says:

        I think the vast majority of people use tools that they are generally pleased w...

        I think the vast majority of people use tools that they are generally pleased with but rarely give positive feedback (myself included). Developers mostly only hear about the problems. But the effect of a positive comment or two are bigger than you can guess.

        True, I've also hear positive feedback from customers with this one.

        We need a simple thumbs up widget for 'Confluence extensions' and 'JIRA ext.' which someone could just press and/or leave a couple words like 'worked' or 'worthy' or 'good enough'.

        It's in the works

  14. Jun 29

    Adam Cohen says:

    ive been using this plugin on 2.10 and its saved me hours....but first attempt a...

    ive been using this plugin on 2.10 and its saved me hours....but first attempt after 3.0 upgrade and its failing on "add users".  is there an update required for compatibility?

    here's a synopsis of the error:

    System Error

    A system error has occurred — our apologies!

    Cause

    java.lang.RuntimeException: Error rendering template for decorator root

        at com.atlassian.confluence.setup.velocity.ApplyDecoratorDirective.render(ApplyDecoratorDirective.java:210)

    caused by: java.lang.RuntimeException: Error rendering template for decorator page

        at com.atlassian.confluence.setup.velocity.ApplyDecoratorDirective.render(ApplyDecoratorDirective.java:210)

    caused by: org.apache.velocity.exception.MethodInvocationException: Invocation of method 'getViewableLabels' in class com.atlassian.confluence.themes.PageHelper threw exception net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection at /labels/labels-editor.vm[line 6, column 25]

        at org.apache.velocity.runtime.parser.node.ASTIdentifier.execute(ASTIdentifier.java:223)

    caused by: net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection

        at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:201)

    caused by: net.sf.hibernate.HibernateException: collection was evicted

        at net.sf.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:3305)

    1. Jun 29

      Brendan Patterson says:

      Hi Adam, Glad to hear you've found this useful in the past. I've spent a few ...

      Hi Adam,

      Glad to hear you've found this useful in the past.

      I've spent a few minutes poking around. I did get it to work once in version 3.0.0_01, but then on another attempt saw the same stack trace.

      Nothing in the stacktrace unfortunately seems to point to any code in this plugin directly (that I can see). So it might take some time to debug.

      Just thought I'd take a quick swing but I don't have time time right now to dig deeper unfortunately. Hopefully someone else will.

      Interestingly everything I tested worked except when trying to add a user who already existed, so it might have something to do with whatever message gets generated when a user already exists. But I was able to add new users, deactivate, reactivate, list users, etc.

      thanks,
      Brendan