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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

1,891 views 25 10
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