spree_auth_devise 4.3.2 → 4.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of spree_auth_devise might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 632dbf0ba8467163e8cff132261a9173f5c4a9b9b670c3e93599d66bb07575a1
4
- data.tar.gz: 2e400ddce6368507961c686f4e094eb9c09ab47ebb8ecd97ade3c1f425e5ce5d
3
+ metadata.gz: 88bd67ceeb209cf0a5429d736103ffad339942eefd7cf7f75d6b84dfbb25a553
4
+ data.tar.gz: 261b34f941e7f6584dfa9fb4a50dc76c8b4aae6f9785db618ef630da1f881312
5
5
  SHA512:
6
- metadata.gz: b07a757183970dc752ad4187daf50acca0783f1914ee4f0ed99a68f533a5e98ee5525dac009bd509760f70c74577f3f6de0d3acf30060bd4319f1b24a495bd02
7
- data.tar.gz: 1c0fb11dbf07ed2c308a7bd693118254a933c5204e535d0765958679ae6576a098f71671eb18c42b7943e7b1fd18af32eaf1b8273664090e6a8e7dd625a804b6
6
+ metadata.gz: 489cf73cb272c2318cc35761e736a9b65fb0549e8ba938550fdf63ed16727a562180e22bfd6f210a6e6384fd8e4bb589e9a4bebf37d0e287e0c712c83e1e7214
7
+ data.tar.gz: 9e16a12db4e028e6318896d5fded01acda724348587a5f6628e437c81be41ccb4f4c6e537aac344c0ed05d223c27cfc03bcf275513ea7d84fa15eafd1f6b271a
data/.gem_release.yml ADDED
@@ -0,0 +1,2 @@
1
+ bump:
2
+ file: 'lib/spree/auth/version.rb'
data/Gemfile CHANGED
@@ -3,4 +3,5 @@ source 'https://rubygems.org'
3
3
  gem 'rails-controller-testing'
4
4
  gem 'spree', github: 'spree/spree', branch: 'master'
5
5
 
6
+ gem 'pry', '~> 0.13.1'
6
7
  gemspec
@@ -14,7 +14,7 @@ module Spree
14
14
  def confirmation_instructions(user, token, _opts = {})
15
15
  current_store_id = _opts[:current_store_id]
16
16
  @current_store = Spree::Store.find(current_store_id) || Spree::Store.current
17
- @confirmation_url = spree_user_confirmation_url(confirmation_token: token, host: Spree::Store.current.url)
17
+ @confirmation_url = spree.confirmation_url(confirmation_token: token, host: Spree::Store.current.url)
18
18
  @email = user.email
19
19
 
20
20
  mail to: user.email, from: from_address, subject: @current_store.name + ' ' + I18n.t(:subject, scope: [:devise, :mailer, :confirmation_instructions]), store_url: @current_store.url
@@ -48,7 +48,7 @@ module Spree
48
48
  end
49
49
 
50
50
  opts = pending_reconfirmation? ? { to: unconfirmed_email } : {}
51
- opts[:current_store_id] = current_store.id
51
+ opts[:current_store_id] = current_store&.id || Spree::Store.default.id
52
52
  send_devise_notification(:confirmation_instructions, @raw_confirmation_token, opts)
53
53
  end
54
54
 
@@ -71,6 +71,10 @@ module Spree
71
71
 
72
72
  protected
73
73
 
74
+ def send_on_create_confirmation_instructions(current_store = nil)
75
+ send_confirmation_instructions(current_store || Spree::Store.default)
76
+ end
77
+
74
78
  def password_required?
75
79
  !persisted? || password.present? || password_confirmation.present?
76
80
  end
@@ -3,7 +3,7 @@ Warden::Manager.after_set_user except: :fetch do |user, auth, _opts|
3
3
  token = auth.cookies.signed[:guest_token] || auth.cookies.signed[:token]
4
4
  token_attr = Spree::Order.has_attribute?(:token) ? :token : :guest_token
5
5
 
6
- if token.present? && user.is_a?(Spree::User)
6
+ if token.present? && user.is_a?(Spree.user_class)
7
7
  Spree::Order.incomplete.where(token_attr => token, user_id: nil).each do |order|
8
8
  order.associate_user!(user)
9
9
  end
data/config/routes.rb CHANGED
@@ -21,7 +21,7 @@ Spree::Core::Engine.add_routes do
21
21
  post '/password/recover' => 'user_passwords#create', :as => :reset_password
22
22
  get '/password/change' => 'user_passwords#edit', :as => :edit_password
23
23
  put '/password/change' => 'user_passwords#update', :as => :update_password
24
- get '/confirm' => 'user_confirmations#show', :as => :confirmation if Spree::Auth::Config[:confirmable]
24
+ get '/confirm' => 'user_confirmations#show', :as => :confirmation
25
25
  end
26
26
 
27
27
  get '/checkout/registration' => 'checkout#registration', :as => :checkout_registration
@@ -42,6 +42,8 @@ Spree::Core::Engine.add_routes do
42
42
  get '/login' => 'user_sessions#new', :as => :login
43
43
  post '/login' => 'user_sessions#create', :as => :create_new_session
44
44
  get '/logout' => 'user_sessions#destroy', :as => :logout
45
+ get '/password/recover' => 'user_passwords#new', :as => :recover_password
46
+ post '/password/recover' => 'user_passwords#create', :as => :reset_password
45
47
  end
46
48
  end
47
49
 
@@ -59,4 +59,20 @@ class Spree::Admin::UserSessionsController < Devise::SessionsController
59
59
  "spree/layouts/admin"
60
60
  end
61
61
  end
62
+
63
+ def respond_to_on_destroy
64
+ # We actually need to hardcode this as Rails default responder doesn't
65
+ # support returning empty response on GET request
66
+ respond_to do |format|
67
+ format.all { head :no_content }
68
+ format.any(*navigational_formats) { redirect_to after_sign_out_redirect(resource_name) }
69
+ end
70
+ end
71
+
72
+ def after_sign_out_redirect(resource_or_scope)
73
+ scope = Devise::Mapping.find_scope!(resource_or_scope)
74
+ router_name = Devise.mappings[scope].router_name
75
+ context = router_name ? send(router_name) : self
76
+ context.respond_to?(:admin_login_path) ? context.admin_login_path : "/"
77
+ end
62
78
  end
@@ -12,7 +12,7 @@ module Spree
12
12
  end
13
13
 
14
14
  initializer "spree_auth_devise.set_user_class", after: :load_config_initializers do
15
- Spree.user_class = "Spree::User"
15
+ Spree.user_class = 'Spree::User' if Spree.user_class.blank? || Spree.user_class.to_s == 'Spree::LegacyUser'
16
16
  end
17
17
 
18
18
  initializer "spree_auth_devise.check_secret_token" do
@@ -29,19 +29,11 @@ module Spree
29
29
  Rails.configuration.cache_classes ? require(c) : load(c)
30
30
  end
31
31
  if Spree::Auth::Engine.backend_available?
32
- Rails.application.config.assets.precompile += [
33
- 'lib/assets/javascripts/spree/backend/spree_auth.js',
34
- 'lib/assets/javascripts/spree/backend/spree_auth.css'
35
- ]
36
32
  Dir.glob(File.join(File.dirname(__FILE__), "../../controllers/backend/*/*/*_decorator*.rb")) do |c|
37
33
  Rails.configuration.cache_classes ? require(c) : load(c)
38
34
  end
39
35
  end
40
36
  if Spree::Auth::Engine.frontend_available?
41
- Rails.application.config.assets.precompile += [
42
- 'lib/assets/javascripts/spree/frontend/spree_auth.js',
43
- 'lib/assets/javascripts/spree/frontend/spree_auth.css'
44
- ]
45
37
  Dir.glob(File.join(File.dirname(__FILE__), "../../controllers/frontend/**/*_decorator*.rb")) do |c|
46
38
  Rails.configuration.cache_classes ? require(c) : load(c)
47
39
  end
@@ -0,0 +1,9 @@
1
+ module Spree
2
+ module Auth
3
+ VERSION = '4.3.3'.freeze
4
+
5
+ def gem_version
6
+ Gem::Version.new(VERSION)
7
+ end
8
+ end
9
+ end
@@ -24,7 +24,7 @@
24
24
  <% end %>
25
25
  </div>
26
26
  <div class="col-lg-6 text-right">
27
- <%= link_to Spree.t(:forgot_password), spree.recover_password_path %>
27
+ <%= link_to Spree.t(:forgot_password), spree.admin_recover_password_path %>
28
28
  </div>
29
29
  </div>
30
30
  </div>
@@ -33,12 +33,13 @@ RSpec.feature 'Admin - Sign In', type: :feature do
33
33
 
34
34
  fill_in 'Email', with: user.email
35
35
  fill_in 'Password', with: 'secret'
36
- click_button 'Log in'
37
36
  if Spree.version.to_f > 4.1
37
+ click_button 'Login'
38
38
  within '.navbar .dropdown-menu' do
39
39
  expect(page).to have_text 'admin@person.com'
40
40
  end
41
41
  else
42
+ click_button 'Log in'
42
43
  within '.user-menu' do
43
44
  expect(page).to have_text 'admin@person.com'
44
45
  end
@@ -89,7 +89,7 @@ RSpec.feature 'Checkout', :js, type: :feature do
89
89
  token_url_regex = /^http:\/\/www.example.com\/user\/spree_user\/password\/edit\?reset_password_token=(.*)$/
90
90
  token = token_url_regex.match(reset_password_email.body.encoded)[1]
91
91
 
92
- visit spree.edit_spree_user_password_path(reset_password_token: token).tr("%0D","")
92
+ visit spree.edit_spree_user_password_path(reset_password_token: token.strip).tr("%0D","")
93
93
  fill_in 'Password', with: 'password'
94
94
  fill_in 'Password Confirmation', with: 'password'
95
95
  click_button 'Update'
@@ -1,13 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.feature 'Confirmation', type: :feature, reload_user: true do
3
+ RSpec.feature 'Confirmation', type: :feature, confirmable: true do
4
4
  before do
5
- set_confirmable_option(true)
6
5
  expect(Spree::UserMailer).to receive(:confirmation_instructions).with(anything, anything, { current_store_id: Spree::Store.current.id }).and_return(double(deliver: true))
7
6
  end
8
7
 
9
- after(:each) { set_confirmable_option(false) }
10
-
11
8
  background do
12
9
  ActionMailer::Base.default_url_options[:host] = 'http://example.com'
13
10
  end
@@ -33,13 +33,14 @@ RSpec.feature 'Sign In', type: :feature do
33
33
 
34
34
  fill_in 'Email', with: user.email
35
35
  fill_in 'Password', with: user.password
36
- click_button 'Log in'
37
36
 
38
37
  if Spree.version.to_f > 4.1
38
+ click_button 'Login'
39
39
  within '.navbar .dropdown-menu' do
40
40
  expect(page).to have_text 'admin@person.com'
41
41
  end
42
42
  else
43
+ click_button 'Log in'
43
44
  within '.user-menu' do
44
45
  expect(page).to have_text 'admin@person.com'
45
46
  end
@@ -65,17 +65,48 @@ RSpec.describe Spree::User, type: :model do
65
65
  end
66
66
  end
67
67
 
68
- describe "confirmable", reload_user: true do
69
- it "is confirmable if the confirmable option is enabled" do
70
- set_confirmable_option(true)
68
+ describe "confirmable" do
69
+ it "is confirmable if the confirmable option is enabled", confirmable: true do
71
70
  Spree::UserMailer.stub(:confirmation_instructions).with(anything, anything, { current_store_id: Spree::Store.current.id }).and_return(double(deliver: true))
72
71
  expect(Spree.user_class.devise_modules).to include(:confirmable)
73
- set_confirmable_option(false)
74
72
  end
75
73
 
76
- it "is not confirmable if the confirmable option is disabled" do
77
- set_confirmable_option(false)
78
- expect(Spree.user_class.devise_modules).to_not include(:confirmable)
74
+ it "is not confirmable if the confirmable option is disabled", confirmable: false do
75
+ expect(Spree.user_class.devise_modules).not_to include(:confirmable)
76
+ end
77
+ end
78
+
79
+ describe "#send_confirmation_instructions", retry: 2 do
80
+ let(:default_store) { Spree::Store.default }
81
+
82
+ context "when current store not exists" do
83
+ it 'takes default store and sends confirmation instruction', confirmable: true do
84
+ user = Spree.user_class.new
85
+ user.email = FFaker::Internet.email
86
+ user.password = user.password_confirmation = 'pass1234'
87
+ user.save
88
+
89
+ expect(Spree::UserMailer).to receive(:confirmation_instructions).with(
90
+ user, anything, { current_store_id: default_store.id }).and_return(double(deliver: true)
91
+ )
92
+
93
+ user.send_confirmation_instructions(nil)
94
+ end
95
+ end
96
+
97
+ context "when current store exists" do
98
+ it 'takes current store and sends confirmation instruction', confirmable: true do
99
+ user = Spree.user_class.new
100
+ user.email = FFaker::Internet.email
101
+ user.password = user.password_confirmation = 'pass1234'
102
+ user.save
103
+
104
+ expect(Spree::UserMailer).to receive(:confirmation_instructions).with(
105
+ user, anything, { current_store_id: store.id }).and_return(double(deliver: true)
106
+ )
107
+
108
+ user.send_confirmation_instructions(store)
109
+ end
79
110
  end
80
111
  end
81
112
  end
@@ -1,11 +1,24 @@
1
- module ConfirmHelpers
2
- def set_confirmable_option(value)
3
- Spree::Auth::Config[:confirmable] = value
4
- Spree.send(:remove_const, 'User')
5
- load File.expand_path("../../../app/models/spree/user.rb", __FILE__)
1
+ RSpec.configure do |config|
2
+ config.around do |example|
3
+ if example.metadata.key?(:confirmable)
4
+ old_user = Spree::User
5
+
6
+ begin
7
+ example.run
8
+ ensure
9
+ Spree.const_set('User', old_user)
10
+ end
11
+ else
12
+ example.run
13
+ end
6
14
  end
7
- end
8
15
 
9
- RSpec.configure do |c|
10
- c.include ConfirmHelpers
16
+ config.before do |example|
17
+ if example.metadata.key?(:confirmable)
18
+ Spree::Auth::Config[:confirmable] = example.metadata[:confirmable]
19
+
20
+ Spree.send(:remove_const, :User)
21
+ load File.expand_path('../../../app/models/spree/user.rb', __FILE__)
22
+ end
23
+ end
11
24
  end
@@ -1,9 +1,13 @@
1
1
  # encoding: UTF-8
2
+ lib = File.expand_path('../lib/', __FILE__)
3
+ $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'spree/auth/version'
2
6
 
3
7
  Gem::Specification.new do |s|
4
8
  s.platform = Gem::Platform::RUBY
5
9
  s.name = 'spree_auth_devise'
6
- s.version = '4.3.2'
10
+ s.version = Spree::Auth::VERSION
7
11
  s.summary = 'Provides authentication and authorization services for use with Spree by using Devise and CanCan.'
8
12
  s.description = s.summary
9
13
 
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_auth_devise
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.2
4
+ version: 4.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Schofield
8
8
  - Spark Solutions
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-01-25 00:00:00.000000000 Z
12
+ date: 2021-02-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: devise
@@ -95,6 +95,7 @@ extensions: []
95
95
  extra_rdoc_files: []
96
96
  files:
97
97
  - ".circleci/config.yml"
98
+ - ".gem_release.yml"
98
99
  - ".gitignore"
99
100
  - ".rspec"
100
101
  - ".travis.yml"
@@ -166,6 +167,7 @@ files:
166
167
  - lib/spree/auth.rb
167
168
  - lib/spree/auth/devise.rb
168
169
  - lib/spree/auth/engine.rb
170
+ - lib/spree/auth/version.rb
169
171
  - lib/spree/authentication_helpers.rb
170
172
  - lib/spree/testing_support/auth_helpers.rb
171
173
  - lib/spree/testing_support/checkout_helpers.rb
@@ -214,17 +216,16 @@ files:
214
216
  - spec/support/configuration_helpers.rb
215
217
  - spec/support/confirm_helpers.rb
216
218
  - spec/support/email.rb
217
- - spec/support/user_helper.rb
218
219
  - spree_auth_devise.gemspec
219
220
  homepage: https://spreecommerce.org
220
221
  licenses:
221
222
  - BSD-3-Clause
222
223
  metadata:
223
224
  bug_tracker_uri: https://github.com/spree/spree_auth_devise/issues
224
- changelog_uri: https://github.com/spree/spree_auth_devise/releases/tag/v4.3.2
225
+ changelog_uri: https://github.com/spree/spree_auth_devise/releases/tag/v4.3.3
225
226
  documentation_uri: https://guides.spreecommerce.org/
226
- source_code_uri: https://github.com/spree/spree_auth_devise/tree/v4.3.2
227
- post_install_message:
227
+ source_code_uri: https://github.com/spree/spree_auth_devise/tree/v4.3.3
228
+ post_install_message:
228
229
  rdoc_options: []
229
230
  require_paths:
230
231
  - lib
@@ -240,8 +241,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
240
241
  version: '0'
241
242
  requirements:
242
243
  - none
243
- rubygems_version: 3.0.3
244
- signing_key:
244
+ rubygems_version: 3.1.4
245
+ signing_key:
245
246
  specification_version: 4
246
247
  summary: Provides authentication and authorization services for use with Spree by
247
248
  using Devise and CanCan.
@@ -281,4 +282,3 @@ test_files:
281
282
  - spec/support/configuration_helpers.rb
282
283
  - spec/support/confirm_helpers.rb
283
284
  - spec/support/email.rb
284
- - spec/support/user_helper.rb
@@ -1,11 +0,0 @@
1
- RSpec.configure do |config|
2
- # allows to keep user const after reload
3
- config.around :each, :reload_user do |example|
4
- old_user = Spree::User
5
-
6
- example.run
7
-
8
- Spree.send(:remove_const, 'User')
9
- Spree.const_set('User', old_user)
10
- end
11
- end