Allow explicit reason for force delete mail template

This commit is contained in:
Karl Erik Õunapuu 2020-12-28 12:41:07 +02:00
parent 8a046b59bf
commit 38cefe7255
No known key found for this signature in database
GPG key ID: C9DD647298A34764
5 changed files with 13 additions and 6 deletions

View file

@ -10,6 +10,9 @@ module Domains
boolean :notify_by_email, boolean :notify_by_email,
default: false, default: false,
description: 'Do we need to send email notification' description: 'Do we need to send email notification'
string :reason,
default: nil,
description: 'Which mail template to use explicitly'
validates :type, inclusion: { in: %i[fast_track soft] } validates :type, inclusion: { in: %i[fast_track soft] }
end end

View file

@ -8,7 +8,7 @@ module Domains
send_email send_email
domain.update(contact_notification_sent_date: Time.zone.today) domain.update(contact_notification_sent_date: Time.zone.today)
else else
domain.update(template_name: domain.notification_template) domain.update(template_name: domain.notification_template(explicit: reason))
end end
end end

View file

@ -19,7 +19,10 @@ module Concerns::Domain::ForceDelete # rubocop:disable Metrics/ModuleLength
end end
end end
def notification_template def notification_template(explicit: nil)
reason = explicit&.downcase
return reason if %w[invalid_email invalid_phone].include?(reason)
if contact_emails_verification_failed.present? if contact_emails_verification_failed.present?
'invalid_email' 'invalid_email'
elsif registrant.org? elsif registrant.org?

View file

@ -23,7 +23,8 @@ class MassAction
dn = Domain.find_by(name_puny: e['domain_name']) dn = Domain.find_by(name_puny: e['domain_name'])
log[:fail] << e['domain_name'] and next unless dn log[:fail] << e['domain_name'] and next unless dn
dn.schedule_force_delete(type: :soft, reason: e['delete_reason']) dn.schedule_force_delete(type: :soft, notify_by_email: false, reason: e['delete_reason'])
log[:ok] << dn.name log[:ok] << dn.name
end end
@ -32,7 +33,7 @@ class MassAction
def self.force_delete_entries_valid?(entries) def self.force_delete_entries_valid?(entries)
entries.each do |e| entries.each do |e|
reasons = %w[ENTITY_BURIED EMAIL PHONE] reasons = %w[ENTITY_BURIED INVALID_EMAIL INVALID_PHONE]
return false unless e['domain_name'].present? && reasons.include?(e['delete_reason']) return false unless e['domain_name'].present? && reasons.include?(e['delete_reason'])
end end

View file

@ -1,5 +1,5 @@
domain_name,delete_reason domain_name,delete_reason
shop.test,ENTITY_BURIED shop.test,ENTITY_BURIED
airport.test,PHONE airport.test,INVALID_PHONE
library.test,EMAIL library.test,INVALID_EMAIL
nonexistant.test,ENTITY_BURIED nonexistant.test,ENTITY_BURIED

1 domain_name delete_reason
2 shop.test ENTITY_BURIED
3 airport.test PHONE INVALID_PHONE
4 library.test EMAIL INVALID_EMAIL
5 nonexistant.test ENTITY_BURIED