2017-03-07 73 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

相关问题