Forums

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

How do I get the "About Me" field from a confluence user macro

Andreas Gounaris
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.
October 17, 2012

My purpose is to write a user macro to display the "about me" section of a user's profile.

Using the $action.remoteUser class I can get only the name and the email. What about the other fields (location website etc)?

Especially I want to get the "About Me" field since it can contain markup and there I can render more info about the user.

There is also the $req.userPrincipal class but I'd like to know what properties are exposed except the "name"?

Thanks

3 answers

1 accepted

6 votes
Answer accepted
Andreas Gounaris
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.
November 5, 2012

Finally I got it. Some reverse engineering (thx to spring) helped me render "About Me" as wiki markup. Yupi! this is exactly what I wanted.

I hope it works for you.

#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($userDetailsManager = $containerContext.getComponent('userDetailsManager'))
#set($personalInformationManager = $containerContext.getComponent('personalInformationManager'))
#set($wikiStyleRenderer = $containerContext.getComponent('wikiStyleRenderer'))

#set($pi = $personalInformationManager.getPersonalInformation($action.remoteUser))
#set($renderedAboutMe = $wikiStyleRenderer.convertWikiToXHtml($pi.toPageContext(), $pi.getBodyAsString()))

<div>
    <b>$action.getText('confluence.user.profile.website'): </b>
    $userDetailsManager.getStringProperty($action.remoteUser, 'website')
</div>
<div>
    <b>$action.getText('confluence.user.profile.location'): </b>
    $userDetailsManager.getStringProperty($action.remoteUser, 'location')
</div>
<div>
    <b>$action.getText('personal.info'): </b>
    <div id="profile-about-me-content">$renderedAboutMe</div>
</div>

2 votes
David at David Simpson Apps
Atlassian Partner
October 18, 2012

Have a look at the Confluence source code, particularly:

  • com.atlassian.confluence.user.actions.EditMyProfileAction
  • com.atlassian.confluence.user.actions.UserDetailsMap
  • /users/editmyprofile.vm

Adapt what you find :)

Andreas Gounaris
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.
October 18, 2012

Thanks David, this is what I was looking for.

1 vote
Stefan Baader
Contributor
March 14, 2013

This User Macro works fine to get the user profile data of a given user.

Only the email address I can't figure out.

I mean this:

$action.getText('confluence.user.profile.email')
    $userDetailsManager.getStringProperty($user, 'email')

Any idea?

## @param Username:title=Username|type=string|required=false|desc=Username

#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($userDetailsManager = $containerContext.getComponent('userDetailsManager'))
#set($personalInformationManager = $containerContext.getComponent('personalInformationManager'))
#set($wikiStyleRenderer = $containerContext.getComponent('wikiStyleRenderer'))
 


#if($paramUsername!="")
   #set( $user = $userAccessor.getUserIfAvailable($paramUsername)  )
#else
   #set( $user = $action.remoteUser)
#end

#set($pi = $personalInformationManager.getPersonalInformation($user))

#set($renderedAboutMe = $wikiStyleRenderer.convertWikiToXHtml($pi.toPageContext(), $pi.getBodyAsString()))


<b>Profildaten von User $user.fullName ($user.name)</b>

<div>
    <b>$action.getText('confluence.user.profile.website'): </b>
    $userDetailsManager.getStringProperty($user, 'website')
</div>
<div>
    <b>$action.getText('confluence.user.profile.location'): </b>
    $userDetailsManager.getStringProperty($user, 'location')
</div>

<div>
    <b>$action.getText('confluence.user.profile.position'): </b>
    $userDetailsManager.getStringProperty($user, 'position')
</div>

<div>
    <b>$action.getText('confluence.user.profile.phone'): </b>
    $userDetailsManager.getStringProperty($user, 'phone')
</div>

<div>
    <b>$action.getText('confluence.user.profile.department'): </b>
    $userDetailsManager.getStringProperty($user, 'department')
</div>

<div>
    <b>$action.getText('confluence.user.profile.email'): </b>
    $userDetailsManager.getStringProperty($user, 'email')
</div>

<div>
    <b>$action.getText('personal.info'): </b>
    $renderedAboutMe
</div>

Andreas Gounaris
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.
March 15, 2013

$user.email

Don't know about the label, (confluence.user.profile.email) you can use your own

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Atlassian Community Events