Watching Categories based on on group in discourse

(Tobias Eigen) #2

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.

(Jared Needell) #3

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.

(Tobias Eigen) #4

yup - you’ve got it right.

(Jared Needell) #5

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…

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?

(Jared Needell) #6

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

(Tobias Eigen) #7

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.

1 Like
(Jared Needell) #8

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

(Jeff Atwood) #9

@techapj worked on it – he can elaborate.

(Jared Needell) #10

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.

1 Like
(Jared Needell) #11

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

(Allen - Watchman Monitoring) #12

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
(Jared Needell) #13

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.

(Michael Downey) #14

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

1 Like
(Jared Needell) #15

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.

(Michael Downey) #16

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

(Arpit Jalan) #17

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.

How do I set category tracking level defaults historically
(Jared Needell) #18

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.

(cpradio) #19

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

(Arpit Jalan) #20

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.

(Jared Needell) #21

Odd that it’s working without having to do that.