How to create a theme which only administrators can use?

How to create a theme, not which only administrators can use?

I’m not sure I know what you mean. Could you go into a little more detail?

1 Like

A lot of problems happen in my forum, I already commented here on meta about it, and as I couldn’t disable the moderators dangerous functions, because the Discourse doesn’t have that option, I made a kludge through CSS, to remove the options that are dangerous for my forum in which they have access , when I did it via CSS it turned out that it was taken from me too, options like see IP, ban, delete all posts etc… I took it out of all themes, I would like to leave only one theme without CSS so I can see the options, but that only I can use this theme

1 Like

i don’t know why you are using CSS and themes to manage your moderators, but, that’s not how you do it. use trust levels to make category mods and also choose your mods more carefully. you are likely just creating more problems for yourself by trying to limit moderator functions via CSS and themes.

1 Like

I solved all my problems by modifying my moderators roles via CSS. It’s a very complex situation and the only real solution was this. I already tried category moderation and it was not viable for my forum, it was not interesting for the demand. The only way that solved my problems was the modifications via CSS. As Discourse leaves the same moderator options to admin, this was the only solution. But now I just need a way for me to be able to use a theme that doesn’t have CSS modifications. So I don’t have to turn it off every time I use it.

I’m going to tell you a little bit about what happened: I live in Brazil, here there are 214.3 million inhabitants, most of them unemployed and without purchasing power. A lot of people use the internet as a means of entertainment, so my forum fits that. But the existence of my forum threatens another forum a lot, which has already made NUMEROUS attacks on mine, and has already bought a lot of my moderators, countless moderators have already deleted users, deleted messages, leaked IPs to others, really destroyed me. I’ve already spent months without any moderators, but it’s very difficult to have a forum without a moderator, I want to put moderators back, but it’s no use choosing well, I don’t know how the culture of the Nordic countries is, but at least in the culture of the sector from forums in my country, people don’t take it very seriously and are easily corrupted, one time or another money talks louder and they can use their powers to destroy my forum, the only solution I have is that the moderators don’t have the same powers as administrators, and that was the only thing that solved it, through CSS.

1 Like

I had already made a topic about this, which started a big debate that went nowhere, many advised me to choose moderators better, so I could have a sense of criteria and choose more reliable people, well, but that doesn’t apply to the world forums I’m on, the only solution was to take some powers away from the moderators (IP, Ban, Delete all posts, check email etc) but that affected me too.

Hello :wave:

You can use Safe Mode (just like your moderators) to disable themes.

With custom sections you can make your quick route to /safe-mode

  1. Create a custom section to your sidebar like this.


    This should looks like this. (Add a title, Name and Link /safe-mode) Be sure you don’t check the Make this section public and visible to everyone checkbox.

  2. It will place in the Navigation Menu (sidebar) custom section.

  3. Here you can disable the themes and theme components. Click Enter Safe Mode button.

4 Likes

Maybe check out category moderators?

2 Likes

If a bad actor discovers safe mode your CSS countermeasures will be ineffective.

The only way to secure Discourse is by careful assignment of privileges via the back end.

4 Likes

That is to say that you would need a custom plugin that made those changes. Unless you have a budget (maybe $1000 to $5000?) , you’ll need to try category moderators or tl4.

2 Likes

They already talked about it here: :slight_smile:

1 Like

I think it should be possible to make the theme component hide the stuff for everyone except for admins.

But safe mode would still be an easy bypass. Maybe a quick and dirty plugin could disable those features without as much time as I originally estimated.

1 Like

I agree with pretty much everything everyone has said here.

If you really want to go the CSS way, here’s how you can make your CSS modifications only apply to non-admins:

In the Head tab of your theme, write this:

<script type="text/discourse-plugin" version="1.4.0">
    let currentUser = api.getCurrentUser();
    if (currentUser.admin == true) {
         document.querySelector("body").classList.add("is-admin");
    }
</script> 

Wrap all your CSS rules with body:not(.is-admin) { (your CSS) } such as:

body:not(.is-admin) {
    #main {
        background: pink;
    }
}

In my example, the pink background will be applied to everyone but the admin users.

3 Likes

Discourse automatically adds group-based classes to the <body> so it should be possible to skip the JS and do something like

body:not(.group-admins) #main { background: pink; }

I don’t have other group-specific class than staff as an admin on my test instance (last Discourse version):

<body class="chat-enabled staff has-sidebar-page navigation-topics docked"

As far as I can see, neither in <html> nor any other tag.

On meta, we use CSS Classes for Current User's Groups, which could also be used in daniela’s case. :slight_smile:

2 Likes

Ahhhhh that’s what confused me - I was just looking on Meta :man_facepalming: Thanks @Canapin

3 Likes

I LOVE YOU SO MUCH

Thank you for showing me this, I couldn’t solve this problem for more than 1 year

2 Likes