Hide categories according to user group membership

Continuing the discussion from How to split the forum into two main parts (general/groups) and how to display only subcategories I can create a new post in?:

Hey everyone,

Here is a theme component that does a thing I’ve been wanting to do for a long time, but I’d like your comments on the code to improve it, or your suggestions.

I don’t believe the code is very good so I don’t want to recommend it before it has been checked by someone else.

What it does

Hide with CSS all the topics for which the user has a category permission restriction in chosen pages.

Repository

Repository link
framagit.org/oca/discourse-theme-shroud-subcategories

Motivation

I’ve got a community with a lot of groups, and I want people to peacefully ignore what is from other groups than theirs. I don’t want to restrict access to the content, I just don’t want it to be on main page. They should be able to access it by going for it, by choosing to go on this category specifically (for example, in order to know what is discussed here). Obviously, the relevant tool would be the watch/ignore function, but since the UI requires more than 2 clicks to set it up, no-one in the community uses it. Some improvement on the Category page might do the trick but they are out of my skill.

So, I use what UI is simple enough for them: the group page. On the same page are displayed all the groups they can access, freely or not, and their description. That’s perfect, they just need to click and chose them. The group page is too hidden for them (inside the hamburger) so I could put a big button link on the main page.

Now, I need to link the group membership and the display of the category posts.

How it works

The trick I used was to setup the category permission as:

  • everyone: read, write
  • that group: start a message, read, write

and then, for each topic in the list, check if there is a category restriction, and if yes, add a class not-in-group to the topic element.

Then, the CSS add display:none accordingly.

UI

The admin can chose the pages where this behaviour is effective. It should not be done on the category page because, by definition, that is where we want to access the content. On my website, all those groups are subcategories that are hidden from the latest page, we access it through the /c/groups/ page, so that is that page which is used.

Improvements

  • Being able to select parents category of the filtered categories (so any category that is not a child of this one is safe from being skipped)
  • Add tags, so that if a topic has this tag, then it will not be removed.
10 Likes

This does not make sense to me. Why not use category permissions to restrict what the groups see?

4 Likes

Because I want them to be able to see those categories, but only if they make the effort to reach it. For example, in order to see what is discussed on that specific project before they register.

But on the main page, I don’t want them to be spammed by topics they don’t care. The best way would be for them to ignore it with the watch/ignore, but that’s too complicated for them. The other option would be to register in the group, go to the category page to read what is discussed, and then unregister from the group. That’s too many clicks for most of them, plus they would not dare do it.

Last option is the category setting «remove from latest» but that setting affects all the users, even the one that are following that category. With this method, I do have the equivalent of the «remove from latest» but only for some users and for all the pages I want.

Hope it’s more clear.

2 Likes

These improvements are done.

4 Likes

I find this very interesting. Could I see an example / join a forum where this component is installed?

1 Like

Also, does filtering with this component also lead to the posts not being sent out via the Summary email? Because that would be AMAZING.

1 Like

No it does not.
It doesn’t remove access to the post, it just hides it with CSS.
Topics are still are still sent to the user, with the instruction not to display it.
The use case is not to remove access but just to remove it from the front page (or any other page chosen).

Sorry I do not have installed it on a forum without login, but feel free to ask questions here or in PM.

2 Likes

Thanks!

What does this part mean?

1 Like

If you look at the source code of the page, the topic information is sent. But the theme-component orders to ignore it.

1 Like

It’s “only” working on the DISPLAY of things when browsing. It’s NOT a mute or ignore function. But I find this solution very interesting for some uses. Congrats @oca for this work !

2 Likes

I’ll take a closer look. Thank you again!

1 Like

Hi, I’ve installed this theme component and am now having trouble setting it up. When I try to choose tags and filtered categories, mine don’t seem to show up. As an example, we definitely have a faq tag, but no luck, I can’t select it. I also tried just typing the tag in, but that doesn’t work, either.

2 Likes

Do you have tags enabled in the Dashboard? It’s under Settings/Tags. First box at the top of the list for tags is to enable them. Then whatever tags you create should work.

1 Like

Yes, tags are enabled.

1 Like

The setting parameter do not know which tags exist. You need to write the tag name here, click create: 'faq', and so the tag name will be selected. You can select as many tags as necessary, any one of them will be enough to un-hide the post.

Be careful, if your account has admin privilege, then it has full permission for every category, but hiding a category is done by checking if the account can effectively create a new post. Yours can, so your account will be able to see every post everywhere. To test the component, I advise you to create a test account to see the same thing a user would see.

2 Likes

Thank you. I believe I got this to work and am very excited to see how it goes. My appreciations for your work.

2 Likes

Could an exception be made for people who are tracking a category?

1 Like