A platform for community discussion. Free, open, simple.
FIX: Make hide_new_user_profiles work with manually upgraded users (#33458)
Ted Johansson02e17ddb7f7a
diff --git a/lib/guardian/user_guardian.rb b/lib/guardian/user_guardian.rbindex 00f1e907c9d..048fdec5a72 100644--- a/lib/guardian/user_guardian.rb+++ b/lib/guardian/user_guardian.rb@@ -137,7 +137,8 @@ module UserGuardianif SiteSetting.hide_new_user_profiles && !SiteSetting.invite_only &&!SiteSetting.must_approve_users- if user.user_stat.blank? || user.user_stat.post_count == 0+ if (user.user_stat.blank? || user.user_stat.post_count == 0) &&+ !user.has_trust_level?(TrustLevel[2])return false if anonymous? || [email protected]_trust_level?(TrustLevel[2])enddiff --git a/spec/lib/guardian/user_guardian_spec.rb b/spec/lib/guardian/user_guardian_spec.rbindex ecb9d50742a..5b1b2030631 100644--- a/spec/lib/guardian/user_guardian_spec.rb+++ b/spec/lib/guardian/user_guardian_spec.rb@@ -156,6 +156,8 @@ RSpec.describe UserGuardian dofab!(:tl0_user) { Fabricate(:user, trust_level: 0) }fab!(:tl1_user) { Fabricate(:user, trust_level: 1) }fab!(:tl2_user) { Fabricate(:user, trust_level: 2) }+ # Admins can manually upgrade users without them meeting the criteria.+ fab!(:vip_tl2_user) { Fabricate(:user, trust_level: 2) }before { tl2_user.user_stat.update!(post_count: 1) }@@ -169,6 +171,13 @@ RSpec.describe UserGuardian doendend+ context "when hide_new_user_profiles is enabled" do+ it "allows anonymous to see a no-posts (manually upgraded) TL2 user's profile" do+ SiteSetting.hide_new_user_profiles = true+ expect(Guardian.new.can_see_profile?(vip_tl2_user)).to eq(true)+ end+ end+context "when site is invite only" doit "allows anonymous to see any profile" doSiteSetting.invite_only = true