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
Display the number of users who have access to each space
Create dropdown menus in Confluence Cloud with custom option sets, multiselect support, and permission-based access controls
Display Confluence users filtered by their email addresses
Create dropdown menus in Confluence Cloud with predefined option sets, multiselect support, and permission-based access controls
Display a list of guest users in a specific Confluence space
Retrieve and display all page content properties in an AUI sortable table
Display Confluence page edit and view restrictions to provide essential permission details, including users, groups, and inherited access
Use sticky previous/next buttons to navigate through your Confluence page tree in a linear reading order