List names in confluence-users

Hi there,

 

Can anyone suggest a user macro for generating all of the user's full names within 'confluence-users' and displaying them in a drop-down list?

 

Any help would be greatly appreciated!

 

Thanks,

 

 

 

3 answers

This widget could not be displayed.
Stephen Deutsch Community Champion Sep 28, 2015

Something like this should work:

## @noparams
#set ( $members = $userAccessor.getMemberNamesAsList($userAccessor.getGroup("confluence-users")) )
<style>
select:required:invalid {
  color: gray;
}
option[value=""][disabled] {
  display: none;
}
option {
  color: black;
}
</style>
<form class="aui" onsubmit="return false;">
    <fieldset>
        <div class="field-group">
            <label for="users-list">Users:</label>
            <select class="select" id="users-list" name="users-list" title="users list" required>
                <option value="" disabled selected>Select a user</option>
                #foreach ( $member in $members )
                    #set ( $member = $userAccessor.getUserByName($member) )
                    <option value="$member.name">$member.fullName</option>
                #end
            </select>
        </div>
    </fieldset>
</form>

Hi Stephen, This works perfectly, except one issue. The drop-down list is ordered by username. Could the list be ordered by full name?

This widget could not be displayed.

Hey there,

You can execute the following query in the database:

select u.user_name,g.group_name from cwd_user u,cwd_group g ,cwd_membership m where g.group_name = 'confluence-users' and m.parent_id=g.id group by u.user_name, g.group_name

However you can download a SQL manager for Confluence like this one and put it on a page.

Hope this will help you smile.

Cheers,

This widget could not be displayed.
Stephen Deutsch Community Champion Sep 29, 2015

Ordering by full name is harder than it seems.  Here are two options, one that renders on the server side (might take a long time, depending on how many users you have):

## @noparams

#set ( $members = $userAccessor.getMemberNamesAsList($userAccessor.getGroup("confluence-users")) )
#set ( $container = $content.class.forName("java.util.TreeMap").newInstance() )

#foreach ( $member in $members )
    #set ( $member = $userAccessor.getUserByName($member) )
    #set ( $dummy = $container.put($member.fullName, $member.name) )
#end

<style>
select:required:invalid {
  color: gray;
}
option[value=""][disabled] {
  display: none;
}
option {
  color: black;
}
</style>

<form class="aui" onsubmit="return false;">
    <fieldset>
        <div class="field-group">
            <label for="users-list">Users:</label>
            <select class="select" id="users-list" name="users-list" title="users list" required>
                <option value="" disabled selected>Select a user</option>
                #foreach ( $member in $container.keySet() )
                    <option value="$container.get($member)">$member</option>
                #end
            </select>
        </div>
    </fieldset>
</form>

and here's one that sorts the list on the client side (i.e. in the browser) that might load the page a little faster:

## @noparams

#set ( $members = $userAccessor.getMemberNamesAsList($userAccessor.getGroup("confluence-users")) )

<style>
select:required:invalid {
  color: gray;
}
option[value=""][disabled] {
  display: none;
}
option {
  color: black;
}
</style>

<form class="aui" onsubmit="return false;">
    <fieldset>
        <div class="field-group">
            <label for="users-list">Users:</label>
            <select class="select" id="users-list" name="users-list" title="users list" required>
                <option value="" disabled selected>Select a user</option>
            </select>
        </div>
    </fieldset>
</form>

<script>
    var members = {
    #foreach ( $member in $members )
        #set ( $member = $userAccessor.getUserByName($member) )
        "$member.fullName": "$member.name", 
    #end
    }
    
    function sortObject(obj) {
        return Object.keys(obj).sort().reduce(function (result, key) {
            result[key] = obj[key];
            return result;
        }, {});
    }
    var sortedMembers = sortObject(members);
    for (var key in sortedMembers) {
        if (sortedMembers.hasOwnProperty(key)) {
            jQuery("#users-list").append('<option value="' + sortedMembers[key] + '">' + key + '</option>');
        }
    }
</script>

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 17, 2018 in Confluence

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

554 views 7 6
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