Skip to content

Commit

Permalink
Ensuring that hidden files cannot be selected for the File System
Browse files Browse the repository at this point in the history
provider; Fixing the Box driver; Adjusting the version requirement for
puma
  • Loading branch information
jrgriffiniii committed Jul 17, 2019
1 parent 2cffe03 commit 86d21fb
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 7 deletions.
3 changes: 2 additions & 1 deletion app/controllers/concerns/browse_everything/parameters.rb
Expand Up @@ -34,7 +34,8 @@ def selected_files
return [] unless selected_params

values = selected_params.values.uniq
values.map { |value| BrowseEverything::Resource.new(value) }
selected_resources = values.map { |value| BrowseEverything::Resource.new(value) }
selected_resources.reject(&:hidden?)
end

# Determine whether or not cloud service files are being uploaded
Expand Down
2 changes: 1 addition & 1 deletion browse-everything.gemspec
Expand Up @@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
spec.add_dependency 'google-api-client', '~> 0.23'
spec.add_dependency 'google_drive', '~> 2.1'
spec.add_dependency 'googleauth', '0.6.6'
spec.add_dependency 'puma', '~> 3.11'
spec.add_dependency 'puma', '< 4.0'
spec.add_dependency 'rails', '>= 4.2'
spec.add_dependency 'ruby-box'
spec.add_dependency 'signet', '~> 0.8'
Expand Down
1 change: 1 addition & 0 deletions lib/browse_everything/driver/box.rb
Expand Up @@ -45,6 +45,7 @@ def contents(id = '', _page_index = 0)
box_client.folder_by_id(id)
end

values = []
folder.items(ITEM_LIMIT, 0, %w[name size created_at]).collect do |f|
values << directory_entry(f)
end
Expand Down
12 changes: 10 additions & 2 deletions lib/browse_everything/driver/file_system.rb
Expand Up @@ -43,6 +43,7 @@ def link_for(path)
end
entries
else
return [] if hidden?(full_path)
file_size = file_size(full_path)
[["file://#{full_path}", { file_name: File.basename(path), file_size: file_size, directory: false }]]
end
Expand All @@ -57,7 +58,7 @@ def authorized?
# @param display [String] display label for the resource
# @return [BrowseEverything::FileEntry]
def details(path, display = File.basename(path))
return nil unless File.exist? path
return unless File.exist?(path)
info = File::Stat.new(path)
BrowseEverything::FileEntry.new(
make_pathname(path),
Expand All @@ -77,7 +78,7 @@ def details(path, display = File.basename(path))
# @return [Array<BrowseEverything::FileEntry>]
def make_directory_entry(real_path)
pattern = File.join(real_path, '*')
Dir[pattern].collect { |f| details(f) }
Dir.glob(pattern).collect { |f| details(f) }
end

def make_pathname(path)
Expand All @@ -93,6 +94,13 @@ def file_size(path)
Rails.logger.error "Failed to find the file size for #{path}: #{error}"
0
end

# Determines whether or not a file entry is hidden
# @param [String] path
# @return [Boolean]
def hidden?(path)
path =~ /^\..+/
end
end
end
end
11 changes: 8 additions & 3 deletions lib/browse_everything/resource.rb
Expand Up @@ -12,13 +12,18 @@ def path
uri
end

def file?
url =~ /^file\:/
end

# Determine whether or not this file is a cloud resource
# @return [Boolean]
def cloud_file?
return false if url.nil?
url =~ /^https?\:/
end

m = /^https?\:/.match(url)
!m.nil?
def hidden?
file? && path =~ /^\./
end

private
Expand Down
Empty file.
8 changes: 8 additions & 0 deletions spec/lib/browse_everything/driver/file_system_spec.rb
Expand Up @@ -55,6 +55,14 @@
its(:type) { is_expected.to eq('application/pdf') }
specify { is_expected.not_to be_container }
end

context 'when there is a hidden file' do
it 'does not retrieve the file path' do
expect(contents.length).to eq 4
file_entry_names = contents.map(&:name)
expect(file_entry_names).not_to include '.hidden.txt'
end
end
end

context 'when there is a subdirectory' do
Expand Down

0 comments on commit 86d21fb

Please sign in to comment.