Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3666 disable dl btn when non dlable is checked files #4008

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/dashboard/app/javascript/files/data_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ class DataTable {
data: null,
orderable: false,
defaultContent: '<input type="checkbox">',
render: (data, type, row, meta) => {
return `<input type='checkbox' data-dl-url='${row.download_url}'>`;
}
},
{ data: 'type', render: (data, type, row, meta) => data == 'd' ? '<span title="directory" class="fa fa-folder" style="color: gold"><span class="sr-only"> dir</span></span>' : '<span title="file" class="fa fa-file" style="color: lightgrey"><span class="sr-only"> file</span></span>' }, // type
{ name: 'name', data: 'name', className: 'text-break', render: (data, type, row, meta) => `<a class="${row.type} name ${row.type == 'd' ? '' : 'view-file'}" href="${row.url}">${Handlebars.escapeExpression(data)}</a>` }, // name
Expand Down
8 changes: 8 additions & 0 deletions apps/dashboard/app/javascript/files/file_ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ jQuery(function() {

}
});

$('#directory-contents tbody').on('click', 'tr td:first-child input[type=checkbox]', function (e) {
if (this.dataset['dlUrl'] == 'undefined' && this.checked) {
$("#download-btn").attr('disabled', true);
} else if ($("input[data-dl-url='undefined']:checked" ).length == 0) {
$("#download-btn").attr('disabled', false);
}
});

$('#directory-contents tbody').on('dblclick', 'tr td:not(:first-child)', function(){
// handle doubleclick
Expand Down
73 changes: 72 additions & 1 deletion apps/dashboard/test/system/files_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ def setup

sleep 5 # give it enough time to download
assert(File.exist?(zip_file), "#{zip_file} was never downloaded!")

Dir.mktmpdir do |unzip_tmp_dir|
`cd #{unzip_tmp_dir}; unzip #{zip_file}`
assert(File.exist?("#{unzip_tmp_dir}/real_directory"))
Expand Down Expand Up @@ -656,6 +656,77 @@ def setup
assert_equal(expected_links, null_links)
end

test 'download button is disabled when non-downloadable item is checked' do
Dir.mktmpdir do |dir|
cant_read = 'cant_read.txt'
can_read = 'can_read.txt'

`touch #{dir}/#{can_read}`
`touch #{dir}/#{cant_read}`
`chmod 000 #{dir}/#{cant_read}`

visit files_url(dir)

can_read_row = find('tbody a', exact_text: can_read).ancestor('tr')
cant_read_row = find('tbody a', exact_text: cant_read).ancestor('tr')

can_read_row.find('input[type="checkbox"]').check

refute find("#download-btn").disabled?

cant_read_row.find('input[type="checkbox"]').check

assert find("#download-btn").disabled?
end
end

test 'download button is re-enabled when non-downloadable item is unchecked' do
Dir.mktmpdir do |dir|
cant_read = 'cant_read.txt'

`touch #{dir}/#{cant_read}`
`chmod 000 #{dir}/#{cant_read}`

visit files_url(dir)

cant_read_row = find('tbody a', exact_text: cant_read).ancestor('tr')
cant_read_row.find('input[type="checkbox"]').check
assert find("#download-btn").disabled?

cant_read_row.find('input[type="checkbox"]').uncheck
refute find("#download-btn").disabled?
end
end

test 'download button is NOT re-enabled until ALL non-downloadable files are unchecked' do
Dir.mktmpdir do |dir|
cant_read1 = 'cant_read1.txt'
cant_read2 = 'cant_read2.txt'

`touch #{dir}/#{cant_read1}`
`touch #{dir}/#{cant_read2}`
`chmod 000 #{dir}/#{cant_read1}`
`chmod 000 #{dir}/#{cant_read2}`

visit files_url(dir)

cant_read1_row = find('tbody a', exact_text: cant_read1).ancestor('tr')
cant_read2_row = find('tbody a', exact_text: cant_read2).ancestor('tr')

cant_read1_row.find('input[type="checkbox"]').check
assert find("#download-btn").disabled?

cant_read2_row.find('input[type="checkbox"]').check
assert find("#download-btn").disabled?

cant_read1_row.find('input[type="checkbox"]').uncheck
assert find("#download-btn").disabled?

cant_read2_row.find('input[type="checkbox"]').uncheck
refute find("#download-btn").disabled?
end
end

test 'allowlist errors flash' do
with_modified_env({ OOD_ALLOWLIST_PATH: Rails.root.to_s }) do
visit(files_url(Rails.root))
Expand Down
Loading