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

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jul 10, 2018 in Confluence

We want to see the templates you've created in Confluence!

Hi Community, Jessica here from the Confluence Product Marketing team!  July’s community challenge is all about sharing pictures  — and as an extension of our first post on what ...

850 views 23 12
Join discussion

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