From e53aa45f540c16cdcf43ee0f53ee9d58dd2da3ef Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 21 Jun 2013 16:35:13 +1000 Subject: [PATCH] I think this is more correct, admins/mods should always be able to invite --- lib/guardian.rb | 10 ++++++---- spec/components/guardian_spec.rb | 9 +++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/guardian.rb b/lib/guardian.rb index 998a7e35e36..e5046d5fd60 100644 --- a/lib/guardian.rb +++ b/lib/guardian.rb @@ -176,11 +176,13 @@ class Guardian is_me?(user) end - # For now, can_invite_to is basically can_see? def can_invite_to?(object) - authenticated? && can_see?(object) && - not(SiteSetting.must_approve_users?) && - (@user.has_trust_level?(:regular) || is_staff?) + authenticated? && + can_see?(object) && + ( + (!SiteSetting.must_approve_users? && @user.has_trust_level?(:regular)) || + is_staff? + ) end def can_see_deleted_posts? diff --git a/spec/components/guardian_spec.rb b/spec/components/guardian_spec.rb index 9c042f2bc49..05bc8b8b584 100644 --- a/spec/components/guardian_spec.rb +++ b/spec/components/guardian_spec.rb @@ -190,9 +190,14 @@ describe Guardian do Guardian.new(user).can_invite_to?(topic).should be_false end - it 'returns false when the site requires approving users' do + it 'returns true when the site requires approving users and is mod' do SiteSetting.expects(:must_approve_users?).returns(true) - Guardian.new(moderator).can_invite_to?(topic).should be_false + Guardian.new(moderator).can_invite_to?(topic).should be_true + end + + it 'returns true when the site requires approving users and is regular' do + SiteSetting.expects(:must_approve_users?).returns(true) + Guardian.new(coding_horror).can_invite_to?(topic).should be_false end end