diff --git a/apps/dashboard/app/javascript/files/data_table.js b/apps/dashboard/app/javascript/files/data_table.js
index 7c4c841e2..cb7c0a4d4 100644
--- a/apps/dashboard/app/javascript/files/data_table.js
+++ b/apps/dashboard/app/javascript/files/data_table.js
@@ -222,6 +222,9 @@ class DataTable {
data: null,
orderable: false,
defaultContent: '',
+ render: (data, type, row, meta) => {
+ return ``;
+ }
},
{ data: 'type', render: (data, type, row, meta) => data == 'd' ? ' dir' : ' file' }, // type
{ name: 'name', data: 'name', className: 'text-break', render: (data, type, row, meta) => `${Handlebars.escapeExpression(data)}` }, // name
diff --git a/apps/dashboard/app/javascript/files/file_ops.js b/apps/dashboard/app/javascript/files/file_ops.js
index d6207baaa..f17656f1e 100644
--- a/apps/dashboard/app/javascript/files/file_ops.js
+++ b/apps/dashboard/app/javascript/files/file_ops.js
@@ -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
diff --git a/apps/dashboard/test/system/files_test.rb b/apps/dashboard/test/system/files_test.rb
index 0e92965d2..dd077aab6 100644
--- a/apps/dashboard/test/system/files_test.rb
+++ b/apps/dashboard/test/system/files_test.rb
@@ -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"))
@@ -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))