mirror of
https://github.com/internetee/registry.git
synced 2025-07-20 09:46:09 +02:00
Merge pull request #41 from internetee/109367018-email-pending-update-mention-old-registrant
109367018 email pending update mention old registrant
This commit is contained in:
commit
a59d61aa44
18 changed files with 419 additions and 260 deletions
|
@ -239,7 +239,7 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
count += 1
|
||||
if domain.pending_update?
|
||||
DomainMailer.pending_update_expired_notification_for_new_registrant(domain.id).deliver
|
||||
send_mail :pending_update_expired_notification_for_new_registrant
|
||||
end
|
||||
if domain.pending_delete? || domain.pending_delete_confirmation?
|
||||
DomainMailer.pending_delete_expired_notification(domain.id, true).deliver
|
||||
|
@ -440,7 +440,6 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def pending_update!
|
||||
old_registrant_id = registrant_id
|
||||
return true if pending_update?
|
||||
self.epp_pending_update = true # for epp
|
||||
|
||||
|
@ -452,8 +451,8 @@ class Domain < ActiveRecord::Base
|
|||
new_registrant_email = registrant.email
|
||||
new_registrant_name = registrant.name
|
||||
|
||||
DomainMailer.pending_update_request_for_old_registrant(id, old_registrant_id, deliver_emails).deliver
|
||||
DomainMailer.pending_update_notification_for_new_registrant(id, old_registrant_id, deliver_emails).deliver
|
||||
send_mail :pending_update_request_for_old_registrant
|
||||
send_mail :pending_update_notification_for_new_registrant
|
||||
|
||||
reload # revert back to original
|
||||
|
||||
|
@ -819,5 +818,10 @@ class Domain < ActiveRecord::Base
|
|||
status_notes[status] = notes[i]
|
||||
end
|
||||
end
|
||||
|
||||
def send_mail(action)
|
||||
DomainMailer.send(action, DomainMailModel.new(self).send(action)).deliver
|
||||
end
|
||||
|
||||
end
|
||||
# rubocop: enable Metrics/ClassLength
|
||||
|
|
180
app/models/domain_mail_model.rb
Normal file
180
app/models/domain_mail_model.rb
Normal file
|
@ -0,0 +1,180 @@
|
|||
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}
|
||||
end
|
||||
|
||||
def pending_update_request_for_old_registrant
|
||||
registrant_old
|
||||
subject(:pending_update_request_for_old_registrant_subject)
|
||||
confirm_update
|
||||
domain_info
|
||||
compose
|
||||
end
|
||||
|
||||
def pending_update_notification_for_new_registrant
|
||||
registrant # new registrant at this point
|
||||
subject(:pending_update_notification_for_new_registrant_subject)
|
||||
domain_info
|
||||
compose
|
||||
end
|
||||
|
||||
def registrant_updated_notification_for_new_registrant
|
||||
registrant
|
||||
subject(:registrant_updated_notification_for_new_registrant_subject)
|
||||
domain_info
|
||||
compose
|
||||
end
|
||||
|
||||
def registrant_updated_notification_for_old_registrant
|
||||
registrant_pending
|
||||
registrant_old
|
||||
subject(:registrant_updated_notification_for_old_registrant_subject)
|
||||
new_registrant = Registrant.find @domain.pending_json['new_registrant_id']
|
||||
@params[:registrant_name] = new_registrant.name
|
||||
@params[:registrant_ident] = new_registrant.ident
|
||||
@params[:registrant_priv] = new_registrant.priv?
|
||||
@params[:registrant_email] = new_registrant.email
|
||||
@params[:registrant_street] = new_registrant.street
|
||||
@params[:registrant_city] = new_registrant.city
|
||||
@params[:registrant_country] = new_registrant.country.name
|
||||
compose
|
||||
end
|
||||
|
||||
def pending_update_rejected_notification_for_new_registrant
|
||||
registrant_pending
|
||||
subject(:pending_update_rejected_notification_for_new_registrant_subject)
|
||||
@params[:deliver_emails] = true # triggered from que
|
||||
@params[:registrar_name] = @domain.registrar.name
|
||||
compose
|
||||
end
|
||||
|
||||
def pending_update_expired_notification_for_new_registrant
|
||||
registrant_pending
|
||||
subject(:pending_update_expired_notification_for_new_registrant_subject)
|
||||
domain_info
|
||||
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)
|
||||
compose
|
||||
end
|
||||
|
||||
def pending_delete_expired_notification
|
||||
registrant
|
||||
subject(:pending_delete_expired_notification_subject)
|
||||
compose
|
||||
end
|
||||
|
||||
def delete_confirmation
|
||||
registrant
|
||||
subject(:delete_confirmation_subject)
|
||||
compose
|
||||
end
|
||||
|
||||
def force_delete
|
||||
admins
|
||||
subject(:force_delete_subject)
|
||||
compose
|
||||
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
|
||||
|
||||
def registrant_pending
|
||||
@params[:recipient] = format @domain.pending_json['new_registrant_email']
|
||||
@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) })
|
||||
@params[:recipient] = emails.uniq.map { |x| format(x) }
|
||||
end
|
||||
|
||||
# puny internet domain name, TODO: username<email>
|
||||
def format(email)
|
||||
return warn_no_email if email.nil?
|
||||
user, host = email.split('@')
|
||||
host = SimpleIDN.to_ascii(host)
|
||||
"#{user}@#{host}"
|
||||
end
|
||||
|
||||
def subject(subject)
|
||||
@params[:name] = @domain.name
|
||||
@params[:subject] = "#{I18n.t(subject, name: @domain.name)}, [#{@domain.name}]"
|
||||
end
|
||||
|
||||
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,
|
||||
:registrant_street,:registrant_city
|
||||
].each do |attr|
|
||||
@params.store attr, @domain.send(attr)
|
||||
end
|
||||
@params.store :registrant_country, @domain.registrant_country.name
|
||||
@params.store :registrant_priv, @domain.registrant.priv?
|
||||
@params.store :old_registrant_name, Registrant.find(@domain.registrant_id_was).name
|
||||
@params
|
||||
end
|
||||
|
||||
def warn_no_email(item = 'email')
|
||||
warn_missing item
|
||||
nil
|
||||
end
|
||||
|
||||
def warn_missing(item)
|
||||
warn_not_delivered "#{item.to_s} is missing for #{@domain.name}"
|
||||
end
|
||||
|
||||
def warn_not_delivered(reason)
|
||||
message = "EMAIL NOT DELIVERED: #{reason}"
|
||||
@params[:errors] << message
|
||||
# Rails.logger.warn message
|
||||
nil
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -500,10 +500,13 @@ class Epp::Domain < Domain
|
|||
# rubocop: enable Metrics/CyclomaticComplexity
|
||||
|
||||
def apply_pending_update!
|
||||
old_registrant_email = DomainMailer.registrant_updated_notification_for_old_registrant(id, deliver_emails)
|
||||
preclean_pendings
|
||||
user = ApiUser.find(pending_json['current_user_id'])
|
||||
frame = Nokogiri::XML(pending_json['frame'])
|
||||
|
||||
self.deliver_emails = true # turn on email delivery
|
||||
send_mail :registrant_updated_notification_for_old_registrant
|
||||
|
||||
statuses.delete(DomainStatus::PENDING_UPDATE)
|
||||
yield(self) if block_given? # need to skip statuses check here
|
||||
self.save
|
||||
|
@ -511,9 +514,9 @@ class Epp::Domain < Domain
|
|||
::PaperTrail.whodunnit = user.id_role_username # updator str should be the request originator not the approval user
|
||||
return unless update(frame, user, false)
|
||||
clean_pendings!
|
||||
self.deliver_emails = true # turn on email delivery
|
||||
DomainMailer.registrant_updated_notification_for_new_registrant(id, deliver_emails).deliver
|
||||
old_registrant_email.deliver
|
||||
|
||||
send_mail :registrant_updated_notification_for_new_registrant
|
||||
update_whois_record
|
||||
true
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue