diff --git a/app/models/discussion_topic.rb b/app/models/discussion_topic.rb index cea8cbef95c..b0b267c4ffe 100644 --- a/app/models/discussion_topic.rb +++ b/app/models/discussion_topic.rb @@ -1427,6 +1427,12 @@ class DiscussionTopic < ActiveRecord::Base return false end + # course can be an account in case the topic context is group + # and the group context is account + unless course.is_a?(Course) + return false + end + course.feature_enabled?(:discussion_summary) && ( course.user_is_instructor?(user) || course.grants_right?(user, :read_as_admin) ) diff --git a/spec/models/discussion_topic_spec.rb b/spec/models/discussion_topic_spec.rb index d6a4542c814..bcec33b3556 100644 --- a/spec/models/discussion_topic_spec.rb +++ b/spec/models/discussion_topic_spec.rb @@ -3590,6 +3590,20 @@ describe DiscussionTopic do expect(@topic.user_can_summarize?(@observer)).to be false expect(@topic.user_can_summarize?(@student)).to be false end + + it "does not crash if the topic is in the context of a group with account context" do + account = @course.root_account + account.enable_feature!(:discussion_summary) + group = account.groups.create! + topic = group.discussion_topics.create!(title: "topic") + + expect(topic.user_can_summarize?(@teacher)).to be false + expect(topic.user_can_summarize?(@ta)).to be false + expect(topic.user_can_summarize?(@admin)).to be false + expect(topic.user_can_summarize?(@designer)).to be false + expect(topic.user_can_summarize?(@observer)).to be false + expect(topic.user_can_summarize?(@student)).to be false + end end describe "low_level_locked_for?" do