fix: guard close user_can_summarize?

course on discussion topic might not be a course
but an account, for topics on account lvl groups
this fix prevents dt crashes

fixes VICE-4534
flag=discussion_summary

Test plan
- Create an account level group
- In the group context create a discussion topic
- Enable discussion_summary feature flag
- Open the topic, app should not crash

Change-Id: I3ddc7cac72aad7ed0d67150470192fbc34713cd6
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/355551
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Ádám Molnár <adam.molnar@instructure.com>
Reviewed-by: Omar Soto-Fortuño <omar.soto@instructure.com>
QA-Review: Ádám Molnár <adam.molnar@instructure.com>
Product-Review: Richard Zana <rzana@instructure.com>
This commit is contained in:
Daniel Vincze 2024-08-21 14:32:48 +02:00 committed by Daniel Matyas Vincze
parent 364cb7bb88
commit 246692628a
2 changed files with 20 additions and 0 deletions

View File

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

View File

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