Is it possible to read out all crowd user groups with their members via user macro?

Rieger_ Ralf November 30, 2021

Hello all,

is it possible to read out or output all existing crowd user groups with their corresponding members.
I have made a first attempt via

## Macro title: Listing Confluence groups
## Macro has a body: Y
## Body processing: N
## Output: Unsorted filtered list of confluence groups
##
## Developed by: xxx
## Date created: xx/xx/20xx
## Installed by: xxx
##
## Parameters
## @noparams

#set ($Count = 0)

<h1>User groups</h1>
<hr>
<ul>
#foreach($group in $userAccessor.getGroups())
  <li>$group.Name</li>
  #set ($Count = $Count + 1)
#end
</ul>
<hr>
<h6>Group count: <b>$Count</b></h6>

started.
Now I would like to replace the previous script with this

## Macro title: Show Group Membership
## Description: List all the members of a group
## Macro has a body: N
##
## Developed by: xxx
## Date created: xx/xx/20xx
## Installed by: xxx
##
## @param Group:title=Group Name|type=string|required=true|desc=Insert group name

#set($containerManagerClass = $action.class.forName('com.atlassian.spring.container.ContainerManager'))
#set($getInstanceMethod = $containerManagerClass.getDeclaredMethod('getInstance',null))
#set($containerManager = $getInstanceMethod.invoke(null,null))
#set($containerContext = $containerManager.containerContext)

#set($userAccessor = $containerManager.containerContext.getComponent('userAccessor'))
#set($groupManager = $containerManager.containerContext.getComponent("groupManager"))
#set($group = $userAccessor.getGroup($paramGroup))
#set($users = $userAccessor.getMemberNamesAsList($group))

<style type="text/css">
@media all {
.show-group-membership-macro .expand-control {
margin-bottom: 0px;
}
}
</style>

<span class="show-group-membership-macro">
<ac:structured-macro ac:name="expand" ac:schema-version="1">
<ac:parameter ac:name="title">$paramGroup</ac:parameter>
<ac:rich-text-body>
<ul>
#foreach( $username in $users )
#set($confluenceUser = $userAccessor.getUserByName($username))
<li><ac:link>
<ri:user ri:userkey="$confluenceUser.key" />
</ac:link></li>
#end
</ul>
</ac:rich-text-body>
</ac:structured-macro>
</span>

couple. Unfortunately I am missing the approach how to implement this.
Does anyone here have an idea or a little help.

Thanks for your help

1 answer

0 votes
Fabian Lim
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 31, 2022

Hi @Rieger_ Ralf

Welcome to the community!

Have you been able to solve this one as I'm interested?

Regards

Rieger_ Ralf January 31, 2022

Hi @Fabian Lim 

currently I can read out and display/list all permissions for Viewers, Editors and Commentors (users and groups) for one space.

Unfortunately, I am still stuck on the iteration of the spaces themselves, i.e. reading out the permissions of all spaces to be displayed as an overview or as an expander for each space.

Best regards

Nicolas Casel
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 22, 2022

Hello @Rieger_ Ralf  ,

Many thanks for the 2nd code snippet you shared, very useful !

In the same way, to get the user email address:

<ri:user ri:userkey="$confluenceUser.email" />

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events