discourse/app/controllers/admin
benj 72e4e53fda
FEATURE: add option to hide IP addresses from moderators (#33682)
# 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](https://github.com/user-attachments/assets/5b315434-7724-4cb9-a3dc-d88750df00a6)


Moderator's view before:
![Screenshot 2025-02-21 at 5 25
41 PM](https://github.com/user-attachments/assets/0fb269e2-db40-488b-b11d-8bdfbe2a5245)
Moderator's view after:
![Screenshot 2025-02-21 at 5 26
59 PM](https://github.com/user-attachments/assets/efb848b0-1d7f-4ec9-8238-d8ee4eddbbe1)

Moderator's view before:
![Screenshot 2025-02-21 at 5 23
52 PM](https://github.com/user-attachments/assets/226e6d63-df3e-45d0-833f-de52593a086e)
Moderator's view after:
![Screenshot 2025-02-21 at 5 23
15 PM](https://github.com/user-attachments/assets/af313af2-2329-46d1-827d-290243c320e5)

---------

Co-authored-by: Bennett Dungan <bennettdungan@gmail.com>
2025-08-05 10:09:02 -05:00
..
config FEATURE: Themeable site settings (#32233) 2025-07-16 11:00:21 +10:00
admin_controller.rb DEV: Drop WithServiceHelper 2024-09-05 09:58:20 +02:00
admin_notices_controller.rb DEV: Make params explicit for services in controllers 2024-10-03 16:56:39 +09:00
api_controller.rb DEV: Require at least one scope for API key granular mode (#31253) 2025-02-10 13:22:08 +08:00
backups_controller.rb FIX: improve "read only" modes (#33521) 2025-07-10 09:08:00 +02:00
badges_controller.rb FIX: Don't overwrite translated titles when updating badge (#33731) 2025-07-23 15:46:00 +08:00
color_schemes_controller.rb DEV: enable Foundation and stop Default (#33610) 2025-07-15 11:16:11 +08:00
dashboard_controller.rb FEATURE: Allow admins to force refresh "What's new?" (#29911) 2024-11-27 09:40:55 +10:00
email_controller.rb DEV: Add e-mail site settings to e-mail admin page (#32214) 2025-04-08 18:59:50 +08:00
email_logs_controller.rb FIX: bug when skipped email logs are filtered (#33557) 2025-07-11 08:55:51 +08:00
email_styles_controller.rb FEATURE: customization of html emails (#7934) 2019-07-30 15:05:08 -04:00
email_templates_controller.rb FEATURE: send email to deleted user (#31947) 2025-03-24 14:45:25 +08:00
embeddable_hosts_controller.rb UX: admins embedding page follows admin ux guideline (#30122) 2025-01-06 13:01:08 +11:00
embedding_controller.rb UX: admins embedding page follows admin ux guideline (#30122) 2025-01-06 13:01:08 +11:00
emoji_controller.rb DEV: Move admin config pages out of /customize/ sub-route (#30511) 2025-01-02 09:13:11 +10:00
form_templates_controller.rb FIX: Process templates before previewing (#33848) 2025-07-29 15:09:02 +08:00
groups_controller.rb DEV: Add dedicated admin groups page (#32377) 2025-04-22 11:23:25 +08:00
impersonate_controller.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
permalinks_controller.rb FIX: Permalink.create didn't work as expected anymore (#29895) 2024-11-22 21:11:26 +01:00
plugins_controller.rb FIX: Don't allow access to plugin page if plugin is not visible (#26431) 2024-04-02 16:26:15 +03:00
reports_controller.rb DEV: Refactor reports index into service (#31667) 2025-03-11 14:36:06 +10:00
robots_txt_controller.rb FIX: Show true content of robots.txt after restoring to default (#24980) 2023-12-20 23:00:37 +03:00
screened_emails_controller.rb SECURITY: Moderators cannot see user emails. 2024-12-19 13:13:18 -03:00
screened_ip_addresses_controller.rb FEATURE: add option to hide IP addresses from moderators (#33682) 2025-08-05 10:09:02 -05:00
screened_urls_controller.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
search_controller.rb DEV: Refactor reports index into service (#31667) 2025-03-11 14:36:06 +10:00
search_logs_controller.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
section_controller.rb DEV: Add a skeleton for section landing page & items (#28477) 2024-10-02 12:19:38 +10:00
site_settings_controller.rb FEATURE: porting type object to site settings (#32706) 2025-05-13 14:30:24 -03:00
site_texts_controller.rb FEATURE: Allow showing site text search in selected locale (#28453) 2024-08-26 11:25:36 +10:00
staff_action_logs_controller.rb FEATURE: Log tag group changes in staff action log (#28787) 2024-09-09 10:50:48 +08:00
staff_controller.rb DEV: Drop WithServiceHelper 2024-09-05 09:58:20 +02:00
themes_controller.rb FEATURE: Add dark color scheme setting for themes (#33967) 2025-08-04 12:33:41 +08:00
unknown_reviewables_controller.rb FEATURE: Gracefully handle unhandled reviewables (#31118) 2025-02-05 14:38:45 +11:00
user_fields_controller.rb DEV: Modernize admin user fields (#29843) 2024-11-25 11:54:43 +08:00
users_controller.rb FEATURE: add option to hide IP addresses from moderators (#33682) 2025-08-05 10:09:02 -05:00
versions_controller.rb Refactor admin base controller (#18453) 2022-10-31 12:02:26 +00:00
watched_words_controller.rb FIX: Ensure uploaded watched word CSVs are converted to utf-8. (#32263) 2025-04-11 16:12:45 +10:00
web_hooks_controller.rb FEATURE: Add Mechanism to redeliver all failed webhook events (#27609) 2024-07-08 15:43:16 -05:00