mirror of
https://github.com/heartcombo/devise.git
synced 2026-01-09 15:47:59 -05:00
Merge pull request #5576 from heartcombo/ca-multiple-orms
Improve support for Devise in apps with multiple ORMs loaded
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
* enhancements
|
||||
* Allow resource class scopes to override the global configuration for `sign_in_after_reset_password` behaviour. [#5429](https://github.com/heartcombo/devise/pull/5429) [@mattr](https://github.com/mattr)
|
||||
* Refactor conditional dirty tracking logic to a centralized module to simplify usage throughout the codebase. [#5575](https://github.com/heartcombo/devise/pull/5575)
|
||||
* Improve support for Devise in apps with Active Record and Mongoid ORMs loaded, so it does not incorrectly uses new Active Record dirty tracking APIs with a Mongoid Devise model. [#5576](https://github.com/heartcombo/devise/pull/5576)
|
||||
|
||||
* bug fixes
|
||||
* Failure app will respond with configured `redirect_status` instead of `error_status` if the recall app returns a redirect status (300..399) [#5573](https://github.com/heartcombo/devise/pull/5573)
|
||||
|
||||
@@ -13,7 +13,7 @@ module Devise
|
||||
autoload :Encryptor, 'devise/encryptor'
|
||||
autoload :FailureApp, 'devise/failure_app'
|
||||
autoload :OmniAuth, 'devise/omniauth'
|
||||
autoload :OrmDirtyTracking, 'devise/orm_dirty_tracking'
|
||||
autoload :Orm, 'devise/orm'
|
||||
autoload :ParameterFilter, 'devise/parameter_filter'
|
||||
autoload :ParameterSanitizer, 'devise/parameter_sanitizer'
|
||||
autoload :TestHelpers, 'devise/test_helpers'
|
||||
|
||||
@@ -84,7 +84,7 @@ module Devise
|
||||
end
|
||||
|
||||
devise_modules_hook! do
|
||||
include Devise::OrmDirtyTracking
|
||||
include Devise::Orm
|
||||
include Devise::Models::Authenticatable
|
||||
|
||||
selected_modules.each do |m|
|
||||
|
||||
@@ -48,7 +48,7 @@ module Devise
|
||||
included do
|
||||
before_create :generate_confirmation_token, if: :confirmation_required?
|
||||
after_create :skip_reconfirmation_in_callback!, if: :send_confirmation_notification?
|
||||
if defined?(ActiveRecord) && self < ActiveRecord::Base # ActiveRecord
|
||||
if Devise::Orm.active_record?(self) # ActiveRecord
|
||||
after_commit :send_on_create_confirmation_instructions, on: :create, if: :send_confirmation_notification?
|
||||
after_commit :send_reconfirmation_instructions, on: :update, if: :reconfirmation_required?
|
||||
else # Mongoid
|
||||
|
||||
@@ -1,10 +1,22 @@
|
||||
module Devise
|
||||
module OrmDirtyTracking # :nodoc:
|
||||
def self.activerecord51?
|
||||
defined?(ActiveRecord) && ActiveRecord.gem_version >= Gem::Version.new("5.1.x")
|
||||
module Orm # :nodoc:
|
||||
def self.active_record?(model)
|
||||
defined?(ActiveRecord) && model < ActiveRecord::Base
|
||||
end
|
||||
|
||||
if activerecord51?
|
||||
def self.active_record_51?(model)
|
||||
active_record?(model) && ActiveRecord.gem_version >= Gem::Version.new("5.1.x")
|
||||
end
|
||||
|
||||
def self.included(model)
|
||||
if Devise::Orm.active_record_51?(model)
|
||||
model.include DirtyTrackingNewMethods
|
||||
else
|
||||
model.include DirtyTrackingOldMethods
|
||||
end
|
||||
end
|
||||
|
||||
module DirtyTrackingNewMethods
|
||||
def devise_email_before_last_save
|
||||
email_before_last_save
|
||||
end
|
||||
@@ -28,7 +40,9 @@ module Devise
|
||||
def devise_respond_to_and_will_save_change_to_attribute?(attribute)
|
||||
respond_to?("will_save_change_to_#{attribute}?") && send("will_save_change_to_#{attribute}?")
|
||||
end
|
||||
else
|
||||
end
|
||||
|
||||
module DirtyTrackingOldMethods
|
||||
def devise_email_before_last_save
|
||||
email_was
|
||||
end
|
||||
Reference in New Issue
Block a user