user list with profile pictures

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

This widget could not be displayed.

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).

This widget could not be displayed.

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>

Waw. This is amazing input.

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

Much appreciated!

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!

This widget could not be displayed.

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.

This widget could not be displayed.

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... ;-)

This widget could not be displayed.

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.

This widget could not be displayed.

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

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published Aug 14, 2018 in Confluence

Add-on evaluation with confluence templates

Atlassian market place contains number of Apps/Addons which improves the capability of out of the box Atlassian products. It is good to follow a plugin evaluation process before install add-ons. So t...

174 views 12 7
Read article

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