From e6ae468af4cfbf23357991031807073493602641 Mon Sep 17 00:00:00 2001 From: Ethan Vizitei Date: Mon, 9 Nov 2020 12:35:51 -0600 Subject: [PATCH] make routes work for media downloads closes FOO-1186 flag=none discussion entries and announcements were generating a lot of failures TEST PLAN: 1) make a new discussion entry with a video embed. 2) notification should get sent, and it should have a media download url pointing at the course the topic lives in Change-Id: I888a8508bd18ac9e37727eab5ede9e7a0102f184 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/252278 Tested-by: Service Cloud Jenkins Reviewed-by: Rob Orton QA-Review: Ethan Vizitei Product-Review: Ethan Vizitei --- lib/api/html/url_proxy.rb | 15 ++++++++++++++- spec/lib/api/html/url_proxy_spec.rb | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/api/html/url_proxy.rb b/lib/api/html/url_proxy.rb index e0ffb3230fe..abd5b7b88b1 100644 --- a/lib/api/html/url_proxy.rb +++ b/lib/api/html/url_proxy.rb @@ -91,11 +91,24 @@ module Api end def media_context + # not all objects are clean to find media urls for. + # If the current context is one of those classes, + # then we should look up what the actual context is that + # would have a reasonable media url on it (usually a course). + # If you are trying to do "media_redirect_url" on a context + # where you're finding a media url helper doesn't exist, you probably + # need to add a case here. case context - when Group + when Announcement context.context when CourseSection context.course + when DiscussionTopic + context.course + when DiscussionEntry + context.discussion_topic.course + when Group + context.context else context end diff --git a/spec/lib/api/html/url_proxy_spec.rb b/spec/lib/api/html/url_proxy_spec.rb index 50b6137c4dc..24bc4623327 100644 --- a/spec/lib/api/html/url_proxy_spec.rb +++ b/spec/lib/api/html/url_proxy_spec.rb @@ -43,6 +43,25 @@ module Api it "passes through polymorphic urls" do expect(proxy.media_redirect_url("123", "video")).to eq("http://example.com/courses/1/media_download?entryId=123&media_type=video&redirect=1") end + + it "has media redirect routes for discussion entries" do + course = course_model + topic = course.discussion_topics.create! + entry = DiscussionEntry.new + entry.id = 1 + entry.discussion_topic = topic + proxy = UrlProxy.new(StubUrlHelper.new, entry, "example.com", "http") + expect(proxy.media_redirect_url("123", "video")).to eq("http://example.com/courses/#{course.id}/media_download?entryId=123&media_type=video&redirect=1") + end + + it "can produce a redirect route for announcements" do + course = course_model + announcement = Announcement.new + announcement.id = 1 + announcement.context = course + proxy = UrlProxy.new(StubUrlHelper.new, announcement, "example.com", "http") + expect(proxy.media_redirect_url("123", "video")).to eq("http://example.com/courses/#{course.id}/media_download?entryId=123&media_type=video&redirect=1") + end end describe "#api_endpoint_info" do