zip up course files
closes OFFW-49 test plan: - Sign in as a user in a course that has Offline Web Downloads turned on - navigate to the modules page - Click on 'Download Course Content' - go to the Rails Console - type: `Attachment.all.last.id` - take the ID it spits out - request that file through the API - ** if the URL attribute has epub_export/:id/ before files/:id/... then delete that part (expub_export/:id/) so that it reads something like localhost:3000/files/:id/download?download_frd=blahblah - in a course without any course files, export the course content and you should get an empty zip file (you need to do all the stuff above) Change-Id: I91fcbf35a1c482eab476dbcf4565f3499453253a Reviewed-on: https://gerrit.instructure.com/97849 Tested-by: Jenkins Reviewed-by: Mysti Sadler <mysti@instructure.com> QA-Review: Nathan Rogowski <nathan@instructure.com> Product-Review: Cameron Sutter <csutter@instructure.com>
This commit is contained in:
parent
3c0c324894
commit
fa3108c807
|
@ -1,4 +1,5 @@
|
|||
class WebZipExport < EpubExport
|
||||
include CC::Exporter::WebZip::Exportable
|
||||
|
||||
def export
|
||||
MustViewModuleProgressor.new(user, course).make_progress
|
||||
|
@ -12,19 +13,23 @@ class WebZipExport < EpubExport
|
|||
end
|
||||
handle_asynchronously :generate, priority: Delayed::LOW_PRIORITY, max_attempts: 1
|
||||
|
||||
# WebZip Exportable overrides
|
||||
def content_cartridge
|
||||
self.content_export.attachment
|
||||
end
|
||||
|
||||
def convert_to_offline_web_zip
|
||||
begin
|
||||
set_locale
|
||||
# TODO: connect to cameron's patchset
|
||||
# file_path = super
|
||||
file_path = "/Users/mysti/canvas/chaos.mov.zip"
|
||||
file_path = super
|
||||
I18n.locale = :en
|
||||
|
||||
create_attachment_from_path!(file_path)
|
||||
rescue => e
|
||||
mark_as_failed
|
||||
raise e
|
||||
end
|
||||
|
||||
create_attachment_from_path!(file_path)
|
||||
mark_as_generated
|
||||
cleanup_file_path!(file_path)
|
||||
end
|
||||
|
|
|
@ -7,9 +7,9 @@ module CC::Exporter::WebZip
|
|||
def convert_to_offline_web_zip
|
||||
exporter = CC::Exporter::WebZip::Exporter.new(content_cartridge.open, false)
|
||||
zip = CC::Exporter::WebZip::ZipPackage.new(exporter)
|
||||
result = zip.create
|
||||
file_path = zip.create || zip.empty_zip_file
|
||||
exporter.cleanup_files
|
||||
result
|
||||
file_path
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,5 +1,22 @@
|
|||
module CC::Exporter::WebZip
|
||||
class ZipPackage < CC::Exporter::Epub::FilesDirectory
|
||||
def initialize(exporter)
|
||||
@files = exporter.unsupported_files + exporter.cartridge_json[:files]
|
||||
@filename_prefix = exporter.filename_prefix
|
||||
end
|
||||
attr_reader :files
|
||||
|
||||
def empty_zip_file
|
||||
zip_file = Zip::File.new(
|
||||
File.join(export_directory, filename),
|
||||
Zip::File::CREATE
|
||||
)
|
||||
tempfile = 'empty.txt'
|
||||
f = File.new(tempfile, "w+")
|
||||
zip_file.add(tempfile, f) { f.close }
|
||||
zip_file.close
|
||||
zip_file.name
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -24,5 +24,14 @@ describe WebZipExport do
|
|||
web_zip_export.generate_without_send_later
|
||||
expect(web_zip_export.generating?).to be_truthy
|
||||
end
|
||||
|
||||
it 'should create and associate an attachment' do
|
||||
web_zip_export.export_without_send_later
|
||||
web_zip_export.content_export.export_without_send_later
|
||||
expect(web_zip_export.zip_attachment).to be_nil, 'precondition'
|
||||
expect{web_zip_export.convert_to_offline_web_zip_without_send_later}.to change{Attachment.count}.by(1)
|
||||
web_zip_export.reload
|
||||
expect(web_zip_export.zip_attachment).not_to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue