browse-everything 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +105 -30
- data/.gitignore +4 -2
- data/.rubocop.yml +54 -34
- data/.rubocop_todo.yml +0 -5
- data/.tool-versions +2 -0
- data/CONTRIBUTING.md +22 -0
- data/Gemfile +41 -33
- data/README.md +66 -31
- data/Rakefile +9 -1
- data/app/assets/javascripts/browse_everything/behavior.js +45 -31
- data/app/assets/javascripts/browse_everything.js +1 -1
- data/app/assets/javascripts/treetable.webpack.js +687 -0
- data/app/controllers/browse_everything_controller.rb +60 -60
- data/app/helpers/browse_everything_helper.rb +4 -0
- data/app/views/browse_everything/_files.html.erb +3 -2
- data/bin/rails +14 -0
- data/browse-everything.gemspec +13 -12
- data/lib/browse_everything/auth/google/credentials.rb +5 -5
- data/lib/browse_everything/auth/google/request_parameters.rb +38 -38
- data/lib/browse_everything/driver/base.rb +15 -14
- data/lib/browse_everything/driver/box.rb +56 -56
- data/lib/browse_everything/driver/dropbox.rb +44 -41
- data/lib/browse_everything/driver/file_system.rb +31 -18
- data/lib/browse_everything/driver/google_drive.rb +38 -38
- data/lib/browse_everything/driver/s3.rb +61 -61
- data/lib/browse_everything/engine.rb +10 -3
- data/lib/browse_everything/file_entry.rb +1 -1
- data/lib/browse_everything/retriever.rb +69 -69
- data/lib/browse_everything/version.rb +1 -1
- data/lib/browse_everything.rb +1 -1
- data/spec/dummy_test_app/Rakefile +6 -0
- data/spec/dummy_test_app/app/assets/config/manifest.js +3 -0
- data/spec/dummy_test_app/app/assets/images/.keep +0 -0
- data/spec/dummy_test_app/app/assets/javascripts/application.js +25 -0
- data/spec/dummy_test_app/app/assets/javascripts/cable.js +13 -0
- data/spec/dummy_test_app/app/assets/javascripts/channels/.keep +0 -0
- data/spec/dummy_test_app/app/assets/stylesheets/application.scss +18 -0
- data/spec/dummy_test_app/app/channels/application_cable/channel.rb +4 -0
- data/spec/dummy_test_app/app/channels/application_cable/connection.rb +4 -0
- data/spec/dummy_test_app/app/controllers/application_controller.rb +3 -0
- data/spec/dummy_test_app/app/controllers/concerns/.keep +0 -0
- data/spec/{support → dummy_test_app}/app/controllers/file_handler_controller.rb +0 -0
- data/spec/dummy_test_app/app/helpers/application_helper.rb +2 -0
- data/spec/dummy_test_app/app/jobs/application_job.rb +2 -0
- data/spec/dummy_test_app/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy_test_app/app/models/application_record.rb +3 -0
- data/spec/dummy_test_app/app/models/concerns/.keep +0 -0
- data/spec/dummy_test_app/app/views/file_handler/index.html.erb +10 -0
- data/spec/{support → dummy_test_app}/app/views/file_handler/main.html.erb +6 -3
- data/spec/dummy_test_app/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy_test_app/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy_test_app/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy_test_app/bin/bundle +3 -0
- data/spec/dummy_test_app/bin/rails +4 -0
- data/spec/dummy_test_app/bin/rake +4 -0
- data/spec/dummy_test_app/bin/setup +38 -0
- data/spec/dummy_test_app/bin/update +29 -0
- data/spec/dummy_test_app/bin/yarn +11 -0
- data/spec/dummy_test_app/config/application.rb +27 -0
- data/spec/dummy_test_app/config/boot.rb +5 -0
- data/spec/dummy_test_app/config/browse_everything_providers.yml +25 -0
- data/spec/dummy_test_app/config/cable.yml +10 -0
- data/spec/dummy_test_app/config/database.yml +25 -0
- data/spec/dummy_test_app/config/environment.rb +5 -0
- data/spec/dummy_test_app/config/environments/development.rb +54 -0
- data/spec/dummy_test_app/config/environments/production.rb +91 -0
- data/spec/dummy_test_app/config/environments/test.rb +42 -0
- data/spec/dummy_test_app/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/dummy_test_app/config/initializers/assets.rb +14 -0
- data/spec/dummy_test_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy_test_app/config/initializers/cookies_serializer.rb +5 -0
- data/spec/dummy_test_app/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy_test_app/config/initializers/inflections.rb +16 -0
- data/spec/dummy_test_app/config/initializers/mime_types.rb +4 -0
- data/spec/dummy_test_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy_test_app/config/locales/en.yml +33 -0
- data/spec/dummy_test_app/config/puma.rb +56 -0
- data/spec/dummy_test_app/config/routes.rb +9 -0
- data/spec/dummy_test_app/config/secrets.yml +32 -0
- data/spec/dummy_test_app/config/spring.rb +6 -0
- data/spec/dummy_test_app/config.ru +5 -0
- data/spec/dummy_test_app/lib/assets/.keep +0 -0
- data/spec/dummy_test_app/log/.keep +0 -0
- data/spec/dummy_test_app/package.json +5 -0
- data/spec/dummy_test_app/public/404.html +67 -0
- data/spec/dummy_test_app/public/422.html +67 -0
- data/spec/dummy_test_app/public/500.html +66 -0
- data/spec/dummy_test_app/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy_test_app/public/apple-touch-icon.png +0 -0
- data/spec/dummy_test_app/public/favicon.ico +0 -0
- data/spec/dummy_test_app/tmp/.gitkeep +0 -0
- data/spec/features/select_files_spec.rb +1 -0
- data/spec/features/test_compiling_stylesheets_spec.rb +1 -1
- data/spec/lib/browse_everything/driver_spec.rb +43 -3
- data/spec/spec_helper.rb +3 -28
- data/tasks/ci.rake +1 -1
- metadata +180 -94
- data/karma.conf.js +0 -71
- data/spec/javascripts/behavior_spec.js +0 -7
- data/spec/javascripts/helpers/jasmine-jquery.js +0 -838
- data/spec/javascripts/helpers/jquery.js +0 -11008
- data/spec/javascripts/karma_spec.rb +0 -16
- data/spec/support/app/views/file_handler/index.html.erb +0 -6
- data/spec/test_app_templates/Gemfile.extra +0 -9
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +0 -61
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require File.expand_path('../helpers/browse_everything_helper', __dir__)
|
4
4
|
|
5
|
-
class BrowseEverythingController <
|
5
|
+
class BrowseEverythingController < ApplicationController
|
6
6
|
layout 'browse_everything'
|
7
7
|
helper BrowseEverythingHelper
|
8
8
|
|
@@ -61,72 +61,72 @@ class BrowseEverythingController < ActionController::Base
|
|
61
61
|
|
62
62
|
private
|
63
63
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
64
|
+
# Constructs or accesses an existing session manager Object
|
65
|
+
# @return [BrowseEverythingSession::ProviderSession] the session manager
|
66
|
+
def provider_session
|
67
|
+
BrowseEverythingSession::ProviderSession.new(session: session, name: provider_name)
|
68
|
+
end
|
69
69
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
70
|
+
# Clears all authentication tokens, codes, and other data from the Rails session
|
71
|
+
def reset_provider_session!
|
72
|
+
return unless @provider_session
|
73
|
+
@provider_session.token = nil
|
74
|
+
@provider_session.code = nil
|
75
|
+
@provider_session.data = nil
|
76
|
+
@provider_session = nil
|
77
|
+
end
|
78
78
|
|
79
|
-
|
80
|
-
|
81
|
-
|
79
|
+
def connector_response_url_options
|
80
|
+
{ protocol: request.protocol, host: request.host, port: request.port }
|
81
|
+
end
|
82
82
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
83
|
+
# Generates the authentication link for a given provider service
|
84
|
+
# @return [String] the authentication link
|
85
|
+
def auth_link
|
86
|
+
@auth_link ||= if provider.present?
|
87
|
+
link, data = provider.auth_link(connector_response_url_options)
|
88
|
+
provider_session.data = data
|
89
|
+
link = "#{link}&state=#{provider.key}" unless link.to_s.include?('state')
|
90
|
+
link
|
91
|
+
end
|
92
|
+
end
|
93
93
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
94
|
+
# Accesses the relative path for browsing from the Rails session
|
95
|
+
# @return [String]
|
96
|
+
def browse_path
|
97
|
+
params[:path] || ''
|
98
|
+
end
|
99
99
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
100
|
+
# Generate the provider name from the Rails session state value
|
101
|
+
# @return [String]
|
102
|
+
def provider_name_from_state
|
103
|
+
params[:state].to_s.split(/\|/).last
|
104
|
+
end
|
105
105
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
106
|
+
# Generates the name of the provider using Rails session values
|
107
|
+
# @return [String]
|
108
|
+
def provider_name
|
109
|
+
params[:provider] || provider_name_from_state || browser.providers.each_key.to_a.first
|
110
|
+
end
|
111
111
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
112
|
+
# Retrieve the Driver for each request
|
113
|
+
# @return [BrowseEverything::Driver::Base]
|
114
|
+
def provider
|
115
|
+
browser.providers[provider_name.to_sym] || browser.first_provider
|
116
|
+
end
|
117
117
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
118
|
+
# Constructs a browser manager Object
|
119
|
+
# Browser state cannot persist between requests to the Controller
|
120
|
+
# Hence, a Browser must be reinstantiated for each request using the state provided in the Rails session
|
121
|
+
# @return [BrowseEverything::Browser]
|
122
|
+
def browser
|
123
|
+
BrowserFactory.build(session: session, url_options: url_options)
|
124
|
+
end
|
125
125
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
126
|
+
helper_method :auth_link
|
127
|
+
helper_method :browser
|
128
|
+
helper_method :browse_path
|
129
|
+
helper_method :provider
|
130
|
+
helper_method :provider_name
|
131
|
+
helper_method :provider_contents
|
132
132
|
end
|
@@ -16,6 +16,7 @@
|
|
16
16
|
<% disabled = false %>
|
17
17
|
<% else %>
|
18
18
|
<% max_size = provider.config[:max_upload_file_size].to_i %>
|
19
|
+
<% max_human_size = file_size_to_human_size(max_size) %>
|
19
20
|
<% disabled = file.size > max_size %>
|
20
21
|
<% end %>
|
21
22
|
|
@@ -28,7 +29,7 @@
|
|
28
29
|
|
29
30
|
<td role="gridcell" title="<%= file.name %>" class="<%=file.container? ? 'ev-container' : 'ev-file'%> ev-file-name">
|
30
31
|
<% if disabled %>
|
31
|
-
<span title="<%= t('browse_everything.size_disabled', max_size:
|
32
|
+
<span title="<%= t('browse_everything.size_disabled', max_size: max_human_size) %>"
|
32
33
|
class="<%=file.container? ? 'folder' : 'file'%>" aria-hidden="true">
|
33
34
|
<%= file.name %>
|
34
35
|
</span>
|
@@ -53,7 +54,7 @@
|
|
53
54
|
|
54
55
|
<% if file.size %>
|
55
56
|
<td role="gridcell" class="ev-file-size">
|
56
|
-
<%=
|
57
|
+
<%= file_size_to_human_size(file.size) %>
|
57
58
|
</td>
|
58
59
|
<% else %>
|
59
60
|
<td role="gridcell" class="ev-file-size">Unknown</td>
|
data/bin/rails
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails gems
|
3
|
+
# installed from the root of your application.
|
4
|
+
|
5
|
+
ENGINE_ROOT = File.expand_path('..', __dir__)
|
6
|
+
ENGINE_PATH = File.expand_path('../lib/browse_everything/engine', __dir__)
|
7
|
+
APP_PATH = File.expand_path('../spec/dummy_test_app/config/application', __dir__)
|
8
|
+
|
9
|
+
# Set up gems listed in the Gemfile.
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
11
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
12
|
+
|
13
|
+
require 'rails/all'
|
14
|
+
require 'rails/engine/commands'
|
data/browse-everything.gemspec
CHANGED
@@ -15,30 +15,30 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.license = 'Apache 2'
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split(/\000/)
|
18
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
19
|
spec.require_paths = ['lib']
|
21
20
|
|
22
21
|
spec.add_dependency 'addressable', '~> 2.5'
|
23
22
|
spec.add_dependency 'aws-sdk-s3'
|
24
|
-
spec.add_dependency 'dropbox_api', '>= 0.1.
|
25
|
-
spec.add_dependency 'google-
|
26
|
-
spec.add_dependency '
|
27
|
-
spec.add_dependency '
|
28
|
-
spec.add_dependency 'rails', '>= 4.2', '< 6.0'
|
23
|
+
spec.add_dependency 'dropbox_api', '>= 0.1.20'
|
24
|
+
spec.add_dependency 'google-apis-drive_v3'
|
25
|
+
spec.add_dependency 'googleauth', '>= 0.6.6', '< 2.0'
|
26
|
+
spec.add_dependency 'rails', '>= 4.2', '< 7.1'
|
29
27
|
spec.add_dependency 'ruby-box'
|
30
28
|
spec.add_dependency 'signet', '~> 0.8'
|
31
|
-
spec.add_dependency 'sprockets', '~> 3.7'
|
32
29
|
spec.add_dependency 'typhoeus'
|
33
30
|
|
34
|
-
|
31
|
+
# Development dependencies include dependencies necessary for running
|
32
|
+
# the dummy test app at ./spec/dummy_test_app
|
33
|
+
|
34
|
+
spec.add_development_dependency 'bixby', '~> 5.0'
|
35
|
+
spec.add_development_dependency 'bootstrap', "~> 4.0" # we do not support bootstrap 5
|
35
36
|
spec.add_development_dependency 'bundler', '>= 1.3'
|
36
37
|
spec.add_development_dependency 'capybara'
|
37
|
-
spec.add_development_dependency 'coveralls'
|
38
|
-
spec.add_development_dependency 'engine_cart', '~> 2.0'
|
39
38
|
spec.add_development_dependency 'factory_bot_rails'
|
40
|
-
spec.add_development_dependency '
|
39
|
+
spec.add_development_dependency 'jquery-rails'
|
41
40
|
spec.add_development_dependency 'pry-byebug'
|
41
|
+
spec.add_development_dependency 'puma'
|
42
42
|
spec.add_development_dependency 'rails-controller-testing'
|
43
43
|
spec.add_development_dependency 'rake'
|
44
44
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
@@ -46,9 +46,10 @@ Gem::Specification.new do |spec|
|
|
46
46
|
spec.add_development_dependency 'rspec-rails'
|
47
47
|
spec.add_development_dependency 'rspec_junit_formatter'
|
48
48
|
spec.add_development_dependency 'rubocop-rspec'
|
49
|
+
spec.add_development_dependency 'sass-rails'
|
49
50
|
spec.add_development_dependency 'selenium-webdriver'
|
50
|
-
spec.add_development_dependency 'simplecov'
|
51
51
|
spec.add_development_dependency 'sqlite3'
|
52
|
+
spec.add_development_dependency 'turbolinks'
|
52
53
|
spec.add_development_dependency 'webdrivers'
|
53
54
|
spec.add_development_dependency 'webmock'
|
54
55
|
end
|
@@ -17,11 +17,11 @@ module BrowseEverything
|
|
17
17
|
|
18
18
|
private
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
# Structure a hash from existing access token values (usually cached within a Cookie)
|
21
|
+
# @return [Hash]
|
22
|
+
def build_token_hash
|
23
|
+
{ 'access_token' => access_token }
|
24
|
+
end
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -14,47 +14,47 @@ module BrowseEverything
|
|
14
14
|
|
15
15
|
private
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
17
|
+
# The default query parameters for the Google Drive API
|
18
|
+
# @return [Hash]
|
19
|
+
def default_params
|
20
|
+
{
|
21
|
+
q: default_query,
|
22
|
+
order_by: 'modifiedTime desc,folder,name',
|
23
|
+
fields: 'nextPageToken,files(name,id,mimeType,size,modifiedTime,parents,web_content_link)',
|
24
|
+
supports_team_drives: true,
|
25
|
+
include_team_drive_items: true,
|
26
|
+
corpora: 'user,allTeamDrives',
|
27
|
+
page_size: 1000
|
28
|
+
}
|
29
|
+
end
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
field_queries.join(' ')
|
31
|
+
def default_query
|
32
|
+
field_queries = []
|
33
|
+
contraints.each_pair do |field, constraints|
|
34
|
+
field_constraint = constraints.join(" and #{field} ")
|
35
|
+
field_queries << "#{field} #{field_constraint}"
|
38
36
|
end
|
37
|
+
field_queries.join(' ')
|
38
|
+
end
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
40
|
+
def contraints
|
41
|
+
{
|
42
|
+
'mimeType' => [
|
43
|
+
'!= \'application/vnd.google-apps.audio\'',
|
44
|
+
'!= \'application/vnd.google-apps.document\'',
|
45
|
+
'!= \'application/vnd.google-apps.drawing\'',
|
46
|
+
'!= \'application/vnd.google-apps.form\'',
|
47
|
+
'!= \'application/vnd.google-apps.fusiontable\'',
|
48
|
+
'!= \'application/vnd.google-apps.map\'',
|
49
|
+
'!= \'application/vnd.google-apps.photo\'',
|
50
|
+
'!= \'application/vnd.google-apps.presentation\'',
|
51
|
+
'!= \'application/vnd.google-apps.script\'',
|
52
|
+
'!= \'application/vnd.google-apps.site\'',
|
53
|
+
'!= \'application/vnd.google-apps.spreadsheet\'',
|
54
|
+
'!= \'application/vnd.google-apps.video\''
|
55
|
+
]
|
56
|
+
}
|
57
|
+
end
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
@@ -32,6 +32,7 @@ module BrowseEverything
|
|
32
32
|
# @param subclass [Class] the class inheriting from BrowseEverything::Driver::Base
|
33
33
|
def inherited(subclass)
|
34
34
|
subclass.sorter = sorter
|
35
|
+
super
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
@@ -100,21 +101,21 @@ module BrowseEverything
|
|
100
101
|
|
101
102
|
private
|
102
103
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
104
|
+
# Generate the options for the Rails URL generation for API callbacks
|
105
|
+
# remove the script_name parameter from the url_options since that is causing issues
|
106
|
+
# with the route not containing the engine path in rails 4.2.0
|
107
|
+
# @return [Hash]
|
108
|
+
def callback_options
|
109
|
+
options = config.to_hash
|
110
|
+
options.deep_symbolize_keys!
|
111
|
+
options[:url_options].reject { |k, _v| k == :script_name }
|
112
|
+
end
|
112
113
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
114
|
+
# Generate the URL for the API callback
|
115
|
+
# @return [String]
|
116
|
+
def callback
|
117
|
+
connector_response_url(callback_options)
|
118
|
+
end
|
118
119
|
end
|
119
120
|
end
|
120
121
|
end
|
@@ -77,72 +77,72 @@ module BrowseEverything
|
|
77
77
|
|
78
78
|
private
|
79
79
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
80
|
+
def token_expired?
|
81
|
+
return true if expiration_time.nil?
|
82
|
+
Time.now.to_i > expiration_time
|
83
|
+
end
|
84
84
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
end
|
90
|
-
RubyBox::Client.new(box_session)
|
85
|
+
def box_client
|
86
|
+
if token_expired?
|
87
|
+
session = box_session
|
88
|
+
register_access_token(session.refresh_token(box_refresh_token))
|
91
89
|
end
|
90
|
+
RubyBox::Client.new(box_session)
|
91
|
+
end
|
92
92
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
93
|
+
def session
|
94
|
+
AuthenticationFactory.new(
|
95
|
+
self.class.authentication_klass,
|
96
|
+
client_id: config[:client_id],
|
97
|
+
client_secret: config[:client_secret],
|
98
|
+
access_token: box_token,
|
99
|
+
refresh_token: box_refresh_token
|
100
|
+
)
|
101
|
+
end
|
102
102
|
|
103
|
-
|
104
|
-
|
105
|
-
|
103
|
+
def authenticate
|
104
|
+
session.authenticate
|
105
|
+
end
|
106
106
|
|
107
|
-
|
108
|
-
|
109
|
-
|
107
|
+
def box_session
|
108
|
+
authenticate
|
109
|
+
end
|
110
110
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
111
|
+
# If there is an active session, {@token} will be set by {BrowseEverythingController} using data stored in the
|
112
|
+
# session. However, if there is no prior session, or the token has expired, we reset it here using # a new
|
113
|
+
# access_token received from {#box_session}.
|
114
|
+
#
|
115
|
+
# @param [OAuth2::AccessToken] access_token
|
116
|
+
def register_access_token(access_token)
|
117
|
+
@token = {
|
118
|
+
'token' => access_token.token,
|
119
|
+
'refresh_token' => access_token.refresh_token,
|
120
|
+
'expires_at' => access_token.expires_at
|
121
|
+
}
|
122
|
+
end
|
123
123
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
124
|
+
def box_token
|
125
|
+
return unless @token
|
126
|
+
@token.fetch('token', nil)
|
127
|
+
end
|
128
128
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
129
|
+
def box_refresh_token
|
130
|
+
return unless @token
|
131
|
+
@token.fetch('refresh_token', nil)
|
132
|
+
end
|
133
133
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
134
|
+
def expiration_time
|
135
|
+
return unless @token
|
136
|
+
@token.fetch('expires_at', nil).to_i
|
137
|
+
end
|
138
138
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
139
|
+
# Constructs a BrowseEverything::FileEntry object for a Box file
|
140
|
+
# resource
|
141
|
+
# @param file [String] ID to the file resource
|
142
|
+
# @return [BrowseEverything::File]
|
143
|
+
def directory_entry(file)
|
144
|
+
BrowseEverything::FileEntry.new(file.id, "#{key}:#{file.id}", file.name, file.size, file.created_at, file.type == 'folder')
|
145
|
+
end
|
146
146
|
end
|
147
147
|
end
|
148
148
|
end
|
@@ -16,14 +16,14 @@ module BrowseEverything
|
|
16
16
|
class << self
|
17
17
|
private
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
19
|
+
def klass_for(metadata)
|
20
|
+
case metadata
|
21
|
+
when DropboxApi::Metadata::File
|
22
|
+
FileFactory
|
23
|
+
else
|
24
|
+
ResourceFactory
|
26
25
|
end
|
26
|
+
end
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -124,11 +124,14 @@ module BrowseEverything
|
|
124
124
|
end
|
125
125
|
|
126
126
|
def auth_link(url_options)
|
127
|
-
authenticator.authorize_url redirect_uri: redirect_uri(url_options)
|
127
|
+
authenticator.auth_code.authorize_url redirect_uri: redirect_uri(url_options)
|
128
128
|
end
|
129
129
|
|
130
130
|
def connect(params, _data, url_options)
|
131
|
-
|
131
|
+
built_redirect_uri = redirect_uri(url_options)
|
132
|
+
token_code = params[:code]
|
133
|
+
|
134
|
+
auth_bearer = authenticator.auth_code.get_token(token_code, redirect_uri: built_redirect_uri)
|
132
135
|
self.token = auth_bearer.token
|
133
136
|
end
|
134
137
|
|
@@ -138,44 +141,44 @@ module BrowseEverything
|
|
138
141
|
|
139
142
|
private
|
140
143
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
144
|
+
def session
|
145
|
+
AuthenticationFactory.new(
|
146
|
+
self.class.authentication_klass,
|
147
|
+
config[:client_id],
|
148
|
+
config[:client_secret]
|
149
|
+
)
|
150
|
+
end
|
148
151
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
+
def authenticate
|
153
|
+
session.authenticate
|
154
|
+
end
|
152
155
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
+
def authenticator
|
157
|
+
@authenticator ||= authenticate
|
158
|
+
end
|
156
159
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
+
def client
|
161
|
+
DropboxApi::Client.new(token)
|
162
|
+
end
|
160
163
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
+
def redirect_uri(url_options)
|
165
|
+
connector_response_url(**url_options)
|
166
|
+
end
|
164
167
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
168
|
+
# Ensures that the "tmp" directory is used if there is no default download
|
169
|
+
# directory specified in the configuration
|
170
|
+
# @return [String]
|
171
|
+
def default_download_directory
|
172
|
+
Rails.root.join('tmp')
|
173
|
+
end
|
171
174
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
175
|
+
# Retrieves the directory path for downloads used when retrieving the
|
176
|
+
# resource from Dropbox
|
177
|
+
# @return [String]
|
178
|
+
def download_directory_path
|
179
|
+
dir_path = config[:download_directory] || default_download_directory
|
180
|
+
File.expand_path(dir_path)
|
181
|
+
end
|
179
182
|
end
|
180
183
|
end
|
181
184
|
end
|