openstax_accounts 6.1.7 → 6.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5baab38c25cc2d119bc67c65740b6fa40a99056
4
- data.tar.gz: 63ae3554c50de33b42dfabd0c7781ca4e5d10ea6
3
+ metadata.gz: a14d93863001f4a2e859e6512e8a24ef577fa1b2
4
+ data.tar.gz: e0b513f8258a6dc438246c0e607ec39b7f474b75
5
5
  SHA512:
6
- metadata.gz: bed53557a3e3179ce6dea7f0382571d9f7e3a6e4b073f30faa6f331e21644088b812f947b29f6dede5ae875d6e36231d55fbe4b16ffcdd5537871467ec12fd51
7
- data.tar.gz: e18a4a56e5e93a5b65a61abf5cff7675aaf6d73620a8d6187953ba25580f4f2055a5e6a37253dd81d2f4da3ef88a523347700a7c545baa36e0768eff1599c785
6
+ metadata.gz: 46c3dfda5ddfe710b79ff9786b2f5615a07393bf92e7e2d6eec6c8f6ee863d817c68eaaf4f0241dc918ee068a4e23016f950abd38d97e6a5faa6d316d0f31cdf
7
+ data.tar.gz: a545e7cd3e78e7902078d6e5f50dbea4268987d6abef5ee3524723fa13c799cbd31ed3837a0e2aae33ab8813313239a621cbdc08e4c05227afd12e2454c9ebaa
@@ -7,6 +7,10 @@ module OpenStax
7
7
 
8
8
  skip_before_filter :authenticate_user!
9
9
 
10
+ def configuration
11
+ OpenStax::Accounts.configuration
12
+ end
13
+
10
14
  end
11
15
 
12
16
  end
@@ -3,7 +3,7 @@ module OpenStax
3
3
  class SessionsController < OpenStax::Accounts::ApplicationController
4
4
 
5
5
  def new
6
- if OpenStax::Accounts.configuration.enable_stubbing?
6
+ if configuration.enable_stubbing?
7
7
  redirect_to dev_accounts_path
8
8
  else
9
9
  store_fallback key: :accounts_return_to, strategies: [:session]
@@ -26,17 +26,12 @@ module OpenStax
26
26
  def destroy
27
27
  sign_out!
28
28
 
29
- # If we're using the Accounts server, need to sign out of it so can't
30
- # log back in automagically
31
- if OpenStax::Accounts.configuration.enable_stubbing?
32
- redirect_to main_app.root_url
33
- else
34
- redirect_to(
35
- OpenStax::Utilities.generate_url(
36
- OpenStax::Accounts.configuration.openstax_accounts_url, "logout"
37
- )
38
- )
39
- end
29
+ # Unless we are stubbing, we redirect to a configurable URL, which is normally
30
+ # (or at least eventually) the Accounts logout URL so that users can't sign back
31
+ # in automagically.
32
+ redirect_to configuration.enable_stubbing? ?
33
+ main_app.root_url :
34
+ configuration.logout_redirect_url(request)
40
35
  end
41
36
 
42
37
  def failure
@@ -46,9 +41,7 @@ module OpenStax
46
41
 
47
42
  def profile
48
43
  # TODO: stub profile if stubbing is enabled
49
- redirect_to(URI.join(
50
- OpenStax::Accounts.configuration.openstax_accounts_url, "/profile"
51
- ).to_s)
44
+ redirect_to URI.join(configuration.openstax_accounts_url, "/profile").to_s
52
45
  end
53
46
 
54
47
  end
@@ -5,6 +5,12 @@ module OpenStax
5
5
  # Base URL for OpenStax Accounts
6
6
  attr_reader :openstax_accounts_url
7
7
 
8
+ def openstax_accounts_url=(url)
9
+ url.gsub!(/https|http/,'https') if !(url =~ /localhost/)
10
+ url = url + "/" if url[url.size-1] != '/'
11
+ @openstax_accounts_url = url
12
+ end
13
+
8
14
  # openstax_application_id
9
15
  # OAuth client_id received from OpenStax Accounts
10
16
  attr_accessor :openstax_application_id
@@ -47,10 +53,22 @@ module OpenStax
47
53
  # If more would be returned, the result will be empty instead
48
54
  attr_accessor :max_search_items
49
55
 
50
- def openstax_accounts_url=(url)
51
- url.gsub!(/https|http/,'https') if !(url =~ /localhost/)
52
- url = url + "/" if url[url.size-1] != '/'
53
- @openstax_accounts_url = url
56
+ # logout_redirect_url
57
+ # A URL to redirect to after the app logs out, can be a string or a Proc.
58
+ # If a Proc (or lambda), it will be called with the logout request.
59
+ # If this field is nil or if the Proc returns nil, the logout will redirect
60
+ # to the default Accounts logout URL.
61
+ attr_writer :logout_redirect_url
62
+
63
+ def logout_redirect_url(request)
64
+ (@logout_redirect_url.is_a?(Proc) ?
65
+ @logout_redirect_url.call(request) :
66
+ @logout_redirect_url) ||
67
+ default_logout_redirect_url
68
+ end
69
+
70
+ def default_logout_redirect_url
71
+ URI.join(openstax_accounts_url, "logout").to_s
54
72
  end
55
73
 
56
74
  def initialize
@@ -66,6 +84,7 @@ module OpenStax
66
84
  @account_user_mapper = OpenStax::Accounts::DefaultAccountUserMapper
67
85
  @min_search_characters = 3
68
86
  @max_search_items = 10
87
+ @logout_redirect_url = nil
69
88
  super
70
89
  end
71
90
 
@@ -1,5 +1,5 @@
1
1
  module OpenStax
2
2
  module Accounts
3
- VERSION = "6.1.7"
3
+ VERSION = "6.2.0"
4
4
  end
5
5
  end
@@ -8,6 +8,10 @@ module OpenStax::Accounts
8
8
  username: 'some_user',
9
9
  openstax_uid: 10 }
10
10
 
11
+ after(:all) {
12
+ OpenStax::Accounts.configuration.logout_redirect_url = nil
13
+ }
14
+
11
15
  it 'should redirect users to the login path' do
12
16
  c = controller
13
17
  get :new
@@ -27,5 +31,16 @@ module OpenStax::Accounts
27
31
  expect(controller.current_account).to eq(AnonymousAccount.instance)
28
32
  expect(controller.current_account.is_anonymous?).to eq(true)
29
33
  end
34
+
35
+ it 'should get signout redirect URL from configured setting' do
36
+ my_lambda = ->(request) { "http://www.google.com" }
37
+ OpenStax::Accounts.configuration.logout_redirect_url = my_lambda
38
+
39
+ allow(OpenStax::Accounts.configuration).to receive(:enable_stubbing?) {false}
40
+ expect(my_lambda).to receive(:call).with(anything())
41
+
42
+ controller.sign_in account
43
+ delete :destroy
44
+ end
30
45
  end
31
46
  end
@@ -0,0 +1,29 @@
1
+ module OpenStax
2
+ module Accounts
3
+ describe Configuration do
4
+
5
+ let!(:config) { Configuration.new.tap {|c| c.openstax_accounts_url = "https://accounts.openstax.org"} }
6
+ let!(:a_fake_request) { OpenStruct.new(url: "http://foo.com") }
7
+
8
+ it "returns the default logout redirect when no explicit URL is set" do
9
+ expect(config.logout_redirect_url(a_fake_request)).to eq "https://accounts.openstax.org/logout"
10
+ end
11
+
12
+ it "returns an explicitly-set string logout redirect URL when set" do
13
+ config.logout_redirect_url = "blah"
14
+ expect(config.logout_redirect_url(a_fake_request)).to eq "blah"
15
+ end
16
+
17
+ it "returns the default URL when Proc logout redirect URL set and returns nil" do
18
+ config.logout_redirect_url = ->(request) { nil }
19
+ expect(config.logout_redirect_url(a_fake_request)).to eq "https://accounts.openstax.org/logout"
20
+ end
21
+
22
+ it "returns the Proc URL when Proc logout redirect URL set and returns non-nil" do
23
+ config.logout_redirect_url = ->(request) { "howdy" }
24
+ expect(config.logout_redirect_url(a_fake_request)).to eq "howdy"
25
+ end
26
+
27
+ end
28
+ end
29
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openstax_accounts
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.1.7
4
+ version: 6.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JP Slavinsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-18 00:00:00.000000000 Z
11
+ date: 2015-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -304,6 +304,20 @@ dependencies:
304
304
  - - ">="
305
305
  - !ruby/object:Gem::Version
306
306
  version: '0'
307
+ - !ruby/object:Gem::Dependency
308
+ name: byebug
309
+ requirement: !ruby/object:Gem::Requirement
310
+ requirements:
311
+ - - ">="
312
+ - !ruby/object:Gem::Version
313
+ version: '0'
314
+ type: :development
315
+ prerelease: false
316
+ version_requirements: !ruby/object:Gem::Requirement
317
+ requirements:
318
+ - - ">="
319
+ - !ruby/object:Gem::Version
320
+ version: '0'
307
321
  description: This gem allows Rails apps to easily access the API's and login infrastructure
308
322
  of OpenStax Accounts.
309
323
  email:
@@ -444,6 +458,7 @@ files:
444
458
  - spec/handlers/openstax/accounts/accounts_search_spec.rb
445
459
  - spec/handlers/openstax/accounts/dev/accounts_search_spec.rb
446
460
  - spec/lib/openstax/accounts/api_spec.rb
461
+ - spec/lib/openstax/accounts/configuration_spec.rb
447
462
  - spec/lib/openstax/accounts/current_user_manager_spec.rb
448
463
  - spec/lib/openstax/accounts/has_many_through_groups/active_record/base_spec.rb
449
464
  - spec/models/openstax/accounts/account_spec.rb
@@ -544,6 +559,7 @@ test_files:
544
559
  - spec/handlers/openstax/accounts/accounts_search_spec.rb
545
560
  - spec/handlers/openstax/accounts/dev/accounts_search_spec.rb
546
561
  - spec/lib/openstax/accounts/api_spec.rb
562
+ - spec/lib/openstax/accounts/configuration_spec.rb
547
563
  - spec/lib/openstax/accounts/current_user_manager_spec.rb
548
564
  - spec/lib/openstax/accounts/has_many_through_groups/active_record/base_spec.rb
549
565
  - spec/models/openstax/accounts/account_spec.rb