Skip to content

Commit

Permalink
fix podcast feeds for media objects on user context
Browse files Browse the repository at this point in the history
test plan:
* create a discussion with podcast feed enabled
 and student posts added to feed
* as a student, use rce enhancements to upload a media
 object (to the student's own context directly) and
 add it to a discussion entry post
* it should show up in the podcast feed

closes #LS-1411

Change-Id: I17c8944921a5170be2d47c30062c0361e896fb25
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/247247
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
QA-Review: Robin Kuss <rkuss@instructure.com>
Product-Review: James Williams <jamesw@instructure.com>
Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
  • Loading branch information
maneframe committed Sep 11, 2020
1 parent 35b1cfe commit 85c73f1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/discussion_topic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1543,7 +1543,7 @@ def self.podcast_elements(messages, context)
media_objects = media_object_ids.empty? ? [] : MediaObject.where(media_id: media_object_ids).to_a
media_objects = media_objects.uniq(&:media_id)
media_objects = media_objects.map do |media_object|
if media_object.media_id == "maybe" || media_object.deleted? || media_object.context != context
if media_object.media_id == "maybe" || media_object.deleted? || (media_object.context_type != "User" && media_object.context != context)
media_object = nil
end
if media_object && media_object.podcast_format_details
Expand Down
43 changes: 43 additions & 0 deletions spec/controllers/discussion_entries_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,49 @@ def topic_with_media_reply
expect(assigns[:discussion_entries][0]).to eql(@entry)
end

it "should include student entries when media is from user context if enabled" do
@topic.update_attribute(:podcast_enabled, true)
@student_mo1 = @student.media_objects.build(:media_id => 'asdf', :title => 'asdf')
@student_mo1.data = {:extensions => {:mp4 => {:size => 100, :extension => 'mp4'}}}
@student_mo1.save!
@entry = @topic.discussion_entries.create!(:user => @student, :message => " media_comment_asdf ")
@entry.update_attribute(:message, "<iframe data-media-id=\"#{@student_mo1.media_id}\"></iframe>")
@topic.update_attribute(:podcast_has_student_posts, true)
get 'public_feed', params: {:discussion_topic_id => @topic.id, :feed_code => @enrollment.feed_code}, :format => 'rss'
expect(assigns[:entries]).not_to be_nil
expect(assigns[:entries]).not_to be_empty
require 'rss/2.0'
rss = RSS::Parser.parse(response.body, false) rescue nil
expect(rss).not_to be_nil
expect(rss.channel.title).to eql("some topic Posts Podcast Feed")
expect(rss.items.length).to eql(1)
expected_url = "users/#{@student.id}/media_download.mp4?type=mp4&entryId=#{@student_mo1.media_id}&redirect=1"
expect(rss.items.first.enclosure.url).to end_with(expected_url)
expect(assigns[:discussion_entries]).not_to be_empty
expect(assigns[:discussion_entries][0]).to eql(@entry)
end

it "should not include media objects from another course if enabled" do
@topic.update_attribute(:podcast_enabled, true)
@other_course = Course.create!
@other_mo = @other_course.media_objects.build(:media_id => 'asdf', :title => 'asdf')
@other_mo.data = {:extensions => {:mp4 => {:size => 100, :extension => 'mp4'}}}
@other_mo.save!
@entry = @topic.discussion_entries.create!(:user => @teacher, :message => " media_comment_asdf ")
@entry.update_attribute(:message, "<iframe data-media-id=\"#{@other_mo.media_id}\"></iframe>")

get 'public_feed', params: {:discussion_topic_id => @topic.id, :feed_code => @enrollment.feed_code}, :format => 'rss'
expect(assigns[:entries]).not_to be_nil
expect(assigns[:entries]).not_to be_empty
require 'rss/2.0'
rss = RSS::Parser.parse(response.body, false) rescue nil
expect(rss).not_to be_nil
expect(rss.channel.title).to eql("some topic Posts Podcast Feed")
expect(rss.items.length).to eql(0)
expect(assigns[:discussion_entries]).not_to be_empty
expect(assigns[:discussion_entries][0]).to eql(@entry)
end

it "should not include student entries if locked" do
topic_with_media_reply
@topic.update_attribute(:podcast_has_student_posts, true)
Expand Down

0 comments on commit 85c73f1

Please sign in to comment.