Watching Categories based on on group in discourse

I found this plugin

https://github.com/discourse/discourse-watch-category-mcneel/blob/master/plugin.rb

Is this only hardcoded for one category and one group? I’d like to try and set this up on a larger scale.

@tobiaseigen

1 Like

What you want to do is fork the plugin on github, update your forked version according to your needs, and then include your forked version in app.yml. I’ve got it working now for I think 5 categories.

My version - to give you an example.

https://github.com/namati/discourse-watch-category-mcneel/blob/master/plugin.rb

2 Likes

Ok sweet

So for your code just make sure I’m reading this right

Namati_Staff gets subscribed to Annoucements
Namati_Leadership get subscribed to Leadership
Network_NGC gets subscribed to NGC
Namati_Culture get subscribed to Culture
namati_assessingopp gets subscribed to assessingopp
namati_scale gets subbed to scale

If that’s right I’m gonna start testing this out, it would be cool to build out a UI for this.

yup - you’ve got it right.

So testing this out

I have a EmployeesOnly group and a category called : “CONFIDENTIALEmployees Only”

So I want everyone in that group subscribed to this category,

I forked the code and tweaked it to this…
https://github.com/jaredneedell/discourse-watch-category-mcneel/blob/master/plugin.rb

Added the plugin to app.yml , rebuilt

I can see this plugin in admin panel

And finally I went to sidekiq to manually trigger the job,

My account has permission to see this category and is a member of of the EmployeesOnly group. Even with triggering the job, my account isn’t being set to watch “CONFIDENTIALEmployees Only”

Any way to see an error log of some type for this?

Tried with the everyone group as well and doesn’t work.

I just tested as well and can confirm that this plugin no longer works.

@techAPJ is it possible this plugin of yours is outdated, now that user settings have moved to the user options table? This is not a priority for me right now - perhaps you or @Jared_Needell could update the plugin.

https://meta.discourse.org/t/edit-a-user-setting-for-all-discourse-users/25162/7?u=tobiaseigen

1 Like

@codinghorror might be able to provide insight on this too.

@techapj worked on it – he can elaborate.

So teaching myself rails tonight!

Breaking down the plugin I did some testing.

Category.find_by_slug(“site-feedback”) doesn’t seem to work, I get a nil return

but if I do

Category.find_by(slug: “site-feedback”) appears to return data.

I made these changes on the plugin and appears to working…

Here’s my code, I’m going to be updating / tweaking it through the night to fit my site needs.

https://github.com/jaredneedell/discourse-watch-category-mcneel/blob/master/plugin.rb

1 Like

Plugin also supports looping through all users just not groups. Helpful when it comes to enforcing notifications

One day this functionality will be in Discourse core, and I will be even happier with the product.

See also

and even more relevant:

1 Like

Agreed, there’s a lot of features that would make me even happier :slight_smile:

Luckily for a first experience debugging a rails plugin it wasn’t too complicated.

Any chance you can submit a pull request back with your fixes? :slight_smile:

1 Like

If you notice, I changed it quite a bit utilizing methods to reduce repetitive code. I might take advantage of that and see if there is some way I can incorporate a UI to this.

I can do the pull request but I still plan on making more changes.

2 Likes

That’s awesome. Keep up the great work, this could make a big impact! :slight_smile:

This is because I added a find_by_slug method in Category model:

As you can see in above snippet, this method requires both category_slug and parent_category_slug, so you will have to pass parent_category_slug as well if applicable.

2 Likes

Doesn’t look like it requires the parent, the method you linked has an if statement to proceed without the parent category if it isn’t provided.

That likely handles top-level categories only. If you want a sub-category, it seems the parent category is required.

3 Likes

In case the parent_category_slug is not passed the method will look for top level categories only, as per this query:

self.where(slug: category_slug, parent_category_id: nil).first

In your case I can see from console screenshot that parent_category_id is 5, so the above condition will not be satisified, hence the method returns nil.