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 end
logger.info text 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) add_nameserver_to_failed(nameserver: nameserver, reason: text)
false false
end end
def failed_log(text:, nameserver:) def failed_log(text:, nameserver:, domain:)
inform_to_tech_contact(text) inform_to_tech_contact(domain: domain, text: text)
inform_to_registrar(text: text, nameserver: nameserver) inform_to_registrar(text: text, nameserver: nameserver)
false false
end end
def inform_to_tech_contact(text) def inform_to_tech_contact(domain:, text:)
"NEED TO DO!" ContactNotification.notify_tech_contact(domain: domain, text: text)
text
end end
def inform_to_registrar(text:, nameserver:) def inform_to_registrar(text:, nameserver:)
# nameserver.domain.registrar.notifications.create!(text: text) # text = "DNSKEYS for #{domain.name} are invalid!"
"NEED TO DO!" logger.info text
ContactNotification.notify_registrar(domain: nameserver.domain, text: text)
end end
def logger def logger

View file

@ -49,8 +49,7 @@ class ValidateDnssecJob < ApplicationJob
text = "DNSKEYS for #{domain.name} are invalid!" text = "DNSKEYS for #{domain.name} are invalid!"
logger.info text logger.info text
ContactNotification.notify_registrar(domain: domain, text: text) ContactNotification.notify_registrar(domain: domain, text: text)
ContactNotification.notify_tech_contact(domain: domain) ContactNotification.notify_tech_contact(domain: domain, text: text)
end end
def validate(hostname:, domain:, type: 'DNSKEY', klass: 'IN') def validate(hostname:, domain:, type: 'DNSKEY', klass: 'IN')

View file

@ -1,9 +1,10 @@
class ContactInformMailer < ApplicationMailer class ContactInformMailer < ApplicationMailer
helper_method :address_processing helper_method :address_processing
def notify(contact:, subject:) def notify(contact:, domain:, subject:)
@contact = email @contact = contact
@subject = subject @subject = subject
@domain = domain
mail(to: contact.email, subject: subject) mail(to: contact.email, subject: subject)
end end

View file

@ -5,13 +5,12 @@ module ContactNotification
domain.registrar.notifications.create(text: text) domain.registrar.notifications.create(text: text)
end end
def notify_tech_contact(domain:) def notify_tech_contact(domain:, text:)
text = "DNSKEYS for #{domain.name} are invalid!" # text = "DNSKEYS for #{domain.name} are invalid!"
domain.tech_contacts.each do |tech| domain.tech_contacts.each do |tech|
contact = Contact.find(tech.id) contact = Contact.find(tech.id)
ContactInformMailer.notify(contact: contact, subject: text) ContactInformMailer.notify(contact: contact, domain: domain, subject: text).deliver_now
end end
end 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