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.
#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
#endFilter Confluence groups based on a specified filter value and display the results in different formats.
Compare unique and common groups between two users
Create dropdown menus in Confluence Cloud with custom sets of options, multiselect features, and permission gates
Basic greeting for user
Display information about how many users have access to each space
Display Confluence users filtered by their email addresses.
Create dropdown menus in Confluence Cloud with predefined sets of options, multiselect features, and permission gates
Display a list of guest users in a specific Confluence space
List out a table to display the assignee history for Issues by JQL. Shows the following information: Issue Key, Summary, and Assignee history
Display page edit and view restrictions in Confluence to get essential permission details, including users, groups, and inherited access.