2017-03-07 29 views
0

嘗試開發一個宏,其中如果用戶提供密鑰,則應遵循以下流程: 1.驗證密鑰是否存在並顯示空間標題 2.獲取空間管理員。匯合宏:獲得空間管理員

了宏觀的從谷歌,能夠執行第二次,但第一個是棘手的檢查(新的宏觀和融合

## Macro title: Space Administrators 
## Macro has a body: Y or N (N) 
## Body processing: Selected body processing option 
## Output: Selected output option 
## usage: {getspacekey: spacekey1} 
## Installed by: Piyush Annadate 

## Macro to list all users and groups with the permission to administer the  current space. 
## @param 0:title=Space Key|type=string|required=true 

#if ($param0) 
## trim and test for illegal characters 
#set ($spacekey1= $param0.trim()) 
#if ($spacekey1.matches("[a-zA-Z0-9]+")) 

    <h1>Space Adminstrators</h1> 

    <p>The following users and groups have permission to administer the <strong>$spacekey1</strong> Space.</p> 

    <h2>Users</h2> 
    <table class="confluenceTable"> 
     <tr> 
     <th class="confluenceTh">Space Administrators</th> 
     </tr> 
     #foreach ($permission in $space.getPermissions()) 
     #if ($permission.isUserPermission() && $permission.getType() == "SETSPACEPERMISSIONS") 
      <tr> 
      <td class="confluenceTd">#usernameLink($permission.getUserName())</td> 
      </tr> 
     #end 
    #end 
    </table> 

    <h2>Groups</h2> 
    #foreach ($permission in $space.getPermissions()) 
     #if ($permission.isGroupPermission() && $permission.getType() == "SETSPACEPERMISSIONS") 
     #set ($groupString = $permission.getGroup()) 
     #set ($groupObject = $userAccessor.getGroup($groupString)) 
     #set ($memberList = $userAccessor.getMemberNamesAsList($groupObject)) 

     <h3>$groupString</h3> 
     <table class="confluenceTable"> 
      <tr> 
      <th class="confluenceTh">Space Administrators</th> 
      </tr> 


      #foreach ($member in $memberList) 
      <tr> 
       <td class="confluenceTd">#usernameLink($member)</td> 
      </tr> 
      #end 
     </table> 
     #end 
    #end 
#else 
    Space key {color:red} is invalid.Space key is not available or does not matched a-z, A-Z, 0-9 pattern. {color} 
#end 
#end 

回答

0

添加條件得到空格鍵和匹配ñ驗證

## Macro title: Space Administrators 
## Macro has a body: Y or N (N) 
## Body processing: Selected body processing option 
## Output: Selected output option 
## 
## Developed by(Modified): Piyush Annadate 
## Date Installed: 03/03/2017 
## Installed by: Piyush Annadate 

## Macro to list all users and groups with the permission to administer the current space. 

##Changes done: Added conditions: 
## @param TargetSpace:title=Target space|type=string|desc=Enter the KEY of the space you want admin details for. For example, coredoc, gscontent, samples, wncontent|required=true|multiple=false 

## trim and test for illegal characters 
#set ($paramTargetSpace= $param0.trim()) 
#set ($targetSpace = $spaceManager.getSpace($paramTargetSpace)) 
#if ((!$paramTargetSpace.matches("[a-zA-Z0-9]+")) && !$targetSpace) 
    Space key is {color:red}invalid{color}.Provided key does not matched a-z, A-Z, 0-9 pattern. 
#end 
#if (($paramTargetSpace.matches("[a-zA-Z0-9]+")) && !$targetSpace) 
    No space exists with <strong>$paramTargetSpace</strong> key. 
#end 
##END OF CHANGES 
#if ($targetSpace) 
    <h1>Space Adminstrators</h1> 

    <p>The following users and groups have permission to administer the <strong>$space.getName()</strong> Space.</p> 

    <h2>Users</h2> 
    <table class="confluenceTable"> 
     <tr> 
     <th class="confluenceTh">Space Administrators</th> 
     </tr> 
     #foreach ($permission in $targetSpace.getPermissions()) 
     #if ($permission.isUserPermission() && $permission.getType() == "SETSPACEPERMISSIONS") 
      <tr> 
      <td class="confluenceTd">#usernameLink($permission.getUserName())</td> 
      </tr> 
     #end 
    #end 
    </table> 

    <h2>Groups</h2> 
    #foreach ($permission in $targetSpace.getPermissions()) 
     #if ($permission.isGroupPermission() && $permission.getType() == "SETSPACEPERMISSIONS") 
     #set ($groupString = $permission.getGroup()) 
     #set ($groupObject = $userAccessor.getGroup($groupString)) 
     #set ($memberList = $userAccessor.getMemberNamesAsList($groupObject)) 

     <h3>$groupString</h3> 
     <table class="confluenceTable"> 
      <tr> 
      <th class="confluenceTh">Space Administrators</th> 
      </tr> 


      #foreach ($member in $memberList) 
      <tr> 
       <td class="confluenceTd">#usernameLink($member)</td> 
      </tr> 
      #end 
     </table> 
     #end 
    #end 
#end 
+0

請簡而言之,你已經改變了什麼。 – ppasler