mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-04 17:02:35 +08:00
# 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:  Moderator's view before:  Moderator's view after:  Moderator's view before:  Moderator's view after:  --------- Co-authored-by: Bennett Dungan <bennettdungan@gmail.com>
59 lines
1.1 KiB
Ruby
59 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class AdminUserSerializer < AdminUserListSerializer
|
|
attributes :name,
|
|
:associated_accounts,
|
|
:can_send_activation_email,
|
|
:can_activate,
|
|
:can_deactivate,
|
|
:can_approve,
|
|
:ip_address,
|
|
:registration_ip_address,
|
|
:include_ip
|
|
|
|
has_one :single_sign_on_record, serializer: SingleSignOnRecordSerializer, embed: :objects
|
|
|
|
def can_approve
|
|
scope.can_approve?(object)
|
|
end
|
|
|
|
def include_can_approve?
|
|
SiteSetting.must_approve_users
|
|
end
|
|
|
|
def can_send_activation_email
|
|
scope.can_send_activation_email?(object)
|
|
end
|
|
|
|
def can_activate
|
|
scope.can_activate?(object)
|
|
end
|
|
|
|
def can_deactivate
|
|
scope.can_deactivate?(object)
|
|
end
|
|
|
|
def ip_address
|
|
object.ip_address.try(:to_s)
|
|
end
|
|
|
|
def registration_ip_address
|
|
object.registration_ip_address.try(:to_s)
|
|
end
|
|
|
|
def include_ip_address?
|
|
scope.can_see_ip?
|
|
end
|
|
|
|
def include_registration_ip_address?
|
|
scope.can_see_ip?
|
|
end
|
|
|
|
def include_can_be_deleted?
|
|
true
|
|
end
|
|
|
|
def include_ip
|
|
@options[:include_ip]
|
|
end
|
|
end
|