Using CSS to hide specific elements based on user role

Hey there!

I am new to being a discourse admin, and just discovered that moderators have almost the same access as administrators. In addition, there is a lack of control as to what access/abilities moderators have.

My main concerns are that Moderators can…
A) Access Private Messages of any user.
B) Access the reports area.
C) Other areas of concern I have yet to find!

So I began to search for a solution, and gave up after reading the post from a co-founder that states…

…so it appears I have to take the matters into my own hands to somehow limit a moderators access.


Here are some solutions I can think of…
Please feel free to correct me or share something better.

A) Discontinue the moderator option, and instead create a new user group/trust level based on a more conservative level of access.

B) Add some JavaScript to disable the reports tab and prevent moderators from accessing private messages.

C) Add some target based CSS to hide the areas I don’t want moderators to see.


Using CSS Targeting to hide the reports tab in the Admin Dashboard.

Due to my lack of know-how, I have resorted to the less preferred option of using CSS to hide specific areas. I found success with hiding the Reports tab for all mods & admins using…

li.navigation-item .reports {
   display: none !important;
}

But I need it to only target moderators. So I tried modifying the code from HERE which specifies how to target specifically moderators using CSS and change their username color. So I tweaked it below, but am unable to get it to work.

li.navigation-item {
  &.moderator {
    .reports {
      display: none !important;
    }
  }

  &.admin {
    .reports {
      display: inline;
    }
  }
}

Is anyone able to help show me what I am doing wrong with the CSS targeting, or provide me with a better solution to this problem?

Thanks so much.

Hello and welcome @UnitedFreedom :slight_smile:

Any CSS changes would only be cosmetic, and could easily be sidestepped by tweaking the page in the browser console. However…

Just to put your mind at ease, Moderators don’t have unfettered access to Personal Messages, they can only view them if someone flags one. :+1: (As opposed to Admins, who can see everything on the site)

I don’t think the reports are particularly sensitive and can be quite useful for moderators to have access to, but there are a couple of admin settings that target the report/dashboard area that you may find useful (though they would apply to both Mods and Admin):

  • You can hide the Reports tab without using custom CSS by using the dashboard visible tabs admin setting (though they could still access the page using the /admin/dashboard/reports link.
  • The dashboard hidden reports admin setting can remove specific reports from the list (you’d need to use their names, which you can get from their URL. eg Admin Logins would be staff_logins)
  • You can choose what to display on the dashboard using dashboard general tab activity metrics

There are also a few extra admin settings that are disabled by default, but would allow moderators to view emails, change post ownership, and create and manage categories and groups:

However, if you think full mods have too much power for your site you could opt for Category Moderation instead. This would elevate certain groups to have enhanced powers for specific categories. They would have access to the Review Queue for flags and post approvals for their categories, as well as edit, delete, split, merge, etc but not have the full suite of powers and access a Moderator would have.

You can see an overview of the differences in Trust Level Permissions Table (inc Moderator Roles)

You can enable Category Moderation using the enable category group moderation admin setting, and then setting a group per category in the Settings tab of the category wrench menu:

Making some highly trusted users TL4s can also be really useful to assist with moderation too.

7 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.