How to get user details (Phone, Position, etc) for macro in Confluence?

Hi everybody,

Starting from the last succefull login macro from Andrew Frayling and from the macro that produces a list of users last login date from Remo Siegwart i want to create a macro that will also take personal details from every user like Phone, Position etc in order to create a report.

Any idea how i can take the personal details?

Thanks in advance,

Kostas

4 answers

1 accepted

I think I have an answer for you, not sure if this is the quickest route but it does the job.

Use your findings in macro that produces a list of users last login date and get another component:

#set($userDetailsManager = $containerContext.getComponent('userDetailsManager'))

You print user details like this:

$userDetailsManager.getStringProperty($action.remoteUser, 'location')

You can even get them by group and iterate using:

$userDetailsManager.getProfileGroups();
$userDetailsManager.getProfileKeys($group);

And lastly, you could load a wiki markup renderer for personal information (about me) user field. This thing was a real pain for me. Check out my findings:

https://answers.atlassian.com/questions/98010/how-do-i-get-the-about-me-field-from-a-confluence-user-macro

it worked !! :)

Hey Andreas,

Thanx for your help.

I'm getting the component below

#set($userDetailsManager = $containerContext.getComponent('userDetailsManager'))

but i don't know how to print user details for all users.

The macro that i have is:

#set($userDetailsManager = $containerContext.getComponent('userDetailsManager'))
 
#set($loginManager = $containerContext.getComponent('loginManager'))
#set($group = $userAccessor.getGroup($paramgroup))
#if($group)
    #set($usernames = $userAccessor.getMemberNames($group))
 
    <table class="confluenceTable">
        <tr>
			<th class="confluenceTh">Count</th>
            <th class="confluenceTh">User</th>
			<th class="confluenceTh">Tel</th>
			<th class="confluenceTh">Groups</th>
            <th class="confluenceTh">Last Successful Login Date</th>
        </tr>
			#set($count = 0)
			#foreach($username in $usernames)
            #set($user = $userAccessor.getUser($username))
			#set($groups = $userAccessor.getGroupNamesForUserName($user.name))
			

        <tr>

			#set($count = $count + 1)
			<td class="confluenceTd">$count</td>
			<td class="confluenceTd">#usernameLink($user.name)</td>
			<td class="confluenceTd">$userDetailsManager.getStringProperty($userAccessor.getUser($username)), 'location')</td>
			<td class="confluenceTd">$groups</td>
			<td class="confluenceTd">$action.dateFormatter.formatDateTime($loginManager.getLoginInfo($user).lastSuccessfulLoginDate)</td>
        </tr>
			#end
    </table>
#else
    <p><i>No group with name "$paramgroup" found!</i></p>
#end

If i use

$userDetailsManager.getStringProperty($userAccessor.getUser($username)), 'location')
 

doesn't print anything.

If i use

$userDetailsManager.getStringProperty($action.remoteUser, 'location')

prints the location of currently logged in user for every use.

I have use various combinations without success.

Any idea?

Thanx again for the help patrioti :)

Cheers,

Kostas

Andreas i've pressed on i don't like this post by mistake. I'm trying to undo the action and i have a warning that an error occurs. I'll try to undo it.

I found the solution with your help.

Cheers,

Kostas

Haven't tried to iterate user objects, some suggestions:

Does your loop works? Where do you place the line to get the user's property? If you have the $user, try using it to get its properties, instead of userAccessor.getUser().

Andreas

Hey andreas,

Macros work fine. The down vote was by mistake.

The problem with undo down vote is not resolved yet. I have raised an issue to atlassian

https://jira.atlassian.com/browse/ANSWERS-818.

Kala Christougenna,

Kostas

No worries Kosta,

Merry Xmas kai KALH XRONIA - Happy new year !!

Andreas

Unless you can access the client through a mobile API, I don't think you can get the position (I assume you mean the GPS coordinates of the requesting device) from Confluence. You could use an analytics tool to give you general location-based information about clients, such as country of origin.

As for "Phone", I assume you mean the type of client device used to access the page. You can use JavaScript to get the clienty type (which would be the browser, which would hint at the phone type), but I don't think you can get the type of phone, again, without accessing a mobile API.

I think he means the user details stored in the confluence user profile.

Yeap. Maybe i didn't make it so clear but i need the details of user profile.

Check out the following two managers:

* com.atlassian.confluence.user.PersonalInformationManager
* com.atlassian.confluence.user.UserDetailsManager

Cheers,
-Stefan

I have the same issue patrioti, need to get the "About Me" field from the user.

David said the trick is to get to the UserDetailsManager object, which is not one of the Confluence Objects Accessible From Velocity. (David says)

Check out his answers in the cases below, a bit tricky, need to have confuence source, eclipse or some other IDE - and go figure.

My problem is with velocity, you can get the userAccessor but then, what route do you follow to get to the userDetailsManager :
$action.getUserAccessor()..?... getEditMyProfileAction().getUserDetailsMap().getProperty('website')

Something like this maybe:
$action.getUserAccessor().getUserPreferences($action.remoteUser).getString('website')

.. doesn't work either :/

Maybe, you can get something out of his comments and share it with us

Case 1: https://answers.atlassian.com/questions/98010/how-do-i-get-the-about-me-field-from-a-confluence-user-macro

Case 2: https://answers.atlassian.com/questions/11686/can-i-pull-a-specific-value-out-of-a-user-s-profile-for-use-in-another-macro



Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Monday in Confluence

Calling all marketing teams who use Confluence - we want to hear from you!

Hi Community! me again 🙂 If you’re a marketing team using Confluence, we want to hear your story! How did you start using Confluence? What are your use cases? What have been some of the benefits?...

194 views 3 3
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you