# \[PAID\] Allow badges to be granted in restricted categories

**URL:** https://meta.discourse.org/t/paid-allow-badges-to-be-granted-in-restricted-categories/72768
**Category:** Marketplace
**Created:** [Outubro 25, 2017, 4:10pm UTC](https://meta.discourse.org/t/paid-allow-badges-to-be-granted-in-restricted-categories/72768 "2017-10-25T16:10:45Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Bernstein](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bernstein/32/304070_2.png) [@Bernstein](https://meta.discourse.org/u/Bernstein)
#### Post date: [Outubro 25, 2017, 4:10pm UTC](https://meta.discourse.org/t/paid-allow-badges-to-be-granted-in-restricted-categories/72768/1 "2017-10-25T16:10:45Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Bernstein](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bernstein/32/304070_2.png) [@Bernstein](https://meta.discourse.org/u/Bernstein)
#### Post date: [Outubro 26, 2017, 3:30pm UTC](https://meta.discourse.org/t/paid-allow-badges-to-be-granted-in-restricted-categories/72768/2 "2017-10-26T15:30:14Z")

</div>

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

---

<div class="post-metadata">

### Author: ![pacharanero](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pacharanero/32/500583_2.png) [@pacharanero](https://meta.discourse.org/u/pacharanero)
#### Post date: [Outubro 27, 2017, 10:20am UTC](https://meta.discourse.org/t/paid-allow-badges-to-be-granted-in-restricted-categories/72768/3 "2017-10-27T10:20:15Z")

</div>

This can presumably be done using the SQL badge granting logic? (this feature needs to be [explicitly enabled](https://meta.discourse.org/t/badge-sql-can-no-longer-be-edited-by-default/47894))

You would just grant a badge to users in the ‘Trust Level 2’ group ([https://yourforum.com/admin/groups/automatic/trust\_level\_2](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:

> [@SQL Free Badge Editing](https://meta.discourse.org/t/sql-free-badge-editing/60933/2):
>
> I like all this and would like to see it implemented, though most of the options available in your screenshot are not really relevant to my community. User groups is important though - I think if the query below were hard coded to a badge option alot of sites would not need to turn on the SQL queries options. I know that the vast majority of badges on my site that I needed to custom create are based on this query. GROUPNAME would be the name of a discourse group that could be specified on the b…

---

<div class="post-metadata">

### Author: ![Bernstein](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bernstein/32/304070_2.png) [@Bernstein](https://meta.discourse.org/u/Bernstein)
#### Post date: [Outubro 27, 2017, 3:02pm UTC](https://meta.discourse.org/t/paid-allow-badges-to-be-granted-in-restricted-categories/72768/4 "2017-10-27T15:02:20Z")

</div>

The current badge query looks like this:

```plaintext
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.)

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [Outubro 27, 2017, 3:53pm UTC](https://meta.discourse.org/t/paid-allow-badges-to-be-granted-in-restricted-categories/72768/5 "2017-10-27T15:53:15Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Bernstein](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bernstein/32/304070_2.png) [@Bernstein](https://meta.discourse.org/u/Bernstein)
#### Post date: [Outubro 27, 2017, 4:08pm UTC](https://meta.discourse.org/t/paid-allow-badges-to-be-granted-in-restricted-categories/72768/6 "2017-10-27T16:08:53Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [Outubro 27, 2017, 4:10pm UTC](https://meta.discourse.org/t/paid-allow-badges-to-be-granted-in-restricted-categories/72768/7 "2017-10-27T16:10:22Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Bernstein](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bernstein/32/304070_2.png) [@Bernstein](https://meta.discourse.org/u/Bernstein)
#### Post date: [Outubro 27, 2017, 4:12pm UTC](https://meta.discourse.org/t/paid-allow-badges-to-be-granted-in-restricted-categories/72768/8 "2017-10-27T16:12:02Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Bernstein](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bernstein/32/304070_2.png) [@Bernstein](https://meta.discourse.org/u/Bernstein)
#### Post date: [Outubro 27, 2017, 4:14pm UTC](https://meta.discourse.org/t/paid-allow-badges-to-be-granted-in-restricted-categories/72768/9 "2017-10-27T16:14:04Z")

</div>

I’ve asked about it here:

> [@Need help with an SQL badge query](https://meta.discourse.org/t/need-help-with-an-sql-badge-query/72021/3):
>
> It is a feature, ask @sam about it.

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

---

<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: [Novembro 26, 2017, 4:14pm UTC](https://meta.discourse.org/t/paid-allow-badges-to-be-granted-in-restricted-categories/72768/10 "2017-11-26T16:14:10Z")

</div>

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