From 9f204806db6483de644c5996463d3e81e20b4e4e Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 21 Nov 2017 08:37:09 +0100 Subject: [PATCH] Fixed issue #1661 - Users mail_delivery_failed is not removed after changing the email address. --- app/models/user.rb | 8 ++++- test/unit/user_mail_delivery_failed_test.rb | 40 +++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 test/unit/user_mail_delivery_failed_test.rb diff --git a/app/models/user.rb b/app/models/user.rb index 95d280ec0..21c32d86a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -38,7 +38,7 @@ class User < ApplicationModel load 'user/search_index.rb' include User::SearchIndex - before_validation :check_name, :check_email, :check_login, :ensure_uniq_email, :ensure_password, :ensure_roles, :ensure_identifier + before_validation :check_name, :check_email, :check_login, :check_mail_delivery_failed, :ensure_uniq_email, :ensure_password, :ensure_roles, :ensure_identifier before_create :check_preferences_default, :validate_ooo, :domain_based_assignment, :set_locale before_update :check_preferences_default, :validate_ooo, :reset_login_failed, :validate_agent_limit_by_attributes, :last_admin_check_by_attribute after_create :avatar_for_email_check @@ -945,6 +945,12 @@ returns true end + def check_mail_delivery_failed + return true if !changes || !changes['email'] + preferences.delete(:mail_delivery_failed) + true + end + def ensure_roles return true if role_ids.present? self.role_ids = Role.signup_role_ids diff --git a/test/unit/user_mail_delivery_failed_test.rb b/test/unit/user_mail_delivery_failed_test.rb new file mode 100644 index 000000000..2ff9e0b9f --- /dev/null +++ b/test/unit/user_mail_delivery_failed_test.rb @@ -0,0 +1,40 @@ +require 'test_helper' + +class UserMailDeliveryFailedTest < ActiveSupport::TestCase + setup do + + UserInfo.current_user_id = 1 + + roles = Role.where(name: 'Customer') + @customer1 = User.create_or_update( + login: 'user-mail-delivery-failed-customer1@example.com', + firstname: 'UserOutOfOffice', + lastname: 'Customer1', + email: 'user-mail-delivery-failed-customer1@example.com', + password: 'agentpw', + active: true, + roles: roles, + ) + + end + + test 'check reset of mail_delivery_failed' do + + @customer1.preferences[:mail_delivery_failed] = true + @customer1.preferences[:mail_delivery_failed_data] = Time.zone.now + @customer1.save! + @customer1.reload + + assert_equal(@customer1.preferences[:mail_delivery_failed], true) + assert(@customer1.preferences[:mail_delivery_failed_data]) + + @customer1.email = 'new-user-mail-delivery-failed-customer1@example.com' + @customer1.save! + @customer1.reload + + assert_not(@customer1.preferences[:mail_delivery_failed], true) + assert(@customer1.preferences[:mail_delivery_failed_data]) + + end + +end