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

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. 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 - Space Administrators should not be able to Remove a space

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).

(Auto-migrated image: description temporarily unavailable)

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 ...

  3. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 <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>

    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 suggested modifications:

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 <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>

    (Auto-migrated image: description temporarily unavailable)
    (Auto-migrated image: description temporarily unavailable)

  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, they will be presented with a message that only a Confluence Administrator can see the Delete Space confirmation form (and actually delete it from the UI): "You don't have permission to delete this Space. Please contact your Confluence administrator."

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.

Updated on February 28, 2025

Still need help?

The Atlassian Community is here for you.