# Invite badges from inviting yourself

**URL:** https://meta.discourse.org/t/invite-badges-from-inviting-yourself/218143
**Category:** UX
**Tags:** invites
**Created:** [February 14, 2022, 5:04pm UTC](https://meta.discourse.org/t/invite-badges-from-inviting-yourself/218143 "2022-02-14T17:04:14Z")
**Posts on this page:** 11
**Page:** 2

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [January 5, 2023, 4:20pm UTC](https://meta.discourse.org/t/invite-badges-from-inviting-yourself/218143/24 "2023-01-05T16:20:38Z")

</div>

They are indeed system badges, and can’t be edited by the UI (though they are visible). That line would need to be added with a PR. 👍

---

<div class="post-metadata">

### Author: ![not-ethan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/not-ethan/32/282617_2.png) [@not-ethan](https://meta.discourse.org/u/not-ethan)
#### Post date: [January 6, 2023, 2:29am UTC](https://meta.discourse.org/t/invite-badges-from-inviting-yourself/218143/27 "2023-01-06T02:29:51Z")

</div>

Mind if I try and make that PR. I think I just need to change the SQL in `discourse/lib/badge_queries.rb` lines 156-167

---

<div class="post-metadata">

### Author: ![twofoursixeight](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/twofoursixeight/32/574822_2.png) [@twofoursixeight](https://meta.discourse.org/u/twofoursixeight)
#### Post date: [January 6, 2023, 11:36pm UTC](https://meta.discourse.org/t/invite-badges-from-inviting-yourself/218143/30 "2023-01-06T23:36:33Z")

</div>

Hello. After my badges were removed one day ago, they suddenly came back. Can someone fix this issue?

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [January 6, 2023, 11:45pm UTC](https://meta.discourse.org/t/invite-badges-from-inviting-yourself/218143/31 "2023-01-06T23:45:01Z")

</div>

They will come back as the queries run daily and you still ‘qualify’. 🙂 We would have to remove them manually every day until the bug gets fixed, which is unrealistic.

> [@not-ethan](#):
>
> Mind if I try and make that PR. I think I just need to change the SQL in `discourse/lib/badge_queries.rb` lines 156-167

I have checked, and we can make this #pr-welcome 👍 (You would need to do all three)

---

<div class="post-metadata">

### Author: ![not-ethan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/not-ethan/32/282617_2.png) [@not-ethan](https://meta.discourse.org/u/not-ethan)
#### Post date: [January 6, 2023, 11:50pm UTC](https://meta.discourse.org/t/invite-badges-from-inviting-yourself/218143/32 "2023-01-06T23:50:18Z")

</div>

Got it Thanks. I should be able to do this

And I don’t see why I would need to do 3. The one for invite links is a function with returns the count if I read the function correctly.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [January 6, 2023, 11:56pm UTC](https://meta.discourse.org/t/invite-badges-from-inviting-yourself/218143/33 "2023-01-06T23:56:15Z")

</div>

I did not look at the code, so you may be right. 🙂

---

<div class="post-metadata">

### Author: ![not-ethan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/not-ethan/32/282617_2.png) [@not-ethan](https://meta.discourse.org/u/not-ethan)
#### Post date: [January 6, 2023, 11:57pm UTC](https://meta.discourse.org/t/invite-badges-from-inviting-yourself/218143/34 "2023-01-06T23:57:35Z")

</div>

```py
  def self.invite_badge(count, trust_level)
    <<~SQL
      SELECT u.id user_id, current_timestamp granted_at
      FROM users u
      WHERE u.id IN (
        SELECT invited_by_id
        FROM invites i
        JOIN invited_users iu ON iu.invite_id = i.id
        JOIN users u2 ON u2.id = iu.user_id
        WHERE i.deleted_at IS NULL AND u2.active AND u2.trust_level >= #{trust_level.to_i} AND u2.silenced_till IS NULL
        GROUP BY invited_by_id
        HAVING COUNT(*) >= #{count.to_i}
      ) AND u.active AND u.silenced_till IS NULL AND u.id > 0 AND
        (:backfill OR u.id IN (:user_ids) )
    SQL
  end

```

Here it is. Seems like its just the 1. And looked through the whole file and nothing else with invites

* * *

Made the PR  
[https://github.com/discourse/discourse/pull/19778](https://github.com/discourse/discourse/pull/19778)

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [January 7, 2023, 5:59am UTC](https://meta.discourse.org/t/invite-badges-from-inviting-yourself/218143/35 "2023-01-07T05:59:26Z")

</div>

Looking at the PR (and bear in mind that PRs aren’t my forte), it looks like you’ve hardcoded it to be just the Promoter version by changing the ` #{count.to_i}` to be `1`?

My example above was only a proof of concept, and would need to be adapted to suit. 👍

(also, looking at the text in that onebox, I’m ‘JammyDodger’ not ‘Jammy Dogger’… 🙂)

---

<div class="post-metadata">

### Author: ![not-ethan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/not-ethan/32/282617_2.png) [@not-ethan](https://meta.discourse.org/u/not-ethan)
#### Post date: [January 12, 2023, 1:41pm UTC](https://meta.discourse.org/t/invite-badges-from-inviting-yourself/218143/36 "2023-01-12T13:41:15Z")

</div>

My bad. Fixed your name

---

<div class="post-metadata">

### Author: ![nat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nat/32/235063_2.png) [@nat](https://meta.discourse.org/u/nat)
#### Post date: [January 27, 2023, 4:32am UTC](https://meta.discourse.org/t/invite-badges-from-inviting-yourself/218143/39 "2023-01-27T04:32:18Z")

</div>

Thank you for your contribution! I’ve merged your PR

Also, a super small note that we typically require tests for modifications, but seeing there was none before we’ll just merge this and backfill.

Hope to see more from you in the future 🤗

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [January 30, 2023, 8:00am UTC](https://meta.discourse.org/t/invite-badges-from-inviting-yourself/218143/40 "2023-01-30T08:00:41Z")

</div>

This topic was automatically closed after 2 days. New replies are no longer allowed.

[Previous page](https://meta.discourse.org/t/invite-badges-from-inviting-yourself/218143.md?page=1)
