solidus_auth_devise 2.3.0 → 2.5.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


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

Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.gem_release.yml +3 -8
  3. data/.github/stale.yml +17 -0
  4. data/.gitignore +12 -8
  5. data/.rubocop.yml +1 -325
  6. data/CHANGELOG.md +106 -6
  7. data/Gemfile +20 -21
  8. data/{LICENSE.md → LICENSE} +2 -2
  9. data/README.md +1 -42
  10. data/app/models/spree/user.rb +4 -0
  11. data/app/overrides/spree/admin/users/edit/_add_reset_password_form.html.erb.deface +20 -0
  12. data/bin/console +17 -0
  13. data/bin/rails +12 -4
  14. data/bin/setup +8 -0
  15. data/config/locales/it.yml +4 -4
  16. data/db/migrate/20200417153503_add_unconfirmed_email_to_spree_users.rb +7 -0
  17. data/lib/controllers/backend/spree/admin/user_passwords_controller.rb +1 -1
  18. data/lib/controllers/frontend/spree/users_controller.rb +5 -2
  19. data/lib/{controllers/backend → decorators/backend/controllers}/spree/admin/base_controller_decorator.rb +0 -0
  20. data/lib/{controllers/backend → decorators/backend/controllers}/spree/admin/orders/customer_details_controller_decorator.rb +6 -2
  21. data/lib/{controllers/frontend → decorators/frontend/controllers}/spree/checkout_controller_decorator.rb +0 -0
  22. data/lib/generators/solidus/auth/install/install_generator.rb +12 -2
  23. data/lib/solidus_auth_devise.rb +10 -12
  24. data/lib/spree/auth/devise.rb +0 -7
  25. data/lib/spree/auth/engine.rb +48 -35
  26. data/lib/spree/auth/version.rb +1 -1
  27. data/{app/models → lib}/spree/auth_configuration.rb +0 -0
  28. data/lib/views/backend/spree/admin/shared/_navigation_footer.html.erb +2 -2
  29. data/lib/views/backend/spree/admin/user_passwords/edit.html.erb +4 -4
  30. data/lib/views/backend/spree/admin/user_passwords/new.html.erb +4 -4
  31. data/lib/views/backend/spree/admin/user_sessions/authorization_failure.html.erb +1 -1
  32. data/lib/views/backend/spree/admin/user_sessions/new.html.erb +9 -9
  33. data/lib/views/backend/spree/layouts/admin/_login_nav.html.erb +4 -4
  34. data/lib/views/frontend/spree/checkout/registration.html.erb +4 -4
  35. data/lib/views/frontend/spree/shared/_login.html.erb +4 -4
  36. data/lib/views/frontend/spree/shared/_login_bar_items.html.erb +3 -3
  37. data/lib/views/frontend/spree/shared/_user_form.html.erb +3 -3
  38. data/lib/views/frontend/spree/user_passwords/edit.html.erb +4 -4
  39. data/lib/views/frontend/spree/user_passwords/new.html.erb +4 -4
  40. data/lib/views/frontend/spree/user_registrations/new.html.erb +3 -3
  41. data/lib/views/frontend/spree/user_sessions/authorization_failure.html.erb +1 -1
  42. data/lib/views/frontend/spree/user_sessions/new.html.erb +2 -2
  43. data/lib/views/frontend/spree/users/edit.html.erb +2 -2
  44. data/lib/views/frontend/spree/users/show.html.erb +13 -13
  45. data/solidus_auth_devise.gemspec +28 -33
  46. data/spec/controllers/spree/admin/base_controller_spec.rb +53 -0
  47. data/spec/controllers/spree/base_controller_spec.rb +53 -0
  48. data/spec/controllers/spree/products_controller_spec.rb +3 -7
  49. data/spec/controllers/spree/users_controller_spec.rb +23 -0
  50. data/spec/features/admin/password_reset_spec.rb +43 -0
  51. data/spec/features/checkout_spec.rb +7 -32
  52. data/spec/features/confirmation_spec.rb +2 -3
  53. data/spec/models/user_spec.rb +13 -8
  54. data/spec/spec_helper.rb +10 -8
  55. data/spec/support/confirm_helpers.rb +19 -10
  56. data/spec/support/features/fill_addresses_fields.rb +29 -0
  57. metadata +3151 -275
  58. data/app/overrides/auth_admin_login_navigation_bar.rb +0 -10
  59. data/app/overrides/auth_shared_login_bar.rb +0 -10
  60. data/lib/assets/javascripts/spree/backend/solidus_auth.js +0 -1
  61. data/lib/assets/javascripts/spree/frontend/solidus_auth.js +0 -1
  62. data/lib/assets/stylesheets/spree/backend/solidus_auth.css +0 -3
  63. data/lib/assets/stylesheets/spree/frontend/solidus_auth.css +0 -3
  64. data/spec/features/admin/orders_spec.rb +0 -31
data/Gemfile CHANGED
@@ -1,30 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
4
5
 
5
6
  branch = ENV.fetch('SOLIDUS_BRANCH', 'master')
6
- gem "solidus", github: "solidusio/solidus", branch: branch
7
-
8
- group :test do
9
- if branch == 'master' || branch >= "v2.0"
10
- gem 'rails-controller-testing', '~> 1.0'
11
- else
12
- gem "rails_test_params_backport"
13
- end
14
-
15
- gem 'factory_bot', (branch < 'v2.5' ? '4.10.0' : '> 4.10.0')
16
- end
17
-
18
- if ENV['DB'] == 'mysql'
19
- gem 'mysql2', '~> 0.4.10'
7
+ gem 'solidus', github: 'solidusio/solidus', branch: branch
8
+
9
+ # Needed to help Bundler figure out how to resolve dependencies,
10
+ # otherwise it takes forever to resolve them.
11
+ # See https://github.com/bundler/bundler/issues/6677
12
+ gem 'rails', '>0.a'
13
+
14
+ case ENV['DB']
15
+ when 'mysql'
16
+ gem 'mysql2'
17
+ when 'postgresql'
18
+ gem 'pg'
20
19
  else
21
- gem 'pg', '~> 0.21'
20
+ gem 'sqlite3'
22
21
  end
23
22
 
24
- group :development, :test do
25
- gem 'pry-rails', '~> 0.3.9'
26
- end
27
-
28
- gem 'deface', '~> 1.3', require: false
23
+ gem 'rails-controller-testing', group: :test
29
24
 
30
25
  gemspec
26
+
27
+ # Use a local Gemfile to include development dependencies that might not be
28
+ # relevant for the project or for other contributors, e.g.: `gem 'pry-debug'`.
29
+ eval_gemfile 'Gemfile-local' if File.exist? 'Gemfile-local'
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014, Spree Commerce, Inc. and other contributors
1
+ Copyright (c) 2020 Solidus Team
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without modification,
@@ -9,7 +9,7 @@ are permitted provided that the following conditions are met:
9
9
  * Redistributions in binary form must reproduce the above copyright notice,
10
10
  this list of conditions and the following disclaimer in the documentation
11
11
  and/or other materials provided with the distribution.
12
- * Neither the name Spree nor the names of its contributors may be used to
12
+ * Neither the name Solidus nor the names of its contributors may be used to
13
13
  endorse or promote products derived from this software without specific
14
14
  prior written permission.
15
15
 
data/README.md CHANGED
@@ -98,45 +98,4 @@ bundle exec rake
98
98
 
99
99
  ## Releasing a new version
100
100
 
101
- #### 1. Bump gem version and push to RubyGems
102
-
103
- We use [gem-release](https://github.com/svenfuchs/gem-release) to release this
104
- extension with ease.
105
-
106
- Supposing you are on the master branch and you are working on a fork of this
107
- extension, `upstream` is the main remote and you have write access to it, you
108
- can simply run:
109
-
110
- ```bash
111
- gem bump --version minor --tag --release
112
- ```
113
-
114
- This command will:
115
-
116
- - bump the gem version to the next minor (changing the `version.rb` file)
117
- - commit the change and push it to upstream master
118
- - create a git tag
119
- - push the tag to the upstream remote
120
- - release the new version on RubyGems
121
-
122
- Or you can run these commands individually:
123
-
124
- ```bash
125
- gem bump --version minor
126
- gem tag
127
- gem release
128
- ```
129
-
130
- #### 2. Publish the updated CHANGELOG
131
-
132
- After the release is done we can generate the updated CHANGELOG
133
- using
134
- [github-changelog-generator](https://github.com/github-changelog-generator/github-changelog-generator)
135
- by running the following command:
136
-
137
-
138
- ```bash
139
- bundle exec github_changelog_generator solidusio/solidus_auth_devise --token YOUR_GITHUB_TOKEN
140
- git commit -am 'Update CHANGELOG'
141
- git push upstream master
142
- ```
101
+ Please refer to the dedicated [page](https://github.com/solidusio/solidus/wiki/How-to-release-extensions) on Solidus wiki.
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'paranoia'
4
+
3
5
  module Spree
4
6
  class User < Spree::Base
5
7
  include UserMethods
@@ -46,6 +48,8 @@ module Spree
46
48
  end
47
49
 
48
50
  def scramble_email_and_password
51
+ return true if destroyed?
52
+
49
53
  self.email = SecureRandom.uuid + "@example.net"
50
54
  self.login = email
51
55
  self.password = SecureRandom.hex(8)
@@ -0,0 +1,20 @@
1
+ <!--
2
+ insert_before "fieldset#admin_user_edit_api_key"
3
+ original "904c52ff702412d1dc8d55ff44d87d7f581f6675"
4
+ -->
5
+
6
+ <% if @user != try_spree_current_user %>
7
+ <fieldset class="no-border-bottom" data-hook="admin_user_reset_password">
8
+ <legend><%= t(:'spree.forgot_password') %></legend>
9
+
10
+ <%= form_for [:admin, @user], as: :spree_user, url: admin_reset_password_path, method: :post do |f| %>
11
+ <%= f.hidden_field :email, value: @user.email %>
12
+
13
+ <% if can?(:update, @user) %>
14
+ <div class="align-center">
15
+ <%= f.submit Spree.user_class.human_attribute_name(:reset_password), class: "button primary" %>
16
+ </div>
17
+ <% end %>
18
+ <% end %>
19
+ </fieldset>
20
+ <% end %>
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require "bundler/setup"
6
+ require "solidus_auth_devise"
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+ $LOAD_PATH.unshift(*Dir["#{__dir__}/../app/*"])
11
+
12
+ # (If you use this, don't forget to add pry to your Gemfile!)
13
+ # require "pry"
14
+ # Pry.start
15
+
16
+ require "irb"
17
+ IRB.start(__FILE__)
data/bin/rails CHANGED
@@ -1,7 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- ENGINE_ROOT = File.expand_path('../..', __FILE__)
4
- ENGINE_PATH = File.expand_path('../../lib/spree/auth/engine', __FILE__)
3
+ # frozen_string_literal: true
5
4
 
6
- require 'rails/all'
7
- require 'rails/engine/commands'
5
+ app_root = 'spec/dummy'
6
+
7
+ unless File.exist? "#{app_root}/bin/rails"
8
+ system "bin/rake", app_root or begin # rubocop:disable Style/AndOr
9
+ warn "Automatic creation of the dummy app failed"
10
+ exit 1
11
+ end
12
+ end
13
+
14
+ Dir.chdir app_root
15
+ exec 'bin/rails', *ARGV
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ gem install bundler --conservative
7
+ bundle update
8
+ bundle exec rake clobber
@@ -1,8 +1,8 @@
1
+ ---
1
2
  it:
2
3
  spree:
3
- admin:
4
- tab:
5
- users: Utenti
4
+ admin_login: Login Amministrazione
5
+ change_my_password: Cambia la password
6
6
  devise:
7
7
  confirmations:
8
8
  confirmed: Il tuo account è stato correttamente confermato. Ora sei collegato.
@@ -65,9 +65,9 @@ it:
65
65
  signed_out: Uscito correttamente.
66
66
  errors:
67
67
  messages:
68
- email_is_invalid: L'indirizzo email non può essere vuoto
69
68
  already_confirmed: è stato già confermato
70
69
  confirmation_period_expired: deve essere confermato entro %{period}, richiedi una nuova conferma
70
+ email_is_invalid: L'indirizzo email non può essere vuoto
71
71
  expired: è scaduto, si prega di richiederne uno nuovo
72
72
  not_found: non trovato
73
73
  not_locked: non era bloccato
@@ -0,0 +1,7 @@
1
+ class AddUnconfirmedEmailToSpreeUsers < SolidusSupport::Migration[5.1]
2
+ def change
3
+ unless column_exists?(:spree_users, :unconfirmed_email)
4
+ add_column :spree_users, :unconfirmed_email, :string
5
+ end
6
+ end
7
+ end
@@ -25,7 +25,7 @@ class Spree::Admin::UserPasswordsController < Devise::PasswordsController
25
25
  set_flash_message(:notice, :send_instructions) if is_navigational_format?
26
26
 
27
27
  if resource.errors.empty?
28
- respond_with resource, location: spree.admin_login_path
28
+ respond_with resource, location: admin_user_path(resource)
29
29
  else
30
30
  respond_with_navigational(resource) { render :new }
31
31
  end
@@ -28,14 +28,17 @@ class Spree::UsersController < Spree::StoreController
28
28
  def update
29
29
  if @user.update(user_params)
30
30
  spree_current_user.reload
31
+ redirect_url = spree.account_url
31
32
 
32
33
  if params[:user][:password].present?
33
34
  # this logic needed b/c devise wants to log us out after password changes
34
- unless Spree::Auth::Config[:signout_after_password_change]
35
+ if Spree::Auth::Config[:signout_after_password_change]
36
+ redirect_url = spree.login_url
37
+ else
35
38
  bypass_sign_in(@user)
36
39
  end
37
40
  end
38
- redirect_to spree.account_url, notice: I18n.t('spree.account_updated')
41
+ redirect_to redirect_url, notice: I18n.t('spree.account_updated')
39
42
  else
40
43
  render :edit
41
44
  end
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Spree::Admin::Orders::CustomerDetailsController.class_eval do
4
- before_action :check_authorization
3
+ module Spree::Admin::Orders::CustomerDetailsControllerDecorator
4
+ def self.prepended(base)
5
+ base.before_action :check_authorization
6
+ end
5
7
 
6
8
  private
7
9
 
@@ -15,4 +17,6 @@ Spree::Admin::Orders::CustomerDetailsController.class_eval do
15
17
 
16
18
  authorize! action, resource, session[:access_token]
17
19
  end
20
+
21
+ Spree::Admin::Orders::CustomerDetailsController.prepend self
18
22
  end
@@ -4,6 +4,9 @@ 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
9
+
7
10
  def self.source_paths
8
11
  paths = superclass.source_paths
9
12
  paths << File.expand_path('templates', __dir__)
@@ -15,11 +18,18 @@ module Solidus
15
18
  end
16
19
 
17
20
  def add_migrations
18
- run 'bundle exec rake railties:install:migrations FROM=solidus_auth_devise'
21
+ run 'bundle exec rake railties:install:migrations FROM=solidus_auth'
19
22
  end
20
23
 
21
24
  def run_migrations
22
- run 'bundle exec rake db:migrate'
25
+ return if options[:skip_migrations]
26
+
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'
30
+ else
31
+ puts 'Skipping rake db:migrate, don\'t forget to run it!' # rubocop:disable Rails/Output
32
+ end
23
33
  end
24
34
  end
25
35
  end
@@ -1,15 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "spree_core"
4
- require "solidus_support"
5
- require "spree/auth/devise"
6
- require "spree/authentication_helpers"
3
+ require 'solidus_core'
4
+ require 'solidus_support'
5
+ require 'deface'
6
+ require 'devise'
7
+ require 'devise-encryptable'
8
+ require 'cancan'
7
9
 
8
- if SolidusSupport.solidus_gem_version < Gem::Version.new('2.5.x')
9
- begin
10
- require "deface"
11
- rescue LoadError
12
- warn "deface is required to run solidus_auth_devise with solidus versions < 2.5. Please add deface to your Gemfile"
13
- raise
14
- end
15
- end
10
+ require 'spree/auth/devise'
11
+ require 'spree/auth/version'
12
+ require 'spree/auth/engine'
13
+ require 'spree/authentication_helpers'
@@ -1,10 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spree/core'
4
- require 'devise'
5
- require 'devise-encryptable'
6
- require 'cancan'
7
-
8
3
  module Spree
9
4
  module Auth
10
5
  def self.config
@@ -12,5 +7,3 @@ module Spree
12
7
  end
13
8
  end
14
9
  end
15
-
16
- require 'spree/auth/engine'
@@ -6,10 +6,14 @@ require 'devise-encryptable'
6
6
  module Spree
7
7
  module Auth
8
8
  class Engine < Rails::Engine
9
+ include SolidusSupport::EngineExtensions
10
+
9
11
  isolate_namespace Spree
10
12
  engine_name 'solidus_auth'
11
13
 
12
14
  initializer "spree.auth.environment", before: :load_config_initializers do |_app|
15
+ require 'spree/auth_configuration'
16
+
13
17
  Spree::Auth::Config = Spree::AuthConfiguration.new
14
18
  end
15
19
 
@@ -18,65 +22,74 @@ module Spree
18
22
  end
19
23
 
20
24
  config.to_prepare do
21
- auth = Spree::Auth::Engine
22
-
23
- auth.prepare_backend if SolidusSupport.backend_available?
24
- auth.prepare_frontend if SolidusSupport.frontend_available?
25
+ Spree::Auth::Engine.prepare_backend if SolidusSupport.backend_available?
26
+ Spree::Auth::Engine.prepare_frontend if SolidusSupport.frontend_available?
25
27
 
26
- ApplicationController.send :include, Spree::AuthenticationHelpers
28
+ ApplicationController.include Spree::AuthenticationHelpers
27
29
  end
28
30
 
29
- def self.prepare_backend
30
- Rails.application.config.assets.precompile += %w[
31
- lib/assets/javascripts/spree/backend/solidus_auth.js
32
- lib/assets/javascripts/spree/backend/solidus_auth.css
33
- ]
31
+ def self.redirect_back_on_unauthorized?
32
+ return false unless Spree::Config.respond_to?(:redirect_back_on_unauthorized)
33
+
34
+ if Spree::Config.redirect_back_on_unauthorized
35
+ true
36
+ else
37
+ Spree::Deprecation.warn <<-WARN.strip_heredoc, caller
38
+ Having Spree::Config.redirect_back_on_unauthorized set
39
+ to `false` is deprecated and will not be supported in Solidus 3.0.
40
+ Please change this configuration to `true` and be sure that your
41
+ application does not break trying to redirect back when there is
42
+ an unauthorized access.
43
+ WARN
34
44
 
35
- Dir.glob(File.join(File.dirname(__FILE__), "../../controllers/backend/*/*/*_decorator*.rb")) do |c|
36
- Rails.configuration.cache_classes ? require(c) : load(c)
45
+ false
37
46
  end
47
+ end
38
48
 
49
+ def self.prepare_backend
39
50
  Spree::Admin::BaseController.unauthorized_redirect = -> do
40
51
  if try_spree_current_user
41
52
  flash[:error] = I18n.t('spree.authorization_failure')
42
- redirect_to spree.admin_unauthorized_path
53
+
54
+ if Spree::Auth::Engine.redirect_back_on_unauthorized?
55
+ redirect_back(fallback_location: spree.admin_unauthorized_path)
56
+ else
57
+ redirect_to spree.admin_unauthorized_path
58
+ end
43
59
  else
44
60
  store_location
45
- redirect_to spree.admin_login_path
61
+
62
+ if Spree::Auth::Engine.redirect_back_on_unauthorized?
63
+ redirect_back(fallback_location: spree.admin_login_path)
64
+ else
65
+ redirect_to spree.admin_login_path
66
+ end
46
67
  end
47
68
  end
48
69
  end
49
70
 
50
- def self.prepare_frontend
51
- Rails.application.config.assets.precompile += %w[
52
- lib/assets/javascripts/spree/frontend/solidus_auth.js
53
- lib/assets/javascripts/spree/frontend/solidus_auth.css
54
- ]
55
-
56
- Dir.glob(File.join(File.dirname(__FILE__), "../../controllers/frontend/*/*_decorator*.rb")) do |c|
57
- Rails.configuration.cache_classes ? require(c) : load(c)
58
- end
59
71
 
72
+ def self.prepare_frontend
60
73
  Spree::BaseController.unauthorized_redirect = -> do
61
74
  if try_spree_current_user
62
75
  flash[:error] = I18n.t('spree.authorization_failure')
63
- redirect_to spree.unauthorized_path
76
+
77
+ if Spree::Auth::Engine.redirect_back_on_unauthorized?
78
+ redirect_back(fallback_location: spree.unauthorized_path)
79
+ else
80
+ redirect_to spree.unauthorized_path
81
+ end
64
82
  else
65
83
  store_location
66
- redirect_to spree.login_path
84
+
85
+ if Spree::Auth::Engine.redirect_back_on_unauthorized?
86
+ redirect_back(fallback_location: spree.login_path)
87
+ else
88
+ redirect_to spree.login_path
89
+ end
67
90
  end
68
91
  end
69
92
  end
70
-
71
- if SolidusSupport.backend_available?
72
- paths["app/controllers"] << "lib/controllers/backend"
73
- paths["app/views"] << "lib/views/backend"
74
- end
75
-
76
- if SolidusSupport.frontend_available?
77
- paths["app/controllers"] << "lib/controllers/frontend"
78
- paths["app/views"] << "lib/views/frontend"
79
- end
80
93
  end
81
94
  end
82
95
  end