Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Reverse old passwords order in the has_many association #32

Closed
wants to merge 1 commit into from

1 participant

@ovargas27

I have some problems with the reverse_order method when there is not old_passwords,
this fix the issue and also improve some performance

Order the old passwords in the has_many association.

@ovargas27

@jedl fix the same issue in jedl@74fda4a

@ovargas27 ovargas27 closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 3 additions and 3 deletions.
  1. +3 −3 lib/devise_security_extension/models/password_archivable.rb
View
6 lib/devise_security_extension/models/password_archivable.rb
@@ -6,7 +6,7 @@ module PasswordArchivable
extend ActiveSupport::Concern
included do
- has_many :old_passwords, :as => :password_archivable, :dependent => :destroy
+ has_many :old_passwords, :as => :password_archivable, :dependent => :destroy, :order => 'id DESC'
before_update :archive_password
validate :validate_password_archive
end
@@ -26,7 +26,7 @@ def password_archive_included?
end
if self.class.deny_old_passwords > 0 and not self.password.nil?
- self.old_passwords.reverse_order(:id).limit(self.class.deny_old_passwords).each do |old_password|
+ self.old_passwords.limit(self.class.deny_old_passwords).each do |old_password|
dummy = self.class.new
dummy.encrypted_password = old_password.encrypted_password
dummy.password_salt = old_password.password_salt if dummy.respond_to?(:password_salt)
@@ -48,7 +48,7 @@ def archive_password
else
self.old_passwords.create! :encrypted_password => self.encrypted_password_change.first
end
- self.old_passwords.reverse_order(:id).offset(self.class.password_archiving_count).destroy_all
+ self.old_passwords.offset(self.class.password_archiving_count).destroy_all
else
self.old_passwords.destroy_all
end
Something went wrong with that request. Please try again.