mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 22:14:47 +08:00
SECURITY: Hide user profiles from public
User profiles, including the summary, should be private to anonymous users if hide_user_profiles_from_public is enabled.
This commit is contained in:
parent
265b3dbb4c
commit
c9888163d7
|
@ -106,7 +106,7 @@ class UsersController < ApplicationController
|
|||
end
|
||||
|
||||
def show(for_card: false)
|
||||
return redirect_to path("/login") if SiteSetting.hide_user_profiles_from_public && !current_user
|
||||
return redirect_to path("/login") if !guardian.public_can_see_profiles?
|
||||
|
||||
@user =
|
||||
fetch_user_from_params(
|
||||
|
@ -155,7 +155,7 @@ class UsersController < ApplicationController
|
|||
|
||||
# This route is not used in core, but is used by theme components (e.g. https://meta.discourse.org/t/144479)
|
||||
def cards
|
||||
return redirect_to path("/login") if SiteSetting.hide_user_profiles_from_public && !current_user
|
||||
return redirect_to path("/login") if !guardian.public_can_see_profiles?
|
||||
|
||||
user_ids = params.require(:user_ids).split(",").map(&:to_i)
|
||||
raise Discourse::InvalidParameters.new(:user_ids) if user_ids.length > 50
|
||||
|
@ -484,6 +484,8 @@ class UsersController < ApplicationController
|
|||
end
|
||||
|
||||
def summary
|
||||
return redirect_to path("/login") if !guardian.public_can_see_profiles?
|
||||
|
||||
@user =
|
||||
fetch_user_from_params(
|
||||
include_inactive:
|
||||
|
|
|
@ -122,6 +122,10 @@ module UserGuardian
|
|||
true
|
||||
end
|
||||
|
||||
def public_can_see_profiles?
|
||||
!SiteSetting.hide_user_profiles_from_public || !anonymous?
|
||||
end
|
||||
|
||||
def can_see_profile?(user)
|
||||
return false if user.blank?
|
||||
return true if !SiteSetting.allow_users_to_hide_profile?
|
||||
|
|
|
@ -4087,6 +4087,24 @@ RSpec.describe UsersController do
|
|||
expect(json["user_summary"]["post_count"]).to eq(0)
|
||||
end
|
||||
|
||||
context "when `hide_user_profiles_from_public` site setting is enabled" do
|
||||
before { SiteSetting.hide_user_profiles_from_public = true }
|
||||
|
||||
it "returns 200 for logged in users" do
|
||||
sign_in(Fabricate(:user))
|
||||
|
||||
get "/u/#{user.username_lower}/summary.json"
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
|
||||
it "returns 403 for anonymous users" do
|
||||
get "/u/#{user.username_lower}/summary.json"
|
||||
|
||||
expect(response).to redirect_to "/login"
|
||||
end
|
||||
end
|
||||
|
||||
context "when `hide_profile_and_presence` user option is checked" do
|
||||
before_all { user1.user_option.update_columns(hide_profile_and_presence: true) }
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user