From 1c27d93dcffb11231721df5503d094dbf6755a1a Mon Sep 17 00:00:00 2001 From: Maja Komel Date: Tue, 13 Feb 2018 07:58:38 +0100 Subject: [PATCH] anonymous shadow users are approved on creation if must_approve_users is enabled (#5569) --- app/services/anonymous_shadow_creator.rb | 3 +++ spec/services/anonymous_shadow_creator_spec.rb | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/app/services/anonymous_shadow_creator.rb b/app/services/anonymous_shadow_creator.rb index 7cb27438a6d..fc602b8255c 100644 --- a/app/services/anonymous_shadow_creator.rb +++ b/app/services/anonymous_shadow_creator.rb @@ -13,6 +13,7 @@ class AnonymousShadowCreator return unless user return unless SiteSetting.allow_anonymous_posting return if user.trust_level < SiteSetting.anonymous_posting_min_trust_level + return if SiteSetting.must_approve_users? && !user.approved? if (shadow_id = user.custom_fields["shadow_id"].to_i) > 0 shadow = User.find_by(id: shadow_id) @@ -40,6 +41,8 @@ class AnonymousShadowCreator active: true, trust_level: 1, manual_locked_trust_level: 1, + approved: true, + approved_at: 1.day.ago, created_at: 1.day.ago # bypass new user restrictions ) diff --git a/spec/services/anonymous_shadow_creator_spec.rb b/spec/services/anonymous_shadow_creator_spec.rb index 2ec4ea90a71..0cc425b946c 100644 --- a/spec/services/anonymous_shadow_creator_spec.rb +++ b/spec/services/anonymous_shadow_creator_spec.rb @@ -16,6 +16,11 @@ describe AnonymousShadowCreator do expect(AnonymousShadowCreator.get(Fabricate.build(:user, trust_level: 0))).to eq(nil) end + it "returns no shadow if must_approve_users is true and user is not approved" do + SiteSetting.must_approve_users = true + expect(AnonymousShadowCreator.get(Fabricate.build(:user, approved: false))).to eq(nil) + end + it "returns a new shadow once time expires" do SiteSetting.anonymous_account_duration_minutes = 1