# 添加移除用户标记的功能

**URL:** https://meta.discourse.org/t/add-function-to-remove-flags-given-to-a-user/192750
**Category:** Feature
**Created:** [2021年六月5日 08:23 UTC](https://meta.discourse.org/t/add-function-to-remove-flags-given-to-a-user/192750 "2021-06-05T08:23:13Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Mattia](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mattia/32/182526_2.png) [@Mattia](https://meta.discourse.org/u/Mattia)
#### Post date: [2021年六月5日 08:23 UTC](https://meta.discourse.org/t/add-function-to-remove-flags-given-to-a-user/192750/1 "2021-06-05T08:23:13Z")

</div>

你好 👋，

添加一个功能或按钮来移除分配给用户的旗帜会很有用，这对版主来说也非常有帮助。

* * *

我的意思是，当一名用户给另一名用户分配旗帜时，该旗帜会保留在个人资料中，仅对管理员/版主可见。确实，如果能删除这些已分配的旗帜就太好了。

---

<div class="post-metadata">

### Author: ![kelv](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kelv/32/524739_2.png) [@kelv](https://meta.discourse.org/u/kelv)
#### Post date: [2023年六月5日 07:11 UTC](https://meta.discourse.org/t/add-function-to-remove-flags-given-to-a-user/192750/2 "2023-06-05T07:11:21Z")

</div>

👋 我将在此功能上进行开发，并通过 MR 随时提供更新 🙂

---

<div class="post-metadata">

### Author: ![kelv](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kelv/32/524739_2.png) [@kelv](https://meta.discourse.org/u/kelv)
#### Post date: [2023年八月1日 08:44 UTC](https://meta.discourse.org/t/add-function-to-remove-flags-given-to-a-user/192750/3 "2023-08-01T08:44:58Z")

</div>

一个部分解决了这个问题的修复程序已被合并——我们现在仅在标志计数器中计算已批准的标准标志帖子。这应该会减少这些计数器中的噪音。

> <https://github.com/discourse/discourse/pull/22799>
>
> \#### Context
> Related topics: 
> 1. Public Request: https://meta.discourse.org/t/…add-function-to-remove-flags-given-to-a-user/192750
> 
> This PR achieves the goal of reducing noise from flagged posts for admins/moderators by updating the counters in the user's profile page & admin view to only count posts with approved flags.
> This more accurately reflects the signal from posts that were correctly flagged, and removes the noise from flags that were rejected, ignored or awaiting review.
> 
> \#### Changes
> \* Modifying User#number\_of\_flagged\_posts to only return the count of posts with approved flags, and associated model unit tests
> \* Updating the flagged post staff counter hyperlink to navigate to a filtered view of that user's approved flagged posts to maintain consistency with the counter
> \* Adding system tests for the profile page to cover the flagged posts staff counter
> \* Minor refactor of the user profile page object used for system testing
> \* Modifying User#flags\_received\_count to return posts with only approved standard flags
> \* Updating the \`Show flags given\` button in the user admin view to navigate to a filtered view of that user's approved flagged posts
> 
> \#### Testing
> How to test:
> 1. Populate a dev instance with topics & posts (with at least 5 from a specific user - this will be the flagged user)
> 4. All posts to be flagged should be from the same user.
> 5. Flag 3 posts with standard flags (i.e. \`spam\`, \`inappropriate\`, \`off topic\`).
> 6. As an admin/mod, review 2 of these posts with reject / ignore actions respectively, the last of these posts should be left as pending review.
> 7. Flag 1 post with a custom flag (i.e. \`something else\`)
> 8. Flag 1 post with 1 custom & 1 standard flag (you will need 2 different users here)
> 9. As an admin/mod, approve the flags from both posts above.
> 10. Navigate to the user's profile page and test for expected behaviour.
> 11. Navigate to the user's admin view via the Admin index of users search page and test for expected behaviour.
> 
> Testing Artifact:
> 
> https://github.com/discourse/discourse/assets/133760061/dd322974-285a-425f-8247-25a365f0c9e3
> 
> \- 00:00 - 00:15 - Scrolling through 5 flagged posts, showing 1 pending, 1 rejected, 1 ignored and 2 approved (of which, one has all custom flags, and the other a mix of standard/custom flags)
> \- 00:15 - 00:25 - Click through to user profile page to show flagged posts counter, and click on that counter to view approved flagged posts for that user
> - Expectation: Flagged Post counter should count all approved flagged posts
> \- 00:32 - 00:42 - View user page through admin users index, click through on Show Received Flags button to view approved flagged posts for that user
> - Expectation: Received Flags counter should count all approved flagged posts with only standard flags
> 
> \#### Considerations / Questions 
> 
> 1. \`User#flags\_received\_count\` and \`User#number\_of\_flagged\_posts\` differ in \*\*2 key aspects - the latter includes custom flags and includes flags from deleted posts\*\*. It is possible that including custom flags in the count adds noise (the extent of which depends on the proportion of custom flags used for non-negative flagging, and also whether the counters should be interpreted as wholly negative signals in the first place). ~I don't have enough data to opine either way (other than \[anecdata\](https://meta.discourse.org/t/please-distinguish-flags-for-bad-things-from-organizational-and-please-help-flags/266073/2)) so would like some input on the approach here if we want to maintain consistency between the counters in the user's profile page & the user's admin view.~ \*\*(UPDATE: we have decided to go forward with consistent behaviour for both methods which exclude custom flags and include flags of deleted posts)\*\* 
> 2. The other tricky part if we opt to exclude custom flags from the count is that the filtered view upon clicking on the \`flagged-posts\` counter / \`Show Flags Received\` button currently has no way to filter out posts with only custom flags (if we want to differentiate the 2, perhaps this could be the subject of a future PR). 
> 
> \---
> 
> \_This PR was ported from a previous one (https://github.com/discourse/discourse/pull/22146), changes made in that earlier PR are captured in this first commit of this PR, and any updates from then are in subsequent commits. I'll squash everything prior to merge so we maintain a clean commit message.\_
