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

Can I pull a specific value out of a user's profile for use in another macro?

Rian Rian September 15, 2011

Hello,

When I look at a user's profile in my Confluence installation, I see a value for "Location" under the heading "Company". From working with our company's LDAP connection I know that the value comes from our LDAP directory.

I'd like to write a user macro that returns the current user's Location as defined in his/her profile. My idea is to feed that into the contentbylabel macro so as to display a list of pages labeled with that location name (i.e. relevant to the current user's location).

In other macros and other traffic on this site I see ways to get the ID of the current user -- but how do I drill down to that "Location" value? And could someone give me an example of how to pass that value to the ContentByLabel macro using replace-and-render or something similar.

(I'm very new to this, so please, of you can help, be explicit as possible.) Thanks, Rian Murphy

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Matthew J. Horn
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 29, 2013

This would be a way to get access to the UserDetailsManager:

#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'))

0 votes
David at David Simpson Apps
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
October 20, 2011

In a user macro, it's pretty easy to get a user's name...

$action.remoteUser.name

Getting a user's location is a bit more tricky as you'll need to get hold of the UserDetailsManager which is not one of the Confluence Objects Accessible From Velocity.

If you do manage to get that object, you can then call it like this:

#set($location = $userDetailsManager.getStringProperty($action.remoteUser, "location")

Once that's done, pass the lcoation through to the contentbylabel macro

$helper.renderConfluenceMacro("{contentbylabel:labels=$location}")

Failing that, you'll have to write a "proper" macro along the same lines.

TAGS
AUG Leaders

Atlassian Community Events