translate user content links to replaced files
changes the user content html rewriter so links to files that were deleted and replaced will still be translated correctly (rather than pointing to the old deleted file) test plan: * upload a file * create an assignment * add a link to the file in the assignment description * delete the file * edit the file locally and re-upload it * edit the assignment and save it * should still be able to click on the link and receive the updated file fixes #CNVS-4799 Change-Id: I527756f02d7b38dda36dbcc3cfae32a3980a25b3 Reviewed-on: https://gerrit.instructure.com/18992 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Jeremy Stanley <jeremy@instructure.com> QA-Review: Adam Phillipps <adam@instructure.com> Product-Review: Jeremy Stanley <jeremy@instructure.com>
This commit is contained in:
parent
228e60a065
commit
6b2da819bb
|
@ -267,7 +267,13 @@ module Api
|
|||
|
||||
rewriter = UserContent::HtmlRewriter.new(context, user)
|
||||
rewriter.set_handler('files') do |match|
|
||||
obj = match.obj_id && match.obj_class.find_by_id(match.obj_id)
|
||||
if match.obj_id
|
||||
if match.obj_class == Attachment && context && !context.is_a?(User)
|
||||
obj = context.attachments.find(match.obj_id) rescue nil
|
||||
else
|
||||
obj = match.obj_class.find_by_id(match.obj_id)
|
||||
end
|
||||
end
|
||||
next unless obj && rewriter.user_can_view_content?(obj)
|
||||
file_download_url(obj.id, :verifier => obj.uuid, :download => '1', :host => host, :protocol => protocol)
|
||||
end
|
||||
|
|
|
@ -38,6 +38,29 @@ describe UserContent, :type => :integration do
|
|||
doc.at_css('img')['src'].should == "http://www.example.com/files/#{@attachment.id}/download?verifier=#{@attachment.uuid}"
|
||||
end
|
||||
|
||||
it "should translate file links to directly-downloadable urls for deleted and replaced files" do
|
||||
course_with_teacher(:active_all => true)
|
||||
attachment_model
|
||||
@attachment.destroy
|
||||
attachment2 = Attachment.create!(:folder => @attachment.folder, :context => @attachment.context, :filename => @attachment.filename, :uploaded_data => StringIO.new("first"))
|
||||
@context.attachments.find(@attachment.id).id.should == attachment2.id
|
||||
|
||||
@assignment = @course.assignments.create!(:title => "first assignment", :description => <<-HTML)
|
||||
<p>
|
||||
Hello, students.<br>
|
||||
This will explain everything: <img src="/courses/#{@course.id}/files/#{@attachment.id}/preview" alt="important">
|
||||
</p>
|
||||
HTML
|
||||
|
||||
json = api_call(:get,
|
||||
"/api/v1/courses/#{@course.id}/assignments/#{@assignment.id}",
|
||||
{ :controller => 'assignments_api', :action => 'show',
|
||||
:format => 'json', :course_id => @course.id.to_s, :id => @assignment.id.to_s })
|
||||
|
||||
doc = Nokogiri::HTML::DocumentFragment.parse(json['description'])
|
||||
doc.at_css('img')['src'].should == "http://www.example.com/files/#{attachment2.id}/download?verifier=#{attachment2.uuid}"
|
||||
end
|
||||
|
||||
it "should translate media comment links to embedded video tags" do
|
||||
course_with_teacher(:active_all => true)
|
||||
attachment_model
|
||||
|
|
Loading…
Reference in New Issue