browse-everything 0.15.1 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +61 -9
  3. data/.rubocop_todo.yml +2 -15
  4. data/.travis.yml +19 -19
  5. data/CONTRIBUTING.md +6 -6
  6. data/Gemfile +12 -8
  7. data/README.md +30 -0
  8. data/Rakefile +2 -1
  9. data/app/assets/javascripts/browse_everything/behavior.js.coffee +5 -0
  10. data/app/controllers/browse_everything_controller.rb +75 -23
  11. data/app/helpers/browse_everything_helper.rb +2 -8
  12. data/app/helpers/font_awesome_version_helper.rb +9 -8
  13. data/app/services/browse_everything_session.rb +10 -0
  14. data/app/services/browse_everything_session/provider_session.rb +42 -0
  15. data/app/services/browser_factory.rb +25 -0
  16. data/app/views/browse_everything/_files.html.erb +56 -6
  17. data/browse-everything.gemspec +29 -25
  18. data/config/routes.rb +7 -2
  19. data/lib/browse-everything.rb +2 -0
  20. data/lib/browse_everything.rb +45 -12
  21. data/lib/browse_everything/auth/google/credentials.rb +28 -0
  22. data/lib/browse_everything/auth/google/request_parameters.rb +61 -0
  23. data/lib/browse_everything/browser.rb +11 -4
  24. data/lib/browse_everything/driver/authentication_factory.rb +22 -0
  25. data/lib/browse_everything/driver/base.rb +72 -19
  26. data/lib/browse_everything/driver/box.rb +46 -17
  27. data/lib/browse_everything/driver/dropbox.rb +36 -10
  28. data/lib/browse_everything/driver/file_system.rb +14 -26
  29. data/lib/browse_everything/driver/google_drive.rb +187 -54
  30. data/lib/browse_everything/driver/s3.rb +81 -75
  31. data/lib/browse_everything/engine.rb +3 -2
  32. data/lib/browse_everything/file_entry.rb +3 -1
  33. data/lib/browse_everything/retriever.rb +103 -31
  34. data/lib/browse_everything/version.rb +3 -1
  35. data/lib/generators/browse_everything/assets_generator.rb +3 -2
  36. data/lib/generators/browse_everything/config_generator.rb +11 -9
  37. data/lib/generators/browse_everything/install_generator.rb +3 -2
  38. data/lib/generators/browse_everything/templates/browse_everything_providers.yml.example +12 -11
  39. data/spec/controllers/browse_everything_controller_spec.rb +80 -0
  40. data/spec/features/select_files_spec.rb +13 -13
  41. data/spec/features/test_compiling_stylesheets_spec.rb +2 -0
  42. data/spec/fixtures/vcr_cassettes/google_drive.yml +331 -0
  43. data/spec/fixtures/vcr_cassettes/retriever.yml +93 -0
  44. data/spec/helper/browse_everything_controller_helper_spec.rb +21 -7
  45. data/spec/javascripts/jasmine_spec.rb +2 -0
  46. data/spec/javascripts/support/jasmine_helper.rb +1 -0
  47. data/spec/lib/browse_everything/auth/google/credentials_spec.rb +41 -0
  48. data/spec/{unit → lib/browse_everything}/browse_everything_helper_spec.rb +2 -0
  49. data/spec/lib/browse_everything/browser_spec.rb +109 -0
  50. data/spec/{unit → lib/browse_everything/driver}/base_spec.rb +5 -4
  51. data/spec/{unit → lib/browse_everything/driver}/box_spec.rb +20 -5
  52. data/spec/{unit → lib/browse_everything/driver}/dropbox_spec.rb +15 -18
  53. data/spec/{unit → lib/browse_everything/driver}/file_system_spec.rb +32 -26
  54. data/spec/lib/browse_everything/driver/google_drive_spec.rb +171 -0
  55. data/spec/{unit → lib/browse_everything/driver}/s3_spec.rb +38 -21
  56. data/spec/lib/browse_everything/driver_spec.rb +38 -0
  57. data/spec/{unit → lib/browse_everything}/file_entry_spec.rb +4 -1
  58. data/spec/lib/browse_everything/retriever_spec.rb +200 -0
  59. data/spec/lib/browse_everything_spec.rb +67 -0
  60. data/spec/services/browse_everything_session/provider_session_spec.rb +50 -0
  61. data/spec/services/browser_factory_spec.rb +40 -0
  62. data/spec/spec_helper.rb +39 -18
  63. data/spec/support/app/controllers/file_handler_controller.rb +4 -4
  64. data/spec/support/app/views/file_handler/main.html.erb +1 -1
  65. data/spec/support/capybara.rb +17 -0
  66. data/spec/support/rake.rb +3 -1
  67. data/spec/support/wait_for_ajax.rb +14 -0
  68. data/spec/test_app_templates/Gemfile.extra +1 -0
  69. data/spec/test_app_templates/lib/generators/test_app_generator.rb +10 -4
  70. data/spec/views/browse_everything/{_file.html.erb_spec.rb → _files.html.erb_spec.rb} +24 -18
  71. data/tasks/ci.rake +2 -0
  72. metadata +159 -107
  73. data/app/views/browse_everything/_file.html.erb +0 -52
  74. data/app/views/browse_everything/resolve.html.erb +0 -1
  75. data/spec/unit/browser_spec.rb +0 -76
  76. data/spec/unit/retriever_spec.rb +0 -109
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 217e127add171d887e8e372ba7505f20bfd3c862
4
- data.tar.gz: f6de9170c170e8df631283bf3817259285798508
2
+ SHA256:
3
+ metadata.gz: f010bc868532bf8d950f23deb2057dbf1ef250d3e3ea6a8350cdd4d5652406e5
4
+ data.tar.gz: 61b2d58f7cec21225de6e85392fb0603d768ac2859aa842763dfdd65d535a0a5
5
5
  SHA512:
6
- metadata.gz: d9cfc43d9f3a117f5e2da42ffd6af90e92897c193c07559da01f7a3789c85212298d74da49fbeeb3fd5c461962cf8f246548d03b60f9a64f31ffffcf76ce1bc6
7
- data.tar.gz: ad1002469c1cddbd63c268f83ef083bcf56d0a1b8c5a6a6177626fe02e83f534eaafbf870223da4b7a8f28e649ec0b072ef34202fccc3856f6f3cad192dde3d1
6
+ metadata.gz: c0580e42f8762c2f29e64860c5e7444f82f4c569e724edd9cac32e894506a62f9a192591e7dbf294f6747906170223f6cd4ff59c09e7a56c9c65ece3065cd275
7
+ data.tar.gz: 311ab92c994db67da4a8f4206edc00a6d50006dbd3a9492a06ea87002067b20121cce4e8afb3110a2f46aef84fbb43682b520d7a47f63709e0d82370ef755236
data/.rubocop.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  inherit_from: .rubocop_todo.yml
2
2
 
3
3
  AllCops:
4
- TargetRubyVersion: 2.1
4
+ TargetRubyVersion: 2.4
5
5
  DisplayCopNames: true
6
6
  Include:
7
7
  - '**/Rakefile'
@@ -10,35 +10,87 @@ AllCops:
10
10
 
11
11
  Rails:
12
12
  Enabled: true
13
+ Rails/FilePath:
14
+ Exclude:
15
+ - 'lib/generators/browse_everything/config_generator.rb'
13
16
 
14
17
  Metrics/ClassLength:
15
18
  Max: 130
16
-
17
- # Configuration parameters: AllowURI, URISchemes.
19
+ Exclude:
20
+ - 'lib/browse_everything/driver/google_drive.rb'
18
21
  Metrics/LineLength:
19
22
  Max: 400
23
+ Metrics/BlockLength:
24
+ Exclude:
25
+ - 'spec/views/browse_everything/_files.html.erb_spec.rb'
26
+ - 'spec/unit/browse_everything_helper_spec.rb'
27
+ - 'spec/unit/browse_everything/retriever_spec.rb'
28
+ - 'spec/unit/browse_everything/file_entry_spec.rb'
29
+ - 'spec/unit/browse_everything/driver/s3_spec.rb'
30
+ - 'spec/unit/browse_everything/driver/google_drive_spec.rb'
31
+ - 'spec/unit/browse_everything/driver/file_system_spec.rb'
32
+ - 'spec/unit/browse_everything/driver/dropbox_spec.rb'
33
+ - 'spec/unit/browse_everything/driver/box_spec.rb'
34
+ - 'spec/unit/browse_everything/browser_spec.rb'
35
+ - 'spec/services/browser_factory_spec.rb'
36
+ - 'spec/services/browse_everything_session/provider_session_spec.rb'
37
+ - 'spec/helper/browse_everything_controller_helper_spec.rb'
38
+ - 'spec/controllers/browse_everything_controller_spec.rb'
39
+ - 'browse-everything.gemspec'
20
40
 
21
41
  RSpec/NestedGroups:
22
42
  Enabled: false
23
43
 
24
- RSpec/FilePath:
25
- Enabled: false
26
-
27
44
  RSpec/LeadingSubject:
28
45
  Enabled: false
29
46
 
30
47
  RSpec/ExampleLength:
31
48
  Exclude:
32
- - 'spec/unit/dropbox_spec.rb'
49
+ - 'spec/unit/browse_everything/driver/base_spec.rb'
50
+ - 'spec/unit/browse_everything/driver/box_spec.rb'
51
+ - 'spec/unit/browse_everything/driver/dropbox_spec.rb'
52
+ - 'spec/unit/browse_everything/driver/file_system_spec.rb'
53
+ - 'spec/unit/browse_everything/driver/google_drive_spec.rb'
54
+ - 'spec/unit/browse_everything/driver/s3_spec.rb'
33
55
  - 'spec/features/select_files_spec.rb'
34
56
  - 'spec/javascripts/jasmine_spec.rb'
35
57
 
36
58
  RSpec/MultipleExpectations:
37
59
  Exclude:
38
- - 'spec/unit/dropbox_spec.rb'
60
+ - 'spec/unit/browse_everything/driver/base_spec.rb'
61
+ - 'spec/unit/browse_everything/driver/box_spec.rb'
62
+ - 'spec/unit/browse_everything/driver/dropbox_spec.rb'
63
+ - 'spec/unit/browse_everything/driver/file_system_spec.rb'
64
+ - 'spec/unit/browse_everything/driver/google_drive_spec.rb'
65
+ - 'spec/unit/browse_everything/driver/s3_spec.rb'
66
+ - 'spec/features/**/*'
67
+ - 'spec/controllers/browse_everything_controller_spec.rb'
68
+ - 'spec/unit/browse_everything/browser_spec.rb'
39
69
 
40
70
  Style/NumericLiterals:
41
71
  MinDigits: 7
42
72
 
43
- Style/IndentationConsistency:
73
+ Layout/IndentationConsistency:
44
74
  EnforcedStyle: rails
75
+
76
+ Naming/FileName:
77
+ Exclude:
78
+ - 'browse-everything.gemspec'
79
+ - 'Gemfile'
80
+ - 'lib/browse-everything.rb'
81
+
82
+ Style/MixinUsage:
83
+ Exclude:
84
+ - 'spec/unit/browse_everything/driver/s3_spec.rb'
85
+ - 'spec/unit/browse_everything/driver/google_drive_spec.rb'
86
+ - 'spec/unit/browse_everything/driver/file_system_spec.rb'
87
+ - 'spec/unit/browse_everything/driver/dropbox_spec.rb'
88
+ - 'spec/unit/browse_everything/driver/box_spec.rb'
89
+ - 'spec/unit/browse_everything/driver/base_spec.rb'
90
+ - 'spec/unit/browse_everything/browser_spec.rb'
91
+ - 'spec/services/browser_factory_spec.rb'
92
+ - 'spec/helper/browse_everything_controller_helper_spec.rb'
93
+
94
+ Bundler/DuplicatedGem:
95
+ Exclude:
96
+ - 'Gemfile'
data/.rubocop_todo.yml CHANGED
@@ -36,13 +36,6 @@ RSpec/DescribeClass:
36
36
  Exclude:
37
37
  - 'spec/javascripts/jasmine_spec.rb'
38
38
 
39
- # Offense count: 2
40
- # Configuration parameters: Max.
41
- RSpec/ExampleLength:
42
- Exclude:
43
- - 'spec/features/select_files_spec.rb'
44
- - 'spec/javascripts/jasmine_spec.rb'
45
-
46
39
  # Offense count: 2
47
40
  RSpec/MultipleExpectations:
48
41
  Max: 2
@@ -83,12 +76,6 @@ Style/ClassAndModuleChildren:
83
76
  Style/Documentation:
84
77
  Enabled: false
85
78
 
86
- # Offense count: 1
87
- # Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts.
88
- Style/FileName:
89
- Exclude:
90
- - 'lib/browse-everything.rb'
91
-
92
79
  # Offense count: 2
93
80
  # Configuration parameters: MinBodyLength.
94
81
  Style/GuardClause:
@@ -102,7 +89,7 @@ Style/MultilineBlockChain:
102
89
 
103
90
  # Offense count: 1
104
91
  # Cop supports --auto-correct.
105
- Style/MultilineBlockLayout:
92
+ Layout/MultilineBlockLayout:
106
93
  Exclude:
107
94
  - 'spec/unit/dropbox_spec.rb'
108
95
 
@@ -111,7 +98,7 @@ Style/MultilineBlockLayout:
111
98
  # NamePrefix: is_, has_, have_
112
99
  # NamePrefixBlacklist: is_, has_, have_
113
100
  # NameWhitelist: is_a?
114
- Style/PredicateName:
101
+ Naming/PredicateName:
115
102
  Exclude:
116
103
  - 'spec/**/*'
117
104
  - 'app/helpers/browse_everything_helper.rb'
data/.travis.yml CHANGED
@@ -1,27 +1,27 @@
1
1
  language: ruby
2
2
  sudo: false
3
+ dist: trusty
4
+ sudo: required
5
+ addons:
6
+ chrome: stable
3
7
  cache:
4
8
  bundler: true
5
- directories:
6
- - "travis_phantomjs"
9
+
7
10
  before_install:
8
- - "phantomjs --version"
9
- - "export PATH=$PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64/bin:$PATH"
10
- - "phantomjs --version"
11
- - "if [ $(phantomjs --version) != '2.1.1' ]; then rm -rf $PWD/travis_phantomjs; mkdir -p $PWD/travis_phantomjs; fi"
12
- - "if [ $(phantomjs --version) != '2.1.1' ]; then wget https://assets.membergetmember.co/software/phantomjs-2.1.1-linux-x86_64.tar.bz2 -O $PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2; fi"
13
- - "if [ $(phantomjs --version) != '2.1.1' ]; then tar -xvf $PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2 -C $PWD/travis_phantomjs; fi"
14
- - "phantomjs --version"
11
+ - gem update --system # https://docs.travis-ci.com/user/languages/ruby/#Upgrading-RubyGems
12
+ - gem install bundler
13
+ - google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost &
15
14
 
16
15
  rvm:
17
- - "2.4.1"
18
- global_env:
19
- - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
16
+ - 2.5.1
17
+ - 2.4.4
18
+ - 2.3.7
19
+
20
20
  env:
21
- - "RAILS_VERSION=5.1.0"
22
- matrix:
23
- include:
24
- - rvm: "2.3.4"
25
- env: "RAILS_VERSION=5.0.2"
26
- - rvm: 2.2.7
27
- env: "RAILS_VERSION=4.2.8"
21
+ global:
22
+ - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
23
+ matrix:
24
+ - "RAILS_VERSION=5.2.0"
25
+ - "RAILS_VERSION=5.1.6"
26
+ - "RAILS_VERSION=5.0.7"
27
+ - "RAILS_VERSION=4.2.10"
data/CONTRIBUTING.md CHANGED
@@ -1,21 +1,21 @@
1
1
  # How to Contribute
2
2
 
3
- We want your help to make Project Hydra great.
3
+ We want your help to make Samvera Community great.
4
4
  There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things.
5
5
 
6
6
  ## Code of Conduct
7
7
 
8
- The Hydra community is dedicated to providing a welcoming and positive experience for all its
8
+ The Samvera Community is dedicated to providing a welcoming and positive experience for all its
9
9
  members, whether they are at a formal gathering, in a social setting, or taking part in activities
10
- online. Please see our [Code of Conduct](https://wiki.duraspace.org/display/hydra/Code+of+Conduct)
10
+ online. Please see our [Code of Conduct](https://wiki.duraspace.org/display/samvera/Code+of+Conduct)
11
11
  for more information.
12
12
 
13
- ## Hydra Project Intellectual Property Licensing and Ownership
13
+ ## Samvera Community Intellectual Property Licensing and Ownership
14
14
 
15
15
  All code contributors must have an Individual Contributor License Agreement (iCLA) on file with the Hydra Project Steering Group.
16
16
  If the contributor works for an institution, the institution must have a Corporate Contributor License Agreement (cCLA) on file.
17
17
 
18
- https://wiki.duraspace.org/display/hydra/Hydra+Project+Intellectual+Property+Licensing+and+Ownership
18
+ https://wiki.duraspace.org/display/samvera/Samvera+Community+Intellectual+Property+Licensing+and+Ownership
19
19
 
20
20
  You should also add yourself to the `CONTRIBUTORS.md` file in the root of the project.
21
21
 
@@ -61,7 +61,7 @@ You should also add yourself to the `CONTRIBUTORS.md` file in the root of the pr
61
61
  * This work greatly increases the usability of the code base and supports the on-ramping of new committers.
62
62
  * We will all be understanding of one another's time constraints in this area.
63
63
  * YARD examples:
64
- * [Hydra::Works::RemoveGenericFile](https://github.com/projecthydra-labs/hydra-works/blob/master/lib/hydra/works/services/generic_work/remove_generic_file.rb)
64
+ * [Hyrax::AdminSet](https://github.com/samvera/hyrax/blob/master/app/models/admin_set.rb)
65
65
  * [ActiveTriples::LocalName::Minter](https://github.com/ActiveTriples/active_triples-local_name/blob/master/lib/active_triples/local_name/minter.rb)
66
66
  * [Getting started with YARD](http://www.rubydoc.info/gems/yard/file/docs/GettingStarted.md)
67
67
 
data/Gemfile CHANGED
@@ -1,8 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in browse_everything.gemspec
4
6
  gemspec
5
7
 
8
+ group :development, :test do
9
+ gem 'pry-byebug' unless ENV['CI']
10
+ end
11
+
6
12
  # BEGIN ENGINE_CART BLOCK
7
13
  # engine_cart: 0.10.0
8
14
  # engine_cart stanza: 0.10.0
@@ -28,17 +34,15 @@ else
28
34
  end
29
35
 
30
36
  case ENV['RAILS_VERSION']
31
- when /^5.1/
32
- gem 'capybara', '~> 2.13.0'
33
- when /^4.2/
34
- gem 'responders', '~> 2.0'
35
- gem 'sass-rails', '>= 5.0'
37
+ when /^5\./
38
+ gem 'capybara', '~> 2.18.0'
39
+ when /^4\.2/
36
40
  gem 'coffee-rails', '~> 4.1.0'
37
41
  gem 'json', '~> 1.8'
42
+ gem 'responders', '~> 2.0'
43
+ gem 'sass-rails', '>= 5.0'
38
44
  end
39
45
  end
40
46
  # END ENGINE_CART BLOCK
41
47
 
42
- unless File.exist?(file)
43
- eval_gemfile File.expand_path('spec/test_app_templates/Gemfile.extra', File.dirname(__FILE__))
44
- end
48
+ eval_gemfile File.expand_path('spec/test_app_templates/Gemfile.extra', File.dirname(__FILE__)) unless File.exist?(file)
data/README.md CHANGED
@@ -16,6 +16,20 @@ download the files.
16
16
 
17
17
  **This gem does not depend on hydra-head**
18
18
 
19
+ ## Supported Ruby Releases
20
+ Currently, the following releases of Ruby are supported:
21
+ - 2.5.1
22
+ - 2.4.4
23
+ - 2.3.7
24
+ - Please note that this is the last release in the 2.3.x series, and support is [scheduled to be withdrawn](https://www.ruby-lang.org/en/news/2018/03/28/ruby-2-3-7-released/). We would strongly recommend that one upgrades from 2.3.7 in response to this.
25
+
26
+ ## Supported Rails Releases
27
+ - 5.2.0
28
+ - 5.1.6
29
+ - 5.0.7
30
+ - 4.2.10
31
+ - The supported Rail releases follow those specified by [the security policy of the Rails Community](https://rubyonrails.org/security/). As is the case with the supported Ruby releases, it is recommended that one upgrades from any Rails release no longer receiving security updates.
32
+
19
33
  ## Installation
20
34
 
21
35
  Add this lines to your application's Gemfile:
@@ -52,6 +66,22 @@ In `app/assets/javascripts/application.js` include jquery and the BrowseEverythi
52
66
  //= require browse_everything
53
67
  ```
54
68
 
69
+ ## Testing
70
+ This is a Rails Engine which is tested using the [engine_cart](https://github.com/cbeer/engine_cart) Gem. Test suites may be executed with the following invocation:
71
+
72
+ ```bash
73
+ bundle exec rake
74
+ ```
75
+
76
+ ### Testing Problems
77
+ Should you attempt to execute the test suite and encounter the following error:
78
+ ```bash
79
+ Your Ruby version is 2.x.x, but your Gemfile specified 2.y.z
80
+ ```
81
+ ...then you must clean the internal test app generated by `engine_cart` with the following:
82
+ ```bash
83
+ bundle exec rake engine_cart:clean
84
+ ```
55
85
 
56
86
  ## Usage
57
87
 
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
- #!/usr/bin/env rake
1
+ # frozen_string_literal: true
2
+
2
3
  require 'bundler/gem_tasks'
3
4
 
4
5
  Dir.glob('tasks/*.rake').each { |r| import r }
@@ -323,6 +323,11 @@ $ ->
323
323
 
324
324
  auto_toggle = ->
325
325
  triggers = $('*[data-toggle=browse-everything]')
326
+ if Rails?
327
+ $.ajaxSetup({
328
+ headers: { 'X-CSRF-TOKEN': (Rails || $.rails).csrfToken() || '' }
329
+ });
330
+
326
331
  triggers.each () ->
327
332
  ctx = $(this).data('ev-state')
328
333
  $(this).browseEverything($(this).data()) unless ctx?
@@ -1,4 +1,6 @@
1
- require File.expand_path('../../helpers/browse_everything_helper', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('../helpers/browse_everything_helper', __dir__)
2
4
 
3
5
  class BrowseEverythingController < ActionController::Base
4
6
  layout 'browse_everything'
@@ -6,66 +8,115 @@ class BrowseEverythingController < ActionController::Base
6
8
 
7
9
  protect_from_forgery with: :exception
8
10
 
9
- after_action { session["#{provider_name}_token"] = provider.token unless provider.nil? }
11
+ after_action do
12
+ provider_session.token = provider.token unless provider.nil? || provider.token.blank?
13
+ end
14
+
15
+ def provider_contents
16
+ raise BrowseEverything::NotImplementedError, 'No provider supported' if provider.nil?
17
+ raise BrowseEverything::NotAuthorizedError, 'Not authorized' unless provider.authorized?
18
+
19
+ provider.contents(browse_path)
20
+ end
10
21
 
11
22
  def index
12
23
  render layout: !request.xhr?
13
24
  end
14
25
 
26
+ # Either render the link to authorization or render the files
27
+ # provider#show method is invoked here
15
28
  def show
16
- render layout: !request.xhr?
29
+ render partial: 'files', layout: !request.xhr?
30
+ rescue StandardError => error
31
+ reset_provider_session!
32
+
33
+ # Should an error be raised, log the error and redirect the use to reauthenticate
34
+ logger.warn "Failed to retrieve the hosted files: #{error}"
35
+ render partial: 'auth', layout: !request.xhr?
17
36
  end
18
37
 
38
+ # Action for the OAuth2 callback
39
+ # Authenticate against the Google API and store the token in the session
19
40
  def auth
20
- session["#{provider_name}_token"] = provider.connect(params, session["#{provider_name}_data"])
41
+ # params contains the access code with with the key :code
42
+ provider_session.token = provider.connect(params, provider_session.data)
21
43
  end
22
44
 
23
45
  def resolve
24
46
  selected_files = params[:selected_files] || []
25
- @links = selected_files.collect do |file|
26
- p, f = file.split(/:/)
27
- (url, extra) = browser.providers[p].link_for(f)
47
+ selected_links = selected_files.collect do |file|
48
+ provider_key_value, uri = file.split(/:/)
49
+ provider_key = provider_key_value.to_sym
50
+ (url, extra) = browser.providers[provider_key].link_for(uri)
28
51
  result = { url: url }
29
52
  result.merge!(extra) unless extra.nil?
30
53
  result
31
54
  end
55
+
32
56
  respond_to do |format|
33
57
  format.html { render layout: false }
34
- format.json { render json: @links }
58
+ format.json { render json: selected_links }
35
59
  end
36
60
  end
37
61
 
38
62
  private
39
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
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
78
+
79
+ # Generates the authentication link for a given provider service
80
+ # @return [String] the authentication link
40
81
  def auth_link
41
82
  @auth_link ||= if provider.present?
42
83
  link, data = provider.auth_link
43
- session["#{provider_name}_data"] = data
84
+ provider_session.data = data
44
85
  link = "#{link}&state=#{provider.key}" unless link.to_s.include?('state')
45
86
  link
46
- end # else nil, implicitly
87
+ end
47
88
  end
48
89
 
49
- def browser
50
- if @browser.nil?
51
- @browser = BrowseEverything::Browser.new(url_options)
52
- @browser.providers.values.each do |p|
53
- p.token = session["#{p.key}_token"]
54
- end
55
- end
56
- @browser
90
+ # Accesses the relative path for browsing from the Rails session
91
+ # @return [String]
92
+ def browse_path
93
+ params[:path] || ''
57
94
  end
58
95
 
59
- def browse_path
60
- @path ||= params[:path] || ''
96
+ # Generate the provider name from the Rails session state value
97
+ # @return [String]
98
+ def provider_name_from_state
99
+ params[:state].to_s.split(/\|/).last
61
100
  end
62
101
 
102
+ # Generates the name of the provider using Rails session values
103
+ # @return [String]
104
+ def provider_name
105
+ params[:provider] || provider_name_from_state || browser.providers.each_key.to_a.first
106
+ end
107
+
108
+ # Retrieve the Driver for each request
109
+ # @return [BrowseEverything::Driver::Base]
63
110
  def provider
64
- @provider ||= browser.providers[provider_name]
111
+ browser.providers[provider_name.to_sym] || browser.first_provider
65
112
  end
66
113
 
67
- def provider_name
68
- @provider_name ||= params[:provider] || params[:state].to_s.split(/\|/).last
114
+ # Constructs a browser manager Object
115
+ # Browser state cannot persist between requests to the Controller
116
+ # Hence, a Browser must be reinstantiated for each request using the state provided in the Rails session
117
+ # @return [BrowseEverything::Browser]
118
+ def browser
119
+ BrowserFactory.build(session: session, url_options: url_options)
69
120
  end
70
121
 
71
122
  helper_method :auth_link
@@ -73,4 +124,5 @@ class BrowseEverythingController < ActionController::Base
73
124
  helper_method :browse_path
74
125
  helper_method :provider
75
126
  helper_method :provider_name
127
+ helper_method :provider_contents
76
128
  end