Group Diff — Confluence Cloud Macro
This macro dynamically retrieves and compares the group memberships of two users, displaying them in categorized tabs. It identifies common groups, as well as unique groups for each user.
Template
## Initialize variables for user 1
#set($user1AccountId = $parameters["user1"])
#set($user1Details = $ConfluenceManager.get("/wiki/rest/api/user?accountId=$user1AccountId"))
#set($user1GroupsResponse = $ConfluenceManager.get("/wiki/rest/api/user/memberof?accountId=$user1AccountId"))
#set($user1Groups = [])
#if($user1GroupsResponse && $user1GroupsResponse.results)
#foreach($group in $user1GroupsResponse.results)
#set($discard = $user1Groups.add($group.name))
#end
#end
## Initialize variables for user 2
#set($user2AccountId = $parameters["user2"])
#set($user2Details = $ConfluenceManager.get("/wiki/rest/api/user?accountId=$user2AccountId"))
#set($user2GroupsResponse = $ConfluenceManager.get("/wiki/rest/api/user/memberof?accountId=$user2AccountId"))
#set($user2Groups = [])
#if($user2GroupsResponse && $user2GroupsResponse.results)
#foreach($group in $user2GroupsResponse.results)
#set($discard = $user2Groups.add($group.name))
#end
#end
## Calculate common groups and unique groups
#set($commonGroups = [])
#set($user1UniqueGroups = [])
#set($user2UniqueGroups = [])
## Find common groups
#foreach($group in $user1Groups)
#if($user2Groups.contains($group))
#set($discard = $commonGroups.add($group))
#else
#set($discard = $user1UniqueGroups.add($group))
#end
#end
## Find unique groups for user 2
#foreach($group in $user2Groups)
#if(!$user1Groups.contains($group))
#set($discard = $user2UniqueGroups.add($group))
#end
#end
## Render output in three tabs
<div class="aui-tabs horizontal-tabs" style="margin-left: 15px; width: 80%;">
<ul class="tabs-menu">
<li class="menu-item active-tab">
<a href="#user1-groups-tab">Groups for $user1Details.displayName</a>
</li>
<li class="menu-item">
<a href="#user2-groups-tab">Groups for $user2Details.displayName</a>
</li>
<li class="menu-item">
<a href="#common-groups-tab">
<span style="font-size: 1.5em; display: inline-flex; align-items: center; vertical-align: top; line-height: 0.7;">∩</span> Common Groups
</a>
</li>
</ul>
<div class="tabs-pane active-pane" id="user1-groups-tab">
<ul>
#foreach($group in $user1UniqueGroups)
<li>$group</li>
#end
#if($user1UniqueGroups.size() == 0)
<li>No unique groups for $user1Details.displayName.</li>
#end
</ul>
</div>
<div class="tabs-pane" id="user2-groups-tab">
<ul>
#foreach($group in $user2UniqueGroups)
<li>$group</li>
#end
#if($user2UniqueGroups.size() == 0)
<li>No unique groups for $user2Details.displayName.</li>
#end
</ul>
</div>
<div class="tabs-pane" id="common-groups-tab">
<ul>
#foreach($group in $commonGroups)
<li>$group</li>
#end
#if($commonGroups.size() == 0)
<li>No common groups between $user1Details.displayName and $user2Details.displayName.</li>
#end
</ul>
</div>
</div>
## Handle cases where there are no groups
#if(!$user1Groups || !$user2Groups)
<p>
No group memberships found for one or both users.
</p>
#endUser Parameters
User1
Select the first user for comparison
User2
Select the second user for comparison
You May Also Like
Filter Confluence groups based on a specified filter value and display the results in different formats.
Display the groups a specified Confluence user belongs to in different formats.
Create dropdown menus in Confluence Cloud with predefined sets of options and permission gates
Space Information macro by space Id
User macro for displaying issues using custom JQL filter
Content that is shown only if a user is in a particular group
The content of this macro will not go to the printing page
Manage frequently used images (for instance, partner's logo) in one place across the whole Confluence instance without re-uploading them on each page. User parameters allow setting the image size.
Create dropdown menus in Confluence Cloud with custom sets of options, multiselect features, and permission gates
Macro for printing all the spaces