Merge branch '107821878-emails' into staging

This commit is contained in:
Stas 2015-11-17 17:27:08 +02:00
commit e40ddbb134
12 changed files with 86 additions and 58 deletions

View file

@ -9,7 +9,7 @@ class DomainDeleteConfirmJob < Que::Job
domain.apply_pending_delete!
domain.clean_pendings!
when RegistrantVerification::REJECTED
DomainMailer.pending_delete_rejected_notification(domain).deliver_now
DomainMailer.pending_delete_rejected_notification(domain_id).deliver
domain.statuses.delete(DomainStatus::PENDING_DELETE_CONFIRMATION)
domain.poll_message!(:poll_pending_delete_rejected_by_registrant)
domain.clean_pendings!

View file

@ -11,7 +11,7 @@ class DomainUpdateConfirmJob < Que::Job
end
domain.clean_pendings!
when RegistrantVerification::REJECTED
DomainMailer.pending_update_rejected_notification_for_new_registrant(domain).deliver_now
DomainMailer.pending_update_rejected_notification_for_new_registrant(domain_id).deliver
domain.poll_message!(:poll_pending_update_rejected_by_registrant)
domain.clean_pendings!
domain.instance_variable_set("@changed_attributes", domain.changed_attributes.merge("statuses"=>[]))

View file

@ -1,10 +1,12 @@
class ContactMailer < ApplicationMailer
def email_updated(email, contact)
include Que::Mailer
def email_updated(email, contact_id)
@contact = Contact.find_by(id: contact_id)
return unless email || @contact
return if delivery_off?(contact)
@contact = contact
return if whitelist_blocked?(email)
begin
mail(to: format(email), subject: "#{I18n.t(:contact_email_update_subject)} [#{@contact.code}]")
rescue EOFError,

View file

@ -1,6 +1,9 @@
class DomainMailer < ApplicationMailer
def pending_update_request_for_old_registrant(domain)
@domain = domain
include Que::Mailer
def pending_update_request_for_old_registrant(domain_id)
@domain = Domain.find_by(id: domain_id)
return unless @domain
return if delivery_off?(@domain)
if @domain.registrant_verification_token.blank?
@ -24,8 +27,9 @@ class DomainMailer < ApplicationMailer
name: @domain.name)} [#{@domain.name}]")
end
def pending_update_notification_for_new_registrant(domain)
@domain = domain
def pending_update_notification_for_new_registrant(domain_id)
@domain = Domain.find_by(id: domain_id)
return unless @domain
return if delivery_off?(@domain)
if @domain.registrant_verification_token.blank?
@ -47,8 +51,9 @@ class DomainMailer < ApplicationMailer
name: @domain.name)} [#{@domain.name}]")
end
def registrant_updated_notification_for_new_registrant(domain)
@domain = domain
def registrant_updated_notification_for_new_registrant(domain_id)
@domain = Domain.find_by(id: domain_id)
return unless @domain
return if delivery_off?(@domain)
return if whitelist_blocked?(@domain.registrant_email)
@ -57,8 +62,9 @@ class DomainMailer < ApplicationMailer
name: @domain.name)} [#{@domain.name}]")
end
def registrant_updated_notification_for_old_registrant(domain)
@domain = domain
def registrant_updated_notification_for_old_registrant(domain_id)
domain = Domain.find_by(id: domain_id)
return unless domain
return if delivery_off?(@domain)
@old_registrant_email = domain.registrant_email # Nb! before applying pending updates
@ -69,8 +75,9 @@ class DomainMailer < ApplicationMailer
name: @domain.name)} [#{@domain.name}]")
end
def pending_update_rejected_notification_for_new_registrant(domain)
@domain = domain
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']
@ -82,8 +89,9 @@ class DomainMailer < ApplicationMailer
name: @domain.name)} [#{@domain.name}]")
end
def pending_update_expired_notification_for_new_registrant(domain)
@domain = domain
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']
@ -99,8 +107,9 @@ class DomainMailer < ApplicationMailer
name: @domain.name)} [#{@domain.name}]")
end
def pending_deleted(domain)
@domain = domain
def pending_deleted(domain_id)
@domain = Domain.find_by(id: domain_id)
return unless @domain
return if delivery_off?(@domain)
if @domain.registrant_verification_token.blank?
@ -124,8 +133,10 @@ class DomainMailer < ApplicationMailer
name: @domain.name)} [#{@domain.name}]")
end
def pending_delete_rejected_notification(domain)
@domain = domain
def pending_delete_rejected_notification(domain_id)
@domain = Domain.find_by(id: domain_id)
return unless @domain
return if delivery_off?(@domain)
# no delivery off control, driggered by que, no epp request
if @domain.registrant_verification_token.blank?
@ -144,8 +155,10 @@ class DomainMailer < ApplicationMailer
name: @domain.name)} [#{@domain.name}]")
end
def pending_delete_expired_notification(domain)
@domain = domain
def pending_delete_expired_notification(domain_id)
@domain = Domain.find_by(id: domain_id)
return unless @domain
return if delivery_off?(@domain)
# no delivery off control, driggered by cron, no epp request
return if whitelist_blocked?(@domain.registrant.email)
@ -154,8 +167,10 @@ class DomainMailer < ApplicationMailer
name: @domain.name)} [#{@domain.name}]")
end
def delete_confirmation(domain)
@domain = domain
def delete_confirmation(domain_id)
@domain = Domain.find_by(id: domain_id)
return unless @domain
return if delivery_off?(@domain)
return if whitelist_blocked?(@domain.registrant.email)
mail(to: format(@domain.registrant.email),
@ -163,8 +178,9 @@ class DomainMailer < ApplicationMailer
name: @domain.name)} [#{@domain.name}]")
end
def force_delete(domain)
@domain = domain
def force_delete(domain_id)
@domain = Domain.find_by(id: domain_id)
return if delivery_off?(@domain)
emails = ([@domain.registrant.email] + @domain.admin_contacts.map { |x| format(x.email) }).uniq
return if whitelist_blocked?(emails)

View file

@ -1,8 +1,15 @@
class InvoiceMailer < ApplicationMailer
def invoice_email(invoice, pdf)
return if whitelist_blocked?(invoice.billing_email)
include Que::Mailer
def invoice_email(invoice_id, html)
@invoice = Invoice.find_by(id: invoice_id)
return unless @invoice
return if whitelist_blocked?(@invoice.billing_email)
kit = PDFKit.new(html)
pdf = kit.to_pdf
invoice = @invoice
@invoice = invoice
attachments[invoice.pdf_name] = pdf
mail(to: format(invoice.billing_email), subject: invoice)
end

View file

@ -50,7 +50,7 @@ class Contact < ActiveRecord::Base
emails << domains.map(&:registrant_email) if domains.present?
emails = emails.flatten.uniq
emails.each do |e|
ContactMailer.email_updated(e, self).deliver_now
ContactMailer.email_updated(e, id).deliver
end
end

View file

@ -238,10 +238,10 @@ class Domain < ActiveRecord::Base
end
count += 1
if domain.pending_update?
DomainMailer.pending_update_expired_notification_for_new_registrant(domain).deliver_now
DomainMailer.pending_update_expired_notification_for_new_registrant(id).deliver
end
if domain.pending_delete? || domain.pending_delete_confirmation?
DomainMailer.pending_delete_expired_notification(domain).deliver_now
DomainMailer.pending_delete_expired_notification(id).deliver
end
domain.clean_pendings!
unless Rails.env.test?
@ -428,8 +428,8 @@ class Domain < ActiveRecord::Base
new_registrant_email = registrant.email
new_registrant_name = registrant.name
DomainMailer.pending_update_request_for_old_registrant(self).deliver_now
DomainMailer.pending_update_notification_for_new_registrant(self).deliver_now
DomainMailer.pending_update_request_for_old_registrant(id).deliver
DomainMailer.pending_update_notification_for_new_registrant(id).deliver
reload # revert back to original
@ -489,7 +489,7 @@ class Domain < ActiveRecord::Base
pending_delete_confirmation!
save(validate: false) # should check if this did succeed
DomainMailer.pending_deleted(self).deliver_now
DomainMailer.pending_deleted(id).deliver
end
def pricelist(operation, period_i = nil, unit = nil)
@ -619,7 +619,7 @@ class Domain < ActiveRecord::Base
registrar.messages.create!(
body: I18n.t('force_delete_set_on_domain', domain: name)
)
DomainMailer.force_delete(self).deliver_now
DomainMailer.force_delete(id).deliver
return true
end
false

View file

@ -478,7 +478,7 @@ class Epp::Domain < Domain
# rubocop: enable Metrics/CyclomaticComplexity
def apply_pending_update!
old_registrant_email = DomainMailer.registrant_updated_notification_for_old_registrant(self)
old_registrant_email = DomainMailer.registrant_updated_notification_for_old_registrant(id)
preclean_pendings
user = ApiUser.find(pending_json['current_user_id'])
frame = Nokogiri::XML(pending_json['frame'])
@ -488,8 +488,8 @@ class Epp::Domain < Domain
return unless update(frame, user, false)
clean_pendings!
self.deliver_emails = true # turn on email delivery
DomainMailer.registrant_updated_notification_for_new_registrant(self).deliver_now
old_registrant_email.deliver_now
DomainMailer.registrant_updated_notification_for_new_registrant(id).deliver
old_registrant_email.deliver
true
end
@ -497,7 +497,7 @@ class Epp::Domain < Domain
preclean_pendings
statuses.delete(DomainStatus::PENDING_DELETE_CONFIRMATION)
statuses.delete(DomainStatus::PENDING_DELETE)
DomainMailer.delete_confirmation(self).deliver_now
DomainMailer.delete_confirmation(id).deliver
# TODO: confirm that this actually makes sense
clean_pendings! if valid? && set_pending_delete!

View file

@ -117,7 +117,7 @@ class Invoice < ActiveRecord::Base
return false unless valid?
return false unless billing_email.present?
InvoiceMailer.invoice_email(self, pdf(html)).deliver_now
InvoiceMailer.invoice_email(id, html).deliver
true
end