user list with profile pictures
Asked by Bert Van Daele:

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.


Answers:
author: Matthew J. Horn
body: 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: &lt;your name&gt;## 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())&lt;table class="confluenceTable"&gt;  &lt;tr&gt;    &lt;th class="confluenceTh"&gt;User&lt;/th&gt;    &lt;th class="confluenceTh"&gt;Profile Image&lt;/th&gt;    &lt;th class="confluenceTh"&gt;Groups&lt;/th&gt;  &lt;/tr&gt;#foreach($user in $users)  #set($crowdUser = $crowdService.getUser($user.name))    &lt;tr&gt;      &lt;td class="confluenceTd"&gt;#usernameLink($user.name)&lt;/td&gt;      &lt;td class="confluenceTd"&gt;&lt;img src="$userAccessor.getUserProfilePicture($user).getDownloadPath()"/&gt;&lt;/td&gt;      &lt;td class="confluenceTd"&gt;$userAccessor.getGroupNamesForUserName($user.name)&lt;/td&gt;    &lt;/tr&gt;#end&lt;/table&gt;
```

comments: author: Bert Van Daele
body: Waw. This is amazing input.

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

Much appreciated!


author: Bert Van Daele
body: 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!


author: Matthew J. Horn
body: 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).


author: Matthew J. Horn
body: 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


author: Matthew J. Horn
body: 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.


author: Bert Van Daele
body: 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... ;-)


author: Daniel Borcherding
body: 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.