Skip to content

Commit 3172e45

Browse files
committed
use display name for files in downloaded zips fixes #6731
test plan: * upload a file * rename it via the ui * download the folder as a zip * the file should be named what it is in the UI Change-Id: I61c29d18d5384d24303e6ce57423fb055884e5ec Reviewed-on: https://gerrit.instructure.com/10418 Reviewed-by: Simon Williams <simon@instructure.com> Tested-by: Jenkins <jenkins@instructure.com>
1 parent 5868bd8 commit 3172e45

2 files changed

Lines changed: 25 additions & 9 deletions

File tree

lib/content_zipper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ def zip_folder(folder, zipfile, folder_names, &callback)
306306
callback.call(attachment, folder_names) if callback
307307
@context = folder.context
308308
@logger.debug(" found attachment: #{attachment.unencoded_filename}")
309-
path = folder_names.empty? ? attachment.filename : File.join(folder_names, attachment.unencoded_filename)
309+
path = folder_names.empty? ? attachment.display_name : File.join(folder_names, attachment.display_name)
310310
@files_added = false unless add_attachment_to_zip(attachment, zipfile, path)
311311
end
312312
folder.active_sub_folders.select{|f| !@check_user || f.grants_right?(@user, nil, :read_contents)}.each do |sub_folder|

spec/lib/content_zipper_spec.rb

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,24 +105,24 @@ def zipped_files_for_user(user=nil, check_user=true)
105105
names = []
106106
@attachment.reload
107107
Zip::ZipFile.foreach(@attachment.full_filename) {|f| names << f.name if f.file? }
108-
names
108+
names.sort
109109
end
110110

111111
context "in a private course" do
112112
it "should give logged in students some files" do
113-
zipped_files_for_user(@user).should == ['visible.png', 'visible/sub-vis.png']
113+
zipped_files_for_user(@user).should == ['visible.png', 'visible/sub-vis.png'].sort
114114
end
115115

116116
it "should give logged in teachers all files" do
117-
zipped_files_for_user(@teacher).should == ["locked/sub-locked-vis.png", "hidden/sub-hidden.png", "hidden.png", "visible.png", "visible/sub-locked.png", "visible/sub-vis.png", "locked.png"]
117+
zipped_files_for_user(@teacher).should == ["locked/sub-locked-vis.png", "hidden/sub-hidden.png", "hidden.png", "visible.png", "visible/sub-locked.png", "visible/sub-vis.png", "locked.png"].sort
118118
end
119119

120120
it "should give logged out people no files" do
121121
zipped_files_for_user(nil).should == []
122122
end
123123

124124
it "should give all files if check_user=false" do
125-
zipped_files_for_user(nil, false).should == ["locked/sub-locked-vis.png", "hidden/sub-hidden.png", "hidden.png", "visible.png", "visible/sub-locked.png", "visible/sub-vis.png", "locked.png"]
125+
zipped_files_for_user(nil, false).should == ["locked/sub-locked-vis.png", "hidden/sub-hidden.png", "hidden.png", "visible.png", "visible/sub-locked.png", "visible/sub-vis.png", "locked.png"].sort
126126
end
127127
end
128128

@@ -133,19 +133,19 @@ def zipped_files_for_user(user=nil, check_user=true)
133133
end
134134

135135
it "should give logged in students some files" do
136-
zipped_files_for_user(@user).should == ['visible.png', 'visible/sub-vis.png']
136+
zipped_files_for_user(@user).should == ['visible.png', 'visible/sub-vis.png'].sort
137137
end
138138

139139
it "should give logged in teachers all files" do
140-
zipped_files_for_user(@teacher).should == ["locked/sub-locked-vis.png", "hidden/sub-hidden.png", "hidden.png", "visible.png", "visible/sub-locked.png", "visible/sub-vis.png", "locked.png"]
140+
zipped_files_for_user(@teacher).should == ["locked/sub-locked-vis.png", "hidden/sub-hidden.png", "hidden.png", "visible.png", "visible/sub-locked.png", "visible/sub-vis.png", "locked.png"].sort
141141
end
142142

143143
it "should give logged out people the same thing as students" do
144-
zipped_files_for_user(nil).should == ['visible.png', 'visible/sub-vis.png']
144+
zipped_files_for_user(nil).should == ['visible.png', 'visible/sub-vis.png'].sort
145145
end
146146

147147
it "should give all files if check_user=false" do
148-
zipped_files_for_user(nil, false).should == ["locked/sub-locked-vis.png", "hidden/sub-hidden.png", "hidden.png", "visible.png", "visible/sub-locked.png", "visible/sub-vis.png", "locked.png"]
148+
zipped_files_for_user(nil, false).should == ["locked/sub-locked-vis.png", "hidden/sub-hidden.png", "hidden.png", "visible.png", "visible/sub-locked.png", "visible/sub-vis.png", "locked.png"].sort
149149
end
150150
end
151151
end
@@ -161,5 +161,21 @@ def zipped_files_for_user(user=nil, check_user=true)
161161
ContentZipper.process_attachment(attachment, @user)
162162
attachment.workflow_state.should == 'zipped'
163163
end
164+
165+
it "should use the display name" do
166+
course_with_student(:active_all => true)
167+
folder = Folder.root_folders(@course).first
168+
attachment_model(:uploaded_data => stub_png_data('hidden.png'), :content_type => 'image/png', :folder => folder, :display_name => 'otherfile.png')
169+
attachment = Attachment.new(:display_name => 'my_download.zip')
170+
attachment.user_id = @user.id
171+
attachment.workflow_state = 'to_be_zipped'
172+
attachment.context = folder
173+
attachment.save!
174+
ContentZipper.process_attachment(attachment, @user)
175+
attachment.reload
176+
names = []
177+
Zip::ZipFile.foreach(attachment.full_filename) {|f| names << f.name if f.file? }
178+
names.should == ['otherfile.png']
179+
end
164180
end
165181
end

0 commit comments

Comments
 (0)