Thursday, January 13, 2011

List users who have specific roles in dotCMS

In dotCMS version 1.7a (not sure about subsequent versions), there is no way see a list of which users belong to what roles. Here is some code that will output a list of users for whatever given roles.

#macro ( outputRoles $roleName )
   <h1>$roleName</h1>
   #set($found = $cmsuser.searchUsersAndUsersProxy(null, null, null, [], false, ["$roleName"], true, null, 1, 1000))
   #set($theUsers = $found.get("users"))
   <p>There are $theUsers.size() users who have role: $roleName</p>
   <ul>
   #foreach ($user in $theUsers)
      <li>$!user.emailAddress</li>
   #end
   </ul>
   <hr/>
#end
## Define the set of roles you want to see here.
#set ($rolesToCheck = [
   "Administrator",
   "Power User"
])
#foreach ($role in $rolesToCheck)
   #outputRoles($role)
#end