mirror of
https://github.com/internetee/registry.git
synced 2025-07-30 22:46:22 +02:00
update validation of email when domain contacts are updated
This commit is contained in:
parent
c972308f03
commit
58db467229
2 changed files with 21 additions and 12 deletions
|
@ -46,7 +46,7 @@ module Actions
|
|||
domain.add_epp_error('2306', nil, nil, %i[registrant cannot_be_missing]) unless params[:registrant][:code]
|
||||
|
||||
contact_code = params[:registrant][:code]
|
||||
contact = Contact.find_by_code(contact_code)
|
||||
contact = Contact.find_by(code: contact_code)
|
||||
validate_email(contact.email)
|
||||
|
||||
regt = Registrant.find_by(code: params[:registrant][:code])
|
||||
|
@ -124,6 +124,15 @@ module Actions
|
|||
@dnskeys << { id: dnkey.id, _destroy: 1 } if dnkey
|
||||
end
|
||||
|
||||
def start_validate_email(props)
|
||||
contact_code = props[0][:contact_code_cache]
|
||||
contact = Contact.find_by(code: contact_code)
|
||||
|
||||
return if contact.nil?
|
||||
|
||||
validate_email(contact.email)
|
||||
end
|
||||
|
||||
def validate_email(email)
|
||||
return true if Rails.env.test?
|
||||
|
||||
|
@ -142,11 +151,7 @@ module Actions
|
|||
def assign_admin_contact_changes
|
||||
props = gather_domain_contacts(params[:contacts].select { |c| c[:type] == 'admin' })
|
||||
|
||||
if props.present?
|
||||
contact_code = props[0][:contact_code_cache]
|
||||
contact = Contact.find_by_code(contact_code)
|
||||
validate_email(contact.email)
|
||||
end
|
||||
start_validate_email(props) if props.present?
|
||||
|
||||
if props.any? && domain.admin_change_prohibited?
|
||||
domain.add_epp_error('2304', 'admin', DomainStatus::SERVER_ADMIN_CHANGE_PROHIBITED,
|
||||
|
@ -161,11 +166,7 @@ module Actions
|
|||
props = gather_domain_contacts(params[:contacts].select { |c| c[:type] == 'tech' },
|
||||
admin: false)
|
||||
|
||||
if props.present?
|
||||
contact_code = props[0][:contact_code_cache]
|
||||
contact = Contact.find_by_code(contact_code)
|
||||
validate_email(contact.email)
|
||||
end
|
||||
start_validate_email(props) if props.present?
|
||||
|
||||
if props.any? && domain.tech_change_prohibited?
|
||||
domain.add_epp_error('2304', 'tech', DomainStatus::SERVER_TECH_CHANGE_PROHIBITED,
|
||||
|
|
|
@ -52,6 +52,8 @@ class ReppV1DomainsContactsTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
def test_can_remove_admin_contacts
|
||||
Spy.on_instance_method(Actions::DomainUpdate, :validate_email).and_return(true)
|
||||
|
||||
contact = contacts(:john)
|
||||
payload = { contacts: [ { code: contact.code, type: 'admin' } ] }
|
||||
post "/repp/v1/domains/#{@domain.name}/contacts", headers: @auth_headers, params: payload
|
||||
|
@ -68,6 +70,8 @@ class ReppV1DomainsContactsTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
def test_can_remove_tech_contacts
|
||||
Spy.on_instance_method(Actions::DomainUpdate, :validate_email).and_return(true)
|
||||
|
||||
contact = contacts(:john)
|
||||
payload = { contacts: [ { code: contact.code, type: 'tech' } ] }
|
||||
post "/repp/v1/domains/#{@domain.name}/contacts", headers: @auth_headers, params: payload
|
||||
|
@ -77,6 +81,9 @@ class ReppV1DomainsContactsTest < ActionDispatch::IntegrationTest
|
|||
delete "/repp/v1/domains/#{@domain.name}/contacts", headers: @auth_headers, params: payload
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
@domain.reload
|
||||
contact.reload
|
||||
|
||||
assert_response :ok
|
||||
assert_equal 1000, json[:code]
|
||||
|
||||
|
@ -84,6 +91,8 @@ class ReppV1DomainsContactsTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
def test_can_not_remove_one_and_only_contact
|
||||
Spy.on_instance_method(Actions::DomainUpdate, :validate_email).and_return(true)
|
||||
|
||||
contact = @domain.admin_contacts.last
|
||||
|
||||
payload = { contacts: [ { code: contact.code, type: 'admin' } ] }
|
||||
|
@ -96,5 +105,4 @@ class ReppV1DomainsContactsTest < ActionDispatch::IntegrationTest
|
|||
|
||||
assert @domain.admin_contacts.any?
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue