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

user list with profile pictures

Bert Van Daele February 19, 2013

Hi,

How can I create a more fancy User List. I want to show a table of the user that belong to one or more groups.

The {user-list} macro gives me the right info, but I would like to show it in a table with each user's profile picture instead of the basic layout the macro currently gives.

I could of course build this list manually, but the whole point is of course that this User List is automatically generated.

Thanks a lot.

6 answers

1 vote
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.
February 24, 2013

So here's a basic macro that just gets the username/email, profile picture, and list of groups they are in. I didn't make it nice or anything, but hopefully it'll help you get started:

## Macro title: User Info
## Macro has a body: N
## Body processing: Selected body processing option
## Output: Selected output option
##
## Developed by: Matthew J. Horn
## Date created: 2/25/13
## Installed by: <your name>
## Macro to display some user info
## @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($crowdService = $containerContext.getComponent('crowdService'))
#set($users = $userAccessor.getUsers())

<table class="confluenceTable">
  <tr>
    <th class="confluenceTh">User</th>
    <th class="confluenceTh">Profile Image</th>
    <th class="confluenceTh">Groups</th>
  </tr>

#foreach($user in $users)
  #set($crowdUser = $crowdService.getUser($user.name))
    <tr>
      <td class="confluenceTd">#usernameLink($user.name)</td>
      <td class="confluenceTd"><img src="$userAccessor.getUserProfilePicture($user).getDownloadPath()"/></td>
      <td class="confluenceTd">$userAccessor.getGroupNamesForUserName($user.name)</td>
    </tr>
#end
</table>

Bert Van Daele February 24, 2013

Waw. This is amazing input.

I'll see if I find some time later this week to get this up and running.

Much appreciated!

Bert Van Daele February 25, 2013

Hi Matthew,

I tried your macro and think I start to understand how to use it for my case.

However, I could use one little extra hint:

What is the simplest way to get only those users that belong to a defined group (given as a parameter)? It seems easier to get a list of groups a user belongs to ($userAccessor.getGroupNamesForUserName($user.name)) then the other way around...

Should I start checking the GroupNamesForUserName output and compare it to the input-parameter to decide whether the user belongs to the group or not? This seems a bit convoluted, doesn't it?

Or is there a command like GetUsers($group.name)? I could not find that so easily in the documentation. (Perhaps I just didn't look hard enough, sorry...)

Much appreciated!

1 vote
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.
February 19, 2013

Have you ever built a custom macro? That's the way to do it. The UserAccessor class (http://docs.atlassian.com/atlassian-confluence/latest/com/atlassian/confluence/user/UserAccessor.html) has a getUserProfilePicture() method, so that would get the image for you (or at least should get you started).

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.
February 25, 2013

Good question. Its pretty simple, but you have to start getting used to looking at the Confluence APIs to find it. Here's the link:

http://docs.atlassian.com/atlassian-confluence/latest/

In this case, you're using the UserAccessor class's getMemberNames() method:

$userAccessor.getMemberNames($myGroup)

This method takes a Group object, not a string, so you have to get the group first. There's lots of ways to do this, but the easiest is probably to pick it out of a list from the getGroups() method.

hth,

matt

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.
February 24, 2013

Bert, if I have some time later today, I'll see if I can help get you started. But I can assure you that once you start creating macros, you'll start to see some really interesting things you can do with Confluence.

0 votes
Bert Van Daele February 24, 2013

Thanks a lot for the answers.

Unfortunately I am not an avid programmer and being new to Confluence I guess I was hoping to find a more 'straightforward' answer.

Guess I will have to slowly dig into making these custom macros, then... Always good to get some exercise... ;-)

0 votes
Daniel Borcherding
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.
February 19, 2013

Hello Bert,

I am not sure what version of Confluence you are on, but more modern version of Confluence have a people direcotry. This is a place where you can see a photo and a short blurb of information abotu a given person. I am including a document below on how you search through the people direcotry to find those users that you are interested in.

https://confluence.atlassian.com/display/DOC/Searching+the+People+Directory

You other option would be to write a custom user macro to acheive this functionality. We have a document on wirting these macros which I will include.

https://confluence.atlassian.com/display/DOC/Writing+User+Macros

Please let us know if you have any questions on these documents.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events