mirror of
https://github.com/internetee/registry.git
synced 2025-07-20 01:36:02 +02:00
Story #109367018 - add new model to handle domain values are changing, and need to be captured now, not later
New model will provide data to DomainMailer customized as needed for the invocation reason as passed via symbol to send_mail(). The mail templetes then required modification to use the new data model. This should handle all the data errors in the update process, including pendingUpdate, confirmed, rejected or expired.
This commit is contained in:
parent
2c916001ad
commit
51a5798914
17 changed files with 366 additions and 254 deletions
|
@ -1,109 +1,41 @@
|
|||
class DomainMailer < ApplicationMailer
|
||||
include Que::Mailer
|
||||
|
||||
def pending_update_request_for_old_registrant(domain_id, old_registrant_id, should_deliver)
|
||||
@domain = Domain.find_by(id: domain_id)
|
||||
@old_registrant = Registrant.find(old_registrant_id)
|
||||
return unless @domain
|
||||
return if delivery_off?(@domain, should_deliver)
|
||||
|
||||
if @domain.registrant_verification_token.blank?
|
||||
logger.warn "EMAIL NOT DELIVERED: registrant_verification_token is missing for #{@domain.name}"
|
||||
return
|
||||
end
|
||||
|
||||
if @domain.registrant_verification_asked_at.blank?
|
||||
logger.warn "EMAIL NOT DELIVERED: registrant_verification_asked_at is missing for #{@domain.name}"
|
||||
return
|
||||
end
|
||||
|
||||
confirm_path = "#{ENV['registrant_url']}/registrant/domain_update_confirms"
|
||||
@verification_url = "#{confirm_path}/#{@domain.id}?token=#{@domain.registrant_verification_token}"
|
||||
|
||||
return if whitelist_blocked?(@old_registrant.email)
|
||||
mail(to: format(@old_registrant.email),
|
||||
subject: "#{I18n.t(:pending_update_request_for_old_registrant_subject,
|
||||
name: @domain.name)} [#{@domain.name}]")
|
||||
def pending_update_request_for_old_registrant(params)
|
||||
compose_from(params)
|
||||
end
|
||||
|
||||
def pending_update_notification_for_new_registrant(domain_id, old_registrant_id, should_deliver)
|
||||
@domain = Domain.find_by(id: domain_id)
|
||||
@old_registrant = Registrant.find(old_registrant_id)
|
||||
return unless @domain
|
||||
return if delivery_off?(@domain, should_deliver)
|
||||
def pending_update_notification_for_new_registrant(params)
|
||||
compose_from(params)
|
||||
end
|
||||
|
||||
if @domain.registrant_verification_token.blank?
|
||||
logger.warn "EMAIL NOT DELIVERED: registrant_verification_token is missing for #{@domain.name}"
|
||||
def registrant_updated_notification_for_new_registrant(params)
|
||||
compose_from(params)
|
||||
end
|
||||
|
||||
def registrant_updated_notification_for_old_registrant(params)
|
||||
compose_from(params)
|
||||
end
|
||||
|
||||
def pending_update_rejected_notification_for_new_registrant(params)
|
||||
compose_from(params)
|
||||
end
|
||||
|
||||
def pending_update_expired_notification_for_new_registrant(params)
|
||||
compose_from(params)
|
||||
end
|
||||
|
||||
# app/models/DomainMailModel provides the data for mail that can be composed_from
|
||||
# which ensures that values of objects are captured when they are valid, not later when this method is executed
|
||||
def compose_from(params)
|
||||
@params = params
|
||||
return if delivery_off?(params, params[:deliver_emails])
|
||||
return if whitelist_blocked?(params[:recipient])
|
||||
params[:errors].map do |error|
|
||||
logger.warn error
|
||||
return
|
||||
end
|
||||
|
||||
if @domain.registrant_verification_asked_at.blank?
|
||||
logger.warn "EMAIL NOT DELIVERED: registrant_verification_asked_at is missing for #{@domain.name}"
|
||||
return
|
||||
end
|
||||
|
||||
@new_registrant = @domain.registrant # NB! new registrant at this point
|
||||
|
||||
return if whitelist_blocked?(@new_registrant.email)
|
||||
mail(to: format(@new_registrant.email),
|
||||
subject: "#{I18n.t(:pending_update_notification_for_new_registrant_subject,
|
||||
name: @domain.name)} [#{@domain.name}]")
|
||||
end
|
||||
|
||||
def registrant_updated_notification_for_new_registrant(domain_id, should_deliver)
|
||||
@domain = Domain.find_by(id: domain_id)
|
||||
return unless @domain
|
||||
return if delivery_off?(@domain, should_deliver)
|
||||
|
||||
return if whitelist_blocked?(@domain.registrant_email)
|
||||
mail(to: format(@domain.registrant_email),
|
||||
subject: "#{I18n.t(:registrant_updated_notification_for_new_registrant_subject,
|
||||
name: @domain.name)} [#{@domain.name}]")
|
||||
end
|
||||
|
||||
def registrant_updated_notification_for_old_registrant(domain_id, should_deliver)
|
||||
domain = Domain.find_by(id: domain_id)
|
||||
return unless domain
|
||||
return if delivery_off?(@domain, should_deliver)
|
||||
|
||||
@old_registrant_email = domain.registrant_email # Nb! before applying pending updates
|
||||
|
||||
return if whitelist_blocked?(@old_registrant_email)
|
||||
mail(to: format(@old_registrant_email),
|
||||
subject: "#{I18n.t(:registrant_updated_notification_for_old_registrant_subject,
|
||||
name: @domain.name)} [#{@domain.name}]")
|
||||
end
|
||||
|
||||
def pending_update_rejected_notification_for_new_registrant(domain_id)
|
||||
@domain = Domain.find_by(id: domain_id)
|
||||
return unless @domain
|
||||
# no delivery off control, driggered by que, no epp request
|
||||
|
||||
@new_registrant_email = @domain.pending_json['new_registrant_email']
|
||||
@new_registrant_name = @domain.pending_json['new_registrant_name']
|
||||
|
||||
return if whitelist_blocked?(@new_registrant_email)
|
||||
mail(to: format(@new_registrant_email),
|
||||
subject: "#{I18n.t(:pending_update_rejected_notification_for_new_registrant_subject,
|
||||
name: @domain.name)} [#{@domain.name}]")
|
||||
end
|
||||
|
||||
def pending_update_expired_notification_for_new_registrant(domain_id)
|
||||
@domain = Domain.find_by(id: domain_id)
|
||||
return unless @domain
|
||||
# no delivery off control, driggered by cron, no epp request
|
||||
|
||||
@new_registrant_email = @domain.pending_json['new_registrant_email']
|
||||
@new_registrant_name = @domain.pending_json['new_registrant_name']
|
||||
|
||||
return if whitelist_blocked?(@new_registrant_email)
|
||||
if @new_registrant_email.blank?
|
||||
logger.info "EMAIL NOT DELIVERED: no registrant email [pending_update_expired_notification_for_new_registrant]"
|
||||
return
|
||||
end
|
||||
mail(to: format(@new_registrant_email),
|
||||
subject: "#{I18n.t(:pending_update_expired_notification_for_new_registrant_subject,
|
||||
name: @domain.name)} [#{@domain.name}]")
|
||||
mail(to: params[:recipient], subject: params[:subject])
|
||||
end
|
||||
|
||||
def pending_deleted(domain_id, old_registrant_id, should_deliver)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue