Fix CC issues

This commit is contained in:
Karl Erik Õunapuu 2020-11-12 17:05:13 +02:00
parent 60a66bc540
commit 54eb1e91de
No known key found for this signature in database
GPG key ID: C9DD647298A34764
4 changed files with 78 additions and 47 deletions

View file

@ -1,4 +1,15 @@
class ApplicationMailer < ActionMailer::Base
append_view_path Rails.root.join('app', 'views', 'mailers')
layout 'mailer'
end
def registrant_confirm_url(domain:, method:)
token = domain.registrant_verification_token
base_url = ENV['registrant_portal_verifications_base_url']
url = registrant_domain_delete_confirm_url(domain, token: token) if method == 'delete'
url ||= registrant_domain_update_confirm_url(domain, token: token)
return url if base_url.blank?
"#{base_url}/confirms/#{domain.name_puny}/#{method}/#{token}"
end
end

View file

@ -6,7 +6,7 @@ class DomainDeleteMailer < ApplicationMailer
def confirmation_request(domain:, registrar:, registrant:)
@domain = DomainPresenter.new(domain: domain, view: view_context)
@registrar = RegistrarPresenter.new(registrar: registrar, view: view_context)
@confirmation_url = confirmation_url(domain)
@confirmation_url = registrant_confirm_url(domain: domain, method: 'delete')
subject = default_i18n_subject(domain_name: domain.name)
mail(to: registrant.email, subject: subject)
@ -52,15 +52,6 @@ class DomainDeleteMailer < ApplicationMailer
private
def confirmation_url(domain)
base_url = ENV['registrant_portal_verifications_base_url']
if base_url.blank?
registrant_domain_delete_confirm_url(domain, token: domain.registrant_verification_token)
else
"#{base_url}/confirmation/#{domain.name_puny}/delete/#{domain.registrant_verification_token}"
end
end
def forced_email_from
ENV['action_mailer_force_delete_from'] || self.class.default[:from]
end

View file

@ -5,7 +5,7 @@ class RegistrantChangeMailer < ApplicationMailer
@domain = DomainPresenter.new(domain: domain, view: view_context)
@registrar = RegistrarPresenter.new(registrar: registrar, view: view_context)
@new_registrant = RegistrantPresenter.new(registrant: new_registrant, view: view_context)
@confirmation_url = confirmation_url(domain)
@confirmation_url = registrant_confirm_url(domain: domain, method: 'change')
subject = default_i18n_subject(domain_name: domain.name)
mail(to: current_registrant.email, subject: subject)
@ -49,15 +49,6 @@ class RegistrantChangeMailer < ApplicationMailer
private
def confirmation_url(domain)
base_url = ENV['registrant_portal_verifications_base_url']
if base_url.blank?
registrant_domain_update_confirm_url(domain, token: domain.registrant_verification_token)
else
"#{base_url}/confirmation/#{domain.name_puny}/change/#{domain.registrant_verification_token}"
end
end
def address_processing
Contact.address_processing?
end

View file

@ -8,17 +8,22 @@ class RegistrantApiVerificationsTest < ApplicationIntegrationTest
@domain = domains(:hospital)
@registrant = @domain.registrant
@new_registrant = contacts(:jack)
@user = users(:api_bestnames)
@token = 'verysecrettoken'
@domain.update(statuses: [DomainStatus::PENDING_UPDATE],
@domain.update!(statuses: [DomainStatus::PENDING_UPDATE],
registrant_verification_asked_at: Time.zone.now - 1.day,
registrant_verification_token: @token)
end
def test_fetches_registrant_change_request
pending_json = { new_registrant_id: @new_registrant.id }
pending_json = { new_registrant_id: @new_registrant.id,
new_registrant_name: @new_registrant.name,
new_registrant_email: @new_registrant.email,
current_user_id: @user.id }
@domain.update(pending_json: pending_json)
@domain.reload
@ -46,31 +51,40 @@ class RegistrantApiVerificationsTest < ApplicationIntegrationTest
end
def test_approves_registrant_change_request
pending_json = { new_registrant_id: @new_registrant.id }
@domain.update(pending_json: pending_json)
pending_json = { new_registrant_id: @new_registrant.id,
new_registrant_name: @new_registrant.name,
new_registrant_email: @new_registrant.email,
current_user_id: @user.id }
@domain.update!(pending_json: pending_json)
@domain.reload
assert @domain.registrant_update_confirmable?(@token)
post "/api/v1/registrant/confirms/#{@domain.name_puny}/change/#{@token}/confirmed"
assert_equal(200, response.status)
perform_enqueued_jobs do
post "/api/v1/registrant/confirms/#{@domain.name_puny}/change/#{@token}/confirmed"
assert_equal(200, response.status)
res = JSON.parse(response.body, symbolize_names: true)
expected_body = {
domain_name: @domain.name,
current_registrant: {
name: @new_registrant.name,
ident: @new_registrant.ident,
country: @new_registrant.ident_country_code
},
status: 'confirmed'
}
assert_equal expected_body, res
res = JSON.parse(response.body, symbolize_names: true)
expected_body = {
domain_name: @domain.name,
current_registrant: {
name: @new_registrant.name,
ident: @new_registrant.ident,
country: @new_registrant.ident_country_code
},
status: 'confirmed'
}
assert_equal expected_body, res
end
end
def test_rejects_registrant_change_request
pending_json = { new_registrant_id: @new_registrant.id }
pending_json = { new_registrant_id: @new_registrant.id,
new_registrant_name: @new_registrant.name,
new_registrant_email: @new_registrant.email,
current_user_id: @user.id }
@domain.update(pending_json: pending_json)
@domain.reload
@ -94,7 +108,11 @@ class RegistrantApiVerificationsTest < ApplicationIntegrationTest
end
def test_registrant_change_requires_valid_attributes
pending_json = { new_registrant_id: @new_registrant.id }
pending_json = { new_registrant_id: @new_registrant.id,
new_registrant_name: @new_registrant.name,
new_registrant_email: @new_registrant.email,
current_user_id: @user.id }
@domain.update(pending_json: pending_json)
@domain.reload
@ -109,7 +127,12 @@ class RegistrantApiVerificationsTest < ApplicationIntegrationTest
end
def test_fetches_domain_delete_request
@domain.update(statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION])
pending_json = { new_registrant_id: @new_registrant.id,
new_registrant_name: @new_registrant.name,
new_registrant_email: @new_registrant.email,
current_user_id: @user.id }
@domain.update(pending_json: pending_json, statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION])
@domain.reload
assert @domain.registrant_delete_confirmable?(@token)
@ -131,8 +154,13 @@ class RegistrantApiVerificationsTest < ApplicationIntegrationTest
end
def test_approves_domain_delete_request
@domain.update(statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION])
@domain.reload
pending_json = { new_registrant_id: @new_registrant.id,
new_registrant_name: @new_registrant.name,
new_registrant_email: @new_registrant.email,
current_user_id: @user.id }
@domain.update(pending_json: pending_json, statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION])
@domain.reload
assert @domain.registrant_delete_confirmable?(@token)
@ -154,8 +182,13 @@ class RegistrantApiVerificationsTest < ApplicationIntegrationTest
end
def test_rejects_domain_delete_request
@domain.update(statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION])
@domain.reload
pending_json = { new_registrant_id: @new_registrant.id,
new_registrant_name: @new_registrant.name,
new_registrant_email: @new_registrant.email,
current_user_id: @user.id }
@domain.update(pending_json: pending_json, statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION])
@domain.reload
assert @domain.registrant_delete_confirmable?(@token)
@ -177,7 +210,12 @@ class RegistrantApiVerificationsTest < ApplicationIntegrationTest
end
def test_domain_delete_requires_valid_attributes
@domain.update(statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION, DomainStatus::PENDING_DELETE])
pending_json = { new_registrant_id: @new_registrant.id,
new_registrant_name: @new_registrant.name,
new_registrant_email: @new_registrant.email,
current_user_id: @user.id }
@domain.update(pending_json: pending_json, statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION])
@domain.reload
get "/api/v1/registrant/confirms/#{@domain.name_puny}/delete/123"