support selective file exports with select[files] param

this is a friendly alias for select[attachments], done to be
more consistent with existing API names, and following the
example of select[modules], select[pages], etc.

test plan:
 - do selective content exports with the content export API,
   using select[files][]=(id), and ensure the correct file(s)
   are exported
 - test both common cartridge and zip exports

fixes CNVS-15129

Change-Id: I004ae1e8ba28ea8b7cf480c8fee5bd9633375781
Reviewed-on: https://gerrit.instructure.com/40115
Reviewed-by: James Williams  <jamesw@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Clare Strong <clare@instructure.com>
Product-Review: Jeremy Stanley <jeremy@instructure.com>
This commit is contained in:
Jeremy Stanley 2014-08-27 13:50:07 -06:00
parent 1c471bb890
commit 8b679c7417
3 changed files with 27 additions and 2 deletions

View File

@ -217,6 +217,14 @@ class ContentExport < ActiveRecord::Base
self.settings[:selected_content] ||= {}
end
def select_content_key(obj)
if zip_export?
obj.asset_string
else
CC::CCHelper.create_key(obj)
end
end
# Method Summary
# Takes in an ActiveRecord object. Determines if the item being
# checked should be exported or not.
@ -231,7 +239,7 @@ class ContentExport < ActiveRecord::Base
return true if is_set?(selected_content["all_#{asset_type}"])
return false unless selected_content[asset_type]
return true if is_set?(selected_content[asset_type][CC::CCHelper.create_key(obj)])
return true if is_set?(selected_content[asset_type][select_content_key(obj)])
false
end
@ -253,7 +261,7 @@ class ContentExport < ActiveRecord::Base
asset_type = type || obj.class.table_name
selected_content[asset_type] ||= {}
selected_content[asset_type][CC::CCHelper.create_key(obj)] = true
selected_content[asset_type][select_content_key(obj)] = true
end
def add_error(user_message, exception_or_info=nil)

View File

@ -626,6 +626,8 @@ class ContentMigration < ActiveRecord::Base
'content_tags'
when 'pages'
'wiki_pages'
when 'files'
'attachments'
else
key
end

View File

@ -359,6 +359,13 @@ describe ContentExportsApiController, type: :request do
{ :select => {:pages => [page_to_copy.id]} })
export3 = t_course.content_exports.find_by_id(json3['id'])
export3.export_object?(page_to_copy).should be_true
file = attachment_model(context: t_course)
json4 = api_call_as_user(t_teacher, :post, "/api/v1/courses/#{t_course.id}/content_exports?export_type=common_cartridge",
{ controller: 'content_exports_api', action: 'create', format: 'json', course_id: t_course.to_param, export_type: 'common_cartridge'},
{ :select => {:files => [file.id]} })
export4 = t_course.content_exports.find_by_id(json4['id'])
export4.export_object?(file).should be_true
end
it "should export by module item id" do
@ -465,6 +472,14 @@ describe ContentExportsApiController, type: :request do
end
end
it "should support 'files' in addition to 'attachments'" do
json = api_call_as_user(t_teacher, :post, "/api/v1/courses/#{t_course.id}/content_exports",
{ controller: 'content_exports_api', action: 'create', format: 'json', course_id: t_course.to_param },
{ export_type: 'zip', select: {'files' => [@file1.id]} })
ce = ContentExport.find(json['id'])
ce.export_object?(@file1).should be true
end
context "as a student" do
it "should exclude non-zip and/or other users' exports from #index" do
my_zip_export = past_export(t_course, t_student, 'zip')