don't try to fix relative urls on import step of course copy

Test Plan:
 * In a wiki page create an image link to "/images/preview.png"
 * copy the course
 * the link to that image should not be broken

closes #8503 #8493

Change-Id: Ib0ed374ac573a826d122d1d9adaa3c3dacc3fda2
Reviewed-on: https://gerrit.instructure.com/10617
Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
This commit is contained in:
Bracken Mosbacker 2012-05-08 14:46:11 -06:00
parent 264a14ef19
commit ee52293fc2
2 changed files with 9 additions and 0 deletions

View File

@ -25,6 +25,10 @@ class ImportedHtmlConverter
doc = Nokogiri::HTML(html || "")
attrs = ['rel', 'href', 'src', 'data', 'value']
course_path = "/#{context.class.to_s.underscore.pluralize}/#{context.id}"
for_course_copy = false
if context.respond_to?(:content_migration) && context.content_migration && context.content_migration.for_course_copy?
for_course_copy = true
end
doc.search("*").each do |node|
attrs.each do |attr|
if node[attr]
@ -80,6 +84,9 @@ class ImportedHtmlConverter
# The file is in the context of an AQ, leave the link alone
elsif val =~ %r{\A/courses/\d+/files/\d+}
# This points to a specific file already, leave it alone
elsif for_course_copy
# For course copies don't try to fix relative urls. Any url we can
# correctly alter was changed during the 'export' step
else
begin
if relative_url?(node[attr])

View File

@ -702,6 +702,8 @@ describe ContentMigration do
different file ref: <img src="/courses/#{@copy_from.id}/file_contents/course%20files/unfiled/test.jpg">
media object: <a id="media_comment_0_l4l5n0wt" class="instructure_inline_media_comment video_comment" href="/media_objects/0_l4l5n0wt">this is a media comment</a>
equation: <img class="equation_image" title="Log_216" src="/equation_images/Log_216" alt="Log_216">
link to some other course: <a href="/courses/#{@copy_from.id + @copy_to.id}">Cool Course</a>
canvas image: <img style="max-width: 723px;" src="/images/preview.png" alt="">
HTML
@question = @bank.assessment_questions.create!(:question_data => data)
@question.reload.question_data['question_text'].should =~ %r{/assessment_questions/}