From 84da39f5dc890007109a4d9e5642d475d5c13d04 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 23 Apr 2014 11:14:34 -0400 Subject: [PATCH] FIX: Admins should always be able to see groups so they can edit them. --- lib/guardian.rb | 2 +- spec/components/guardian_spec.rb | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/guardian.rb b/lib/guardian.rb index b223540ed1f..94456170791 100644 --- a/lib/guardian.rb +++ b/lib/guardian.rb @@ -110,7 +110,7 @@ class Guardian alias :can_grant_badges? :can_moderate? def can_see_group?(group) - group.present? && group.visible? + group.present? && (is_admin? || group.visible?) end diff --git a/spec/components/guardian_spec.rb b/spec/components/guardian_spec.rb index 9cf9177341b..50092b41976 100644 --- a/spec/components/guardian_spec.rb +++ b/spec/components/guardian_spec.rb @@ -239,12 +239,20 @@ describe Guardian do end describe 'a Group' do + let(:group) { Group.new } + let(:invisible_group) { Group.new(visible: false) } + it "returns true when the group is visible" do - Guardian.new.can_see?(Group.new).should be_true + Guardian.new.can_see?(group).should be_true + end + + it "returns true when the group is visible but the user is an admin" do + admin = Fabricate.build(:admin) + Guardian.new(admin).can_see?(invisible_group).should be_true end it "returns false when the group is invisible" do - Guardian.new.can_see?(Group.new(visible: false)).should be_false + Guardian.new.can_see?(invisible_group).should be_false end end