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

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

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!

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.

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

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.

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