Refactor domain mailer views

#180
This commit is contained in:
Artur Beljajev 2016-11-12 01:14:11 +02:00
parent 962e98317d
commit a6de3761c5
57 changed files with 238 additions and 203 deletions

View file

@ -379,6 +379,9 @@ class Domain < ActiveRecord::Base
new_registrant_email = registrant.email
new_registrant_name = registrant.name
current_registrant = Registrant.find(registrant_id_was)
RegistrantChangeMailer.confirmation(domain: self, current_registrant: current_registrant).deliver
send_mail :pending_update_request_for_old_registrant
send_mail :pending_update_notification_for_new_registrant
@ -441,8 +444,8 @@ class Domain < ActiveRecord::Base
pending_delete_confirmation!
save(validate: false) # should check if this did succeed
previous_registrant = Registrant.find(registrant_id_was)
DomainMailer.pending_deleted(domain: self, registrant: previous_registrant).deliver
old_registrant = Registrant.find(registrant_id_was)
DeleteDomainMailer.pending(domain: self, old_registrant: old_registrant).deliver
end
def cancel_pending_delete

View file

@ -1,6 +1,6 @@
class DomainMailModel
# Capture current values used in app/views/mailers/domain_mailer/* and app/mailers/domain_mailer will send later
def initialize(domain)
@domain = domain
@params = {errors: [], deliver_emails: domain.deliver_emails, id: domain.id}
@ -15,13 +15,13 @@ class DomainMailModel
end
def pending_update_notification_for_new_registrant
registrant # new registrant at this point
registrant # new registrant at this point
subject(:pending_update_notification_for_new_registrant_subject)
domain_info
compose
end
def pending_update_rejected_notification_for_new_registrant
registrant_pending
subject(:pending_update_rejected_notification_for_new_registrant_subject)
@ -37,13 +37,6 @@ class DomainMailModel
compose
end
def pending_deleted
registrant
subject(:domain_pending_deleted_subject)
confirm_delete
compose
end
def pending_delete_rejected_notification
registrant
subject(:pending_delete_rejected_notification_subject)
@ -69,11 +62,11 @@ class DomainMailModel
end
private
def registrant_old
@params[:recipient] = format Registrant.find(@domain.registrant_id_was).email
end
def registrant
@params[:recipient] = format @domain.registrant.email
end
@ -83,7 +76,7 @@ class DomainMailModel
@params[:new_registrant_name] = @domain.pending_json['new_registrant_name']
@params[:old_registrant_name] = @domain.registrant.name
end
# registrant and domain admin contacts
def admins
emails = ([@domain.registrant.email] + @domain.admin_contacts.map { |x| format(x.email) })
@ -106,26 +99,22 @@ class DomainMailModel
def confirm_update
verification_url('domain_update_confirms')
end
def confirm_delete
verification_url('domain_delete_confirms')
end
def compose
@params
end
def verification_url(path)
token = verification_token or return
@params[:verification_url] = "#{ENV['registrant_url']}/registrant/#{path}/#{@domain.id}?token=#{token}"
end
def verification_token
return warn_missing(:registrant_verification_token) if @domain.registrant_verification_token.blank?
return warn_missing(:registrant_verification_asked_at) if @domain.registrant_verification_asked_at.blank?
@domain.registrant_verification_token
end
def domain_info
[:name, :registrar_name,
:registrant_name, :registrant_ident, :registrant_email,
@ -143,7 +132,7 @@ class DomainMailModel
warn_missing item
nil
end
def warn_missing(item)
warn_not_delivered "#{item.to_s} is missing for #{@domain.name}"
end
@ -154,6 +143,6 @@ class DomainMailModel
# Rails.logger.warn message
nil
end
end