Listing Space Admins on Page Not Found and Not Permitted pages

Somewhat related to this question... Know space administrators

I'd like to embed this list of Space Admins on the pages that come up most commonly when people try to email a link to someone that's not permitted to view it.

From poking around, I've noticed that the templates in question are primarily these three:

confluence/notpermitted.vm <- Space permissions
confluence/pages/pagenotpermitted.vm <- Page restrictions
confluence/404.vm <- Space and page restrictions (and 404)

Am I allowed to embed my own velocity code in there or does that void my warranty? Is there a less brutal option?

1 answer

1 accepted

1 vote
Answer accepted

This is what I've got so far. A new template I've added to the confluence directory...

confluence/spaceadmins.vm
#set($querystring=$req.getQueryString())
##&lt;p&gt;$querystring&lt;/p&gt; &lt;!--uncomment for debugging--&gt;
#if($querystring)
  ## Try pulling a spacekey out of the query string
  #if($querystring.toLowerCase().contains("key="))
    #set($pos1=$querystring.toLowerCase().indexOf("key=")+4)
    #set($pos2=$querystring.indexOf("&amp;",$pos1))
    #if($pos2==-1)
      #set($pos2=$querystring.length())
    #end
    #set($spacekey = $querystring.substring($pos1,$pos2))
  #elseif($querystring.contains("pageId="))
    #set($pos1=$querystring.indexOf("pageId=")+7)
    #set($pos2=$querystring.indexOf("&amp;",$pos1))
    #set($Integer = 0)
    #if($pos2==-1)
      #set($pos2=$querystring.length())
    #end
    #set($pageid = $querystring.substring($pos1,$pos2))
    #set($spacekey=$pageManager.getPage($Integer.parseInt($pageid)).getSpaceKey())
  #end
  ## Validate any spacekey we might have gotten
  #if($spacekey)
    #set($space=$spaceManager.getSpace($spacekey))
  #end
  #if($space)
    If you believe this is an error, please contact any of the
    &lt;a href="$req.contextPath/display/$space.getKey()"&gt;$space.getKey()&lt;/a&gt; Space Administrators below:
    &lt;ul&gt;
    #set($admincount=0)
    ## List groups...
    #foreach ($permission in $space.getPermissions())
      #if($permission.isGroupPermission() &amp;&amp; $permission.getType() == "SETSPACEPERMISSIONS")
        #set($admincount=$admincount+1)
        &lt;li&gt;
          #set ( $groupString = $permission.getGroup() )
          #set ( $groupObject = $userAccessor.getGroup($groupString) )
          #set ( $memberList = $userAccessor.getMemberNamesAsList($groupObject) )
          (group) $groupString &lt;a href="javascript:void(0);" onclick="AJS.$('.hidgroup_$admincount').show();AJS.$(this).hide();"&gt;[ expand ]&lt;/a&gt;
          &lt;ul class="hidgroup_$admincount" style="display:none"&gt;
             #foreach ($member in $memberList)
               #if(!$userAccessor.isDeactivated($member))
                 &lt;li&gt;#usernameLink($member)&lt;/li&gt;
               #end
             #end
          &lt;/ul&gt;
        &lt;/li&gt;
      #end
    #end
    ## List users...
    #foreach ($permission in $space.getPermissions())
      #if ($permission.isUserPermission() &amp;&amp; $permission.getType() == "SETSPACEPERMISSIONS")
        #if(!$userAccessor.isDeactivated($permission.getUserName()))
          #set($admincount=$admincount+1)
          &lt;li&gt;#usernameLink($permission.getUserName())&lt;/li&gt;
        #end
      #end
    #end
    &lt;/ul&gt;
    #if ($admincount==0)
      &lt;p&gt;
        No space administrators found, this space may have been deleted or abandoned.
        You may report this issue to the &lt;a href="$req.contextPath/contactadministrators.action"&gt;Site Administrators&lt;/a&gt;.
      &lt;/p&gt;
    #end
  #end
#end

Then I add this to the templates where ever it seems like a good place to list space admins:

#parse ( "/spaceadmins.vm" )

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 12, 2019 in Confluence

Confluence Admin Certification now $150 for Community Members

More and more people are building their careers with Atlassian, and we want you to be at the front of this wave! Important Dates Start the Certification Prep Course by 2 April 2019 Take your e...

1,353 views 2 13
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you