Hey Community,
i´ve got a Macro to get a list about the last Logins for Confluence.
But it doesn´t give me the important information about the last login of my users.
## @Param group:title=Gruppe|type=string|required=true|desc=Group to show
#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($t1=$content.currentDate.time)
#set($group = $userAccessor.getGroup($paramgroup))
#if($group)
#set($usernames = $userAccessor.getMemberNames($group))
<table class="confluenceTable" width="660px">
<tr>
<th class="confluenceTh " width="220px">Name</th>
<th class="confluenceTh" width="110px">Create date</th>
<th class="confluenceTh" width="110px">Last Login</th>
<th class="confluenceTh" width="110px" style="text-align:center;">Activated</th>
<th class="confluenceTh" width="110px" style="text-align:center;">Days</th>
</tr>
#foreach($username in $usernames)
#set($t3=9999)
#set($user = $userAccessor.getUser($username))
#set($crowdUser = $crowdService.getUser($user.name))
<tr>
<td class="confluenceTd">#usernameLink($user.name)</td>
<td class="confluenceTd" style="text-align:center;">$action.dateFormatter.formatGivenString('dd.MM.yyyy', $crowdUser.createdDate)</td>
<td class="confluenceTd" style="text-align:center;">$loginManager.getLoginInfo($user).lastSuccessfulLoginDate.toString</td>
<td class="confluenceTd" style="text-align:center;">
#if($userAccessor.isDeactivated($user))
<ac:macro ac:name="status">
<ac:parameter ac:name="colour">Red</ac:parameter>
<ac:parameter ac:name="title">Nein</ac:parameter>
</ac:macro>
#else
<ac:macro ac:name="status">
<ac:parameter ac:name="colour">Green</ac:parameter>
<ac:parameter ac:name="title">Ja</ac:parameter>
</ac:macro>
#set($totalactiveusers = $totalactiveusers + 1)
#end
</td>
#if($loginManager.getLoginInfo($user).lastSuccessfulLoginDate)
#set($t3= $content.currentDate.time - $loginManager.getLoginInfo($user).lastSuccessfulLoginDate.time)
#set($t3=$t3/1000/24/60/60)
#end
<td class="confluenceTd" style="text-align:center;">
#if($t3 < 7)
<ac:macro ac:name="status">
<ac:parameter ac:name="colour">Green</ac:parameter>
<ac:parameter ac:name="title">$t3</ac:parameter>
</ac:macro>
#elseif($t3 < 14)
<ac:macro ac:name="status">
<ac:parameter ac:name="colour">Yellow</ac:parameter>
<ac:parameter ac:name="title">$t3</ac:parameter>
</ac:macro>
#elseif($t3 < 9999)
<ac:macro ac:name="status">
<ac:parameter ac:name="colour">Red</ac:parameter>
<ac:parameter ac:name="title">$t3</ac:parameter>
</ac:macro>
#else
<ac:macro ac:name="status">
<ac:parameter ac:name="colour">Magenta</ac:parameter>
<ac:parameter ac:name="title">$t3</ac:parameter>
</ac:macro>
#end
</td>
</tr>
#end
</table>
#end
What do you get? Blank in that cell? Error rendering macro? Have you looked at the Confluence log for errors?
Hey Bill thank you for your Response,
I get a blank cell.
The Check of redenering is Marked. The Macro works but i dont get the Information about rhe last Lagin. It stays blank.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you access the logs? It may give some insight into what is wrong. Blank often means that the method/property you are using does not exist in the Velocity context. I am guessing that this is where your macro fails:
#if($loginManager.getLoginInfo($user).lastSuccessfulLoginDate)
In other words, that construct is null so the condition is evaluated is false.
In a case like this, I start with a very simple test macro to try to determine what properties and methods are visible to me. I would create a simple user macro that lets you select a user, and try to see how to get what you want. It might be as simple as having to be more explicit in your structures, using getLastSuccessfulLoginDate()
rather than .lastSuccessfulLoginDate
Which version of Confluence are you using?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Kaya, Rahmi ,
can you post your new working macro code please? I've got the same problem.
Thank you!
KR, Marco
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear Marco,
i´ve builded a SQL.file and a Batch.file to get these informations as a csv. I´ve worked more then 3 Hours for this.
But currently it only works with PostgreSQL.
Best Regards,
Rahmi Kaya
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Kaya_Rahmi,
I would be interested as well. I read in another Thread that Atlassian tighened the security so that you cannot access the loginmanager without modifying the velocity.properties. Is that correct?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the hint! I have found the solution here:
KR, Marco
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.