How to prevent user group from creating/editing a comment and Likes in Confluence

WW
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 28, 2023

Requirements

  • Allow a certain user group to only View comments. No:
    • Creating
    • Editing
    • Replying
    • Liking
    • Resolving
    • or any other interaction besides viewing
  • Applies to all types of comments in all places
    • Bottom of page
    • Inline
    • In Notifications area
    • From email notifications
    • Pages and blogs
    • Anywhere else they may be hiding
  • Must be global, not by space or page
  • Do not hide comments altogether from group
  • Cannot cause performance impacts - it's a huge instance
  • Can just hide an element but still be accessible (or not) via URL
  • Preferably, no server-side file updates would be involved
  • Will need page likes to be hidden at some point, too - very nice to have

Tools

  • Confluence Data Center 7.19.2 (will be 8.x soon)
  • ScriptRunner
  • Open to plugin suggestions that cover all requirements

What I've tried

Help!

If it's ScriptRunner, just point me in the right direction, and I'll get there.

If there's some other magical way to do this, please let me know.

Thank you in advance!

 

1 answer

0 votes
Pankaj Jangid
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 10, 2023

To prevent a certain user group from creating, editing, replying, or liking comments in Confluence while still allowing them to view comments, you can use ScriptRunner for Confluence. Here are the steps you can follow:

  1. Create a new Script Fragment in ScriptRunner for Confluence. This can be done by navigating to the Script Fragments section in the ScriptRunner Console.

  2. In the Script Fragment, use the following code to hide the elements related to commenting and liking:

    AJS.toInit(function(){
      // Replace 'groupname' with the name of your user group
      if(AJS.$('.comment').length > 0 && !AJS.$('.user-group-groupname').length){
        AJS.$('.comment').remove();
        AJS.$('.comment-reply').remove();
        AJS.$('.comment-likes').remove();
      }
    });

     

    This code will remove the elements related to commenting and liking if the user is not a member of the specified group. You can adjust the group name as needed.
  3. Save the Script Fragment.

  4. Create a new Layout in Confluence. This can be done by navigating to the Layouts section in the Confluence Administration console.

  5. In the Layout, use the following code to include the Script Fragment:

    #if($!remoteUser.groups.contains("groupname"))
    <script src="/s/-/s/atlassian-scriptrunner-webresources/translations/latest/all.js"></script>
    <script src="/s/-/s/atlassian-scriptrunner-webresources/fragments/1.0.0/run.fragment.js"></script>
    #end

    This code will include the Script Fragment only if the user is a member of the specified group. Again, you can adjust the group name as needed.

  6. Save the Layout and set it as the default Confluence Layout.

This approach should hide the elements related to commenting and liking for users who are not members of the specified group, while still allowing them to view comments. Note that this approach does not hide the comments altogether, so they will still be accessible via the URL. Also, you may need to adjust the code to hide page likes as well, but the basic approach should be similar.

WW
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 17, 2023

Hi @Pankaj Jangid ,

Thank you for replying. I already have the main comments hidden though as I stated:

 

  • ScriptRunner Fragment to Hide Elements - partially works
    • Hid all elements with "Like" or "Comment" in the name
    • This only worked on the:
      • bottom of page comments
      • pop-up for inline commenting when highlighting text - it hid the comment pop-up

The ScriptRunner Fragment to Hide Elements actually already does most of the work for you, So you don't need JavaScript or to update a Layout.

I'm slowly finding round about ways of hiding the bits and pieces of Confluence for this user group that I need to. It's hacky, but so far, it's all I can come up with.

Inline comments are giving me fits.

Pankaj Jangid
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 17, 2023

I see, my apologies for misunderstanding. In that case, to hide inline comments for the specific user group, you can try adding custom CSS to the page. You can do this by going to the page and clicking on the "..." button in the top right corner, then selecting "Edit" > "Edit in HTML".

Once you're in the HTML editor, you can add the following CSS code to hide the inline comment button and tooltip:

/* Hide inline comment button */
a[data-type="inline-comment"] {
  display: none !important;
}

/* Hide inline comment tooltip */
div[data-tooltip*="inline-comment"] {
  display: none !important;
}

This should only hide the inline comment button and tooltip for the specific user group while leaving it visible for everyone else.

Note that this solution relies on CSS, so it may not be completely foolproof and could potentially be circumvented by determined users. However, it should work in most cases and is relatively simple to implement.

WW
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 20, 2023

Hi @Pankaj Jangid ,

I'm not sure how hiding the inline comments section on one page will fit my requirements, including how it would hide for a specific group.

  • Must be global, not by space or page

I'm also running Confluence Data Center 8.0.2, not Cloud. DC doesn't have ... Edit -> Edit in HTML. I know I could put it in an HTML macro, but it'd still not fit the global requirement that way.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events