mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 01:47:18 +02:00
Merge branch '107821878-emails' into staging
This commit is contained in:
commit
e40ddbb134
12 changed files with 86 additions and 58 deletions
3
Gemfile
3
Gemfile
|
@ -94,6 +94,9 @@ gem 'uuidtools', '2.1.5' # For unique IDs (used by the epp gem)
|
|||
gem 'que', '0.10.0'
|
||||
gem 'que-web', '0.4.0'
|
||||
gem 'daemons-rails', '1.2.1'
|
||||
gem 'que_mailer',
|
||||
github: 'prehnRA/que-mailer',
|
||||
branch: 'master'
|
||||
|
||||
# for importing legacy db
|
||||
gem 'activerecord-import', '0.7.0' # for inserting dummy data
|
||||
|
|
|
@ -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!
|
||||
|
|
|
@ -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"=>[]))
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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!
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ describe ContactMailer do
|
|||
describe 'email changed notification when delivery turned off' do
|
||||
before :all do
|
||||
@contact = Fabricate(:contact, email: 'test@example.ee')
|
||||
@mail = ContactMailer.email_updated('test@example.com', @contact)
|
||||
@mail = ContactMailer.email_updated('test@example.com', @contact.id)
|
||||
end
|
||||
|
||||
it 'should not render email subject' do
|
||||
|
@ -34,7 +34,7 @@ describe ContactMailer do
|
|||
@contact = @domain.registrant
|
||||
@contact.reload # until figured out why registrant_domains not loaded
|
||||
@contact.deliver_emails = true
|
||||
@mail = ContactMailer.email_updated('info@example.org', @contact)
|
||||
@mail = ContactMailer.email_updated('info@example.org', @contact.id)
|
||||
end
|
||||
|
||||
it 'should render email subject' do
|
||||
|
@ -60,7 +60,7 @@ describe ContactMailer do
|
|||
@contact = @domain.registrant
|
||||
@contact.reload # until figured out why registrant_domains not loaded
|
||||
@contact.deliver_emails = true
|
||||
@mail = ContactMailer.email_updated('info@ääöü.org', @contact)
|
||||
@mail = ContactMailer.email_updated('info@ääöü.org', @contact.id)
|
||||
end
|
||||
|
||||
it 'should render email subject' do
|
||||
|
|
|
@ -9,7 +9,7 @@ describe DomainMailer do
|
|||
before :all do
|
||||
@registrant = Fabricate(:registrant, email: 'test@example.com')
|
||||
@domain = Fabricate(:domain, registrant: @registrant)
|
||||
@mail = DomainMailer.pending_update_request_for_old_registrant(@domain)
|
||||
@mail = DomainMailer.pending_update_request_for_old_registrant(@domain.id)
|
||||
end
|
||||
|
||||
it 'should not render email subject' do
|
||||
|
@ -38,7 +38,7 @@ describe DomainMailer do
|
|||
@domain.registrant_verification_token = '123'
|
||||
@domain.registrant_verification_asked_at = Time.zone.now
|
||||
@domain.registrant = @new_registrant
|
||||
@mail = DomainMailer.pending_update_request_for_old_registrant(@domain)
|
||||
@mail = DomainMailer.pending_update_request_for_old_registrant(@domain.id)
|
||||
end
|
||||
|
||||
it 'should render email subject' do
|
||||
|
@ -71,7 +71,7 @@ describe DomainMailer do
|
|||
@domain.registrant_verification_token = '123'
|
||||
@domain.registrant_verification_asked_at = Time.zone.now
|
||||
@domain.registrant = @new_registrant
|
||||
@mail = DomainMailer.pending_update_notification_for_new_registrant(@domain)
|
||||
@mail = DomainMailer.pending_update_notification_for_new_registrant(@domain.id)
|
||||
end
|
||||
|
||||
it 'should render email subject' do
|
||||
|
@ -100,7 +100,7 @@ describe DomainMailer do
|
|||
@domain.registrant_verification_token = '123'
|
||||
@domain.registrant_verification_asked_at = Time.zone.now
|
||||
@domain.registrant = @new_registrant
|
||||
@mail = DomainMailer.pending_update_notification_for_new_registrant(@domain)
|
||||
@mail = DomainMailer.pending_update_notification_for_new_registrant(@domain.id)
|
||||
end
|
||||
|
||||
it 'should render email subject' do
|
||||
|
@ -128,7 +128,7 @@ describe DomainMailer do
|
|||
@domain.deliver_emails = true
|
||||
@domain.pending_json['new_registrant_email'] = 'new@example.org'
|
||||
@domain.pending_json['new_registrant_name'] = 'test name'
|
||||
@mail = DomainMailer.pending_update_rejected_notification_for_new_registrant(@domain)
|
||||
@mail = DomainMailer.pending_update_rejected_notification_for_new_registrant(@domain.id)
|
||||
end
|
||||
|
||||
it 'should render email subject' do
|
||||
|
@ -153,7 +153,7 @@ describe DomainMailer do
|
|||
@registrant = Fabricate(:registrant, email: 'test@example.com')
|
||||
@domain = Fabricate(:domain, registrant: @registrant)
|
||||
@domain.deliver_emails = true
|
||||
@mail = DomainMailer.registrant_updated_notification_for_new_registrant(@domain)
|
||||
@mail = DomainMailer.registrant_updated_notification_for_new_registrant(@domain.id)
|
||||
end
|
||||
|
||||
it 'should render email subject' do
|
||||
|
@ -178,7 +178,7 @@ describe DomainMailer do
|
|||
@registrant = Fabricate(:registrant, email: 'test@example.com')
|
||||
@domain = Fabricate(:domain, registrant: @registrant)
|
||||
@domain.deliver_emails = true
|
||||
@mail = DomainMailer.registrant_updated_notification_for_old_registrant(@domain)
|
||||
@mail = DomainMailer.registrant_updated_notification_for_old_registrant(@domain.id)
|
||||
end
|
||||
|
||||
it 'should render email subject' do
|
||||
|
@ -202,7 +202,7 @@ describe DomainMailer do
|
|||
before :all do
|
||||
@registrant = Fabricate(:registrant, email: 'test@example.com')
|
||||
@domain = Fabricate(:domain, registrant: @registrant)
|
||||
@mail = DomainMailer.pending_deleted(@domain)
|
||||
@mail = DomainMailer.pending_deleted(@domain.id)
|
||||
end
|
||||
|
||||
it 'should not render email subject' do
|
||||
|
@ -229,7 +229,7 @@ describe DomainMailer do
|
|||
@domain.deliver_emails = true
|
||||
@domain.registrant_verification_token = '123'
|
||||
@domain.registrant_verification_asked_at = Time.zone.now
|
||||
@mail = DomainMailer.pending_deleted(@domain)
|
||||
@mail = DomainMailer.pending_deleted(@domain.id)
|
||||
end
|
||||
|
||||
it 'should render email subject' do
|
||||
|
@ -260,7 +260,7 @@ describe DomainMailer do
|
|||
@domain.deliver_emails = true
|
||||
@domain.registrant_verification_token = '123'
|
||||
@domain.registrant_verification_asked_at = Time.zone.now
|
||||
@mail = DomainMailer.pending_delete_rejected_notification(@domain)
|
||||
@mail = DomainMailer.pending_delete_rejected_notification(@domain.id)
|
||||
end
|
||||
|
||||
it 'should render email subject' do
|
||||
|
@ -287,7 +287,7 @@ describe DomainMailer do
|
|||
@domain.deliver_emails = true
|
||||
@domain.registrant_verification_token = '123'
|
||||
@domain.registrant_verification_asked_at = Time.zone.now
|
||||
@mail = DomainMailer.pending_delete_expired_notification(@domain)
|
||||
@mail = DomainMailer.pending_delete_expired_notification(@domain.id)
|
||||
end
|
||||
|
||||
it 'should render email subject' do
|
||||
|
@ -314,7 +314,7 @@ describe DomainMailer do
|
|||
@domain.deliver_emails = true
|
||||
@domain.registrant_verification_token = '123'
|
||||
@domain.registrant_verification_asked_at = Time.zone.now
|
||||
@mail = DomainMailer.delete_confirmation(@domain)
|
||||
@mail = DomainMailer.delete_confirmation(@domain.id)
|
||||
end
|
||||
|
||||
it 'should render email subject' do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue