Skip to content

Commit 5200fc2

Browse files
authored
Skip enforcement checks unless User model requires a password. (ValiMail#12)
* Update the migration code to accomodate changes in underlying ActiveRecord * Rubocop fixes * [VME-2162] Fix to work with invitable gem and SSO. * [VME-2162] Fix typo in README. * [VME-2162] Update README to note manual intervention for timestamp field creation. * [VME-2162] Bump version to 1.0.3. * [VME-2162] Update test databases.
1 parent 773e9fd commit 5200fc2

File tree

7 files changed

+9
-7
lines changed

7 files changed

+9
-7
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ The following database migration needs to be applied:
147147
prompt> rails generate migration create_previous_passwords salt:string encrypted_password:string user:references
148148
```
149149

150-
Edit the resulting file to disallow null values for the hash and to add indexes for both hash and user_id fields:
150+
Edit the resulting file to disallow null values for the hash,add indexes for both hash and user_id fields, and to also
151+
add the timestamp (created_at, updated_at) fields:
151152

152153
```ruby
153154
class CreatePreviousPasswords < ActiveRecord::Migration[5.1]
@@ -194,7 +195,7 @@ prompt> bundle exec rake
194195
To determine the Ruby on Rails versions supported by this release, run the following commands:
195196

196197
```bash
197-
prompt> gem install flay ruby2ruby rubucop rspec
198+
prompt> gem install flay ruby2ruby rubocop rspec
198199
prompt> rake test:spec:targets
199200

200201
Available Rails targets: 5.0.6, 5.1.4

lib/devise/secure_password/models/password_disallows_frequent_changes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class ConfigurationError < RuntimeError; end
77

88
included do
99
include ActionView::Helpers::DateHelper
10-
validate :validate_password_frequent_change
10+
validate :validate_password_frequent_change, if: :password_required?
1111

1212
set_callback(:initialize, :before, :before_resource_initialized)
1313
set_callback(:initialize, :after, :after_resource_initialized)

lib/devise/secure_password/models/password_disallows_frequent_reuse.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module PasswordDisallowsFrequentReuse
1212
class_name: 'Devise::Models::PreviousPassword',
1313
foreign_key: 'user_id',
1414
dependent: :destroy
15-
validate :validate_password_frequent_reuse
15+
validate :validate_password_frequent_reuse, if: :password_required?
1616

1717
set_callback(:save, :before, :before_resource_saved)
1818
set_callback(:save, :after, :after_resource_saved, if: :dirty_password?)
@@ -53,6 +53,7 @@ def previous_password?(password)
5353
end
5454

5555
def dirty_password?
56+
return false unless password_required?
5657
if Rails.version > '5.1'
5758
saved_change_to_encrypted_password?
5859
else

lib/devise/secure_password/models/password_has_required_content.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ module PasswordHasRequiredContent
88
LENGTH_MAX = 255
99

1010
included do
11-
validate :validate_password_content
12-
validate :validate_password_confirmation_content
11+
validate :validate_password_content, if: :password_required?
12+
validate :validate_password_confirmation_content, if: :password_required?
1313
end
1414

1515
def validate_password_content

lib/devise/secure_password/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Devise
22
module SecurePassword
3-
VERSION = '1.0.2'.freeze
3+
VERSION = '1.0.3'.freeze
44
end
55
end

spec/rails-app-5_0_6/db/test.sqlite3

0 Bytes
Binary file not shown.

spec/rails-app-5_1_4/db/test.sqlite3

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)