%PDF- %PDF-
| Direktori : /home/waritko/jetty-distribution-9.4.21.v20190926/webapps/ROOT/templates/ |
| Current File : //home/waritko/jetty-distribution-9.4.21.v20190926/webapps/ROOT/templates/getusersandgroups.vm |
###
### Template used by the AJAX table that displays users and groups. It returns a sublist of users
### and/or groups, filtered according to some parameters, in the JSON format.
###
###
$response.setContentType("application/json")
#set($offset = $mathtool.toInteger($request.get('offset')))
## offset starts from 0 in velocity and 1 in javascript
#set($off = $offset - 1)
#set($limit = $mathtool.toInteger($request.get('limit')))
#set($rm = $xwiki.rightsmanager)
##
## Get all the request parameters which are filters
#set($params = $request.getParameterMap())
#set($keys = $params.keySet())
## Params which are not supposed to be used for filtering
#set($defaultKeys = ["xpage", "offset", "limit", "wiki", "uorg", "clsname", "space", "reqNo", "sort", "dir"])
## Params that should filter the document, not object properties
#set($docProps = ["fullName", "name"])
## The filter being constructed. It will be passed to the rightsmanager API.
#set($filterMap = {})
##
#set($orderList = [])
#foreach($key in $keys)
## foreach needed because request.getParameterMap returns a list of values for each parameter
#foreach($i in $params.get($key)) #set($value = $i) #end
#if(!$defaultKeys.contains($key))
## Put in the filters map
#if($docProps.contains($key))
## Each filter is: key=>[propType, value], where propType is null for document properties
#set($arr = [])
#set($discard = $arr.add($NULL))## null => document property
#set($discard = $arr.add("$value"))
#set($discard = $filterMap.put("$key", $arr))
## Question: Why do we order using the filter fields?
## #set($discard = $orderList.add("$key"))
#else
#set($arr = [])
## This may be variable... For the moment, assume it is a StringProperty
#set($discard = $arr.add("StringProperty"))
#set($discard = $arr.add("$value"))
#set($discard = $filterMap.put("$key", $arr))
## #set($arr2 = [])
## #set($discard = $arr2.add("$key"))
## #set($discard = $arr2.add("StringProperty"))
## #set($discard = $orderList.add($arr2))
#end
#elseif($key == "uorg")
#set($uorg = $value)
#elseif($key == "clsname")
#set($clsname = $value)
#end
#end
#if($orderList.size() == 0)
#set($discard = $orderList.add("name")) ## By default, order by document name
#end
##
## Get the list of users/groups
#set($wiki = $request.wiki)
#if($wiki == "local")
#if($uorg == "users")
## Get local users
#set($users = $rm.usersApi.getAllMatchedLocalUsers($filterMap, $limit, $off, $orderList))
#set($matchedCount = $rm.usersApi.countAllMatchedLocalUsers($filterMap))
#else
## Get local groups
#set($users = $rm.groupsApi.getAllMatchedLocalGroups($filterMap, $limit, $off, $orderList))
#set($matchedCount = $rm.groupsApi.countAllMatchedLocalGroups($filterMap))
#end
#elseif($wiki == "global")
#if($uorg == "users")
## Get global users
#set($users = $rm.usersApi.getAllMatchedGlobalUsers($filterMap, $limit, $off, $orderList))
#set($matchedCount = $rm.usersApi.countAllMatchedGlobalUsers($filterMap))
#else
## Get global group
#set($users = $rm.groupsApi.getAllMatchedGlobalGroups($filterMap, $limit, $off, $orderList))
#set($matchedCount = $rm.groupsApi.countAllMatchedGlobalGroups($filterMap))
#end
#else
#if($uorg == "users")
## Get both local and global users
#set($users = $rm.usersApi.getAllMatchedUsers($filterMap, $limit, $off, $orderList))
#set($matchedCount = $rm.usersApi.countAllMatchedUsers($filterMap))
#else
## Get both local and global groups
#set($users = $rm.groupsApi.getAllMatchedGroups($filterMap, $limit, $off, $orderList))
#set($matchedCount = $rm.groupsApi.countAllMatchedGroups($filterMap))
#end
#end
#set($rightsWithAllowPrecedence = [ 'admin', 'programming', 'register', 'createwiki' ])
### json starts
#set($userGroupsMap = {})
#set($discard = $userGroupsMap.put("totalrows", $matchedCount))
#set($discard = $userGroupsMap.put("reqNo" , $mathtool.toInteger($request.reqNo)))
#set($discard = $userGroupsMap.put("returnedrows", $mathtool.min($matchedCount, $limit)))
#set($discard = $userGroupsMap.put("offset" , $offset))
#set($discard = $userGroupsMap.put("clsname" , $clsname))
#set($discard = $userGroupsMap.put("uorg" , $uorg))
#set($rows = [])
#foreach($user in $users)
#set($wikiname = $user.getWiki())
#if($wikiname != "xwiki" || $wikiname == $xcontext.database) #set($wikiname = "local") #end
#if($wikiname == "xwiki")
#set($username = $user.getPrefixedFullName())
#set($usermatch = ${regextool.quote($username)})
#else
#set($username = $user.fullName)
## in subwikis users may be referenced by wiki:Space.Username or Space.Username
## try to match both with one regexp. See XWIKI-9730
#set($usermatch = "("+${regextool.quote($user.getWiki())}+":)?"+${regextool.quote($username)} )
#end
#set($allows = {})
#set($denys = {})
## Get the rights for that user or group
#foreach($obj in $doc.getObjects($clsname)) ## $clsname = XWiki.XWikiGlobalRights or XWiki.XWikiRights
#set($pers = "$!obj.getProperty($uorg).getValue()")
#if(($pers != "") && (($pers.matches("^(.*,)?${usermatch}(,.*)?$")) ) )
#foreach($right in $!obj.getProperty('levels').getValue().split(","))
#set($right = $right.trim())
#if($right != "")
#if($obj.getProperty('allow').getValue() == 1)
#if($rightsWithAllowPrecedence.contains($right))
## If the same right is specified both as allow and deny, allow is stronger.
#set($discard = $allows.put($right, "1"))
#set($discard = $denys.remove($right))
#else
## If the same right is specified both as allow and deny, deny is stronger.
#if(!$denys.containsKey($right)) #set($discard = $allows.put($right, "1")) #end
#end
#else
#if($rightsWithAllowPrecedence.contains($right))
## If the same right is specified both as allow and deny, allow is stronger.
#if(!$allows.containsKey($right)) #set($discard = $denys.put($right, "1")) #end
#else
#set($discard = $denys.put($right, "1"))
## If the same right is specified both as allow and deny, deny is stronger.
#set($discard = "$!allows.remove($right)")
#end
#end
#end
#end
#end
#end ## foreach rights object
#set($row = {})
#set($discard = $row.put("username", $user.documentReference.name))
#set($discard = $row.put("fullname", $username))
#set($discard = $row.put("title" , $user.title))
#set($discard = $row.put("wikiname", $wikiname))
#set($discard = $row.put("userurl" , $xwiki.getURL($user.fullName)))
#set($discard = $row.put("allows" , $allows.keySet()))
#set($discard = $row.put("denys" , $denys.keySet()))
#if ($uorg == "groups")
#set($discard = $row.put("isuseringroup", $xwiki.getUser().isUserInGroup($user.fullName)))
#else
#set($discard = $row.put("isuseringroup", false))
#end
#set($discard = $rows.add($row))
#end ## foreach user in users
#set($discard = $userGroupsMap.put("rows" , $rows))
$jsontool.serialize($userGroupsMap)