FIX: Allow invites if must_approve_users is true (#13257)

FIX: Allow invites if must_approve_users is true (#13257)

diff --git a/lib/guardian.rb b/lib/guardian.rb
index 7e5a11c..33ef954 100644
--- a/lib/guardian.rb
+++ b/lib/guardian.rb
@@ -354,7 +354,7 @@ class Guardian
     return false if !authenticated?
 
     invites_available = SiteSetting.max_invites_per_day.to_i.positive?
-    trust_level_requirement_met = !SiteSetting.must_approve_users? && @user.has_trust_level?(SiteSetting.min_trust_level_to_allow_invite.to_i)
+    trust_level_requirement_met = @user.has_trust_level?(SiteSetting.min_trust_level_to_allow_invite.to_i)
 
     if !is_staff?
       return false if !invites_available
diff --git a/spec/components/guardian_spec.rb b/spec/components/guardian_spec.rb
index aa686ba..1f61ea5 100644
--- a/spec/components/guardian_spec.rb
+++ b/spec/components/guardian_spec.rb
@@ -506,11 +506,6 @@ describe Guardian do
       expect(Guardian.new(moderator).can_invite_to_forum?).to be_truthy
     end
 
-    it 'returns false when the site requires approving users and is regular' do
-      SiteSetting.expects(:must_approve_users?).returns(true)
-      expect(Guardian.new(user).can_invite_to_forum?).to be_falsey
-    end
-
     context 'with groups' do
       let(:groups) { [group, another_group] }
 
diff --git a/spec/models/invite_redeemer_spec.rb b/spec/models/invite_redeemer_spec.rb
index aee4dcc..7fe1cb5 100644
--- a/spec/models/invite_redeemer_spec.rb
+++ b/spec/models/invite_redeemer_spec.rb
@@ -85,6 +85,22 @@ describe InviteRedeemer do
       expect(user.approved).to eq(true)
       expect(user.active).to eq(false)
     end
+
+    it "does not automatically approve users if must_approve_users is true" do
+      SiteSetting.must_approve_users = true
+
+      invite = Fabricate(:invite, email: 'test@example.com')
+      user = InviteRedeemer.create_user_from_invite(invite: invite, email: invite.email, username: 'test')
+      expect(user.approved).to eq(false)
+    end
+
+    it "approves user if invited by staff" do
+      SiteSetting.must_approve_users = true
+
+      invite = Fabricate(:invite, email: 'test@example.com', invited_by: Fabricate(:admin))
+      user = InviteRedeemer.create_user_from_invite(invite: invite, email: invite.email, username: 'test')
+      expect(user.approved).to eq(true)
+    end
   end
 
   describe "#redeem" do

GitHub sha: 36e0e6a3

This commit appears in #13257 which was approved by ZogStriP. It was merged by udan11.