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

1 vote
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?

0 vote

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,

0 vote
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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

381 views 21 10
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