mirror of
https://github.com/internetee/registry.git
synced 2025-05-18 18:29:40 +02:00
EPP email change will send notification to registrant
This commit is contained in:
parent
73637b1a28
commit
64fec42a69
14 changed files with 330 additions and 22 deletions
13
app/mailers/contact_mailer.rb
Normal file
13
app/mailers/contact_mailer.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
class ContactMailer < ApplicationMailer
|
||||
def email_updated(contact)
|
||||
unless Rails.env.production?
|
||||
return unless TEST_EMAILS.include?(contact.email) || TEST_EMAILS.include?(contact.email_was)
|
||||
end
|
||||
|
||||
# turn on delivery on specific request only, thus rake tasks does not deliver anything
|
||||
return if contact.deliver_emails != true
|
||||
|
||||
@contact = contact
|
||||
mail(to: [@contact.email, @contact.email_was], subject: I18n.t(:contact_email_update_subject))
|
||||
end
|
||||
end
|
|
@ -1,12 +1,8 @@
|
|||
class InvoiceMailer < ApplicationMailer
|
||||
def invoice_email(invoice, pdf)
|
||||
unless Rails.env.production?
|
||||
test_emails = ['martin@gitlab.eu', 'priit@gitlab.eu']
|
||||
return unless test_emails.include?(invoice.billing_email)
|
||||
end
|
||||
return if Rails.env.production? ? false : TEST_EMAILS.include?(invoice.billing_email)
|
||||
|
||||
@invoice = invoice
|
||||
|
||||
attachments[invoice.pdf_name] = pdf
|
||||
mail(to: invoice.billing_email, subject: invoice)
|
||||
end
|
||||
|
|
|
@ -29,6 +29,13 @@ class Contact < ActiveRecord::Base
|
|||
before_validation :set_ident_country_code
|
||||
before_validation :prefix_code
|
||||
before_create :generate_auth_info
|
||||
|
||||
before_update :manage_emails
|
||||
def manage_emails
|
||||
return nil unless email_changed?
|
||||
ContactMailer.email_updated(self).deliver_now
|
||||
end
|
||||
|
||||
after_save :manage_statuses
|
||||
def manage_statuses
|
||||
ContactStatus.manage(statuses, self)
|
||||
|
@ -48,6 +55,8 @@ class Contact < ActiveRecord::Base
|
|||
BIRTHDAY # Birthday date
|
||||
]
|
||||
|
||||
attr_accessor :deliver_emails
|
||||
|
||||
class << self
|
||||
def search_by_query(query)
|
||||
res = search(code_cont: query).result
|
||||
|
|
|
@ -16,6 +16,12 @@ class DomainContact < ActiveRecord::Base
|
|||
}
|
||||
end
|
||||
|
||||
def name
|
||||
return 'Tech' if type == 'TechDomainContact'
|
||||
return 'Admin' if type == 'AdminDomainContact'
|
||||
''
|
||||
end
|
||||
|
||||
validates :contact, presence: true
|
||||
|
||||
before_save :update_contact_code_cache
|
||||
|
|
|
@ -145,7 +145,7 @@ class Epp::Contact < Contact
|
|||
at.merge!(self.class.ident_attrs(frame.css('ident').first))
|
||||
legal_frame = frame.css('legalDocument').first
|
||||
at[:legal_documents_attributes] = self.class.legal_document_attrs(legal_frame)
|
||||
|
||||
self.deliver_emails = true # turn on email delivery for epp
|
||||
super(at)
|
||||
end
|
||||
end
|
||||
|
|
51
app/views/contact_mailer/email_updated.html.erb
Normal file
51
app/views/contact_mailer/email_updated.html.erb
Normal file
|
@ -0,0 +1,51 @@
|
|||
Tere <%= @contact.name %>
|
||||
<br><br>
|
||||
Kontakti <%= @contact.name %> eposti aadress on muudetud<br>
|
||||
endine aadress: <%= @contact.email_was %><br>
|
||||
uus aadress: <%= @contact.email %>
|
||||
<br><br>
|
||||
Eposti aadressile saadetakse domeenidega seotud infot seal hulgas kinnitustaotluseid omaniku vahetuse ja domeeni kustutamise korral. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduga oma registripidaja poole. Teie registripidaja on <%= @contact.registrar.name %>
|
||||
<br><br>
|
||||
Muudatusega seotud domeenid:<br>
|
||||
<% @contact.domain_contacts.each do |dc| %>
|
||||
<%= dc.domain.name %> (<%= dc.name %>)<br>
|
||||
<% end %>
|
||||
<br>
|
||||
Kontaktandmed:<br>
|
||||
Nimi: <%= @contact.name %><br>
|
||||
Isikukood: <%= @contact.ident %><br>
|
||||
Epost: <%= @contact.email %><br>
|
||||
Tel: <%= @contact.phone %><br>
|
||||
Tänav: <%= @contact.street %><br>
|
||||
Linn: <%= @contact.city %><br>
|
||||
Riik: <%= @contact.country %>
|
||||
<br><br>
|
||||
Lugupidamisega
|
||||
Eesti Interneti SA
|
||||
<br><br>
|
||||
<hr>
|
||||
<br><br>
|
||||
Hi <%= @contact.name %>
|
||||
<br><br>
|
||||
E-mail address of <% @contact.name %> has been changed<br>
|
||||
previous address: <% @contact.email_was %><br>
|
||||
new address: <% @contact.email %>
|
||||
<br><br>
|
||||
E-mail addresses are used to send important information regarding your registered domains including applications for approval of registrant change and domain deletion. Please make sure that the update and contact information are correct. Incase of problems please turn to your registrar. Your registrar is <%= @contact.registrar.name %>
|
||||
<br><br>
|
||||
Domains affected by this update:<br>
|
||||
<% @contact.domain_contacts.each do |dc| %>
|
||||
<%= dc.domain.name %> (<%= dc.name %>)<br>
|
||||
<% end %>
|
||||
<br>
|
||||
Contact information:<br>
|
||||
Name: <%= @contact.name %><br>
|
||||
Identity Code: <%= @contact.ident %><br>
|
||||
E-mail: <%= @contact.email %><br>
|
||||
Tel: <%= @contact.phone %><br>
|
||||
Street: <%= @contact.street %><br>
|
||||
City: <%= @contact.city %><br>
|
||||
Country: <%= @contact.country %>
|
||||
<br><br>
|
||||
Best Regards,
|
||||
Eesti Interneti SA
|
51
app/views/contact_mailer/email_updated.text.erb
Normal file
51
app/views/contact_mailer/email_updated.text.erb
Normal file
|
@ -0,0 +1,51 @@
|
|||
Tere <%= @contact.name %>
|
||||
|
||||
Kontakti <%= @contact.name %> eposti aadress on muudetud
|
||||
endine aadress: <%= @contact.email_was %>
|
||||
uus aadress: <%= @contact.email %>
|
||||
|
||||
Eposti aadressile saadetakse domeenidega seotud infot seal hulgas kinnitustaotluseid omaniku vahetuse ja domeeni kustutamise korral. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduga oma registripidaja poole. Teie registripidaja on <%= @contact.registrar.name %>
|
||||
|
||||
Muudatusega seotud domeenid:
|
||||
<% @contact.domain_contacts.each do |dc| %>
|
||||
<%= dc.domain.name %> (<%= dc.name %>)
|
||||
<% end %>
|
||||
|
||||
Kontaktandmed:
|
||||
Nimi: <%= @contact.name %>
|
||||
Isikukood: <%= @contact.ident %>
|
||||
Epost: <%= @contact.email %>
|
||||
Tel: <%= @contact.phone %>
|
||||
Tänav: <%= @contact.street %>
|
||||
Linn: <%= @contact.city %>
|
||||
Riik: <%= @contact.country %>
|
||||
|
||||
Lugupidamisega
|
||||
Eesti Interneti SA
|
||||
|
||||
----------------------------------------------------------------------------------
|
||||
|
||||
Hi <%= @contact.name %>
|
||||
|
||||
E-mail address of <% @contact.name %> has been changed
|
||||
previous address: <% @contact.email_was %>
|
||||
new address: <% @contact.email %>
|
||||
|
||||
E-mail addresses are used to send important information regarding your registered domains including applications for approval of registrant change and domain deletion. Please make sure that the update and contact information are correct. Incase of problems please turn to your registrar. Your registrar is <%= @contact.registrar.name %>
|
||||
|
||||
Domains affected by this update:
|
||||
<% @contact.domain_contacts.each do |dc| %>
|
||||
<%= dc.domain.name %> (<%= dc.name %>)
|
||||
<% end %>
|
||||
|
||||
Contact information:
|
||||
Name: <%= @contact.name %>
|
||||
Identity Code: <%= @contact.ident %>
|
||||
E-mail: <%= @contact.email %>
|
||||
Tel: <%= @contact.phone %>
|
||||
Street: <%= @contact.street %>
|
||||
City: <%= @contact.city %>
|
||||
Country: <%= @contact.country %>
|
||||
|
||||
Best Regards,
|
||||
Eesti Interneti SA
|
11
config/initializers/settings.rb
Normal file
11
config/initializers/settings.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
TEST_EMAILS = %w(
|
||||
test@example.ee
|
||||
test@example.com
|
||||
martin@gitlab.eu
|
||||
priit@gitlab.eu
|
||||
timo.vohmar@internet.ee
|
||||
rene.vahtel@internet.ee
|
||||
martin.mettig@internet.ee
|
||||
hannes.klausen@internet.ee
|
||||
georg.kahest@internet.ee
|
||||
)
|
|
@ -761,3 +761,4 @@ en:
|
|||
no_hostnames_replaced: 'No hostnames replaced'
|
||||
forbidden_code: 'is forbidden to use'
|
||||
unimplemented_object_service: 'Unimplemented object service'
|
||||
contact_email_update_subject: 'Teie domeenide kontakt epostiaadress on muutunud / Contact e-mail addresses of your domains have changed'
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
Fabricator(:admin_domain_contact) do
|
||||
contact { Fabricate(:contact) }
|
||||
after_build do |x|
|
||||
x.contact_code_cache = x.contact.code
|
||||
end
|
||||
end
|
|
@ -1,7 +1,12 @@
|
|||
Fabricator(:domain_contact) do
|
||||
contact { Fabricate(:contact) }
|
||||
contact_type 'admin'
|
||||
after_build do |x|
|
||||
x.contact_code_cache = x.contact.code
|
||||
end
|
||||
type 'TechDomainContact'
|
||||
end
|
||||
|
||||
Fabricator(:tech_domain_contact, from: :domain_contact) do
|
||||
type 'TechDomainContact'
|
||||
end
|
||||
|
||||
Fabricator(:admin_domain_contact, from: :domain_contact) do
|
||||
type 'AdminDomainContact'
|
||||
end
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
Fabricator(:tech_domain_contact) do
|
||||
contact { Fabricate(:contact) }
|
||||
after_build do |x|
|
||||
x.contact_code_cache = x.contact.code
|
||||
end
|
||||
end
|
52
spec/mailers/contact_mailer_spec.rb
Normal file
52
spec/mailers/contact_mailer_spec.rb
Normal file
|
@ -0,0 +1,52 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe ContactMailer do
|
||||
describe 'email changed notification when delivery turned off' do
|
||||
before :all do
|
||||
@contact = Fabricate(:contact, email: 'test@example.ee')
|
||||
@contact.email = 'test@example.com' # new email
|
||||
@mail = ContactMailer.email_updated(@contact)
|
||||
end
|
||||
|
||||
it 'should not render email subject' do
|
||||
@mail.subject.should == nil
|
||||
end
|
||||
|
||||
it 'should not have sender email' do
|
||||
@mail.from.should == nil
|
||||
end
|
||||
|
||||
it 'should not have reveiver email' do
|
||||
@mail.to.should == nil
|
||||
end
|
||||
|
||||
it 'should not render body' do
|
||||
@mail.body.should == ''
|
||||
end
|
||||
end
|
||||
|
||||
describe 'email changed notification' do
|
||||
before :all do
|
||||
@contact = Fabricate(:contact, email: 'test@example.ee')
|
||||
@contact.deliver_emails = true
|
||||
@contact.email = 'test@example.com' # new email
|
||||
@mail = ContactMailer.email_updated(@contact)
|
||||
end
|
||||
|
||||
it 'should render email subject' do
|
||||
@mail.subject.should =~ /Teie domeenide kontakt epostiaadress on muutunud/
|
||||
end
|
||||
|
||||
it 'should have sender email' do
|
||||
@mail.from.should == ["noreply@internet.ee"]
|
||||
end
|
||||
|
||||
it 'should have both old and new receiver email' do
|
||||
@mail.to.should == ['test@example.com', 'test@example.ee']
|
||||
end
|
||||
|
||||
it 'should render body' do
|
||||
@mail.body.encoded.should =~ /Kontaktandmed:/
|
||||
end
|
||||
end
|
||||
end
|
125
spec/models/domain_contact_spec.rb
Normal file
125
spec/models/domain_contact_spec.rb
Normal file
|
@ -0,0 +1,125 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe DomainContact do
|
||||
before :all do
|
||||
@api_user = Fabricate(:domain_contact)
|
||||
end
|
||||
|
||||
context 'with invalid attribute' do
|
||||
before :all do
|
||||
@domain_contact = DomainContact.new
|
||||
end
|
||||
|
||||
it 'should not be valid' do
|
||||
@domain_contact.valid?
|
||||
@domain_contact.errors.full_messages.should match_array([
|
||||
"Contact Contact was not found"
|
||||
])
|
||||
end
|
||||
|
||||
it 'should not have creator' do
|
||||
@domain_contact.creator.should == nil
|
||||
end
|
||||
|
||||
it 'should not have updater' do
|
||||
@domain_contact.updator.should == nil
|
||||
end
|
||||
|
||||
it 'should not have any name' do
|
||||
@domain_contact.name.should == ''
|
||||
end
|
||||
end
|
||||
|
||||
context 'with valid attributes' do
|
||||
before :all do
|
||||
@domain_contact = Fabricate(:domain_contact)
|
||||
end
|
||||
|
||||
it 'should be valid' do
|
||||
@domain_contact.valid?
|
||||
@domain_contact.errors.full_messages.should match_array([])
|
||||
end
|
||||
|
||||
it 'should be valid twice' do
|
||||
@domain_contact = Fabricate(:domain_contact)
|
||||
@domain_contact.valid?
|
||||
@domain_contact.errors.full_messages.should match_array([])
|
||||
end
|
||||
|
||||
it 'should have Tech name' do
|
||||
@domain_contact.name.should == 'Tech'
|
||||
end
|
||||
|
||||
it 'should have one version' do
|
||||
with_versioning do
|
||||
@domain_contact.versions.reload.should == []
|
||||
@domain_contact.updated_at = Time.zone.now # trigger new version
|
||||
@domain_contact.save
|
||||
@domain_contact.errors.full_messages.should match_array([])
|
||||
@domain_contact.versions.size.should == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with valid attributes with tech domain contact' do
|
||||
before :all do
|
||||
@domain_contact = Fabricate(:tech_domain_contact)
|
||||
end
|
||||
|
||||
it 'should be valid' do
|
||||
@domain_contact.valid?
|
||||
@domain_contact.errors.full_messages.should match_array([])
|
||||
end
|
||||
|
||||
it 'should be valid twice' do
|
||||
@domain_contact = Fabricate(:tech_domain_contact)
|
||||
@domain_contact.valid?
|
||||
@domain_contact.errors.full_messages.should match_array([])
|
||||
end
|
||||
|
||||
it 'should have Tech name' do
|
||||
@domain_contact.name.should == 'Tech'
|
||||
end
|
||||
|
||||
it 'should have one version' do
|
||||
with_versioning do
|
||||
@domain_contact.versions.reload.should == []
|
||||
@domain_contact.updated_at = Time.zone.now # trigger new version
|
||||
@domain_contact.save
|
||||
@domain_contact.errors.full_messages.should match_array([])
|
||||
@domain_contact.versions.size.should == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with valid attributes with admin domain contact' do
|
||||
before :all do
|
||||
@domain_contact = Fabricate(:admin_domain_contact)
|
||||
end
|
||||
|
||||
it 'should be valid' do
|
||||
@domain_contact.valid?
|
||||
@domain_contact.errors.full_messages.should match_array([])
|
||||
end
|
||||
|
||||
it 'should be valid twice' do
|
||||
@domain_contact = Fabricate(:admin_domain_contact)
|
||||
@domain_contact.valid?
|
||||
@domain_contact.errors.full_messages.should match_array([])
|
||||
end
|
||||
|
||||
it 'should have Tech name' do
|
||||
@domain_contact.name.should == 'Admin'
|
||||
end
|
||||
|
||||
it 'should have one version' do
|
||||
with_versioning do
|
||||
@domain_contact.versions.reload.should == []
|
||||
@domain_contact.updated_at = Time.zone.now # trigger new version
|
||||
@domain_contact.save
|
||||
@domain_contact.errors.full_messages.should match_array([])
|
||||
@domain_contact.versions.size.should == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue