This script examines the membership of every group in Confluence.  It returns information in three groups:

  • The Confluence user directories
  • Information about each group in Confluence
  • Information about each user in Confluence

The output looks like the blob below.  As noted, the information is divided into three sections. Formatting is provided by the script:

 

Directory Info

Directory name: Confluence Internal Directory

Group Info

confluence-administrators has 1 members. 1 of those members are active and 0 of those members are inactive
confluence-users has 2 members. 1 of those members are active and 1 of those members are inactive

User Info

Group: confluence-administrators. Username: admin. User account is active. User is in directory: Confluence Internal Directory
Group: confluence-users. Username: admin. User account is active. User is in directory: Confluence Internal Directory
Group: confluence-users. Username: slaurin. User account is inactive. User is in directory: Confluence Internal Directory

 

 

And here is the code:

import com.atlassian.user.GroupManager
import com.atlassian.confluence.user.DisabledUserManager
import com.atlassian.crowd.manager.directory.DirectoryManager

def disUse = ComponentLocator.getComponent(DisabledUserManager)

def userAccessor = ComponentLocator.getComponent(UserAccessor)
def groupManager = ComponentLocator.getComponent(GroupManager)

def directoryManager = ComponentLocator.getComponent(DirectoryManager)

def activeUsers = 0
def inactiveUsers = 0

def groups = groupManager.getGroups()
def groupInfoStringBuffer = ["<h1>Group Info</h1>"]
def userInfoStringBuffer = ["<h1>User Info</h1>"]
def directoryInfoStringBuffer = ["<h1>Directory Info</h1>"]


directoryManager.findAllDirectories().each{directory ->
    directoryInfoStringBuffer.add("Directory name: " + directory.getName() + "<br>")
}



groups.each{ group ->
//For each group in Confluence

activeUsers = 0
inactiveUsers = 0
//After the group has been selected, delcare that the count of active and inactive users is zero

    groupManager.getMemberNames(group).each{ member ->
    //Get each member of the group

    def userObj = userAccessor.getUserByName(member)
    def userDirectoryID = userObj.getProperties().values()[0].directoryId
    def userDirectoryName = directoryManager.findDirectoryById(userDirectoryID)

    //Declare a user object, using the name of the currently selected user

      if (disUse.isDisabled(userObj) == true) {
        inactiveUsers += 1
        //If the user account is disabled, increase the count of disabled users by 1
      } else if (disUse.isDisabled(userObj) == false) {
        activeUsers += 1
        //If the user account is not disabled, increase the count of active users by 1
      }
      
      def accountStatus = ""

      if(disUse.isDisabled(userObj) == false){

        accountStatus = "<span style='color:green'>active</span>"
      }else if(disUse.isDisabled(userObj) == true){

        accountStatus = "<span style='color:red'>inactive</span>"
      }



      userInfoStringBuffer.add("Group: <i>" + group.getName() + "</i>. Username: <i>" + member + "</i>. User account is " + accountStatus + ". User is in directory: <i>" + userDirectoryName.getName() + "</i><br>")
      //Log the name of the group, the name of the user, and whether or not the user's account is disable(true) or active (false)
    }

  groupInfoStringBuffer.add(group.getName() + " has " + groupManager.getMemberNames(group).size() + " members. " + activeUsers.toString() + " of those members are <span style='color:green'>active</span> and " + inactiveUsers.toString() + " of those members are <span style='color:red'>inactive</span> <br>")
  //Note the information pertaining to each group
 }

return directoryInfoStringBuffer.toString().replace(",", "").replace("[", "").replace("]", "") + groupInfoStringBuffer.toString().replace(",", "").replace("[", "").replace("]", "") + userInfoStringBuffer.toString().replace(",", "").replace("[", "").replace("]", "")
//Return the values stored to the string buffer

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>