# 존재하지 않는 사용자에게 배지를 부여하지 않는 것이 좋을까요?

**URL:** https://meta.discourse.org/t/dont-grant-badges-to-users-who-dont-exist/185700
**Category:** Bug
**Created:** [4월 5, 2021, 9:28오후 UTC](https://meta.discourse.org/t/dont-grant-badges-to-users-who-dont-exist/185700 "2021-04-05T21:28:11Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [4월 5, 2021, 9:28오후 UTC](https://meta.discourse.org/t/dont-grant-badges-to-users-who-dont-exist/185700/1 "2021-04-05T21:28:11Z")

</div>

[one our badge pages](https://meta.discourse.org/badges/21/nice-share) 페이지를 살펴보니

 ![image](https://global.discourse-cdn.com/meta/original/3X/6/3/630760d6a0e6eba276acd33d718e66f2c317be86.png)

이런 모습이 보여서 궁금해졌습니다. 모든 아바타는 어디로 사라진 걸까요?

알고 보니 해당 사용자들은 존재하지 않는 사용자들이었습니다.

아마 더 이상 존재하지 않는 사용자에게 배지를 부여하는 것을 피해야 하지 않을까요? 아니면 표시되는 것을 막아야 할까요? 어쨌든, 이들은 _실제 사용자_—우리가 신경 써야 할 사용자들—의 아바타를 밀어내고 있습니다!

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [4월 6, 2021, 3:06오전 UTC](https://meta.discourse.org/t/dont-grant-badges-to-users-who-dont-exist/185700/4 "2021-04-06T03:06:13Z")

</div>

음… 여기 뭔가 이상한데, 그 이유는:

> <https://github.com/discourse/discourse/blob/dc6b547ed89f652b5406489d76140b76cf8e0d1d/app/models/user.rb#L30-L30>

grant는 이미 user에 조인되어 있으므로, user id를 어딘가에서 가져와야 합니다.

이렇게 스코프가 설정되어 있으면 dependent destroy가 제대로 작동하지 않는 것 같기도 합니다.

어쨌든 주간 정리 작업을 추가할 수는 있습니다.

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [4월 6, 2021, 1:20오후 UTC](https://meta.discourse.org/t/dont-grant-badges-to-users-who-dont-exist/185700/5 "2021-04-06T13:20:17Z")

</div>

> [@sam](#):
>
> 이 스코프링 방식 때문에 종속 삭제(dependent destroy)가 제대로 작동하지 않는 건 아닌지 궁금합니다.

이 배지들이 언제 부여되었는지를 고려해 보면(작성 시점 기준으로 가장 최근이었던 것들), 계정 삭제 시 삭제되지 않는 것이 아니라, 사용자 계정이 존재하지 않을 때 부여되는 것으로 추정됩니다.

확인해 봐야겠습니다.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [4월 7, 2021, 1:50오전 UTC](https://meta.discourse.org/t/dont-grant-badges-to-users-who-dont-exist/185700/6 "2021-04-07T01:50:10Z")

</div>

행에는 사용자 ID가 포함되어 있는데, 사용자가 삭제되면 이 ID를 가져올 곳이 없기 때문에 이상합니다.

---

<div class="post-metadata">

### Author: ![William\_Houston](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/william_houston/32/199509_2.png) [@William\_Houston](https://meta.discourse.org/u/William_Houston)
#### Post date: [7월 22, 2021, 12:48오전 UTC](https://meta.discourse.org/t/dont-grant-badges-to-users-who-dont-exist/185700/7 "2021-07-22T00:48:24Z")

</div>

사용자 ID가 incoming\_links 테이블에 저장되어 있다고 생각합니다. 해당 레코드는 종속적으로 삭제되지 않으며, 공유 배지 쿼리는 incoming\_links 테이블에서 user\_id가 null인 경우만 방지합니다:

[https://github.com/discourse/discourse/blob/main/lib/badge\_queries.rb#L199](https://github.com/discourse/discourse/blob/main/lib/badge_queries.rb#L199)

First Share 배지도 유사한 버그가 있을 수 있습니다:

[https://github.com/discourse/discourse/blob/main/lib/badge\_queries.rb#L64](https://github.com/discourse/discourse/blob/main/lib/badge_queries.rb#L64)

---

<div class="post-metadata">

### Author: ![William\_Houston](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/william_houston/32/199509_2.png) [@William\_Houston](https://meta.discourse.org/u/William_Houston)
#### Post date: [7월 27, 2021, 2:07오전 UTC](https://meta.discourse.org/t/dont-grant-badges-to-users-who-dont-exist/185700/8 "2021-07-27T02:07:12Z")

</div>

사용자 테이블에 해당 배지 쿼리를 조인하는 pull request를 만들었습니다. 제 첫 pull request이니, 모든 것을 올바르게 했기를 바랍니다!

> <https://github.com/discourse/discourse/pull/13851>
>
> Check that the user exists in badge queries for 'First Share' and 
> 'Nice/Good/G…reat Share' badges,
> 
> For 'Nice+ Share' badges, also grant badges if the number of shares is
> equal to the threshold count to better match the descriptions.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [7월 27, 2021, 6:37오전 UTC](https://meta.discourse.org/t/dont-grant-badges-to-users-who-dont-exist/185700/9 "2021-07-27T06:37:49Z")

</div>


