尝试开发一个宏,其中如果用户提供密钥,则后续处理: 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 :(得分:0)
添加条件以获取空格键并匹配n验证
## 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