fix wiki sidebar file link translation in api content
test plan: * add an inlineable file to a course (e.g. a '.html' file) * create a wiki page content and add a link to the file through the wiki sidebar * following the link on the saved page should take you to a preview page for the inlined content fixes #CNVS-14211 Change-Id: I14d2fc6d90f893086eff5498d0c670b9251fdddd Reviewed-on: https://gerrit.instructure.com/39191 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Jeremy Stanley <jeremy@instructure.com> QA-Review: Clare Strong <clare@instructure.com> Product-Review: James Williams <jamesw@instructure.com>
This commit is contained in:
parent
00f6adb248
commit
6ff5b114de
|
@ -407,10 +407,13 @@ module Api
|
|||
next unless obj && rewriter.user_can_view_content?(obj)
|
||||
|
||||
if ["Course", "Group", "Account", "User"].include?(obj.context_type)
|
||||
opts = {:verifier => obj.uuid, :only_path => true}
|
||||
if match.rest.start_with?("/preview")
|
||||
url = self.send("#{obj.context_type.downcase}_file_preview_url", obj.context_id, obj.id, :verifier => obj.uuid, :only_path => true)
|
||||
url = self.send("#{obj.context_type.downcase}_file_preview_url", obj.context_id, obj.id, opts)
|
||||
else
|
||||
url = self.send("#{obj.context_type.downcase}_file_download_url", obj.context_id, obj.id, :verifier => obj.uuid, :download => '1', :only_path => true)
|
||||
opts[:download] = '1'
|
||||
opts[:wrap] = '1' if match.rest.include?('wrap=1')
|
||||
url = self.send("#{obj.context_type.downcase}_file_download_url", obj.context_id, obj.id, opts)
|
||||
end
|
||||
else
|
||||
url = file_download_url(obj.id, :verifier => obj.uuid, :download => '1', :only_path => true)
|
||||
|
|
|
@ -98,6 +98,22 @@ describe UserContent, type: :request do
|
|||
doc.at_css('img')['src'].should == "http://www.example.com/courses/#{@course.id}/files/#{@attachment.id}/download?verifier=#{@attachment.uuid}"
|
||||
end
|
||||
|
||||
it "should not remove wrap parameter on file download links" do
|
||||
attachment_model(:context => @course)
|
||||
@topic = @course.discussion_topics.create!(:title => "course topic", :user => @teacher, :message => <<-HTML)
|
||||
<p>
|
||||
Hello, students.<br>
|
||||
This will explain everything: <img src="/courses/#{@course.id}/files/#{@attachment.id}/download?wrap=1" alt="important">
|
||||
</p>
|
||||
HTML
|
||||
json = api_call(:get,
|
||||
"/api/v1/courses/#{@course.id}/discussion_topics/#{@topic.id}",
|
||||
{ :controller => 'discussion_topics_api', :action => 'show',
|
||||
:format => 'json', :course_id => @course.id.to_s, :topic_id => @topic.id.to_s })
|
||||
doc = Nokogiri::HTML::DocumentFragment.parse(json['message'])
|
||||
doc.at_css('img')['src'].should == "http://www.example.com/courses/#{@course.id}/files/#{@attachment.id}/download?verifier=#{@attachment.uuid}&wrap=1"
|
||||
end
|
||||
|
||||
it "should translate file preview links to directly-downloadable preview urls" do
|
||||
@assignment = @course.assignments.create!(:title => "first assignment", :description => <<-HTML)
|
||||
<p>
|
||||
|
|
Loading…
Reference in New Issue