From 557805249defdcfb13ce363cd8121cbed6cc8ee4 Mon Sep 17 00:00:00 2001 From: Bianca Nenciu Date: Tue, 25 Jun 2019 13:49:29 +0300 Subject: [PATCH] FIX: Ensure topic exists before making a banner. (#7781) --- lib/guardian/topic_guardian.rb | 2 +- spec/components/guardian_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/guardian/topic_guardian.rb b/lib/guardian/topic_guardian.rb index e7cc4f28a9..d52c1e7a99 100644 --- a/lib/guardian/topic_guardian.rb +++ b/lib/guardian/topic_guardian.rb @@ -174,6 +174,6 @@ module TopicGuardian end def can_banner_topic?(topic) - authenticated? && !topic.private_message? && is_staff? + topic && authenticated? && !topic.private_message? && is_staff? end end diff --git a/spec/components/guardian_spec.rb b/spec/components/guardian_spec.rb index c5c9b2bbf4..13369ec0c4 100644 --- a/spec/components/guardian_spec.rb +++ b/spec/components/guardian_spec.rb @@ -776,6 +776,13 @@ describe Guardian do PostActionCreator.create(user, first_post, :off_topic) expect(Guardian.new(moderator).can_see?(private_topic)).to be_truthy end + + it "allows staff to set banner topics" do + topic = Fabricate(:topic) + + expect(Guardian.new(admin).can_banner_topic?(nil)).to be_falsey + expect(Guardian.new(admin).can_banner_topic?(topic)).to be_truthy + end end describe 'a Post' do