[PAID] Allow badges to be granted in restricted categories

What would you like done?
By default, Discourse prevents badges from being granted in categories that have restrictions (I have a category where only trust levels 2+ are allowed to see/post/reply.) I would like to be able to grant badges to users who are able to see/post/reply in that category. I don’t mind if all users can see the granted badges because access to this category is something to earn.

When do you need it done?
I’d love it done in the next two weeks.

What is your budget, in $ USD that you can offer for this task?
I can offer $100 or slightly more if I am woefully underestimating the amount of work this will require.

Happily willing to pay more if someone thinks this is possible?

This can presumably be done using the SQL badge granting logic? (this feature needs to be explicitly enabled)

You would just grant a badge to users in the ‘Trust Level 2’ group (https://yourforum.com/admin/groups/automatic/trust_level_2)

It may be something you can do yourself if you can enable SQL editing in the Rails Console and craft a query similar to the template given by @tobiaseigen here:


The current badge query looks like this:

SELECT P.user_id, MIN(P.created_at) granted_at, MAX(P.id) post_id 
FROM badge_posts P JOIN topics T ON T.id = P.topic_id 
WHERE T.category_id IN (SELECT id FROM categories WHERE id = 50 OR parent_category_id = 50) 
AND P.user_id >= 0 GROUP BY P.user_id HAVING COUNT(*) >= 1

Where users are rewarded for their first post in this category (it’s a creative writing/roleplay thing) and then I have other badges for 10, 25, 50, and 100. So it would be based on their interaction AND ability to see the category, not just their trust level (if I’m even understanding your suggestion, I admit this is all beyond my skillset as an author/publisher.)

Does this work, or is that your question?

You don’t really need to check whether they can see the category, as it’s safe to assume that if they can’t see it, they haven’t posted anything there.

1 Like

This is a query I’d used in previous categories that I’ve been reusing for this (with altered cat #). It doesn’t currently work because the category is considered restricted and Discourse won’t allow or ignores queries for badges granted for activity in that category.

Have you tried it? I’m not sure that the restriction holds for custom badge queries.

1 Like

I have. I have five set up and they return 0 results when tested. When I briefly open the category to everyone though, they work.

I’ve asked about it here:

So the prevention is built in, even for custom queries.


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