%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/waritko/jetty-distribution-9.4.21.v20190926/webapps/ROOT/templates/
Upload File :
Create Path :
Current File : //home/waritko/jetty-distribution-9.4.21.v20190926/webapps/ROOT/templates/saverights.vm

#set($fullname = $request.get("fullname"))
#set($uorg = $request.get("uorg"))
#set($right = $request.get("right")) ## right name: edit, view, comment...
#set($action = $request.get("action"))  ## can be allow, deny or clear(delete) that right
#set($clsname = $request.get("clsname"))
## found allow or deny for the user or group
#set($founda = false)
#set($foundd = false)

#if ($!{services.csrf.isTokenValid("$!{request.getParameter('form_token')}")})
#foreach($obj in $doc.getObjects($clsname)) ## XWiki.XWikiGlobalRights or XWiki.XWikiRights
  #set($pers = "$!obj.getProperty($uorg).getValue()")
  #if($pers.matches("${regextool.quote($fullname)},?")) ## found the rule containing that person
    #set($levels = "$obj.getProperty('levels').getValue()") ## get the levels
    #if($obj.getProperty('allow').getValue() == 1) ## found allow rule
      ### if action = allow, add the right to the allow rule, if it does not exist; 
      ### if action = deny, remove the right from the allow rule, if exists;
      ### if action = clear, remove the right from the allow rule, if exists
      #set($founda = true)
      #if($action == "allow")
        #if(!$levels.matches(".*\b${right}\b.*")) ## the right is not in the allow list, add it
          #set($levels = $levels + "," + $right)
          
##1. person: $pers; rule: allow; action: allow; levels: $levels
          $doc.getObject($clsname, $obj.number).set('levels', $levels) ## set the new levels
        #end
      #else ## deny or clean action
        #set($i = $levels.indexOf($right))
        #if($i > -1) ## the right was found in the allow levels, remove it
          #if($i == 0)
            #set($levels = $levels.replaceAll("\b${right}(,|$)", ""))
          #else
            #set($levels = $levels.replaceAll(",${right}\b", ""))
          #end
        #end

##2. person: $pers; rule: allow; action: deny/clean; levels: $levels
        #if($levels != "")
          $doc.getObject($clsname, $obj.number).set('levels', $levels) ## set the new levels
        #else ## no other righs in the levels, remove the rule completely
          #set($discard = $doc.removeObject($obj))
        #end
      #end
    #else ## found deny rule
      #set($foundd = true)
      ### if action = allow, delete the right from the deny rule, if exists; 
      ### if action = deny, add the right to the deny rule, if it does not exist;
      ### if action = clear, remove the right from the deny rule, if exists
      #if($action == "deny")
        #if(!$levels.matches(".*\b${right}\b.*")) ## the right is not in the allow list, add it
          #set($levels = $levels + "," + $right)

##3. person: $pers; rule: deny; action:deny; levels: $levels
          $doc.getObject($clsname, $obj.number).set('levels', $levels) ## set the new levels
        #end
      #else ## allow or clean action
        #set($i = $levels.indexOf($right))
        #if($i > -1) ## the right was found in the allow levels, remove it
          #if($i == 0)
            #set($levels = $levels.replaceAll("\b${right}(,|$)", ""))
          #else
            #set($levels = $levels.replaceAll(",${right}\b", ""))
          #end
        #end

##4. person: $pers; rule: deny; action: allow/clean; levels: $levels
        #if($levels != "")
          $doc.getObject($clsname, $obj.number).set('levels', $levels) ## set the new levels
        #else ## no other righs in the levels, remove the rule completely
          #set($discard = $doc.removeObject($obj))
        #end
      #end
    #end ## end get property
  #elseif($pers.matches("^(.*,)?${regextool.quote($fullname)}(,.*)?$")) ## The person is in a multiple selection rule, remove it from there.
    #set($pers = $pers.replaceAll("^${fullname}(,|$)", ""))
    #set($pers = $pers.replaceAll("(^|,)${fullname}(,|$)", "$2"))
    $doc.getObject($clsname, $obj.number).set($uorg, $pers)

##5. person: $pers
  #end
#end ## end foreach existing rule

#if(($founda == false) && ($action == "allow"))
  ## could not find the rule -> create one
  #set($obj = $doc.newObject($clsname))
  ## set the new rules
  $obj.set($uorg, $fullname)
  $obj.set('levels', $right)

##6. person: $fullname; rule: allow; action: allow; levels: $right
  $obj.set('allow', '1')
#end
#if(($foundd == false) && ($action == "deny"))
  ## could not find the rule -> create one
  #set($obj = $doc.newObject($clsname))
  ## set the new rules
  $obj.set($uorg, $fullname)
  $obj.set('levels', $right)

##7. person: $fullname; rule: deny; action: deny; levels: $right
  $obj.set('allow', '0')
#end
$doc.save($services.localization.render('platform.core.rightsManagement.saveComment', [${action}, ${right}, ${fullname}]), true)
SUCCESS
#end

Zerion Mini Shell 1.0