Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

User macro now displays user name instead of full name

Patrick Vanhoof
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.
April 5, 2023

After we upgraded to version 7.19.7 the result of a user macro has changed, namely it now shows the user name instead of the full name.

The macro code is the following:

## Macro title: Space Administrators
## Macro has a body: N
## Body processing: Selected body processing option
## Output: Selected output option
##
## Developed by: Andrew Frayling
## Date created: 21/03/2012
## Installed by: <your name>
## Macro to display a list of user that are able to administer the current space.
## @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($users = $userAccessor.getUsers())

<table class="confluenceTable">
<tr>
<th class="confluenceTh">Beheerders</th>
</tr>

#foreach ($permission in $space.getPermissions())
#if ($permission.isUserPermission() && $permission.getType() == "SETSPACEPERMISSIONS")
<tr>
<td class="confluenceTd">#usernameLink($permission.getUserName())</td>
</tr>
#end
#end
</table>

Where before the upgrade it would display 'Patrick Vanhoof' as a result of the macro, it now shows 'PVanhoof'.

Why?

2 answers

1 accepted

4 votes
Answer accepted
Fabio Racobaldo _Herzum_
Community Champion
April 5, 2023

Hey @Patrick Vanhoof ,

try to substitute the following row:

...
<td class="confluenceTd">#usernameLink($permission.getUserName())</td>
...

with :

...
<td class="confluenceTd">#usernameLink($permission.getUserSubject().getFullName() )</td>
...

Hope this helps,

Fabio

Patrick Vanhoof
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.
April 5, 2023

Thanks a lot!

Fabio Racobaldo _Herzum_
Community Champion
April 5, 2023

you're welcome @Patrick Vanhoof ;)

Like Patrick Vanhoof likes this
Ulrich Hinze June 6, 2023

In this context I found the one which we are using which is slightly different. It also shows the groups and their members which are having access.

 

Now the macro editor shows the following:

"User Macro users-in-space may use context keys [ userAccessor ] which are not set in system property macro.required.velocity.context.keys. If the macro is not rendered as expected, try to manually add those keys into the system property."

 

This is the code for the group extension which is affected by the message above:

#if($paramShowGroups == true)
<h2>Gruppen ... </h2>
#if($paramListUsers == true)
#foreach ($permission in $space.getPermissions())
#if ($permission.isGroupPermission() && $permission.getType() == "SETSPACEPERMISSIONS")
#set ( $groupString = $permission.getGroup() )
#set ( $groupObject = $userAccessor.getGroup($groupString) )
#set ( $memberList = $userAccessor.getMemberNamesAsList($groupObject) )
<h3>$groupString</h3>
<table class="confluenceTable">
<tr>
<th class="confluenceTh">... mit Administratorrechten</th>
</tr>
#foreach ($member in $memberList)
<tr>
<td class="confluenceTd">#usernameLink($member)</td>
</tr>
#end
</table>
#end
#end
#foreach ($permission in $space.getPermissions())
#if ($permission.isGroupPermission() && $permission.getType() == "VIEWSPACE")
#set ( $groupString = $permission.getGroup() )
#set ( $groupObject = $userAccessor.getGroup($groupString) )
#set ( $memberList = $userAccessor.getMemberNamesAsList($groupObject) )
<h3>$groupString</h3>
<table class="confluenceTable">
<tr>
<th class="confluenceTh">... ohne Administratorrechte</th>
</tr>
#foreach ($member in $memberList)
<tr>
<td class="confluenceTd">#usernameLink($member)</td>
</tr>
#end
</table>
#end
#end
#else
#foreach ($permission in $space.getPermissions())
#if ($permission.isGroupPermission() && $permission.getType() == "SETSPACEPERMISSIONS")
#set ( $groupString = $permission.getGroup() )
#set ( $groupObject = $userAccessor.getGroup($groupString) )
<li>$groupString</li>
#end
#end
#foreach ($permission in $space.getPermissions())
#if ($permission.isGroupPermission() && $permission.getType() == "VIEWSPACE")
#set ( $groupString = $permission.getGroup() )
#set ( $groupObject = $userAccessor.getGroup($groupString) )
<li>$groupString</li>
#end

 Now the question for me is, how to "manually add those keys into the system property."

Any help would be appreciated.

Thanks

Uli

0 votes
Ulrich Hinze August 15, 2023

Oh btw. we got it fixed the way it was described above. Our system administrator added the missing velocity key into teh system properties and now it works fine again.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events