From dd91d5b02f74bf0226a5d2b7502eb6f000f72dca Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 19 May 2015 16:51:21 +1000 Subject: [PATCH] FEATURE: disable invites by setting max_invites_per_day to 0 --- lib/guardian.rb | 2 ++ spec/components/guardian_spec.rb | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/guardian.rb b/lib/guardian.rb index 69f2db0b7ec..06518f6afe5 100644 --- a/lib/guardian.rb +++ b/lib/guardian.rb @@ -200,6 +200,7 @@ class Guardian def can_invite_to_forum?(groups=nil) authenticated? && + SiteSetting.max_invites_per_day.to_i > 0 && !SiteSetting.enable_sso && SiteSetting.enable_local_logins && ( @@ -212,6 +213,7 @@ class Guardian def can_invite_to?(object, group_ids=nil) return false if ! authenticated? return false unless ( SiteSetting.enable_local_logins && (!SiteSetting.must_approve_users? || is_staff?) ) + return false if SiteSetting.max_invites_per_day.to_i == 0 return true if is_admin? return false if ! can_see?(object) return false if group_ids.present? diff --git a/spec/components/guardian_spec.rb b/spec/components/guardian_spec.rb index fa9bf066276..d5e6a8c1375 100644 --- a/spec/components/guardian_spec.rb +++ b/spec/components/guardian_spec.rb @@ -245,6 +245,12 @@ describe Guardian do expect(Guardian.new(moderator).can_invite_to_forum?).to be_truthy end + it 'returns false when max_invites_per_day is 0' do + # let's also break it while here + SiteSetting.max_invites_per_day = "a" + expect(Guardian.new(moderator).can_invite_to_forum?).to be_falsey + 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 @@ -275,6 +281,9 @@ describe Guardian do expect(Guardian.new(moderator).can_invite_to?(nil)).to be_falsey expect(Guardian.new(moderator).can_invite_to?(topic)).to be_truthy expect(Guardian.new(user).can_invite_to?(topic)).to be_falsey + + SiteSetting.max_invites_per_day = 0 + expect(Guardian.new(moderator).can_invite_to?(topic)).to be_falsey end it 'returns true when the site requires approving users and is mod' do