Merge pull request #2718 from internetee/daily-fd-domains-subscription

Daily email notification to admins about new FD statuses
This commit is contained in:
Timo Võhmar 2024-12-31 10:56:52 +02:00 committed by GitHub
commit e38c46757b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 155 additions and 0 deletions

View file

@ -0,0 +1,41 @@
class ForceDeleteDailyAdminNotifierJob < ApplicationJob
queue_as :default
def perform
domains = Domain.where("'#{DomainStatus::FORCE_DELETE}' = ANY (statuses)")
.where("force_delete_start = ?", Time.zone.now)
return if domains.empty?
notify_admins(domains)
end
private
def notify_admins(domains)
summary = generate_summary(domains)
AdminMailer.force_delete_daily_summary(summary).deliver_now
end
def generate_summary(domains)
domains.map do |domain|
{
name: domain.name,
reason: determine_reason(domain),
force_delete_type: domain.force_delete_type,
force_delete_start: domain.force_delete_start,
force_delete_date: domain.force_delete_date
}
end
end
def determine_reason(domain)
if domain.template_name.present?
domain.template_name
elsif domain.status_notes[DomainStatus::FORCE_DELETE].present?
"Manual force delete: #{domain.status_notes[DomainStatus::FORCE_DELETE]}"
else
'Unknown reason'
end
end
end

View file

@ -0,0 +1,9 @@
class AdminMailer < ApplicationMailer
def force_delete_daily_summary(domains_summary)
@domains = domains_summary
mail(
to: ENV['admin_notification_email'] || 'admin@registry.test',
subject: "Force Delete Daily Summary - #{Date.current}"
)
end
end

View file

@ -0,0 +1,24 @@
<h1>Force Delete Daily Summary - <%= Date.current %></h1>
<table>
<thead>
<tr>
<th>Domain</th>
<th>Reason</th>
<th>Type</th>
<th>Start Date</th>
<th>Delete Date</th>
</tr>
</thead>
<tbody>
<% @domains.each do |domain| %>
<tr>
<td><%= domain[:name] %></td>
<td><%= domain[:reason] %></td>
<td><%= domain[:force_delete_type] %></td>
<td><%= domain[:force_delete_start]&.to_date %></td>
<td><%= domain[:force_delete_date]&.to_date %></td>
</tr>
<% end %>
</tbody>
</table>