Skip to content

Commit

Permalink
Prevent deprecated validations when email is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagoyoussef committed May 12, 2022
1 parent 7a2256a commit ec71ae1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/interactions/actions/contact_update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ def commit
contact.email_history = old_email
updated = contact.save

if updated && email_changed && contact.registrant?
ContactMailer.email_changed(contact: contact, old_email: old_email).deliver_now
if updated && email_changed
contact.validation_events.where('event_data @> ?', { 'email': old_email }.to_json).destroy_all
ContactMailer.email_changed(contact: contact, old_email: old_email).deliver_now if contact.registrant?
end

updated
Expand Down
29 changes: 29 additions & 0 deletions test/integration/epp/contact/update/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,35 @@ def test_notifies_contact_by_email_when_email_is_changed
assert_emails 1
end

def test_destroy_old_validation_when_email_is_changed
@contact.verify_email
old_validation_event = @contact.validation_events.first
@contact.update_columns(code: @contact.code.upcase)

request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="#{Xsd::Schema.filename(for_prefix: 'epp-ee', for_version: '1.0')}">
<command>
<update>
<contact:update xmlns:contact="#{Xsd::Schema.filename(for_prefix: 'contact-ee', for_version: '1.1')}">
<contact:id>john-001</contact:id>
<contact:chg>
<contact:email>[email protected]</contact:email>
</contact:chg>
</contact:update>
</update>
</command>
</epp>
XML

post epp_update_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }

assert_raises(ActiveRecord::RecordNotFound) do
ValidationEvent.find(old_validation_event.id)
end
end

def test_skips_notifying_contact_when_email_is_not_changed
assert_equal 'john-001', @contact.code
assert_equal '[email protected]', @contact.email
Expand Down

0 comments on commit ec71ae1

Please sign in to comment.