enable "download zip" link for students, closes #4305

Change-Id: Ifd22d7d79e21d0cc8a4d1326b062058f06f6a0dc
Reviewed-on: https://gerrit.instructure.com/4357
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Brian Whitmer <brian@instructure.com>
This commit is contained in:
Brian Palmer 2011-06-23 14:16:37 -06:00
parent b9fe6ae0df
commit 6a1bddc9bc
7 changed files with 90 additions and 8 deletions

View File

@ -94,6 +94,16 @@ ul.instTree li.leaf
.content_panel.addable_content_panel .links .sub_links
display: block
.content_panel.downloadable_content_panel .links .sub_links
display: block
float: right
> span
visibility: hidden
> a
visibility: hidden
> .download_zip
visibility: visible
.content_panel #rename_entry_field
font-size: 1.2em

View File

@ -90,13 +90,13 @@
<div class="sub_links">
<!-- replace "Add File" with "Add Files" flash button if possible -->
<span id="file_uploads_link">&nbsp;</span>
<a href="#" class="add_file_link" id="add_file_link"><%= t 'links.add_file', "Add File" %></a> |
<a href="#" class="add_file_link" id="add_file_link"><%= t 'links.add_file', "Add File" %></a><span> | </span>
<a href="#" class="add_folder_link"><%= t 'links.add_folder', "Add Folder" %></a>
<span class="download_zip" style="padding-left: 5px;">
<a href="#" class="download_zip_link no-hover" title="<%= t 'links.download_as_zip', "Download files in this folder as a zip" %>"><%= image_tag "inst_tree/file_types/page_white_zip.png" %></a>
</span>
<span class="upload_zip" style="padding-left: 5px;">
<a href="#" class="upload_zip_link no-hover" title="<%= t 'links.import_zip', "Import a zip file" %>""><%= image_tag "file_upload.png" %></a>
<a href="#" class="upload_zip_link no-hover" title="<%= t 'links.import_zip', "Import a zip file" %>"><%= image_tag "file_upload.png" %></a>
</span>
<span class="edit_link" style="padding-left: 5px;">
<a href="#" class="lock_item_link no-hover folder_url" title="<%= t 'links.lock_folder', "Lock this Folder" %>"><%= image_tag "lock.png" %></a>

View File

@ -275,7 +275,12 @@ class ContentZipper
if callback && (folder.hidden? || folder.locked)
callback.call(folder, folder_names)
end
folder.file_attachments.scoped(:conditions => "file_state IN ('available', 'hidden')").select{|a| !@user || a.grants_right?(@user, nil, :download)}.each do |attachment|
attachments = if !@user || folder.context.grants_right?(@user, nil, :manage_files)
folder.active_file_attachments
else
folder.visible_file_attachments
end
attachments.select{|a| !@user || a.grants_right?(@user, nil, :download)}.each do |attachment|
callback.call(attachment, folder_names) if callback
@context = folder.context
@logger.debug(" found attachment: #{attachment.unencoded_filename}")

View File

@ -1322,7 +1322,8 @@ var fileStructureData = [];
$panel.find(".rename_item_link,.delete_item_link,.folder_url").attr('href', folder_url);
$panel.find(".breadcrumb").empty().append(files.breadcrumb());
$panel.toggleClass('editable_content_panel', !!((data.context && data.context.permissions && data.context.permissions.manage_files) || (data.permissions && data.permissions.update)))
.toggleClass('addable_content_panel', !!((data.context && data.context.permissions && data.context.permissions.manage_files) || (data.permissions && data.permissions.update)));
.toggleClass('addable_content_panel', !!((data.context && data.context.permissions && data.context.permissions.manage_files) || (data.permissions && data.permissions.update)))
.toggleClass('downloadable_content_panel', !$panel.hasClass('editable_content_panel') && !$panel.hasClass('addable_content_panel') && !!(data.permissions && data.permissions.read_contents));
$panel.removeClass('to_be_hidden');
$panel.find(".download_zip,.upload_zip").hide();
@ -2363,4 +2364,4 @@ var fileUpload = {
attempt: 0,
file_details: {}
};
});
});

View File

@ -37,9 +37,11 @@ def valid_attachment_attributes(opts={})
}
end
def stub_png_data
sio = StringIO.new("ohai")
sio.stub!(:original_filename).and_return('test.png')
def stub_png_data(filename = 'test.png', data = nil)
$stub_file_counter ||= 0
data ||= "ohai#{$stub_file_counter += 1}"
sio = StringIO.new(data)
sio.stub!(:original_filename).and_return(filename)
sio.stub!(:content_type).and_return('image/png')
sio
end

View File

@ -0,0 +1,51 @@
#
# Copyright (C) 2011 Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
describe ContentZipper do
describe "zip_folder" do
it "should only zip up files/folders the user has access to" do
course_with_student(:active_all => true)
folder = Folder.root_folders(@course).first
attachment_model(:uploaded_data => stub_png_data('hidden.png'), :content_type => 'image/png', :hidden => true, :folder => folder)
attachment_model(:uploaded_data => stub_png_data('visible.png'), :content_type => 'image/png', :folder => folder)
attachment_model(:uploaded_data => stub_png_data('locked.png'), :content_type => 'image/png', :folder => folder, :locked => true)
hidden_folder = folder.sub_folders.create!(:context => @course, :name => 'hidden', :hidden => true)
visible_folder = folder.sub_folders.create!(:context => @course, :name => 'visible')
locked_folder = folder.sub_folders.create!(:context => @course, :name => 'locked', :locked => true)
attachment_model(:uploaded_data => stub_png_data('sub-hidden.png'), :content_type => 'image/png', :folder => hidden_folder)
attachment_model(:uploaded_data => stub_png_data('sub-vis.png'), :content_type => 'image/png', :folder => visible_folder)
attachment_model(:uploaded_data => stub_png_data('sub-locked.png'), :content_type => 'image/png', :folder => visible_folder, :locked => true)
attachment_model(:uploaded_data => stub_png_data('sub-locked-vis.png'), :content_type => 'image/png', :folder => locked_folder)
attachment = Attachment.new(:display_name => 'my_download.zip')
attachment.user_id = @user.id
attachment.workflow_state = 'to_be_zipped'
attachment.context = folder
attachment.save!
ContentZipper.process_attachment(attachment, @user)
names = []
attachment.reload
Zip::ZipFile.foreach(attachment.full_filename) do |f|
names << f.name if f.file?
end
names.sort.should == ['visible.png', 'visible/sub-vis.png']
end
end
end

View File

@ -0,0 +1,13 @@
require File.expand_path(File.dirname(__FILE__) + '/common')
describe "files view" do
it_should_behave_like "in-process server selenium tests"
it "should show students link to download zip of folder" do
course_with_student_logged_in
get "/courses/#{@course.id}/files"
link = keep_trying_until { driver.find_element(:css, "div.links a.download_zip_link") }
link.should be_displayed
link.attribute('href').should match(%r"/courses/#{@course.id}/folders/\d+/download")
end
end