Confluence, Atlassian’s popular collaborative wiki tool, offers a robust set of features that allow administrators to control and manage content visibility and user permissions. One such feature is the ability to grant or deny anonymous access. However, administrators often want to hide the anonymous access section from space permissions for various reasons, such as security or clarity.

In this article, we’ll walk you through the steps to hide the anonymous access section in Confluence space permissions using JavaScript.

Problem:

By default, Confluence allows space administrators to grant anonymous access to individual spaces, even if the global setting for anonymous access is disabled. This can be problematic, especially if the organization wishes to strictly control content visibility.

Solution:

To hide the anonymous access section from space permissions, you can use JavaScript snippets. Here are the scripts that can achieve this:

Hide Anonymous Access for Non-Admins

<script type="text/javascript">
    AJS.toInit(function(){
        if (!AJS.params.isConfluenceAdmin) {
            AJS.$('#aPermissionsTable').hide();
        }
    });
</script>

Hide Anonymous Access for All Users

This script hides the anonymous access section for all users.

<script type="text/javascript">
    AJS.toInit(function(){
        AJS.$('#aPermissionsTable').hide();
    });
</script>

Remove the Anonymous Section Entirely

If you want to remove the anonymous section entirely from the DOM (Document Object Model), this script will do the trick:

<script type="text/javascript">
    AJS.toInit(function(){
        if (AJS.$('table#aPermissionsTable').length > 0) {
            if (AJS.$('table#aPermissionsTable + form[name^=editspacepermissions]').length > 0) {
                AJS.$('.steptitle:contains("Anonymous Access")')
                    .nextUntil('table#aPermissionsTable + form#editspacepermissions')
                    .andSelf()
                    .add('table#aPermissionsTable + form#editspacepermissions')
                    .remove();
            } else {
                AJS.$('.steptitle:contains("Anonymous Access")')
                    .nextUntil('div.primary-button-container')
                    .andSelf()
                    .remove();
            }
        }
    });
</script>

How to Implement the Scripts

  1. Log in to Confluence as an administrator.
  2. Navigate to the Confluence admin panel.
  3. Go to General configuration.
  4. Click on Custom HTML.
  5. Paste the desired script at the end of the body.
  6. Save the changes.

Note: Implementing these scripts will not alter permissions stored in the database. If you wish to modify actual permissions, do so manually or use a database query.

By using the above scripts, administrators can enhance security by hiding or removing the anonymous access section from space permissions. Remember to always backup your Confluence instance before making any modifications.

Categorized in:

Tagged in: