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
Community moderators have prevented the ability to post new answers.
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'))
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.
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.