Fixed issue #1661 - Users mail_delivery_failed is not removed after changing the email address.

This commit is contained in:
Martin Edenhofer 2017-11-21 08:37:09 +01:00
parent 3417618798
commit 9f204806db
2 changed files with 47 additions and 1 deletions

View file

@ -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

View file

@ -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