browse-everything 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@
2
2
 
3
3
  require File.expand_path('../helpers/browse_everything_helper', __dir__)
4
4
 
5
- class BrowseEverythingController < ActionController::Base
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
- # 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
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
- # 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
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
- def connector_response_url_options
80
- { protocol: request.protocol, host: request.host, port: request.port }
81
- end
79
+ def connector_response_url_options
80
+ { protocol: request.protocol, host: request.host, port: request.port }
81
+ end
82
82
 
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
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
- # Accesses the relative path for browsing from the Rails session
95
- # @return [String]
96
- def browse_path
97
- params[:path] || ''
98
- end
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
- # 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
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
- # 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
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
- # 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
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
- # 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
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
- 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
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
@@ -20,4 +20,8 @@ module BrowseEverythingHelper
20
20
  acceptable_types << 'application/x-directory'
21
21
  acceptable_types.any? { |type| mime_match?(file.type, type) }
22
22
  end
23
+
24
+ def file_size_to_human_size(file_size)
25
+ "#{file_size} bytes"
26
+ end
23
27
  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: number_to_human_size(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
- <%= number_to_human_size(file.size).sub(/Bytes/,'bytes') %>
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>
@@ -25,13 +25,13 @@ Gem::Specification.new do |spec|
25
25
  spec.add_dependency 'google-api-client', '~> 0.23'
26
26
  spec.add_dependency 'google_drive', '>= 2.1', "< 4"
27
27
  spec.add_dependency 'googleauth', '>= 0.6.6', '< 1.0'
28
- spec.add_dependency 'rails', '>= 4.2', '< 6.0'
28
+ spec.add_dependency 'rails', '>= 4.2', '< 7.0'
29
29
  spec.add_dependency 'ruby-box'
30
30
  spec.add_dependency 'signet', '~> 0.8'
31
31
  spec.add_dependency 'sprockets', '~> 3.7'
32
32
  spec.add_dependency 'typhoeus'
33
33
 
34
- spec.add_development_dependency 'bixby', '>= 1.0'
34
+ spec.add_development_dependency 'bixby', '~> 3.0'
35
35
  spec.add_development_dependency 'bundler', '>= 1.3'
36
36
  spec.add_development_dependency 'capybara'
37
37
  spec.add_development_dependency 'coveralls'
@@ -17,11 +17,11 @@ module BrowseEverything
17
17
 
18
18
  private
19
19
 
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
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
- # 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
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
- 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}"
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
- 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
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
@@ -100,21 +100,21 @@ module BrowseEverything
100
100
 
101
101
  private
102
102
 
103
- # Generate the options for the Rails URL generation for API callbacks
104
- # remove the script_name parameter from the url_options since that is causing issues
105
- # with the route not containing the engine path in rails 4.2.0
106
- # @return [Hash]
107
- def callback_options
108
- options = config.to_hash
109
- options.deep_symbolize_keys!
110
- options[:url_options].reject { |k, _v| k == :script_name }
111
- end
103
+ # Generate the options for the Rails URL generation for API callbacks
104
+ # remove the script_name parameter from the url_options since that is causing issues
105
+ # with the route not containing the engine path in rails 4.2.0
106
+ # @return [Hash]
107
+ def callback_options
108
+ options = config.to_hash
109
+ options.deep_symbolize_keys!
110
+ options[:url_options].reject { |k, _v| k == :script_name }
111
+ end
112
112
 
113
- # Generate the URL for the API callback
114
- # @return [String]
115
- def callback
116
- connector_response_url(callback_options)
117
- end
113
+ # Generate the URL for the API callback
114
+ # @return [String]
115
+ def callback
116
+ connector_response_url(callback_options)
117
+ end
118
118
  end
119
119
  end
120
120
  end
@@ -77,72 +77,72 @@ module BrowseEverything
77
77
 
78
78
  private
79
79
 
80
- def token_expired?
81
- return true if expiration_time.nil?
82
- Time.now.to_i > expiration_time
83
- end
80
+ def token_expired?
81
+ return true if expiration_time.nil?
82
+ Time.now.to_i > expiration_time
83
+ end
84
84
 
85
- def box_client
86
- if token_expired?
87
- session = box_session
88
- register_access_token(session.refresh_token(box_refresh_token))
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
- 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
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
- def authenticate
104
- session.authenticate
105
- end
103
+ def authenticate
104
+ session.authenticate
105
+ end
106
106
 
107
- def box_session
108
- authenticate
109
- end
107
+ def box_session
108
+ authenticate
109
+ end
110
110
 
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
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
- def box_token
125
- return unless @token
126
- @token.fetch('token', nil)
127
- end
124
+ def box_token
125
+ return unless @token
126
+ @token.fetch('token', nil)
127
+ end
128
128
 
129
- def box_refresh_token
130
- return unless @token
131
- @token.fetch('refresh_token', nil)
132
- end
129
+ def box_refresh_token
130
+ return unless @token
131
+ @token.fetch('refresh_token', nil)
132
+ end
133
133
 
134
- def expiration_time
135
- return unless @token
136
- @token.fetch('expires_at', nil).to_i
137
- end
134
+ def expiration_time
135
+ return unless @token
136
+ @token.fetch('expires_at', nil).to_i
137
+ end
138
138
 
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
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