FEATURE: disable invites by setting max_invites_per_day to 0

This commit is contained in:
Sam 2015-05-19 16:51:21 +10:00
parent 15a59dcde7
commit dd91d5b02f
2 changed files with 11 additions and 0 deletions

View File

@ -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?

View File

@ -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