How to prevent user group from creating/editing a comment and Likes in Confluence
Asked by WW:

Requirements {#toc-hId--492817473}
----------------------------------

* 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 {#toc-hId-1994695360}
---------------------------

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

What I've tried {#toc-hId-187240897}
------------------------------------

* **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
* **CSS** affects everyone, not a group
* **Space permissions** don't have negative permissions
* Found **no plugins** that meet requirements
* [How to display different appearance for different users using Confluence layouts](https://confluence.atlassian.com/confkb/how-to-display-different-appearance-for-different-users-using-confluence-layouts-296911031.html)

  * and [Hide element based on group membership and pageid](https://community.atlassian.com/t5/Confluence-questions/Hide-element-based-on-group-membership-and-pageid/qaq-p/1222018)
  * promising, but I don't know **what the elements are all called,**how to find their names, or if the elements are even hide-able

Help! {#toc-hId--1620213566}
----------------------------

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!


Answers:
author: Pankaj Jangid
body: 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.

comments: author: WW
body: Hi [@Pankaj Jangid](/t5/user/viewprofilepage/user-id/853501) ,

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.


author: Pankaj Jangid
body: 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.


author: WW
body: Hi [@Pankaj Jangid](/t5/user/viewprofilepage/user-id/853501) ,

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.


Tags: comment

confluence-server

data-center

hide

like

server