correctly handle /file_contents/ urls when exporting; fixed #4335

Change-Id: I6ce3f0f2c67ea29b33a7371b30087cc98a3ea2c2
Reviewed-on: https://gerrit.instructure.com/3214
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Bracken Mosbacker <bracken@instructure.com>
This commit is contained in:
Zach Wily 2011-04-22 15:47:21 -06:00
parent dca9d437f4
commit 6eec8d43d3
2 changed files with 40 additions and 35 deletions

View File

@ -113,42 +113,47 @@ module CCHelper
sub_spot = $1
new_url = nil
{'assignments' => Assignment,
'announcements' => Announcement,
'calendar_events' => CalendarEvent,
'discussion_topics' => DiscussionTopic,
'collaborations' => Collaboration,
'files' => Attachment,
'conferences' => WebConference,
'quizzes' => Quiz,
'groups' => Group,
'wiki' => WikiPage,
'grades' => nil,
'users' => nil
}.each do |type, obj_class|
if type != 'wiki' && sub_spot =~ %r{#{type}/(\d+)[^\s"]*$}
# it's pointing to a specific file or object
obj = obj_class.find($1) rescue nil
if obj && obj.respond_to?(:grants_right?) && obj.grants_right?(user, nil, :read)
if type == 'files'
folder = obj.folder.full_name.gsub("course files", WEB_CONTENT_TOKEN)
new_url = "#{folder}/#{obj.display_name}"
elsif migration_id = CCHelper.create_key(obj)
new_url = "#{OBJECT_TOKEN}/#{type}/#{migration_id}"
if sub_spot =~ %r{\Afile_contents/(.*)$}
new_url = $1.gsub(/course( |%20)files/, WEB_CONTENT_TOKEN)
else
{'assignments' => Assignment,
'announcements' => Announcement,
'calendar_events' => CalendarEvent,
'discussion_topics' => DiscussionTopic,
'collaborations' => Collaboration,
'files' => Attachment,
'conferences' => WebConference,
'quizzes' => Quiz,
'groups' => Group,
'wiki' => WikiPage,
'grades' => nil,
'users' => nil
}.each do |type, obj_class|
if type != 'wiki' && sub_spot =~ %r{#{type}/(\d+)[^\s"]*$}
# it's pointing to a specific file or object
obj = obj_class.find($1) rescue nil
if obj && obj.respond_to?(:grants_right?) && obj.grants_right?(user, nil, :read)
if type == 'files'
folder = obj.folder.full_name.gsub(/course( |%20)files/, WEB_CONTENT_TOKEN)
new_url = "#{folder}/#{obj.display_name}"
elsif migration_id = CCHelper.create_key(obj)
new_url = "#{OBJECT_TOKEN}/#{type}/#{migration_id}"
end
end
break
elsif sub_spot =~ %r{#{type}(?:/([^\s"]*))?$}
# it's pointing to a course content index or a wiki page
if type == 'wiki' && $1
new_url = "#{WIKI_TOKEN}/#{type}/#{$1}"
else
new_url = "#{COURSE_TOKEN}/#{type}"
new_url += "/#{$1}" if $1
end
break
end
break
elsif sub_spot =~ %r{#{type}(?:/([^\s"]*))?$}
# it's pointing to a course content index or a wiki page
if type == 'wiki' && $1
new_url = "#{WIKI_TOKEN}/#{type}/#{$1}"
else
new_url = "#{COURSE_TOKEN}/#{type}"
new_url += "/#{$1}" if $1
end
break
end
end
new_url || relative_url
end

View File

@ -389,8 +389,8 @@ describe "Common Cartridge importing" do
end
it "should import wiki pages" do
body_with_link = "<p>Watup? <strong>eh?</strong><a href=\"/courses/%s/assignments\">Assignments</a></p>"
page = @copy_from.wiki.wiki_pages.create!(:title => "some page", :body => body_with_link % @copy_from.id)
body_with_link = "<p>Watup? <strong>eh?</strong><a href=\"/courses/%s/assignments\">Assignments</a><a href=\"/courses/%s/file_contents/course%%20files/tbe_banner.jpg\">Some file</a></p>"
page = @copy_from.wiki.wiki_pages.create!(:title => "some page", :body => body_with_link % [ @copy_from.id, @copy_from.id ])
@copy_from.save!
#export to html file
@ -406,7 +406,7 @@ describe "Common Cartridge importing" do
page_2 = @copy_to.wiki.wiki_pages.find_by_migration_id(migration_id)
page_2.title.should == page.title
page_2.url.should == page.url
page_2.body.should == body_with_link % @copy_to.id
page_2.body.should == body_with_link % [ @copy_to.id, @copy_to.id ]
end
it "should import assignments" do