# Prevent users from moving topics in other categories

**URL:** https://meta.discourse.org/t/prevent-users-from-moving-topics-in-other-categories/255933
**Category:** Development
**Created:** [February 22, 2023, 1:08pm UTC](https://meta.discourse.org/t/prevent-users-from-moving-topics-in-other-categories/255933 "2023-02-22T13:08:26Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Crius](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/crius/32/317214_2.png) [@Crius](https://meta.discourse.org/u/Crius)
#### Post date: [February 22, 2023, 1:08pm UTC](https://meta.discourse.org/t/prevent-users-from-moving-topics-in-other-categories/255933/1 "2023-02-22T13:08:26Z")

</div>

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](https://meta.discourse.org/t/access-rights-for-moving-a-topic-to-another-category/133435) 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 😃

---

<div class="post-metadata">

### Author: ![Heliosurge](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/heliosurge/32/571810_2.png) [@Heliosurge](https://meta.discourse.org/u/Heliosurge)
#### Post date: [February 22, 2023, 5:17pm UTC](https://meta.discourse.org/t/prevent-users-from-moving-topics-in-other-categories/255933/2 "2023-02-22T17:17:48Z")

</div>

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 #Customization > Plugin Custom Trust Levels as well.

---

<div class="post-metadata">

### Author: ![Crius](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/crius/32/317214_2.png) [@Crius](https://meta.discourse.org/u/Crius)
#### Post date: [February 22, 2023, 6:01pm UTC](https://meta.discourse.org/t/prevent-users-from-moving-topics-in-other-categories/255933/3 "2023-02-22T18:01:50Z")

</div>

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 🙂

---

<div class="post-metadata">

### Author: ![Heliosurge](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/heliosurge/32/571810_2.png) [@Heliosurge](https://meta.discourse.org/u/Heliosurge)
#### Post date: [February 22, 2023, 6:25pm UTC](https://meta.discourse.org/t/prevent-users-from-moving-topics-in-other-categories/255933/4 "2023-02-22T18:25:05Z")

</div>

@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.

> [@Looking to hide Likes & Decorate Op](https://meta.discourse.org/t/looking-to-hide-likes-decorate-op/255729/2):
>
> You can hide the like button with CSS, but that won’t prevent users from liking posts (a plugin would be required to ensure that), if they figure out how to un-hide the button for example. I suppose the easiest way would be using [CSS Classes for Current User's Groups](https://meta.discourse.org/t/css-classes-for-current-users-groups/226068) which adds the current user groups to the body classes, then use CSS such as: body.category-your-category-slug:not(.group-group\_name) { button.like { display: none; } } Let me know if you have trouble understandi…

fixed link

---

<div class="post-metadata">

### Author: ![Crius](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/crius/32/317214_2.png) [@Crius](https://meta.discourse.org/u/Crius)
#### Post date: [February 22, 2023, 6:47pm UTC](https://meta.discourse.org/t/prevent-users-from-moving-topics-in-other-categories/255933/5 "2023-02-22T18:47:50Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Heliosurge](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/heliosurge/32/571810_2.png) [@Heliosurge](https://meta.discourse.org/u/Heliosurge)
#### Post date: [February 22, 2023, 6:49pm UTC](https://meta.discourse.org/t/prevent-users-from-moving-topics-in-other-categories/255933/6 "2023-02-22T18:49:21Z")

</div>

Your quite welcome! The team and this community are awesome in my xp. 🍻😎👍

---

<div class="post-metadata">

### Author: ![Crius](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/crius/32/317214_2.png) [@Crius](https://meta.discourse.org/u/Crius)
#### Post date: [February 22, 2023, 7:39pm UTC](https://meta.discourse.org/t/prevent-users-from-moving-topics-in-other-categories/255933/7 "2023-02-22T19:39:06Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [February 22, 2023, 10:18pm UTC](https://meta.discourse.org/t/prevent-users-from-moving-topics-in-other-categories/255933/8 "2023-02-22T22:18:20Z")

</div>

I’m pretty sure a component would suffice.

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [February 22, 2023, 10:56pm UTC](https://meta.discourse.org/t/prevent-users-from-moving-topics-in-other-categories/255933/9 "2023-02-22T22:56:01Z")

</div>

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:

```js
<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) {
                categoryInput.remove();
                if(miniTagChoser != null) {
                    miniTagChoser.style.marginLeft = '0';
                }
            }
        }
      }
    });
</script>

```

![chrome_NTAAc37JXB](https://global.discourse-cdn.com/meta/original/4X/9/2/1/92106025090a0cbb19f99a970b7fa59736c3c7ae.gif)

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/app/assets/javascripts/discourse/app/templates/topic.hbs at 53695e7d29e718041fa53bf4fef21e02354a4088 · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/53695e7d29e718041fa53bf4fef21e02354a4088/app/assets/javascripts/discourse/app/templates/topic.hbs)

[discourse/app/assets/javascripts/discourse/app/controllers/topic.js at 8fc11215e195a5bd8db130f52717c126c119432b · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/8fc11215e195a5bd8db130f52717c126c119432b/app/assets/javascripts/discourse/app/controllers/topic.js)

---

<div class="post-metadata">

### Author: ![Crius](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/crius/32/317214_2.png) [@Crius](https://meta.discourse.org/u/Crius)
#### Post date: [February 23, 2023, 12:30am UTC](https://meta.discourse.org/t/prevent-users-from-moving-topics-in-other-categories/255933/10 "2023-02-23T00:30:43Z")

</div>

Thank you so much @Canapin

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

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

---

<div class="post-metadata">

### Author: ![Crius](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/crius/32/317214_2.png) [@Crius](https://meta.discourse.org/u/Crius)
#### Post date: [February 23, 2023, 12:35am UTC](https://meta.discourse.org/t/prevent-users-from-moving-topics-in-other-categories/255933/11 "2023-02-23T00:35:19Z")

</div>

This [discourse/app/assets/javascripts/discourse/app/templates/topic.hbs at 53695e7d29e718041fa53bf4fef21e02354a4088 · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/53695e7d29e718041fa53bf4fef21e02354a4088/app/assets/javascripts/discourse/app/templates/topic.hbs#L59)

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

---

<div class="post-metadata">

### Author: ![Crius](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/crius/32/317214_2.png) [@Crius](https://meta.discourse.org/u/Crius)
#### Post date: [February 23, 2023, 4:27pm UTC](https://meta.discourse.org/t/prevent-users-from-moving-topics-in-other-categories/255933/12 "2023-02-23T16:27:24Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Crius](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/crius/32/317214_2.png) [@Crius](https://meta.discourse.org/u/Crius)
#### Post date: [February 24, 2023, 10:08am UTC](https://meta.discourse.org/t/prevent-users-from-moving-topics-in-other-categories/255933/13 "2023-02-24T10:08:42Z")

</div>

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

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)

> **[GitHub - netgamers-forum/discourse-restrict-edit-category](https://github.com/netgamers-forum/discourse-restrict-edit-category)**
>
> Contribute to netgamers-forum/discourse-restrict-edit-category development by creating an account on GitHub.

I’ll go create a new topic in the #Customization > Plugin section now.

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

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [February 24, 2023, 10:25am UTC](https://meta.discourse.org/t/prevent-users-from-moving-topics-in-other-categories/255933/14 "2023-02-24T10:25:29Z")

</div>

I looked at your code, great work 👍

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

Just a note, what you created is a #Customization > Theme component, not a #Customization > Plugin 🙂

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [February 24, 2023, 11:21am UTC](https://meta.discourse.org/t/prevent-users-from-moving-topics-in-other-categories/255933/15 "2023-02-24T11:21:10Z")

</div>

> [@Crius](#):
>
> 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.

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. 🙂👍

* * *

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

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [February 24, 2023, 12:31pm UTC](https://meta.discourse.org/t/prevent-users-from-moving-topics-in-other-categories/255933/16 "2023-02-24T12:31:17Z")

</div>

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

 ![image](https://global.discourse-cdn.com/meta/original/4X/e/a/0/ea09b7143829013268b2b8a5b4a7f588052b61e4.png)

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](https://meta.discourse.org/t/discourse-automation/195773).

---

<div class="post-metadata">

### Author: ![Crius](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/crius/32/317214_2.png) [@Crius](https://meta.discourse.org/u/Crius)
#### Post date: [February 24, 2023, 8:34pm UTC](https://meta.discourse.org/t/prevent-users-from-moving-topics-in-other-categories/255933/17 "2023-02-24T20:34:48Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [February 24, 2023, 9:22pm UTC](https://meta.discourse.org/t/prevent-users-from-moving-topics-in-other-categories/255933/18 "2023-02-24T21:22:33Z")

</div>

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](https://meta.discourse.org/t/53504?silent=true) 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.

---

<div class="post-metadata">

### Author: ![Crius](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/crius/32/317214_2.png) [@Crius](https://meta.discourse.org/u/Crius)
#### Post date: [February 27, 2023, 4:55pm UTC](https://meta.discourse.org/t/prevent-users-from-moving-topics-in-other-categories/255933/19 "2023-02-27T16:55:29Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [March 29, 2023, 4:56pm UTC](https://meta.discourse.org/t/prevent-users-from-moving-topics-in-other-categories/255933/20 "2023-03-29T16:56:09Z")

</div>

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