diff --git a/app/jobs/nameserver_record_validation_job.rb b/app/jobs/nameserver_record_validation_job.rb index a1787e9d7..5a32ce133 100644 --- a/app/jobs/nameserver_record_validation_job.rb +++ b/app/jobs/nameserver_record_validation_job.rb @@ -95,27 +95,27 @@ class NameserverRecordValidationJob < ApplicationJob end logger.info text - failed_log(text: text, nameserver: nameserver) + failed_log(text: text, nameserver: nameserver, domain: domain) add_nameserver_to_failed(nameserver: nameserver, reason: text) false end - def failed_log(text:, nameserver:) - inform_to_tech_contact(text) + def failed_log(text:, nameserver:, domain:) + inform_to_tech_contact(domain: domain, text: text) inform_to_registrar(text: text, nameserver: nameserver) false end - def inform_to_tech_contact(text) - "NEED TO DO!" - text + def inform_to_tech_contact(domain:, text:) + ContactNotification.notify_tech_contact(domain: domain, text: text) end def inform_to_registrar(text:, nameserver:) - # nameserver.domain.registrar.notifications.create!(text: text) - "NEED TO DO!" + # text = "DNSKEYS for #{domain.name} are invalid!" + logger.info text + ContactNotification.notify_registrar(domain: nameserver.domain, text: text) end def logger diff --git a/app/jobs/validate_dnssec_job.rb b/app/jobs/validate_dnssec_job.rb index ad6b4b768..54f7818c5 100644 --- a/app/jobs/validate_dnssec_job.rb +++ b/app/jobs/validate_dnssec_job.rb @@ -49,8 +49,7 @@ class ValidateDnssecJob < ApplicationJob text = "DNSKEYS for #{domain.name} are invalid!" logger.info text ContactNotification.notify_registrar(domain: domain, text: text) - ContactNotification.notify_tech_contact(domain: domain) - + ContactNotification.notify_tech_contact(domain: domain, text: text) end def validate(hostname:, domain:, type: 'DNSKEY', klass: 'IN') diff --git a/app/mailers/contact_inform_mailer.rb b/app/mailers/contact_inform_mailer.rb index 5c6f28f2c..00834a8ae 100644 --- a/app/mailers/contact_inform_mailer.rb +++ b/app/mailers/contact_inform_mailer.rb @@ -1,9 +1,10 @@ class ContactInformMailer < ApplicationMailer helper_method :address_processing - def notify(contact:, subject:) - @contact = email + def notify(contact:, domain:, subject:) + @contact = contact @subject = subject + @domain = domain mail(to: contact.email, subject: subject) end diff --git a/app/services/contact_notification.rb b/app/services/contact_notification.rb index 6c5648f74..d14526fea 100644 --- a/app/services/contact_notification.rb +++ b/app/services/contact_notification.rb @@ -5,13 +5,12 @@ module ContactNotification domain.registrar.notifications.create(text: text) end - def notify_tech_contact(domain:) - text = "DNSKEYS for #{domain.name} are invalid!" + def notify_tech_contact(domain:, text:) + # text = "DNSKEYS for #{domain.name} are invalid!" domain.tech_contacts.each do |tech| contact = Contact.find(tech.id) - ContactInformMailer.notify(contact: contact, subject: text) + ContactInformMailer.notify(contact: contact, domain: domain, subject: text).deliver_now end end - end diff --git a/test/services/contact_notification_test.rb b/test/services/contact_notification_test.rb new file mode 100644 index 000000000..317cbb470 --- /dev/null +++ b/test/services/contact_notification_test.rb @@ -0,0 +1,22 @@ +require 'test_helper' + +class ContactNotificationTest < ActionMailer::TestCase + + setup do + @domain = domains(:shop) + @text = 'text' + end + + def test_notify_registrar + assert_difference -> { @domain.registrar.notifications.count } do + ContactNotification.notify_registrar(domain: @domain, text: @text) + end + end + + def test_notify_tech_contacts + ContactNotification.notify_tech_contact(domain: @domain, text: @text) + assert_equal @domain.tech_contacts.count, 2 + assert_emails 2 + end +end +