Stand with Ukraine 🇺🇦

User Groups — Confluence Cloud Macro

confluence-contentadmin

The User Groups macro retrieves and displays the groups a specified Confluence user belongs to. It supports multiple output formats—Table, Ordered List, and Unordered List—allowing users to customize how the information is presented. The macro also visually highlights the user's name as a clickable link to their Confluence profile.

Try for free

User Parameters

User

Select a user to display their groups

Output type parameter

Select an output type to render user groups

Template

#set($accountId = $parameters.user) ## Get the user account ID from parameters
#set($userDetails = $ConfluenceManager.get("/wiki/rest/api/user?accountId=$accountId")) ## Fetch user details
#set($userGroups = $ConfluenceManager.get("/wiki/rest/api/user/memberof?accountId=$accountId")) ## Fetch groups the user belongs to
#set($displayFormat = $parameters.outputTypeParameter) ## Determine the format for displaying the output

## Determine if the specified user is the current user
#set($isCurrentUser = $StringUtils.equals($accountId, $page.authorId))

## Set the appropriate lozenge style based on whether the user is the current user
#set($lozengeStyle = "aui-lozenge-default")
#if ($isCurrentUser)
#set($lozengeStyle = "aui-lozenge-inprogress")
#end

## Add styles for the output formats
<style>
    table {
        width: fit-content;
    }
    ol, ul {
        width: fit-content;
    }
    ol li, ul li {
        border-bottom: 1px solid #DFE1E6;
        padding: 3px;
    }
    ul li {
        list-style-type: circle;
    }
</style>

## Add AUI styles for table
#set($tableClass = "aui aui-table-sortable aui-table-interactive aui-table-rowhover")

## Check if the user belongs to any groups
#if (!$userGroups || $userGroups.size() == 0)
No groups found for <strong>$userDetails.displayName</strong>
#break
#end

## Render Table
#if ($displayFormat == "Table")
<table class="$tableClass">
    <thead>
        <tr>
            <th>Groups for <a href="${baseUrl}/people/$accountId"><span class="aui-lozenge $lozengeStyle">@$userDetails.displayName</span></a></th>
        </tr>
    </thead>
    <tbody>
        #foreach($group in $userGroups.results)
        <tr>
            <td>$group.name</td>
        </tr>
        #end
    </tbody>
</table>
#break
#end

## Render Ordered List
#if ($displayFormat == "Ordered list")
Groups for <a href="${baseUrl}/people/$accountId"><span class="aui-lozenge $lozengeStyle">@$userDetails.displayName</span></a>
<ol>
    #foreach($group in $userGroups.results)
    <li>$group.name</li>
    #end
</ol>
#break
#end

## Render Unordered List
#if ($displayFormat == "Unordered list")
Groups for <a href="${baseUrl}/people/$accountId"><span class="aui-lozenge $lozengeStyle">@$userDetails.displayName</span></a>
<ul>
    #foreach($group in $userGroups.results)
    <li>$group.name</li>
    #end
</ul>
#break
#end