Skip to content

FEATURE: add option to hide IP addresses from moderators #33682

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 78 commits into from
Aug 5, 2025

Conversation

brrusselburg
Copy link
Contributor

@brrusselburg brrusselburg commented Jul 17, 2025

Hide IP Addresses from Moderators When moderators_view_ips is Disabled

Summary

Feature Request Link - https://meta.discourse.org/t/option-to-hide-ip-addresses-from-moderators/207715/51
This PR implements a feature to hide IP addresses from moderators when the moderators_view_ips site setting is disabled. Previously, moderators could view IPs in multiple locations across the admin UI. This update ensures that IP addresses are visible to moderators when the setting allows it.

Changes Implemented

Backend Updates

  • Added moderators_view_ips site setting in site_settings.yml
  • Updated CurrentUserSerializer to include can_see_ip field based on the user’s role and site setting.
  • Modified AdminUserSerializer to restrict IP address visibility.
  • Updated UsersController to prevent IP addresses from being included in API responses.
  • Restricted IPs in ScreenedIpAddressesController by throwing Discourse::InvalidAccess if the user lacks permission.

Frontend Updates

  • Hid "Screened IPs" tab in /admin/logs when moderators_view_ips is disabled.
  • Blocked direct access to /admin/logs/screened_ip_addresses for unauthorized users.
  • Updated user-index.hbs and logs.hbs to conditionally hide IP fields.

UI Screenshots

New option for Admins in the Admin Security settings dashboard:
Screenshot 2025-02-21 at 5 32 00 PM

Moderator's view before:
Screenshot 2025-02-21 at 5 25 41 PM
Moderator's view after:
Screenshot 2025-02-21 at 5 26 59 PM

Moderator's view before:
Screenshot 2025-02-21 at 5 23 52 PM
Moderator's view after:
Screenshot 2025-02-21 at 5 23 15 PM

@github-actions github-actions bot added i18n PRs which update English locale files or i18n related code discourse-assign discourse-oauth2-basic discourse-data-explorer labels Jul 17, 2025
@brrusselburg brrusselburg changed the title Hide ips option DEV: Hide ips option Jul 18, 2025
@brrusselburg brrusselburg changed the title DEV: Hide ips option FEATURE: add option to hide IP addresses from moderators Jul 18, 2025
@brrusselburg brrusselburg marked this pull request as ready for review July 18, 2025 18:09
@brrusselburg brrusselburg force-pushed the hide-ips-option branch 4 times, most recently from e4a3d6f to 9d8fa22 Compare August 1, 2025 00:30
@@ -0,0 +1,9 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file intended to be included?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it!

@github-actions github-actions bot added chat PRs which include a change to Chat plugin migrations-tooling PR which includes changes to migrations tooling styleguide discourse-calendar discourse-ai discourse-affiliate labels Aug 4, 2025
Beznet added 5 commits August 4, 2025 15:42
a new field named moderators_view_ips  with default/client/hidden values has been added to site_settings.yml
add SiteSettings check and moderator check on the ip definitions before return
updated guardian.rb to have can_see_ip that the serializer can reference instead, also reusable elsewhere
updated the admin user_controller to determin ip_address should return, updated the history_serializer to prevent ip from returning on can_see_ip
removed unnecessary argument of user on guardian.can_see_ip, added an if block conditional on IP fields in Admin user dash view
Beznet and others added 20 commits August 4, 2025 15:46
PR review changes: updated the current_user_serializer and admin_user_serializer to have the  pattern appended to the can_see_ip to prevent this from showing at all instead of . Also updated the server.en.yml to include a description of the new Moderator IP setting in the Admin security options
site_settings rspec was failing on integrity checks, hidden: false was the culprit. removed unnecessary field and now passes
a new field named moderators_view_ips  with default/client/hidden values has been added to site_settings.yml
add SiteSettings check and moderator check on the ip definitions before return
updated guardian.rb to have can_see_ip that the serializer can reference instead, also reusable elsewhere
updated the admin user_controller to determin ip_address should return, updated the history_serializer to prevent ip from returning on can_see_ip
removed unnecessary argument of user on guardian.can_see_ip, added an if block conditional on IP fields in Admin user dash view
added can_see_ip to CurrentUserSerializer to be used in the user-index for currentUser
added functionality to prevent the Screened IP tab and route from being accessed when ip access is restricted
added to the guardian and current_user_serializer rspec tests to vet IP access and restrictions
PR review changes: updated the current_user_serializer and admin_user_serializer to have the  pattern appended to the can_see_ip to prevent this from showing at all instead of . Also updated the server.en.yml to include a description of the new Moderator IP setting in the Admin security options
site_settings rspec was failing on integrity checks, hidden: false was the culprit. removed unnecessary field and now passes
@github-actions github-actions bot removed chat PRs which include a change to Chat plugin migrations-tooling PR which includes changes to migrations tooling styleguide discourse-calendar discourse-ai discourse-affiliate labels Aug 4, 2025
@brrusselburg brrusselburg merged commit 72e4e53 into main Aug 5, 2025
27 of 28 checks passed
@brrusselburg brrusselburg deleted the hide-ips-option branch August 5, 2025 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
i18n PRs which update English locale files or i18n related code
Development

Successfully merging this pull request may close these issues.

3 participants