Prevent users from moving topics in other categories

I’m looking for an option to disable this feature as it may cause some complexity in managing threads when you have different moderators teams for different categories and suddenly they find themselves with a big or controversial thread in their category without prior notice.

I’ve read here Access rights for moving a topic to another category but it says that this is something that only Trust Level 3 should be able to do. I’ve a test environment in which a Trust Level 2 user was able to do that.

I tried to enable the “disable editing after staff edit a post” but it didn’t seem to affect the ability to change category for a thread.

Am I missing something here? I probably am :smiley:


Not sure would need to do some testing. A category group mod may still be able to move a topic via edit or move command.

You may want to look into the plugin Custom Trust Levels as well.

I checked that and will take it into consideration but I’ll try first to create a simple component that hide that select for editing except for staff.

I prefer plugins that does simple things :slight_smile:

1 Like

@Canapin provided me code to hide like button from groups not within a specified groups.

It may give you a good baseline to work from.

fixed link


Thank you so much @Heliosurge (and the ubiquitous @Canapin :stuck_out_tongue: ) I was just thinking of where I could look for a similar plugin to use as example :slight_smile:


Your quite welcome! The team and this community are awesome in my xp. :beers::sunglasses::+1:

1 Like

I gave it a look, it’s a good MVP but the community I look for is quite tech savvy and it would be better if the DOM would entirely skip drawing that component instead of simply hiding it from view.

Would that require a plugin or is it something I could achieve anyway with a component?

What I need to do, roughly is basically determine if the HTML for that select is generated or not, based on the role.

1 Like

I’m pretty sure a component would suffice.

1 Like

I’m not a coder.

To hide the category selector when you edit the first post (from the edit post action, not the edit title), this works:

<script type="text/discourse-plugin" version="1.6.0">
    let currentUser = api.getCurrentUser();
    api.modifyClass("component:composer-title", {
      pluginId: "PreventCategoryChange",
      didInsertElement: function() {
        if(currentUser.trust_level == 1) {
            let categoryInput = document.getElementsByClassName('category-input')[0];
            let miniTagChoser = document.getElementsByClassName('mini-tag-chooser')[0];
            if(categoryInput != null) {
                if(miniTagChoser != null) {
           = '0';


I used the trust level, but I think you can manage to check the user group instead, it’s all in the currentUser object.

I don’t know how to dynamically remove the category selector when we edit the title.
Maybe you can figure it out from the files that seems related:

discourse/topic.hbs at 53695e7d29e718041fa53bf4fef21e02354a4088 · discourse/discourse · GitHub

discourse/topic.js at 8fc11215e195a5bd8db130f52717c126c119432b · discourse/discourse · GitHub


Thank you so much @Canapin

I’ll need to add something also for the edit from the title but this definitely help already :slight_smile:

When it’s done, I’ll post it in the theme components section here so other may use it :wink:


This discourse/topic.hbs at 53695e7d29e718041fa53bf4fef21e02354a4088 · discourse/discourse · GitHub

seems to be the right handle to access, now if someone knows how to interact with it via theme component… :stuck_out_tongue:

1 Like

For the love of the gods I can’t find a hook to detect when the title editing is being triggered. Anyone knows what I could listen for?

The hiding of category change when editing the first message of a topic works, it detects only when being in editing mode and all.

1 Like

Alright, thanks to a good friend who suffer from insomnia we figure out where to find the right hook :stuck_out_tongue:

Here is it, it also adjust the form visuals and allow to select a minimum trust level from which the access to editing category will be available anyway (default trust level 0 to be in line with default discourse settings)

I’ll go create a new topic in the plugin section now.

Thanks a LOT @Canapin for pointing us in the right direction at the start :heart_eyes:


I looked at your code, great work :+1:

I believe you taught me more to me than the opposite!

Just a note, what you created is a theme-component, not a plugin :slight_smile:


Just to note, a TL3 and TL4 can recategorise any topic as long as trusted users can edit others is enabled. A TL0/1/2 should only be able to do it on their own topic, and only within their editing period [1]. If you lock the first post using the post wrench then that should also stop the category (and title and tags) from being edited.

I’m not 100% sure I’m following your use case, but I’m glad you found a solution. :slightly_smiling_face::+1:

  1. set by post edit time limit for TL0 and TL1 and tl2 post edit time limit for TL2 and TL3 ↩︎


Ah, yes, I wasn’t aware of this option:

It prevents any further modification (except being deleted) even from a category moderator.

But a first post lock can’t be automated from a topic timer nor an automated task.

1 Like

Yes, I was aware of it.

However, my intent was to prevent the moderators to have to deal with several occurrence of category hopping which may lead to complication in the moderation when a topic is first in a category, then move into another etc etc

1 Like

I think it would be important to add since it’s a theme component, a user can circumvent these limitations by injecting javascript (I think) or enabling the safe mode if it’s available for them (see enable safe mode setting).

You need a plugin if you want a more secure way to do it.


Yes, that’s why I was looking into plugins as well but for a first version, a component is enough.

1 Like

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