improve notification feature

This commit is contained in:
olegphenomenon 2022-01-10 12:05:32 +02:00
parent 053382ffa3
commit 35f60e53e5
5 changed files with 37 additions and 16 deletions

View file

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

View file

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

View file

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

View file

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

View file

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