Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Macro to get User ID along with Full Name and Login Activity

Arun Ghanta October 18, 2019

We're using below macro to dynamically get the list of users in our Confluence and report their activity. It's working pretty well.

The only problem is the full name isn't helping us.

We sometimes perform lookups with other data we generate from LDAP. As our confluence is linked to LDAP having a Confluence user login ID instead of the name helps us a lot. Right now below is the block of code in our Confluence user reporting macro.

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

#set($loginManager = $containerContext.getComponent('loginManager'))
#set($crowdService = $containerContext.getComponent('crowdService'))
#set($users = $userAccessor.getUsers())

<table class="confluenceTable">
<tr>
<th class="confluenceTh">User</th>
<th class="confluenceTh">Last Successful Login Date</th>
<th class="confluenceTh">Creation Date</th>
<th class="confluenceTh">Active</th>
</tr>
#foreach($user in $users)
#set($crowdUser = $crowdService.getUser($user.name))
<tr>
<td class="confluenceTd">#usernameLink($user.name)</td>
<td class="confluenceTd">$action.dateFormatter.formatDateTime($loginManager.getLoginInfo($user).lastSuccessfulLoginDate)</td>
<td class="confluenceTd">$action.dateFormatter.formatDateTime($crowdUser.createdDate)</td>
<td class="confluenceTd" style="text-align:center;">
#if($userAccessor.isDeactivated($user))
<img src="/s/en_GB/3047/11/_/images/icons/emoticons/error.png" width="18" height="18" border="0">
#else
<img src="/s/en_GB/3047/11/_/images/icons/emoticons/check.png" width="18" height="18" border="0">
#end
</td>
</tr>
#end
</table>

I need some help with the below line to generate Confluence user id instead of user's name.

<td class="confluenceTd">#usernameLink($user.name)</td>

 

Thanks in advance.

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events