solidus_auth_devise 2.5.5 → 2.5.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eabe96f35091dbe9f4cac913044f4eb301bd049adb5cb1f8b7b98616847cdf0f
4
- data.tar.gz: '009afc8b8585d494940949bebaae6dc3ffdf2f80fb26f16189ecd1299c65c669'
3
+ metadata.gz: 2af5db5a4a28f17bc5159f1ccae8e0a6ad3f54aee0c03150a750a76129d89be7
4
+ data.tar.gz: 69aef17ae84f348294dff74150a24845a3924d8ec6258c3f230d61967e496c82
5
5
  SHA512:
6
- metadata.gz: 7991cf3c2104f5e1cb21fe59d251a0d38c060ffb1b98788abc21598419034d19307879e0ebc075c1b9683a8c77bf1c2cb94438f21f197e6acb3a8105da0c76a8
7
- data.tar.gz: 0abb460d4822728befdbfa648d3b190412968b3e75049e64f05b3b3304368ec4212cfb5feaedb7c3f3b1a92b8f256e7815c8daa37f82611eadb36be3ca0ab51c
6
+ metadata.gz: 171dd785ee3843aed488389a69049dbdf435c4df7ab7ba72e1d5be820b26a7cb422a531716afcbeaead38381e4a1efdab4197b232632ef9dd8066439c24a5918
7
+ data.tar.gz: 8b5f64a426df8e2ee9f7efbad70c7faecffc57968e9c4242b3bbd0a44ef77498781422bc6c3f63c90924fa626edc9018416585342557485b742b0f66a54b0afd
data/.circleci/config.yml CHANGED
@@ -16,8 +16,8 @@ jobs:
16
16
  name: solidusio_extensions/postgres
17
17
  ruby_version: '3.1'
18
18
  steps:
19
- - browser-tools/install-browser-tools
20
19
  - checkout
20
+ - browser-tools/install-chrome
21
21
  - solidusio_extensions/run-tests-solidus-master
22
22
  - solidusio_extensions/store-test-results
23
23
 
@@ -26,8 +26,8 @@ jobs:
26
26
  name: solidusio_extensions/mysql
27
27
  ruby_version: '3.0'
28
28
  steps:
29
- - browser-tools/install-browser-tools
30
29
  - checkout
30
+ - browser-tools/install-chrome
31
31
  - solidusio_extensions/run-tests-solidus-current
32
32
  - solidusio_extensions/store-test-results
33
33
 
@@ -36,15 +36,14 @@ jobs:
36
36
  name: solidusio_extensions/sqlite
37
37
  ruby_version: '2.7'
38
38
  steps:
39
- - browser-tools/install-browser-tools
40
39
  - checkout
40
+ - browser-tools/install-chrome
41
41
  - solidusio_extensions/run-tests-solidus-older
42
42
  - solidusio_extensions/store-test-results
43
43
 
44
44
  lint-code:
45
- executor: solidusio_extensions/sqlite-memory
45
+ executor: solidusio_extensions/sqlite
46
46
  steps:
47
- - browser-tools/install-browser-tools
48
47
  - solidusio_extensions/lint-code
49
48
 
50
49
  workflows:
data/CHANGELOG.md CHANGED
@@ -1,11 +1,20 @@
1
1
  # Changelog
2
2
 
3
- ## [v2.5.5](https://github.com/solidusio/solidus_auth_devise/tree/v2.5.5) (2022-09-19)
3
+ ## [v2.5.7](https://github.com/solidusio/solidus_auth_devise/tree/v2.5.7) (2022-10-31)
4
4
 
5
- [Full Changelog](https://github.com/solidusio/solidus_auth_devise/compare/v2.5.4...v2.5.5)
5
+ [Full Changelog](https://github.com/solidusio/solidus_auth_devise/compare/v2.5.6...v2.5.7)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - Fix the standard generator alias and remove interactivity from seeds [\#233](https://github.com/solidusio/solidus_auth_devise/pull/233) ([elia](https://github.com/elia))
10
+
11
+ ## [v2.5.6](https://github.com/solidusio/solidus_auth_devise/tree/v2.5.6) (2022-09-30)
12
+
13
+ [Full Changelog](https://github.com/solidusio/solidus_auth_devise/compare/v2.5.5...v2.5.6)
6
14
 
7
15
  **Merged pull requests:**
8
16
 
17
+ - Revert "Utilize Devise location helpers for redirecting" [\#232](https://github.com/solidusio/solidus_auth_devise/pull/232) ([elia](https://github.com/elia))
9
18
  - Run the CI on all supported ruby versions [\#229](https://github.com/solidusio/solidus_auth_devise/pull/229) ([elia](https://github.com/elia))
10
19
  - Utilize Devise location helpers for redirecting [\#228](https://github.com/solidusio/solidus_auth_devise/pull/228) ([cpfergus1](https://github.com/cpfergus1))
11
20
  - Update to use forked solidus\_frontend when needed [\#227](https://github.com/solidusio/solidus_auth_devise/pull/227) ([waiting-for-dev](https://github.com/waiting-for-dev))
@@ -16,12 +25,14 @@
16
25
  - Update to the latest solidus\_dev\_support defaults [\#220](https://github.com/solidusio/solidus_auth_devise/pull/220) ([elia](https://github.com/elia))
17
26
  - Fix build [\#219](https://github.com/solidusio/solidus_auth_devise/pull/219) ([gsmendoza](https://github.com/gsmendoza))
18
27
 
28
+ ## [v2.5.5](https://github.com/solidusio/solidus_auth_devise/tree/v2.5.5) (2022-09-19)
29
+
30
+ [Full Changelog](https://github.com/solidusio/solidus_auth_devise/compare/v2.5.4...v2.5.5)
31
+
19
32
  ## [v2.5.4](https://github.com/solidusio/solidus_auth_devise/tree/v2.5.4) (2021-11-17)
20
33
 
21
34
  [Full Changelog](https://github.com/solidusio/solidus_auth_devise/compare/v2.5.3...v2.5.4)
22
35
 
23
- - Fix authentication bypass by CSRF weakness [GHSA-xm34-v85h-9pg2](https://github.com/solidusio/solidus_auth_devise/security/advisories/GHSA-xm34-v85h-9pg2)
24
-
25
36
  **Closed issues:**
26
37
 
27
38
  - This line doesn't do anything [\#214](https://github.com/solidusio/solidus_auth_devise/issues/214)
data/Gemfile CHANGED
@@ -25,13 +25,13 @@ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3')
25
25
  # the 'async' gem that relies on the latest ruby, since RubyGems doesn't
26
26
  # resolve gems based on the required ruby version.
27
27
  gem 'async', '< 3', require: false
28
-
29
- # 'net/smtp' is required by 'mail', see:
30
- # - https://github.com/ruby/net-protocol/issues/10
31
- # - https://stackoverflow.com/a/72474475
32
- gem 'net-smtp', require: false
33
28
  end
34
29
 
30
+ # 'net/smtp' is required by 'mail', see:
31
+ # - https://github.com/ruby/net-protocol/issues/10
32
+ # - https://stackoverflow.com/a/72474475
33
+ gem 'net-smtp', require: false
34
+
35
35
  gemspec
36
36
 
37
37
  # Use a local Gemfile to include development dependencies that might not be
data/bin/rails CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- if %w[g generate].include? ARGV.first
3
+ if %w[g generate].include?(ARGV.first) && ARGV[1] !~ /^(solidus:auth:|solidus_auth_devise:)/
4
4
  exec "#{__dir__}/rails-engine", *ARGV
5
5
  else
6
6
  exec "#{__dir__}/rails-sandbox", *ARGV
data/bin/sandbox CHANGED
@@ -71,6 +71,7 @@ cat <<RUBY >> Gemfile
71
71
  gem 'solidus', github: 'solidusio/solidus', branch: '$BRANCH'
72
72
  gem 'rails-i18n'
73
73
  gem 'solidus_i18n'
74
+ gem 'net-smtp', require: false
74
75
 
75
76
  gem '$extension_name', path: '..'
76
77
 
data/db/default/users.rb CHANGED
@@ -1,78 +1,38 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # see last line where we create an admin if there is none, asking for email and password
4
- def prompt_for_admin_password
5
- if ENV['ADMIN_PASSWORD']
6
- password = ENV['ADMIN_PASSWORD'].dup
7
- puts "Admin Password #{password}"
8
- else
9
- print "Password [test123]: "
10
- password = STDIN.gets.strip
11
- password = 'test123' if password.blank?
12
- end
3
+ admin_role = Spree::Role.find_or_create_by(name: 'admin')
13
4
 
14
- password
5
+ if Spree::User.admin.any?
6
+ puts 'No admin user created.'
7
+ return
15
8
  end
16
9
 
17
- def prompt_for_admin_email
18
- if ENV['ADMIN_EMAIL']
19
- email = ENV['ADMIN_EMAIL'].dup
20
- puts "Admin User #{email}"
21
- else
22
- print "Email [admin@example.com]: "
23
- email = STDIN.gets.strip
24
- email = 'admin@example.com' if email.blank?
25
- end
10
+ email = ENV['ADMIN_EMAIL'] || 'admin@example.com'
11
+ password = ENV['ADMIN_PASSWORD'] || 'test123'
26
12
 
27
- email
28
- end
29
-
30
- def create_admin_user
31
- if ENV['AUTO_ACCEPT']
32
- password = 'test123'
33
- email = 'admin@example.com'
34
- else
35
- puts 'Create the admin user (press enter for defaults).'
36
- # name = prompt_for_admin_name unless name
37
- email = prompt_for_admin_email
38
- password = prompt_for_admin_password
39
- end
40
- attributes = {
41
- password: password,
42
- password_confirmation: password,
43
- email: email,
44
- login: email
45
- }
46
-
47
- load 'spree/user.rb'
13
+ puts "Creating admin user with:"
14
+ puts " - email: #{email}"
15
+ puts " - password: #{password}"
16
+ puts "(please use the ADMIN_EMAIL and ADMIN_PASSWORD environment variables to control how the default admin user is created)"
48
17
 
49
- if Spree::User.find_by(email: email)
50
- puts "\nWARNING: There is already a user with the email: #{email}, so no account changes were made. If you wish to create an additional admin user, please run rake spree_auth:admin:create again with a different email.\n\n"
51
- else
52
- admin = Spree::User.new(attributes)
53
- if admin.save
54
- role = Spree::Role.find_or_create_by(name: 'admin')
55
- admin.spree_roles << role
56
- admin.save
57
- admin.generate_spree_api_key!
58
- puts "Done!"
59
- else
60
- puts "There were some problems with persisting a new admin user:"
61
- admin.errors.full_messages.each do |error|
62
- puts error
63
- end
64
- end
65
- end
18
+ if Spree::User.find_by(email: email)
19
+ warn "WARNING: There is already a user with the email: #{email}, so no account changes were made."
20
+ return
66
21
  end
67
22
 
68
- if Spree::User.admin.empty?
69
- create_admin_user
23
+ admin = Spree::User.new(
24
+ password: password,
25
+ password_confirmation: password,
26
+ email: email,
27
+ login: email,
28
+ )
29
+
30
+ if admin.save
31
+ admin.spree_roles << admin_role
32
+ admin.save
33
+ admin.generate_spree_api_key!
70
34
  else
71
- puts 'Admin user has already been created.'
72
- puts 'Would you like to create a new admin user? (yes/no)'
73
- if ["yes", "y"].include? STDIN.gets.strip.downcase
74
- create_admin_user
75
- else
76
- puts 'No admin user created.'
77
- end
35
+ warn "There were some problems while creating the admin user:"
36
+ warn(admin.errors.full_messages.map { |m| "- #{m}" })
37
+ warn "(attributes: #{admin.attributes.inspect})"
78
38
  end
@@ -17,7 +17,7 @@ class Spree::Admin::UserSessionsController < Devise::SessionsController
17
17
  respond_to do |format|
18
18
  format.html {
19
19
  flash[:success] = I18n.t('spree.logged_in_succesfully')
20
- redirect_to stored_spree_user_location_or(after_sign_in_path_for(spree_current_user))
20
+ redirect_back_or_default(after_sign_in_path_for(spree_current_user))
21
21
  }
22
22
  format.js {
23
23
  user = resource.record
@@ -47,4 +47,9 @@ class Spree::Admin::UserSessionsController < Devise::SessionsController
47
47
  def accurate_title
48
48
  I18n.t('spree.login')
49
49
  end
50
+
51
+ def redirect_back_or_default(default)
52
+ redirect_to(session["spree_user_return_to"] || default)
53
+ session["spree_user_return_to"] = nil
54
+ end
50
55
  end
@@ -19,7 +19,7 @@ class Spree::UserSessionsController < Devise::SessionsController
19
19
  respond_to do |format|
20
20
  format.html do
21
21
  flash[:success] = I18n.t('spree.logged_in_succesfully')
22
- redirect_to stored_spree_user_location_or(after_sign_in_path_for(spree_current_user))
22
+ redirect_back_or_default(after_sign_in_path_for(spree_current_user))
23
23
  end
24
24
  format.js { render success_json }
25
25
  end
@@ -49,6 +49,11 @@ class Spree::UserSessionsController < Devise::SessionsController
49
49
  I18n.t('spree.login')
50
50
  end
51
51
 
52
+ def redirect_back_or_default(default)
53
+ redirect_to(session["spree_user_return_to"] || default)
54
+ session["spree_user_return_to"] = nil
55
+ end
56
+
52
57
  def success_json
53
58
  {
54
59
  json: {
@@ -17,7 +17,7 @@ class Spree::UsersController < Spree::StoreController
17
17
  session[:guest_token] = nil
18
18
  end
19
19
 
20
- redirect_to stored_spree_user_location_or(root_url)
20
+ redirect_back_or_default(root_url)
21
21
  else
22
22
  render :new
23
23
  end
@@ -45,6 +45,7 @@ module Spree
45
45
  def check_registration
46
46
  return unless registration_required?
47
47
 
48
+ store_location
48
49
  redirect_to spree.checkout_registration_path
49
50
  end
50
51
 
@@ -4,31 +4,38 @@ module Solidus
4
4
  module Auth
5
5
  module Generators
6
6
  class InstallGenerator < Rails::Generators::Base
7
- class_option :auto_run_migrations, type: :boolean, default: false
8
- class_option :skip_migrations, type: :boolean, default: false
7
+ class_option :auto_run_migrations, type: :boolean, desc: "Run migrations automatically"
8
+ class_option :skip_migrations, type: :boolean, desc: "Skip migrations"
9
9
 
10
- def self.source_paths
11
- paths = superclass.source_paths
12
- paths << File.expand_path('templates', __dir__)
13
- paths.flatten
14
- end
10
+ class_option :interactive, type: :boolean, default: false, desc: "Enable interactive mode"
11
+ class_option :admin_email, type: :string
12
+ class_option :admin_password, type: :string
13
+
14
+ source_root "#{__dir__}/templates"
15
15
 
16
16
  def generate_devise_key
17
17
  template 'config/initializers/devise.rb', 'config/initializers/devise.rb', skip: true
18
18
  end
19
19
 
20
20
  def add_migrations
21
- run 'bundle exec rake railties:install:migrations FROM=solidus_auth'
21
+ admin_email = options[:admin_email] || (options[:interactive] && ask("Email:", default: 'admin@example.com'))
22
+ admin_password = options[:admin_password] || (options[:interactive] && ask("Password:", default: 'test123'))
23
+
24
+ options = []
25
+ options << "ADMIN_EMAIL=#{admin_email}" if admin_email
26
+ options << "ADMIN_PASSWORD=#{admin_password}" if admin_password
27
+
28
+ rake "railties:install:migrations FROM=solidus_auth #{options.shelljoin}"
22
29
  end
23
30
 
24
31
  def run_migrations
25
- return if options[:skip_migrations]
32
+ if options[:skip_migrations] ||
33
+ options[:auto_run_migrations] == false || # exclude nil
34
+ options[:interactive] && no?('Would you like to run the migrations now?')
26
35
 
27
- run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]'))
28
- if run_migrations
29
- run 'bundle exec rake db:migrate'
36
+ say_status :skip, 'Skipping rake db:migrate, don\'t forget to run it!', :yellow
30
37
  else
31
- puts 'Skipping rake db:migrate, don\'t forget to run it!' # rubocop:disable Rails/Output
38
+ rake 'db:migrate'
32
39
  end
33
40
  end
34
41
  end
@@ -1,8 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative '../../solidus/auth/install/install_generator'
4
+
4
5
  module SolidusAuthDevise
5
6
  module Generators
6
- InstallGenerator = ::Solidus::Auth::Generators::InstallGenerator
7
+ class InstallGenerator < Rails::Generators::Base
8
+ # Copy over any class option from the legacy install generator
9
+ Solidus::Auth::Generators::InstallGenerator.class_options.each do |name, option|
10
+ class_options[name] ||= option.dup
11
+ end
12
+
13
+ def forward_to_spree_auth_install
14
+ generate 'solidus:auth:install', *ARGV
15
+ end
16
+ end
7
17
  end
8
18
  end
@@ -1,7 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'spree/auth/engine'
4
-
5
- module SolidusAuthDevise
6
- Engine = ::Spree::Auth::Engine
7
- end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusAuthDevise
4
- VERSION = '2.5.5'
4
+ VERSION = '2.5.7'
5
5
  end
@@ -59,6 +59,7 @@ module Spree
59
59
  redirect_to spree.admin_unauthorized_path
60
60
  end
61
61
  else
62
+ store_location
62
63
 
63
64
  if Spree::Auth::Engine.redirect_back_on_unauthorized?
64
65
  redirect_back(fallback_location: spree.admin_login_path)
@@ -69,6 +70,7 @@ module Spree
69
70
  end
70
71
  end
71
72
 
73
+
72
74
  def self.prepare_frontend
73
75
  Spree::BaseController.unauthorized_redirect = -> do
74
76
  if spree_current_user
@@ -80,6 +82,7 @@ module Spree
80
82
  redirect_to spree.unauthorized_path
81
83
  end
82
84
  else
85
+ store_location
83
86
 
84
87
  if Spree::Auth::Engine.redirect_back_on_unauthorized?
85
88
  redirect_back(fallback_location: spree.login_path)
@@ -92,3 +95,5 @@ module Spree
92
95
  end
93
96
  end
94
97
  end
98
+
99
+ SolidusAuthDevise::Engine = Spree::Auth::Engine
@@ -23,30 +23,5 @@ module Spree
23
23
  to: :spree,
24
24
  prefix: :spree
25
25
  end
26
-
27
- private
28
-
29
- def authenticate_spree_user!
30
- store_spree_user_location! if storable_spree_user_location?
31
-
32
- super
33
- end
34
-
35
- # It's important that the location is NOT stored if:
36
- # - The request method is not GET (non idempotent)
37
- # - The request is handled by a Devise controller such as Devise::SessionsController as that could cause an
38
- # infinite redirect loop.
39
- # - The request is an Ajax request as this can lead to very unexpected behaviour.
40
- def storable_spree_user_location?
41
- request.get? && is_navigational_format? && !devise_controller? && !request.xhr?
42
- end
43
-
44
- def store_spree_user_location!
45
- store_location_for(:spree_current_user, request.fullpath)
46
- end
47
-
48
- def stored_spree_user_location_or(fallback_location)
49
- stored_location_for(:spree_current_user) || fallback_location
50
- end
51
26
  end
52
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_auth_devise
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.5
4
+ version: 2.5.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Solidus Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-19 00:00:00.000000000 Z
11
+ date: 2022-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deface