From 2135ae5e5e3c0256480343e36c0015b1e0931bc7 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Fri, 10 Mar 2017 08:56:33 -0300 Subject: [PATCH] Change email_change => email_changed notification This better indicates what the setting is for, and when it's supposed to be triggered. We might eventually deprecate the existing password_change on in favor of password_changed. --- CHANGELOG.md | 2 +- app/mailers/devise/mailer.rb | 4 ++-- ...mail_change.html.erb => email_changed.html.erb} | 0 config/locales/en.yml | 2 +- lib/devise.rb | 4 ++-- lib/devise/models/confirmable.rb | 6 +++--- lib/devise/models/database_authenticatable.rb | 14 +++++++------- lib/generators/templates/devise.rb | 2 +- ...{email_change.markerb => email_changed.markerb} | 0 test/models/confirmable_test.rb | 2 +- test/models/database_authenticatable_test.rb | 2 +- 11 files changed, 19 insertions(+), 19 deletions(-) rename app/views/devise/mailer/{email_change.html.erb => email_changed.html.erb} (100%) rename lib/generators/templates/markerb/{email_change.markerb => email_changed.markerb} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 567d1323..9ae4f021 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ * `Devise::Mailer#scope_name` and `Devise::Mailer#resource` are now protected methods instead of public. * enhancements - * Notify the original email when it is changed with a new `Devise.send_email_change_notification` setting. + * Notify the original email when it is changed with a new `Devise.send_email_changed_notification` setting. When using `reconfirmable`, the notification will be sent right away instead of when the unconfirmed email is confirmed. (original change by @ethirajsrinivasan) diff --git a/app/mailers/devise/mailer.rb b/app/mailers/devise/mailer.rb index 0011a060..857a8bc6 100644 --- a/app/mailers/devise/mailer.rb +++ b/app/mailers/devise/mailer.rb @@ -17,8 +17,8 @@ if defined?(ActionMailer) devise_mail(record, :unlock_instructions, opts) end - def email_change(record, opts={}) - devise_mail(record, :email_change, opts) + def email_changed(record, opts={}) + devise_mail(record, :email_changed, opts) end def password_change(record, opts={}) diff --git a/app/views/devise/mailer/email_change.html.erb b/app/views/devise/mailer/email_changed.html.erb similarity index 100% rename from app/views/devise/mailer/email_change.html.erb rename to app/views/devise/mailer/email_changed.html.erb diff --git a/config/locales/en.yml b/config/locales/en.yml index ac059bbe..0b8f1302 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -23,7 +23,7 @@ en: subject: "Reset password instructions" unlock_instructions: subject: "Unlock instructions" - email_change: + email_changed: subject: "Email Changed" password_change: subject: "Password Changed" diff --git a/lib/devise.rb b/lib/devise.rb index 3f4f4154..2262c9b8 100755 --- a/lib/devise.rb +++ b/lib/devise.rb @@ -154,8 +154,8 @@ module Devise @@pepper = nil # Used to send notification to the original user email when their email is changed. - mattr_accessor :send_email_change_notification - @@send_email_change_notification = false + mattr_accessor :send_email_changed_notification + @@send_email_changed_notification = false # Used to enable sending notification to user when their password is changed. mattr_accessor :send_password_change_notification diff --git a/lib/devise/models/confirmable.rb b/lib/devise/models/confirmable.rb index f5ad5bce..3b4bdd60 100644 --- a/lib/devise/models/confirmable.rb +++ b/lib/devise/models/confirmable.rb @@ -26,7 +26,7 @@ module Devise # initial account confirmation) to be applied. Requires additional unconfirmed_email # db field to be set up (t.reconfirmable in migrations). Until confirmed, new email is # stored in unconfirmed email column, and copied to email column on successful - # confirmation. Also, when used in conjunction with `send_email_change_notification`, + # confirmation. Also, when used in conjunction with `send_email_changed_notification`, # the notification is sent to the original email when the change is requested, # not when the unconfirmed email is confirmed. # * +confirm_within+: the time before a sent confirmation token becomes invalid. @@ -281,9 +281,9 @@ module Devise # With reconfirmable, notify the original email when the user first # requests the email change, instead of when the change is confirmed. - def send_email_change_notification? + def send_email_changed_notification? if self.class.reconfirmable - self.class.send_email_change_notification && reconfirmation_required? + self.class.send_email_changed_notification && reconfirmation_required? else super end diff --git a/lib/devise/models/database_authenticatable.rb b/lib/devise/models/database_authenticatable.rb index 7494a31b..bb8ea50b 100644 --- a/lib/devise/models/database_authenticatable.rb +++ b/lib/devise/models/database_authenticatable.rb @@ -14,7 +14,7 @@ module Devise # # * +stretches+: the cost given to bcrypt. # - # * +send_email_change_notification+: notify original email when it changes. + # * +send_email_changed_notification+: notify original email when it changes. # # * +send_password_change_notification+: notify email when password changes. # @@ -26,7 +26,7 @@ module Devise extend ActiveSupport::Concern included do - after_update :send_email_change_notification, if: :send_email_change_notification? + after_update :send_email_changed_notification, if: :send_email_changed_notification? after_update :send_password_change_notification, if: :send_password_change_notification? attr_reader :password, :current_password @@ -138,8 +138,8 @@ module Devise end # Send notification to user when email changes. - def send_email_change_notification - send_devise_notification(:email_change, to: email_was) + def send_email_changed_notification + send_devise_notification(:email_changed, to: email_was) end # Send notification to user when password changes. @@ -158,8 +158,8 @@ module Devise Devise::Encryptor.digest(self.class, password) end - def send_email_change_notification? - self.class.send_email_change_notification && email_changed? + def send_email_changed_notification? + self.class.send_email_changed_notification && email_changed? end def send_password_change_notification? @@ -167,7 +167,7 @@ module Devise end module ClassMethods - Devise::Models.config(self, :pepper, :stretches, :send_email_change_notification, :send_password_change_notification) + Devise::Models.config(self, :pepper, :stretches, :send_email_changed_notification, :send_password_change_notification) # We assume this method already gets the sanitized values from the # DatabaseAuthenticatable strategy. If you are using this method on diff --git a/lib/generators/templates/devise.rb b/lib/generators/templates/devise.rb index 49060987..e3d9ede7 100755 --- a/lib/generators/templates/devise.rb +++ b/lib/generators/templates/devise.rb @@ -111,7 +111,7 @@ Devise.setup do |config| # config.pepper = '<%= SecureRandom.hex(64) %>' # Send a notification to the original email when the user's email is changed. - # config.send_email_change_notification = false + # config.send_email_changed_notification = false # Send a notification email when the user's password is changed. # config.send_password_change_notification = false diff --git a/lib/generators/templates/markerb/email_change.markerb b/lib/generators/templates/markerb/email_changed.markerb similarity index 100% rename from lib/generators/templates/markerb/email_change.markerb rename to lib/generators/templates/markerb/email_changed.markerb diff --git a/test/models/confirmable_test.rb b/test/models/confirmable_test.rb index 2e566abd..e0f08cc0 100644 --- a/test/models/confirmable_test.rb +++ b/test/models/confirmable_test.rb @@ -518,7 +518,7 @@ class ReconfirmableTest < ActiveSupport::TestCase end test 'should notify previous email on email change when configured' do - swap Devise, send_email_change_notification: true do + swap Devise, send_email_changed_notification: true do admin = create_admin original_email = admin.email diff --git a/test/models/database_authenticatable_test.rb b/test/models/database_authenticatable_test.rb index 11bd69a6..a5c7c77f 100644 --- a/test/models/database_authenticatable_test.rb +++ b/test/models/database_authenticatable_test.rb @@ -237,7 +237,7 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase end test 'should notify previous email on email change when configured' do - swap Devise, send_email_change_notification: true do + swap Devise, send_email_changed_notification: true do user = create_user original_email = user.email assert_email_sent original_email do