How to customize Velocity Template to allow only a Confluence administrator to delete a Space

Still need help?

The Atlassian Community is here for you.

Ask the community


Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

Deleting a Space in Confluence is a permanent action, meaning that there's no feature in the application that can revert the operation.

Using the Space Permissions, only the Space Administrator can delete a Space.

There may be environments on which the Confluence Administrator would need to control space deletion, revoking this permission from the Space Administrator.

While this isn't possible with the default granularity of Space Permissions, we can customize Confluence in a way on which only a Confluence Administrator can remove a Space.

This customization would be valid while the following feature request isn't implemented: CONFSERVER-1909 - Getting issue details... STATUS


This document is provided as-is

Confluence is flexible enough to allow some customization, however Atlassian's Support Offerings do not cover assistance on this area. Consequently, Atlassian cannot guarantee providing any support for them.

If any assistance with customization is required, please check one of the following channels:


Solution

Confluence relies on Velocity for many of its UI components.
The contents of the <confluence-install>/confluence/spaces/removespace.vm Velocity Template file controls the appearance of the Delete Space feature in the UI.

This is how this UI looks when using the default contents for that file (Confluence 7.9.0).


Follow the steps below to modify this template and allow only a Confluence Administrator to confirm the deletion of a Space:

  1. Access the Confluence server and go to <confluence-install>/confluence/spaces folder.
  2. Take a backup copy of removespace.vm.

    Original file contents as of Confluence 7.9.0 ...
    <html>
        <head>
            <title>$action.getText("title.remove.space")</title>
        </head>
    
        #applyDecorator("root")
            #decoratorParam("helper" $action.helper)
            #decoratorParam("context" "space-administration")
            #decoratorParam("mode"  "view-space-administration")
    
            <body>
                #applyDecorator ("root")
                    #decoratorParam ("context" "spaceadminpanel")
                    #decoratorParam ("selection" "removespace")
                    #decoratorParam ("title" "$action.getText('title.remove.space')")
                    #decoratorParam ("selectedTab" "admin")
                    #decoratorParam ("selectedSpaceToolsWebItem", "removespace")
                    #decoratorParam("helper" $action.helper)
    
                    #applyDecorator ("confirm")
    
                        <p>$action.getText("remove.space.desc")</p>
                        #if( $action.showLargeQueueWarning)
                            #applyDecorator("message" "$action.getText('info.word')")
                                #decoratorParam("type" "info")
                                $action.getText("com.atlassian.confluence.spaces.actions.RemoveSpaceAction.warn.large.indexqueue", [$action.indexQueueSize])
                            #end
                        #end
                        #applyDecorator ("message" "$action.getText('warning.word')")
                            #decoratorParam("type" "warning")
                            $action.getText('removespace.operation.cannot.be.undone')
                        #end
    
                        #decoratorParam ("formAction" "doremovespace.action?key=$htmlUtil.urlEncode($space.key)")
                        #decoratorParam ("formName" "removespaceform")
    
                        $action.getText("alert.remove.space", [$htmlUtil.htmlEncodeAndReplaceSpaces($space.key), $htmlUtil.htmlEncode($space.name)])
                    #end
                #end
    
            </body>
    
        #end
    </html>
    
    
    
  3. Edit the removespace.vm file and add a permission validation on top of the #applyDecorator ("confirm") code block as it is shown in the image below.

    Template with the suggested modifications...
    <html>
        <head>
            <title>$action.getText("title.remove.space")</title>
        </head>
    
        #applyDecorator("root")
            #decoratorParam("helper" $action.helper)
            #decoratorParam("context" "space-administration")
            #decoratorParam("mode"  "view-space-administration")
    
            <body>
                #applyDecorator ("root")
                    #decoratorParam ("context" "spaceadminpanel")
                    #decoratorParam ("selection" "removespace")
                    #decoratorParam ("title" "$action.getText('title.remove.space')")
                    #decoratorParam ("selectedTab" "admin")
                    #decoratorParam ("selectedSpaceToolsWebItem", "removespace")
                    #decoratorParam("helper" $action.helper)
    
                    #if( $permissionHelper.isConfluenceAdministrator($remoteUser) )
                        #applyDecorator ("confirm")
    
                            <p>$action.getText("remove.space.desc")</p>
                            #if( $action.showLargeQueueWarning)
                                #applyDecorator("message" "$action.getText('info.word')")
                                    #decoratorParam("type" "info")
                                    $action.getText("com.atlassian.confluence.spaces.actions.RemoveSpaceAction.warn.large.indexqueue", [$action.indexQueueSize])
                                #end
                            #end
                            #applyDecorator ("message" "$action.getText('warning.word')")
                                #decoratorParam("type" "warning")
                                $action.getText('removespace.operation.cannot.be.undone')
                            #end
    
                            #decoratorParam ("formAction" "doremovespace.action?key=$htmlUtil.urlEncode($space.key)")
                            #decoratorParam ("formName" "removespaceform")
    
                            $action.getText("alert.remove.space", [$htmlUtil.htmlEncodeAndReplaceSpaces($space.key), $htmlUtil.htmlEncode($space.name)])
                        #end
                    #else
                        #applyDecorator ("message" "$action.getText('info.word')")
                            #decoratorParam("type" "info")
                            <p>You don't have permission to delete this Space.</br>Please contact your Confluence administrator.</p>
                        #end
                    #end
                #end
    
            </body>
    
        #end
    </html>
    
    
    






  4. Save the file.
    1. If running Confluence on a Data Center cluster, apply the same modification on all nodes.


Then, if a Space Administrator tries to delete a Space, this is the UI that will be presented and only a Confluence Administrator will be able to see the Delete Space confirmation form (and actually delete it from the UI):


Some notes about this customization:

  • Confluence doesn't need to be restarted to have this modification applied.
  • This is only valid when performing the operation from the UI and a Space Administrator still could delete a Space through the REST API.
  • The removespace.vm file will be overwritten with any upgrade and you will need to reapply this modification after a succesfull upgrade, making sure it is still valid.



Last modified on Jan 26, 2021

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.