From 1c7febf47ad5b344d8c67b28bd1ca2d37d461c5a Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 28 Jul 2015 19:58:16 +0300 Subject: [PATCH 01/25] Email block list logging and fix --- app/mailers/application_mailer.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 40266edb4..e89954b24 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -8,8 +8,8 @@ class ApplicationMailer < ActionMailer::Base emails = [emails] unless emails.is_a?(Array) emails = emails.flatten emails.each do |email| - next unless TEST_EMAILS.include?(email) - logger.warn "EMAIL SENDING WAS BLOCKED BY WHITELIST: #{email}" + next if TEST_EMAILS.include?(email) + logger.info "EMAIL SENDING WAS BLOCKED BY WHITELIST: #{email}" return true end false @@ -18,7 +18,7 @@ class ApplicationMailer < ActionMailer::Base # turn on delivery on specific (epp) request only, thus rake tasks does not deliver anything def delivery_off?(model) return false if model.deliver_emails == true - logger.warn "EMAIL SENDING WAS NOT ACTIVATED " \ + logger.info "EMAIL SENDING WAS NOT ACTIVATED " \ "BY MODEL OBJECT: id ##{model.try(:id)} deliver_emails returned false" true end From e876bf59a576f438068b2375fb858fc08066096f Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 28 Jul 2015 20:28:26 +0300 Subject: [PATCH 02/25] Refactor emails #2786 --- app/mailers/contact_mailer.rb | 42 +++++++++++++---------------- app/models/contact.rb | 9 ++++++- config/initializers/settings.rb | 4 +++ spec/mailers/contact_mailer_spec.rb | 11 +++----- 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/app/mailers/contact_mailer.rb b/app/mailers/contact_mailer.rb index 859f73088..0fda0fde0 100644 --- a/app/mailers/contact_mailer.rb +++ b/app/mailers/contact_mailer.rb @@ -1,33 +1,27 @@ class ContactMailer < ApplicationMailer # rubocop:disable Metrics/MethodLength - def email_updated(contact) + def email_updated(email, contact) return if delivery_off?(contact) @contact = contact - emails = [] - emails << [@contact.email, @contact.email_was] if @contact.registrant_domains.present? - emails << @contact.domains.map(&:registrant_email) if @contact.domains.present? - emails = emails.uniq - return if whitelist_blocked?(emails) - emails.each do |email| - begin - mail(to: email, subject: "#{I18n.t(:contact_email_update_subject)} [#{@contact.code}]") - rescue EOFError, - IOError, - TimeoutError, - Errno::ECONNRESET, - Errno::ECONNABORTED, - Errno::EPIPE, - Errno::ETIMEDOUT, - Net::SMTPAuthenticationError, - Net::SMTPServerBusy, - Net::SMTPFatalError, - Net::SMTPSyntaxError, - Net::SMTPUnknownError, - OpenSSL::SSL::SSLError => e - logger.warn "EMAIL SENDING FAILED: #{email}: #{e}" - end + return if whitelist_blocked?(email) + begin + mail(to: email, subject: "#{I18n.t(:contact_email_update_subject)} [#{@contact.code}]") + rescue EOFError, + IOError, + TimeoutError, + Errno::ECONNRESET, + Errno::ECONNABORTED, + Errno::EPIPE, + Errno::ETIMEDOUT, + Net::SMTPAuthenticationError, + Net::SMTPServerBusy, + Net::SMTPFatalError, + Net::SMTPSyntaxError, + Net::SMTPUnknownError, + OpenSSL::SSL::SSLError => e + logger.info "EMAIL SENDING FAILED: #{email}: #{e}" end end # rubocop:enable Metrics/MethodLength diff --git a/app/models/contact.rb b/app/models/contact.rb index 2ffba7a4f..51a9e5d6c 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -42,7 +42,14 @@ class Contact < ActiveRecord::Base before_update :manage_emails def manage_emails return nil unless email_changed? - ContactMailer.email_updated(self).deliver_now + return nil unless deliver_emails == true + emails = [] + emails << [email, email_was] + emails << domains.map(&:registrant_email) if domains.present? + emails = emails.flatten.uniq + emails.each do |e| + ContactMailer.email_updated(e, contact).deliver_now + end end before_save :manage_statuses diff --git a/config/initializers/settings.rb b/config/initializers/settings.rb index f121e3816..5dd1507c4 100644 --- a/config/initializers/settings.rb +++ b/config/initializers/settings.rb @@ -13,4 +13,8 @@ TEST_EMAILS = %w( info@gitlab.eu test@example.com test@example.org + old@example.org + new@example.org + old@example.com + new@example.com ) diff --git a/spec/mailers/contact_mailer_spec.rb b/spec/mailers/contact_mailer_spec.rb index fe4ccc84c..ce4adabef 100644 --- a/spec/mailers/contact_mailer_spec.rb +++ b/spec/mailers/contact_mailer_spec.rb @@ -4,8 +4,7 @@ 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) + @mail = ContactMailer.email_updated('test@example.com', @contact) end it 'should not render email subject' do @@ -31,8 +30,7 @@ describe ContactMailer do @contact = @domain.registrant @contact.reload # until figured out why registrant_domains not loaded @contact.deliver_emails = true - @contact.email = 'test@example.org' # new email - @mail = ContactMailer.email_updated(@contact) + @mail = ContactMailer.email_updated('info@example.org', @contact) end it 'should render email subject' do @@ -43,9 +41,8 @@ describe ContactMailer do @mail.from.should == ["noreply@internet.ee"] end - it 'should have both old and new receiver email' do - @mail.to.size.should == 2 - @mail.to.include? "test@example.org" + it 'should send to info email' do + @mail.to.should == ['info@example.org'] end it 'should render body' do From 1c64188eae7cecd5861ec498acfaf440ba9ed116 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 28 Jul 2015 20:31:22 +0300 Subject: [PATCH 03/25] Fix typo #2786 --- app/models/contact.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/contact.rb b/app/models/contact.rb index 51a9e5d6c..027eb31cd 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -48,7 +48,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, contact).deliver_now + ContactMailer.email_updated(e, self).deliver_now end end From 3d43c53c9d3dbd0a757e5527a6e326fbf4534a9f Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 28 Jul 2015 20:37:20 +0300 Subject: [PATCH 04/25] Updated email content #2804 --- app/views/contact_mailer/email_updated.html.erb | 6 +++--- app/views/contact_mailer/email_updated.text.erb | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/views/contact_mailer/email_updated.html.erb b/app/views/contact_mailer/email_updated.html.erb index e4785444b..552e97cdf 100644 --- a/app/views/contact_mailer/email_updated.html.erb +++ b/app/views/contact_mailer/email_updated.html.erb @@ -29,9 +29,9 @@ 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 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 %>

diff --git a/app/views/contact_mailer/email_updated.text.erb b/app/views/contact_mailer/email_updated.text.erb index 61d875351..ce43b5401 100644 --- a/app/views/contact_mailer/email_updated.text.erb +++ b/app/views/contact_mailer/email_updated.text.erb @@ -29,9 +29,9 @@ 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 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 %> From f43c6bbf9859c3535fd9430d113e2d5d42fdb8d9 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 28 Jul 2015 21:02:09 +0300 Subject: [PATCH 05/25] Added default sort #2741 --- app/controllers/admin/pricelists_controller.rb | 1 + app/views/admin/pricelists/index.haml | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/pricelists_controller.rb b/app/controllers/admin/pricelists_controller.rb index 200d27e48..34dd1e783 100644 --- a/app/controllers/admin/pricelists_controller.rb +++ b/app/controllers/admin/pricelists_controller.rb @@ -4,6 +4,7 @@ class Admin::PricelistsController < AdminController def index @q = Pricelist.search(params[:q]) + @q.sorts = ['category asc', 'duration asc', 'operation_category asc', 'valid_from desc'] if @q.sorts.empty? @pricelists = @q.result.page(params[:page]) end diff --git a/app/views/admin/pricelists/index.haml b/app/views/admin/pricelists/index.haml index 6cf83f6b8..2f51a4329 100644 --- a/app/views/admin/pricelists/index.haml +++ b/app/views/admin/pricelists/index.haml @@ -14,10 +14,10 @@ %tr %th{class: 'col-xs-2'} = sort_link(@q, 'category', t(:category)) - %th{class: 'col-xs-2'} - = sort_link(@q, 'operation_category', t(:operation)) %th{class: 'col-xs-2'} = sort_link(@q, 'duration', t(:duration)) + %th{class: 'col-xs-2'} + = sort_link(@q, 'operation_category', t(:operation)) %th{class: 'col-xs-2'} = sort_link(@q, 'price', t(:price)) %th{class: 'col-xs-2'} @@ -31,8 +31,8 @@ - @pricelists.each do |pricelist| %tr %td= pricelist.category - %td= pricelist.operation_category %td= pricelist.duration + %td= pricelist.operation_category %td= pricelist.price %td= l(pricelist.valid_from, format: :ydate) %td= l(pricelist.valid_to, format: :ydate) From eec118868d13cfa4f823a8fb57b134c62efed6ba Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 28 Jul 2015 21:19:52 +0300 Subject: [PATCH 06/25] Updated default pricelist sort #2741 --- app/controllers/admin/pricelists_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/pricelists_controller.rb b/app/controllers/admin/pricelists_controller.rb index 34dd1e783..0ddfff825 100644 --- a/app/controllers/admin/pricelists_controller.rb +++ b/app/controllers/admin/pricelists_controller.rb @@ -4,7 +4,7 @@ class Admin::PricelistsController < AdminController def index @q = Pricelist.search(params[:q]) - @q.sorts = ['category asc', 'duration asc', 'operation_category asc', 'valid_from desc'] if @q.sorts.empty? + @q.sorts = ['category asc', 'duration asc', 'operation_category asc', 'valid_from desc', 'valid_to desc'] if @q.sorts.empty? @pricelists = @q.result.page(params[:page]) end From 4935e5c1215a1bab168e2145e9c941443fa8fffb Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 28 Jul 2015 21:29:39 +0300 Subject: [PATCH 07/25] Updated default pricelist sort #2741 --- app/controllers/admin/pricelists_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/pricelists_controller.rb b/app/controllers/admin/pricelists_controller.rb index 0ddfff825..2e1c3fbc8 100644 --- a/app/controllers/admin/pricelists_controller.rb +++ b/app/controllers/admin/pricelists_controller.rb @@ -4,7 +4,7 @@ class Admin::PricelistsController < AdminController def index @q = Pricelist.search(params[:q]) - @q.sorts = ['category asc', 'duration asc', 'operation_category asc', 'valid_from desc', 'valid_to desc'] if @q.sorts.empty? + @q.sorts = ['category asc', 'duration asc', 'operation_category asc', 'valid_from asc', 'valid_to asc'] if @q.sorts.empty? @pricelists = @q.result.page(params[:page]) end From e7a492dde5786880cef01fdca274c2574cb03c3d Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 28 Jul 2015 21:31:18 +0300 Subject: [PATCH 08/25] Updated default pricelist sort #2741 --- app/controllers/admin/pricelists_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/pricelists_controller.rb b/app/controllers/admin/pricelists_controller.rb index 2e1c3fbc8..ccbe3166f 100644 --- a/app/controllers/admin/pricelists_controller.rb +++ b/app/controllers/admin/pricelists_controller.rb @@ -4,7 +4,7 @@ class Admin::PricelistsController < AdminController def index @q = Pricelist.search(params[:q]) - @q.sorts = ['category asc', 'duration asc', 'operation_category asc', 'valid_from asc', 'valid_to asc'] if @q.sorts.empty? + @q.sorts = ['category asc', 'duration asc', 'operation_category asc', 'valid_from desc', 'valid_to asc'] if @q.sorts.empty? @pricelists = @q.result.page(params[:page]) end From b82ae85be2abb9f0265e410346255a7e77f6e67d Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 28 Jul 2015 21:47:57 +0300 Subject: [PATCH 09/25] rubocop update --- app/mailers/contact_mailer.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/mailers/contact_mailer.rb b/app/mailers/contact_mailer.rb index 0fda0fde0..42968fe5a 100644 --- a/app/mailers/contact_mailer.rb +++ b/app/mailers/contact_mailer.rb @@ -1,5 +1,4 @@ class ContactMailer < ApplicationMailer - # rubocop:disable Metrics/MethodLength def email_updated(email, contact) return if delivery_off?(contact) @@ -24,5 +23,4 @@ class ContactMailer < ApplicationMailer logger.info "EMAIL SENDING FAILED: #{email}: #{e}" end end - # rubocop:enable Metrics/MethodLength end From 030f7a18b74181e9f555df50e609d194a0f24d9f Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 28 Jul 2015 21:53:06 +0300 Subject: [PATCH 10/25] More room for admin epp log output --- app/views/admin/epp_logs/show.haml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/admin/epp_logs/show.haml b/app/views/admin/epp_logs/show.haml index 0840360f7..583124af7 100644 --- a/app/views/admin/epp_logs/show.haml +++ b/app/views/admin/epp_logs/show.haml @@ -31,7 +31,7 @@ %dd= @epp_log.created_at .row - .col-md-6 + .col-md-12 .panel.panel-default .panel-heading %h3.panel-title= t(:request) @@ -43,7 +43,8 @@ = formatted_req - else = @epp_log.request - .col-md-6 +.row + .col-md-12 .panel.panel-default .panel-heading %h3.panel-title= t(:response) From 86e01597a8f21b8bc3c0b07c330f02c1c7d47379 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Mon, 27 Jul 2015 21:09:39 +0300 Subject: [PATCH 11/25] Updated cron log #2792 --- app/models/contact.rb | 16 +++++++++++++--- app/models/domain.rb | 34 ++++++++++++++++++++++------------ app/models/invoice.rb | 6 ++++++ config/schedule.rb | 7 ++++--- 4 files changed, 45 insertions(+), 18 deletions(-) diff --git a/app/models/contact.rb b/app/models/contact.rb index 027eb31cd..c69797403 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -166,9 +166,19 @@ class Contact < ActiveRecord::Base end def destroy_orphans - logger.info "#{Time.zone.now.utc} - Destroying orphaned contacts\n" - count = find_orphans.destroy_all.count - logger.info "#{Time.zone.now.utc} - Successfully destroyed #{count} orphaned contacts\n" + STDOUT << "#{Time.zone.now.utc} - Destroying orphaned contacts\n" unless Rails.env.test? + + orphans = find_orphans + + unless Rails.env.test? + orphans.each do |m| + STDOUT << "#{Time.zone.now.utc} Contact.destroy_orphans: ##{m.id}\n" + end + end + + count = orphans.destroy_all.count + + STDOUT << "#{Time.zone.now.utc} - Successfully destroyed #{count} orphaned contacts\n" unless Rails.env.test? end def privs diff --git a/app/models/domain.rb b/app/models/domain.rb index 89dffb5b9..b9eaff917 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -182,6 +182,8 @@ class Domain < ActiveRecord::Base ) end + # rubocop: disable Metrics/AbcSize + # rubocop: disable Metrics/CyclomaticComplexity def clean_expired_pendings STDOUT << "#{Time.zone.now.utc} - Clean expired domain pendings\n" unless Rails.env.test? @@ -197,18 +199,24 @@ class Domain < ActiveRecord::Base end count += 1 domain.clean_pendings! + STDOUT << "#{Time.zone.now.utc} Domain.clean_expired_pendings: ##{domain.id}\n" unless Rails.env.test? end STDOUT << "#{Time.zone.now.utc} - Successfully cancelled #{count} domain pendings\n" unless Rails.env.test? count end + # rubocop: enable Metrics/AbcSize + # rubocop: enable Metrics/CyclomaticComplexity + # rubocop: disable Metrics/LineLength def start_expire_period STDOUT << "#{Time.zone.now.utc} - Expiring domains\n" unless Rails.env.test? domains = Domain.where('valid_to <= ?', Time.zone.now) domains.each do |domain| next unless domain.expirable? - domain.set_expired! + domain.set_expired + STDOUT << "#{Time.zone.now.utc} Domain.start_expire_period: ##{domain.id} #{domain.changes}\n" unless Rails.env.test? + domain.save(validate: false) end STDOUT << "#{Time.zone.now.utc} - Successfully expired #{domains.count} domains\n" unless Rails.env.test? @@ -218,12 +226,11 @@ class Domain < ActiveRecord::Base STDOUT << "#{Time.zone.now.utc} - Setting server_hold to domains\n" unless Rails.env.test? d = Domain.where('outzone_at <= ?', Time.zone.now) - d.each do |x| - next unless x.server_holdable? - x.statuses << DomainStatus::SERVER_HOLD - # TODO: This should be managed by automatic_statuses - x.statuses.delete(DomainStatus::OK) - x.save + d.each do |domain| + next unless domain.server_holdable? + domain.statuses << DomainStatus::SERVER_HOLD + STDOUT << "#{Time.zone.now.utc} Domain.start_redemption_grace_period: ##{domain.id} #{domain.changes}\n" unless Rails.env.test? + domain.save end STDOUT << "#{Time.zone.now.utc} - Successfully set server_hold to #{d.count} domains\n" unless Rails.env.test? @@ -233,11 +240,11 @@ class Domain < ActiveRecord::Base STDOUT << "#{Time.zone.now.utc} - Setting delete_candidate to domains\n" unless Rails.env.test? d = Domain.where('delete_at <= ?', Time.zone.now) - d.each do |x| - x.statuses << DomainStatus::DELETE_CANDIDATE if x.delete_candidateable? - # TODO: This should be managed by automatic_statuses - x.statuses.delete(DomainStatus::OK) - x.save + d.each do |domain| + next unless domain.delete_candidateable? + domain.statuses << DomainStatus::DELETE_CANDIDATE + STDOUT << "#{Time.zone.now.utc} Domain.start_delete_period: ##{domain.id} #{domain.changes}\n" unless Rails.env.test? + domain.save end return if Rails.env.test? @@ -251,17 +258,20 @@ class Domain < ActiveRecord::Base c = 0 Domain.where("statuses @> '{deleteCandidate}'::varchar[]").each do |x| x.destroy + STDOUT << "#{Time.zone.now.utc} Domain.destroy_delete_candidates: by deleteCandidate ##{x.id}\n" unless Rails.env.test? c += 1 end Domain.where('force_delete_at <= ?', Time.zone.now).each do |x| x.destroy + STDOUT << "#{Time.zone.now.utc} Domain.destroy_delete_candidates: by force delete time ##{x.id}\n" unless Rails.env.test? c += 1 end STDOUT << "#{Time.zone.now.utc} - Successfully destroyed #{c} domains\n" unless Rails.env.test? end # rubocop:enable Rails/FindEach + # rubocop: enable Metrics/LineLength end def name=(value) diff --git a/app/models/invoice.rb b/app/models/invoice.rb index f55851849..3232b34b9 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -45,6 +45,12 @@ class Invoice < ActiveRecord::Base 'due_date < ? AND cancelled_at IS NULL', cr_at ) + unless Rails.env.test? + invoices.each do |m| + STDOUT << "#{Time.zone.now.utc} Invoice.cancel_overdue_invoices: ##{m.id}\n" + end + end + count = invoices.update_all(cancelled_at: Time.zone.now) STDOUT << "#{Time.zone.now.utc} - Successfully cancelled #{count} overdue invoices\n" unless Rails.env.test? diff --git a/config/schedule.rb b/config/schedule.rb index c418de420..265306904 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -24,9 +24,10 @@ every :day, at: '12:10am' do runner 'Invoice.cancel_overdue_invoices' end -every :day, at: '12:15am' do - runner 'Domain.expire_domains' -end +# TODO +# every :day, at: '12:15am' do + # runner 'Domain.expire_domains' +# end every :day, at: '12:20am' do runner 'Domain.clean_expired_pendings' From 682d2918ce059a7f6327373627cbee128be0dbe3 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Mon, 27 Jul 2015 22:55:47 +0300 Subject: [PATCH 12/25] Log invalid cert message #2808 --- app/models/depp/user.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/depp/user.rb b/app/models/depp/user.rb index 4efbd42d9..d510edecd 100644 --- a/app/models/depp/user.rb +++ b/app/models/depp/user.rb @@ -90,7 +90,8 @@ module Depp server.close_connection - rescue OpenSSL::SSL::SSLError + rescue OpenSSL::SSL::SSLError => e + Rails.logger.error "INVALID CERT: #{e}" errors.add(:base, :invalid_cert) end end From 7f44227370c1b5dcfb403d1c96011d27c75cb78e Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Mon, 27 Jul 2015 23:00:01 +0300 Subject: [PATCH 13/25] Api log contains only username + refactor #2793 --- app/controllers/application_controller.rb | 19 ++++--------------- app/controllers/epp_controller.rb | 6 ++++-- app/models/concerns/versions.rb | 20 ++++++++++---------- spec/epp/contact_spec.rb | 2 +- spec/epp/domain_spec.rb | 4 ++-- spec/epp/poll_spec.rb | 2 +- spec/epp/session_spec.rb | 6 +++--- spec/models/domain_spec.rb | 16 ++++++++-------- 8 files changed, 33 insertions(+), 42 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5aa6c40f1..87099d6fa 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -56,15 +56,7 @@ class ApplicationController < ActionController::Base end def user_for_paper_trail - if defined?(current_user) && current_user.present? - # Most of the time it's not loaded in correct time because PaperTrail before filter kicks in - # before current_user is defined. PaperTrail is triggered also at current_user - api_user_log_str(current_user) - elsif current_user.present? - "#{current_user.id}-#{current_user.username}" - else - 'public' - end + user_log_str(current_user) end def depp_current_user @@ -74,11 +66,8 @@ class ApplicationController < ActionController::Base ) end - def api_user_log_str(user) - if user.present? - "#{user.id}-api-#{user.username}" - else - 'api-public' - end + def user_log_str(user) + return 'public' if user.nil? + "#{user.id}-#{user.class}: #{user.username}" end end diff --git a/app/controllers/epp_controller.rb b/app/controllers/epp_controller.rb index f5133a74c..a61b155a1 100644 --- a/app/controllers/epp_controller.rb +++ b/app/controllers/epp_controller.rb @@ -120,7 +120,7 @@ class EppController < ApplicationController @current_user ||= ApiUser.find_by_id(epp_session[:api_user_id]) # by default PaperTrail uses before filter and at that # time current_user is not yet present - ::PaperTrail.whodunnit = api_user_log_str(@current_user) + ::PaperTrail.whodunnit = user_log_str(@current_user) ::PaperSession.session = epp_session.session_id if epp_session.session_id.present? @current_user end @@ -350,6 +350,7 @@ class EppController < ApplicationController # rubocop: enable Style/PredicateName # rubocop: disable Metrics/CyclomaticComplexity + # rubocop: disable Metrics/PerceivedComplexity def write_to_epp_log # return nil if EPP_LOG_ENABLED request_command = params[:command] || params[:action] # error receives :command, other methods receive :action @@ -366,12 +367,13 @@ class EppController < ApplicationController request_successful: epp_errors.empty?, request_object: params[:epp_object_type], response: @response, - api_user_name: api_user_log_str(@api_user || current_user), + api_user_name: @api_user.try(:username) || current_user.try(:username) || 'api-public', api_user_registrar: @api_user.try(:registrar).try(:to_s) || current_user.try(:registrar).try(:to_s), ip: request.ip }) end # rubocop: enable Metrics/CyclomaticComplexity + # rubocop: enable Metrics/PerceivedComplexity def iptables_counter_update return if ENV['iptables_counter_enabled'].blank? && ENV['iptables_counter_enabled'] != 'true' diff --git a/app/models/concerns/versions.rb b/app/models/concerns/versions.rb index eff834218..2cbdca838 100644 --- a/app/models/concerns/versions.rb +++ b/app/models/concerns/versions.rb @@ -20,17 +20,15 @@ module Versions true end - # needs refactoring - # TODO: optimization work - # belongs_to :api_creator, class_name: 'ApiUser', foreign_key: :creator_str - # belongs_to :creator, class_name: 'User', foreign_key: :creator_str def creator return nil if creator_str.blank? - if creator_str =~ /^\d-api-/ - creator = ApiUser.find_by(id: creator_str) - else + if creator_str =~ /^\d+-AdminUser:/ creator = AdminUser.find_by(id: creator_str) + elsif creator_str =~ /^\d+-ApiUser:/ + creator = ApiUser.find_by(id: creator_str) + elsif creator_str =~ /^\d+-api-/ # depricated + creator = ApiUser.find_by(id: creator_str) end creator.present? ? creator : creator_str @@ -39,10 +37,12 @@ module Versions def updator return nil if updator_str.blank? - if updator_str =~ /^\d-api-/ - updator = ApiUser.find_by(id: updator_str) - else + if updator_str =~ /^\d+-AdminUser:/ updator = AdminUser.find_by(id: updator_str) + elsif updator_str =~ /^\d+-ApiUser:/ + updator = ApiUser.find_by(id: updator_str) + elsif updator_str =~ /^\d+-api-/ # depricated + updator = ApiUser.find_by(id: updator_str) end updator.present? ? updator : updator_str diff --git a/spec/epp/contact_spec.rb b/spec/epp/contact_spec.rb index dcd5e79db..b7b6bc976 100644 --- a/spec/epp/contact_spec.rb +++ b/spec/epp/contact_spec.rb @@ -85,7 +85,7 @@ describe 'EPP Contact', epp: true do log.request_command.should == 'create' log.request_object.should == 'contact' log.request_successful.should == true - log.api_user_name.should == '1-api-registrar1' + log.api_user_name.should == 'registrar1' log.api_user_registrar.should == 'registrar1' end diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index b0c7535fc..d89c846b0 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -67,7 +67,7 @@ describe 'EPP Domain', epp: true do log.request_command.should == 'create' log.request_object.should == 'domain' log.request_successful.should == false - log.api_user_name.should == '1-api-registrar1' + log.api_user_name.should == 'registrar1' log.api_user_registrar.should == 'registrar1' log.request.should_not be_blank log.response.should_not be_blank @@ -1061,7 +1061,7 @@ describe 'EPP Domain', epp: true do log.request_command.should == 'transfer' log.request_object.should == 'domain' log.request_successful.should == true - log.api_user_name.should == '2-api-registrar2' + log.api_user_name.should == 'registrar2' log.api_user_registrar.should == 'registrar2' log.request.should_not be_blank log.response.should_not be_blank diff --git a/spec/epp/poll_spec.rb b/spec/epp/poll_spec.rb index 99e91103c..53f82221a 100644 --- a/spec/epp/poll_spec.rb +++ b/spec/epp/poll_spec.rb @@ -32,7 +32,7 @@ describe 'EPP Poll', epp: true do log.request_command.should == 'poll' log.request_object.should == 'poll' log.request_successful.should == true - log.api_user_name.should == '1-api-registrar1' + log.api_user_name.should == 'registrar1' log.api_user_registrar.should == @registrar1.name log.request.should_not be_blank log.response.should_not be_blank diff --git a/spec/epp/session_spec.rb b/spec/epp/session_spec.rb index 56910c1a3..d36e8f694 100644 --- a/spec/epp/session_spec.rb +++ b/spec/epp/session_spec.rb @@ -47,7 +47,7 @@ describe 'EPP Session', epp: true do log = ApiLog::EppLog.last log.request_command.should == 'login' log.request_successful.should == false - log.api_user_name.should == '2-api-inactive-user' + log.api_user_name.should == 'inactive-user' end it 'prohibits further actions unless logged in' do @@ -88,7 +88,7 @@ describe 'EPP Session', epp: true do log = ApiLog::EppLog.last log.request_command.should == 'login' log.request_successful.should == true - log.api_user_name.should == '1-api-gitlab' + log.api_user_name.should == 'gitlab' end it 'does not log in twice' do @@ -104,7 +104,7 @@ describe 'EPP Session', epp: true do log = ApiLog::EppLog.last log.request_command.should == 'login' log.request_successful.should == false - log.api_user_name.should == '1-api-gitlab' + log.api_user_name.should == 'gitlab' end it 'logs out epp user' do diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index 4546ef580..dcb344c93 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -387,10 +387,10 @@ describe Domain do @api_user = Fabricate(:api_user) @user.id.should == 1 @api_user.id.should == 2 - ::PaperTrail.whodunnit = '2-api-testuser' + ::PaperTrail.whodunnit = '2-ApiUser: testuser' @domain = Fabricate(:domain) - @domain.creator_str.should == '2-api-testuser' + @domain.creator_str.should == '2-ApiUser: testuser' @domain.creator.should == @api_user @domain.creator.should_not == @user @@ -399,14 +399,14 @@ describe Domain do it 'should return api_creator when created by api user' do with_versioning do - @user = Fabricate(:admin_user) - @api_user = Fabricate(:api_user) - @user.id.should == 3 - @api_user.id.should == 4 - ::PaperTrail.whodunnit = '3-testuser' + @user = Fabricate(:admin_user, id: 1000) + @api_user = Fabricate(:api_user, id: 2000) + @user.id.should == 1000 + @api_user.id.should == 2000 + ::PaperTrail.whodunnit = '1000-AdminUser: testuser' @domain = Fabricate(:domain) - @domain.creator_str.should == '3-testuser' + @domain.creator_str.should == '1000-AdminUser: testuser' @domain.creator.should == @user @domain.creator.should_not == @api_user From 4178b7d97d1a3f2c822d2a673e453124cc167097 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 28 Jul 2015 10:33:13 +0300 Subject: [PATCH 14/25] Restore eis custom files #2793 --- .../initializers/eis_custom_active_model.rb | 18 +++++++++++++ .../initializers/eis_custom_active_record.rb | 7 +++++ config/initializers/eis_custom_flash.rb | 27 +++++++++++++++++++ config/initializers/eis_custom_rack.rb | 14 ++++++++++ 4 files changed, 66 insertions(+) create mode 100644 config/initializers/eis_custom_active_model.rb create mode 100644 config/initializers/eis_custom_active_record.rb create mode 100644 config/initializers/eis_custom_flash.rb create mode 100644 config/initializers/eis_custom_rack.rb diff --git a/config/initializers/eis_custom_active_model.rb b/config/initializers/eis_custom_active_model.rb new file mode 100644 index 000000000..f41a42325 --- /dev/null +++ b/config/initializers/eis_custom_active_model.rb @@ -0,0 +1,18 @@ +# Log all active model user errors +module ActiveModel + class Errors + def add(attribute, message = :invalid, options = {}) + message = normalize_message(attribute, message, options) + if exception = options[:strict] + exception = ActiveModel::StrictValidationFailed if exception == true + raise exception, full_message(attribute, message) + end + + # CUSTOM logging + Rails.logger.info "USER MSG: ACTIVEMODEL: #{@base.try(:class)} [#{attribute}] #{message}" if message.present? + # END of CUSTOM logging + + self[attribute] << message + end + end +end diff --git a/config/initializers/eis_custom_active_record.rb b/config/initializers/eis_custom_active_record.rb new file mode 100644 index 000000000..546f5a4ae --- /dev/null +++ b/config/initializers/eis_custom_active_record.rb @@ -0,0 +1,7 @@ +# Log all user issues raised by active record +class ActiveRecord::Base + after_validation do |m| + Rails.logger.info "USER MSG: ACTIVERECORD: #{m.class} ##{m.id} #{m.errors.full_messages} #{m.errors['epp_errors']}" if m.errors.present? + true + end +end diff --git a/config/initializers/eis_custom_flash.rb b/config/initializers/eis_custom_flash.rb new file mode 100644 index 000000000..ed5832e85 --- /dev/null +++ b/config/initializers/eis_custom_flash.rb @@ -0,0 +1,27 @@ +# Log all flash messages +module ActionDispatch + class Flash + def call(env) + @app.call(env) + ensure + session = Request::Session.find(env) || {} + flash_hash = env[KEY] + + if flash_hash && (flash_hash.present? || session.key?('flash')) + session["flash"] = flash_hash.to_session_value + + # EIS custom logging + Rails.logger.info "USER MSG: FLASH: #{session['flash']['flashes'].inspect}" if session['flash'] + # END OF EIS custom logging + + env[KEY] = flash_hash.dup + end + + if (!session.respond_to?(:loaded?) || session.loaded?) && # (reset_session uses {}, which doesn't implement #loaded?) + session.key?('flash') && session['flash'].nil? + session.delete('flash') + end + end + end +end + diff --git a/config/initializers/eis_custom_rack.rb b/config/initializers/eis_custom_rack.rb new file mode 100644 index 000000000..52dbd8244 --- /dev/null +++ b/config/initializers/eis_custom_rack.rb @@ -0,0 +1,14 @@ +# EIS custom rack hack in order to enable test external interfaces EPP/REPP inside webserver network +# rubocop:disable Metrics/LineLength +module Rack + class Request + def trusted_proxy?(ip) + if ENV['eis_trusted_proxies'] + ENV['eis_trusted_proxies'].split(',').map(&:strip).include?(ip) + else + ip =~ /\A127\.0\.0\.1\Z|\A(10|172\.(1[6-9]|2[0-9]|30|31)|192\.168)\.|\A::1\Z|\Afd[0-9a-f]{2}:.+|\Alocalhost\Z|\Aunix\Z|\Aunix:/i + end + end + end +end +# rubocop:enable Metrics/LineLength From 7fd6f6a55d5a76910f59f9e1429ecccdb008f893 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 28 Jul 2015 11:47:48 +0300 Subject: [PATCH 15/25] Added domain pending update new registrant notification #2804 --- app/mailers/domain_mailer.rb | 23 +++++++++ ...pdate_new_registrant_notification.html.erb | 49 +++++++++++++++++++ ...pdate_new_registrant_notification.text.erb | 49 +++++++++++++++++++ config/locales/en.yml | 1 + spec/mailers/domain_mailer_spec.rb | 31 +++++++++++- 5 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 app/views/domain_mailer/pending_update_new_registrant_notification.html.erb create mode 100644 app/views/domain_mailer/pending_update_new_registrant_notification.text.erb diff --git a/app/mailers/domain_mailer.rb b/app/mailers/domain_mailer.rb index 936a4559c..f7de5171a 100644 --- a/app/mailers/domain_mailer.rb +++ b/app/mailers/domain_mailer.rb @@ -23,6 +23,29 @@ class DomainMailer < ApplicationMailer subject: "#{I18n.t(:domain_registrant_pending_updated_subject, name: @domain.name)} [#{@domain.name}]") end + def pending_update_new_registrant_notification(domain) + @domain = domain + return if delivery_off?(@domain) + + if @domain.registrant_verification_token.blank? + logger.warn "EMAIL NOT DELIVERED: registrant_verification_token is missing for #{@domain.name}" + return + end + + if @domain.registrant_verification_asked_at.blank? + logger.warn "EMAIL NOT DELIVERED: registrant_verification_asked_at is missing for #{@domain.name}" + return + end + + @new_registrant = @domain.registrant # NB! new registrant at this point + @old_registrant = Registrant.find(@domain.registrant_id_was) + + return if whitelist_blocked?(@new_registrant.email) + mail(to: @new_registrant.email, + subject: "#{I18n.t(:domain_pending_update_new_registrant_notification_subject, + name: @domain.name)} [#{@domain.name}]") + end + def registrant_updated(domain) @domain = domain return if delivery_off?(@domain) diff --git a/app/views/domain_mailer/pending_update_new_registrant_notification.html.erb b/app/views/domain_mailer/pending_update_new_registrant_notification.html.erb new file mode 100644 index 000000000..27bec4401 --- /dev/null +++ b/app/views/domain_mailer/pending_update_new_registrant_notification.html.erb @@ -0,0 +1,49 @@ +Tere, +

+Registripidaja <%= @domain.registrar_name %> vahendusel on algatatud <%= @domain.name %> domeeni omanikuvahetuse protseduur. +

+Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja poole. Teie registripidaja on <%= @domain.registrar_name %> +

+Uued registreerija andmed:
+Nimi: <%= @domain.registrant_name %>
+<% if @domain.registrant.priv? %> + Isikukood: <%= @domain.registrant_ident %>
+<% else %> + Äriregistrikood: <%= @domain.registrant_ident %>
+<% end %> +Tänav: <%= @domain.registrant_street %>
+Linn: <%= @domain.registrant_city %>
+Riik: <%= @domain.registrant_country %> +

+Juhime Teie tähelepanu asjaolule, et omanikuvahetuse protseduur viiaks lõpule vaid juhul, kui domeeni hetkel kehtiv registreerija <%= @old_registrant.name %> omanikuvahetuse tähtaegselt kinnitab. +

+Juhul kui <%= @old_registrant.name %> lükkab omanikuvahtuse taotluse tagasi või ei anna kinnitust enne <%= Setting.expire_pending_confirmation %> tundi, omanikuvahetuse protseduur tühistatakse.
+

+Taotlus on aktiivne <%= Setting.expire_pending_confirmation %> tundi ja lükatakse automaatselt tagasi kui te seda enne ise ei kinnita või tagasi lükka. +

+Küsimuste korral palun võtke ühendust registripidajaga <%= @domain.registrar_name %>, kelle kontaktid leiate http://internet.ee/registripidajad/akrediteeritud-registripidajad +

+Lugupidamisega
+Eesti Interneti SA +

+
+

+Hi, +

+Registrant change process for the domain <%= @domain.name %> has been started. +

+New registrant:
+Name: <%= @domain.registrant_name %>
+<% if @domain.registrant.priv? %> +Personal code: <%= @domain.registrant_ident %>
+<% else %> +Business Registry code: <%= @domain.registrant_ident %>
+<% end %> +Street: <%= @domain.registrant_street %>
+City: <%= @domain.registrant_city %>
+Country: <%= @domain.registrant_country %>
+

+Please contact to your registrar <%= @domain.registrar_name %> if you have any questions. +

+Best Regards,
+Estonian Internet Foundation diff --git a/app/views/domain_mailer/pending_update_new_registrant_notification.text.erb b/app/views/domain_mailer/pending_update_new_registrant_notification.text.erb new file mode 100644 index 000000000..e4a401977 --- /dev/null +++ b/app/views/domain_mailer/pending_update_new_registrant_notification.text.erb @@ -0,0 +1,49 @@ +Tere, + +Registripidaja <%= @domain.registrar_name %> vahendusel on algatatud <%= @domain.name %> domeeni omanikuvahetuse protseduur. + +Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja poole. Teie registripidaja on <%= @domain.registrar_name %> + +Uued registreerija andmed: +Nimi: <%= @domain.registrant_name %> +<% if @domain.registrant.priv? %> +Isikukood: <%= @domain.registrant_ident %> +<% else %> +Äriregistrikood: <%= @domain.registrant_ident %> +<% end %> +Tänav: <%= @domain.registrant_street %> +Linn: <%= @domain.registrant_city %> +Riik: <%= @domain.registrant_country %> + +Juhime Teie tähelepanu asjaolule, et omanikuvahetuse protseduur viiaks lõpule vaid juhul, kui domeeni hetkel kehtiv registreerija <%= @old_registrant.name %> omanikuvahetuse tähtaegselt kinnitab. + +Juhul kui <%= @old_registrant.name %> lükkab omanikuvahtuse taotluse tagasi või ei anna kinnitust enne <%= Setting.expire_pending_confirmation %> tundi, omanikuvahetuse protseduur tühistatakse. + +Taotlus on aktiivne <%= Setting.expire_pending_confirmation %> tundi ja lükatakse automaatselt tagasi kui te seda enne ise ei kinnita või tagasi lükka. + +Küsimuste korral palun võtke ühendust registripidajaga <%= @domain.registrar_name %>, kelle kontaktid leiate http://internet.ee/registripidajad/akrediteeritud-registripidajad + +Lugupidamisega +Eesti Interneti SA + +-------------------------------------- + +Hi, + +Registrant change process for the domain <%= @domain.name %> has been started. + +New registrant: +Name: <%= @domain.registrant_name %> +<% if @domain.registrant.priv? %> +Personal code: <%= @domain.registrant_ident %> +<% else %> +Business Registry code: <%= @domain.registrant_ident %> +<% end %> +Street: <%= @domain.registrant_street %> +City: <%= @domain.registrant_city %> +Country: <%= @domain.registrant_country %> + +Please contact to your registrar <%= @domain.registrar_name %> if you have any questions. + +Best Regards, +Estonian Internet Foundation diff --git a/config/locales/en.yml b/config/locales/en.yml index fc124e6a4..a25260496 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -778,6 +778,7 @@ en: contact_email_update_subject: 'Teie domeenide kontakt epostiaadress on muutunud / Contact e-mail addresses of your domains have changed' object_status_prohibits_operation: 'Object status prohibits operation' domain_registrant_pending_updated_subject: "Kinnitustaotlus domeeni %{name} registreerija vahetuseks / Application for approval for registrant chache of %{name}" + domain_pending_update_new_registrant_notification_subject: "Domeeni %{name} registreerija vahetus protseduur on algatatud / %{name} registrant change" domain_pending_deleted_subject: "Kinnitustaotlus domeeni %{name} kustutamiseks .ee registrist / Application for approval for deletion of %{name}" whois: WHOIS login_failed_check_id_card: 'Log in failed, check ID card' diff --git a/spec/mailers/domain_mailer_spec.rb b/spec/mailers/domain_mailer_spec.rb index ada60a741..a0701c1bd 100644 --- a/spec/mailers/domain_mailer_spec.rb +++ b/spec/mailers/domain_mailer_spec.rb @@ -25,7 +25,7 @@ describe DomainMailer do end end - describe 'email changed notification' do + describe 'registrant change request for old registrant' do before :all do @registrant = Fabricate(:registrant, email: 'test@example.com') @new_registrant = Fabricate(:registrant, email: 'test@example.org') @@ -58,6 +58,35 @@ describe DomainMailer do end end + describe 'registrant change notification for new registrant' do + before :all do + @registrant = Fabricate(:registrant, email: 'old@example.com') + @new_registrant = Fabricate(:registrant, email: 'new@example.org') + @domain = Fabricate(:domain, registrant: @registrant) + @domain.deliver_emails = true + @domain.registrant_verification_token = '123' + @domain.registrant_verification_asked_at = Time.zone.now + @domain.registrant = @new_registrant + @mail = DomainMailer.pending_update_new_registrant_notification(@domain) + end + + it 'should render email subject' do + @mail.subject.should =~ /protseduur on algatatud/ + end + + it 'should have sender email' do + @mail.from.should == ["noreply@internet.ee"] + end + + it 'should send confirm email to new registrant email' do + @mail.to.should == ["new@example.org"] + end + + it 'should render body' do + @mail.body.encoded.should =~ /vahendusel on algatatud/ + end + end + describe 'domain pending delete notification when delivery turned off' do before :all do @registrant = Fabricate(:registrant, email: 'test@example.com') From 0b132d5c1a1f8035f4222ed08157c152ee9e175e Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 28 Jul 2015 11:55:01 +0300 Subject: [PATCH 16/25] Move all mailers under subdir #2804 --- app/mailers/application_mailer.rb | 1 + app/views/{ => mailers}/contact_mailer/email_updated.html.erb | 0 app/views/{ => mailers}/contact_mailer/email_updated.text.erb | 0 app/views/{ => mailers}/domain_mailer/pending_deleted.html.erb | 0 app/views/{ => mailers}/domain_mailer/pending_deleted.text.erb | 0 .../pending_update_new_registrant_notification.html.erb | 0 .../pending_update_new_registrant_notification.text.erb | 0 .../domain_mailer/registrant_pending_updated.html.erb | 0 .../domain_mailer/registrant_pending_updated.text.erb | 0 .../{ => mailers}/domain_mailer/registrant_updated.html.erb | 0 .../{ => mailers}/domain_mailer/registrant_updated.text.erb | 0 app/views/{ => mailers}/invoice_mailer/invoice_email.html.erb | 0 app/views/{ => mailers}/invoice_mailer/invoice_email.text.erb | 0 13 files changed, 1 insertion(+) rename app/views/{ => mailers}/contact_mailer/email_updated.html.erb (100%) rename app/views/{ => mailers}/contact_mailer/email_updated.text.erb (100%) rename app/views/{ => mailers}/domain_mailer/pending_deleted.html.erb (100%) rename app/views/{ => mailers}/domain_mailer/pending_deleted.text.erb (100%) rename app/views/{ => mailers}/domain_mailer/pending_update_new_registrant_notification.html.erb (100%) rename app/views/{ => mailers}/domain_mailer/pending_update_new_registrant_notification.text.erb (100%) rename app/views/{ => mailers}/domain_mailer/registrant_pending_updated.html.erb (100%) rename app/views/{ => mailers}/domain_mailer/registrant_pending_updated.text.erb (100%) rename app/views/{ => mailers}/domain_mailer/registrant_updated.html.erb (100%) rename app/views/{ => mailers}/domain_mailer/registrant_updated.text.erb (100%) rename app/views/{ => mailers}/invoice_mailer/invoice_email.html.erb (100%) rename app/views/{ => mailers}/invoice_mailer/invoice_email.text.erb (100%) diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index e89954b24..1ed7e0ce7 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,4 +1,5 @@ class ApplicationMailer < ActionMailer::Base + append_view_path Rails.root.join('app', 'views', 'mailers') default from: 'noreply@internet.ee' layout 'mailer' diff --git a/app/views/contact_mailer/email_updated.html.erb b/app/views/mailers/contact_mailer/email_updated.html.erb similarity index 100% rename from app/views/contact_mailer/email_updated.html.erb rename to app/views/mailers/contact_mailer/email_updated.html.erb diff --git a/app/views/contact_mailer/email_updated.text.erb b/app/views/mailers/contact_mailer/email_updated.text.erb similarity index 100% rename from app/views/contact_mailer/email_updated.text.erb rename to app/views/mailers/contact_mailer/email_updated.text.erb diff --git a/app/views/domain_mailer/pending_deleted.html.erb b/app/views/mailers/domain_mailer/pending_deleted.html.erb similarity index 100% rename from app/views/domain_mailer/pending_deleted.html.erb rename to app/views/mailers/domain_mailer/pending_deleted.html.erb diff --git a/app/views/domain_mailer/pending_deleted.text.erb b/app/views/mailers/domain_mailer/pending_deleted.text.erb similarity index 100% rename from app/views/domain_mailer/pending_deleted.text.erb rename to app/views/mailers/domain_mailer/pending_deleted.text.erb diff --git a/app/views/domain_mailer/pending_update_new_registrant_notification.html.erb b/app/views/mailers/domain_mailer/pending_update_new_registrant_notification.html.erb similarity index 100% rename from app/views/domain_mailer/pending_update_new_registrant_notification.html.erb rename to app/views/mailers/domain_mailer/pending_update_new_registrant_notification.html.erb diff --git a/app/views/domain_mailer/pending_update_new_registrant_notification.text.erb b/app/views/mailers/domain_mailer/pending_update_new_registrant_notification.text.erb similarity index 100% rename from app/views/domain_mailer/pending_update_new_registrant_notification.text.erb rename to app/views/mailers/domain_mailer/pending_update_new_registrant_notification.text.erb diff --git a/app/views/domain_mailer/registrant_pending_updated.html.erb b/app/views/mailers/domain_mailer/registrant_pending_updated.html.erb similarity index 100% rename from app/views/domain_mailer/registrant_pending_updated.html.erb rename to app/views/mailers/domain_mailer/registrant_pending_updated.html.erb diff --git a/app/views/domain_mailer/registrant_pending_updated.text.erb b/app/views/mailers/domain_mailer/registrant_pending_updated.text.erb similarity index 100% rename from app/views/domain_mailer/registrant_pending_updated.text.erb rename to app/views/mailers/domain_mailer/registrant_pending_updated.text.erb diff --git a/app/views/domain_mailer/registrant_updated.html.erb b/app/views/mailers/domain_mailer/registrant_updated.html.erb similarity index 100% rename from app/views/domain_mailer/registrant_updated.html.erb rename to app/views/mailers/domain_mailer/registrant_updated.html.erb diff --git a/app/views/domain_mailer/registrant_updated.text.erb b/app/views/mailers/domain_mailer/registrant_updated.text.erb similarity index 100% rename from app/views/domain_mailer/registrant_updated.text.erb rename to app/views/mailers/domain_mailer/registrant_updated.text.erb diff --git a/app/views/invoice_mailer/invoice_email.html.erb b/app/views/mailers/invoice_mailer/invoice_email.html.erb similarity index 100% rename from app/views/invoice_mailer/invoice_email.html.erb rename to app/views/mailers/invoice_mailer/invoice_email.html.erb diff --git a/app/views/invoice_mailer/invoice_email.text.erb b/app/views/mailers/invoice_mailer/invoice_email.text.erb similarity index 100% rename from app/views/invoice_mailer/invoice_email.text.erb rename to app/views/mailers/invoice_mailer/invoice_email.text.erb From 8536ac2d6fca25fcf41f0f90e7788c98c45b6db0 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 28 Jul 2015 12:00:02 +0300 Subject: [PATCH 17/25] Activate pending update new registrant notification #2804 --- app/models/domain.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/domain.rb b/app/models/domain.rb index b9eaff917..cd9f61e89 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -361,6 +361,7 @@ class Domain < ActiveRecord::Base changes_cache = changes DomainMailer.registrant_pending_updated(self).deliver_now + DomainMailer.pending_update_new_registrant_notification(self).deliver_now reload # revert back to original From 726231c4e6c87a4f35aac13dc0efe13aa623effa Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 28 Jul 2015 12:10:28 +0300 Subject: [PATCH 18/25] Refactor domain mailers pending updates #2804 --- app/mailers/domain_mailer.rb | 13 ++++++++----- app/models/domain.rb | 2 +- ... pending_update_old_registrant_request.html.erb} | 0 ... pending_update_old_registrant_request.text.erb} | 0 config/locales/en.yml | 4 ++-- spec/mailers/domain_mailer_spec.rb | 6 +++--- 6 files changed, 14 insertions(+), 11 deletions(-) rename app/views/mailers/domain_mailer/{registrant_pending_updated.html.erb => pending_update_old_registrant_request.html.erb} (100%) rename app/views/mailers/domain_mailer/{registrant_pending_updated.text.erb => pending_update_old_registrant_request.text.erb} (100%) diff --git a/app/mailers/domain_mailer.rb b/app/mailers/domain_mailer.rb index f7de5171a..822d4a22f 100644 --- a/app/mailers/domain_mailer.rb +++ b/app/mailers/domain_mailer.rb @@ -1,5 +1,5 @@ class DomainMailer < ApplicationMailer - def registrant_pending_updated(domain) + def pending_update_old_registrant_request(domain) @domain = domain return if delivery_off?(@domain) @@ -20,7 +20,8 @@ class DomainMailer < ApplicationMailer return if whitelist_blocked?(@old_registrant.email) mail(to: @old_registrant.email, - subject: "#{I18n.t(:domain_registrant_pending_updated_subject, name: @domain.name)} [#{@domain.name}]") + subject: "#{I18n.t(:pending_update_old_registrant_request_subject, + name: @domain.name)} [#{@domain.name}]") end def pending_update_new_registrant_notification(domain) @@ -42,7 +43,7 @@ class DomainMailer < ApplicationMailer return if whitelist_blocked?(@new_registrant.email) mail(to: @new_registrant.email, - subject: "#{I18n.t(:domain_pending_update_new_registrant_notification_subject, + subject: "#{I18n.t(:pending_update_new_registrant_notification_subject, name: @domain.name)} [#{@domain.name}]") end @@ -52,7 +53,8 @@ class DomainMailer < ApplicationMailer return if whitelist_blocked?(@domain.registrant_email) mail(to: @domain.registrant_email, - subject: "#{I18n.t(:domain_registrant_updated, name: @domain.name)} [#{@domain.name}]") + subject: "#{I18n.t(:domain_registrant_updated, + name: @domain.name)} [#{@domain.name}]") end def pending_deleted(domain) @@ -76,6 +78,7 @@ class DomainMailer < ApplicationMailer return if whitelist_blocked?(@old_registrant.email) mail(to: @old_registrant.email, - subject: "#{I18n.t(:domain_pending_deleted_subject, name: @domain.name)} [#{@domain.name}]") + subject: "#{I18n.t(:domain_pending_deleted_subject, + name: @domain.name)} [#{@domain.name}]") end end diff --git a/app/models/domain.rb b/app/models/domain.rb index cd9f61e89..d77587d40 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -360,7 +360,7 @@ class Domain < ActiveRecord::Base asked_at = registrant_verification_asked_at changes_cache = changes - DomainMailer.registrant_pending_updated(self).deliver_now + DomainMailer.pending_update_old_registrant_request(self).deliver_now DomainMailer.pending_update_new_registrant_notification(self).deliver_now reload # revert back to original diff --git a/app/views/mailers/domain_mailer/registrant_pending_updated.html.erb b/app/views/mailers/domain_mailer/pending_update_old_registrant_request.html.erb similarity index 100% rename from app/views/mailers/domain_mailer/registrant_pending_updated.html.erb rename to app/views/mailers/domain_mailer/pending_update_old_registrant_request.html.erb diff --git a/app/views/mailers/domain_mailer/registrant_pending_updated.text.erb b/app/views/mailers/domain_mailer/pending_update_old_registrant_request.text.erb similarity index 100% rename from app/views/mailers/domain_mailer/registrant_pending_updated.text.erb rename to app/views/mailers/domain_mailer/pending_update_old_registrant_request.text.erb diff --git a/config/locales/en.yml b/config/locales/en.yml index a25260496..f083a40e3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -777,8 +777,8 @@ en: 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' object_status_prohibits_operation: 'Object status prohibits operation' - domain_registrant_pending_updated_subject: "Kinnitustaotlus domeeni %{name} registreerija vahetuseks / Application for approval for registrant chache of %{name}" - domain_pending_update_new_registrant_notification_subject: "Domeeni %{name} registreerija vahetus protseduur on algatatud / %{name} registrant change" + pending_update_old_registrant_request_subject: "Kinnitustaotlus domeeni %{name} registreerija vahetuseks / Application for approval for registrant chache of %{name}" + pending_update_new_registrant_notification_subject: "Domeeni %{name} registreerija vahetus protseduur on algatatud / %{name} registrant change" domain_pending_deleted_subject: "Kinnitustaotlus domeeni %{name} kustutamiseks .ee registrist / Application for approval for deletion of %{name}" whois: WHOIS login_failed_check_id_card: 'Log in failed, check ID card' diff --git a/spec/mailers/domain_mailer_spec.rb b/spec/mailers/domain_mailer_spec.rb index a0701c1bd..a78e4d030 100644 --- a/spec/mailers/domain_mailer_spec.rb +++ b/spec/mailers/domain_mailer_spec.rb @@ -1,11 +1,11 @@ require 'rails_helper' describe DomainMailer do - describe 'registrant changed notification when delivery turned off' do + describe 'registrant change request for old registrant when delivery turned off' do before :all do @registrant = Fabricate(:registrant, email: 'test@example.com') @domain = Fabricate(:domain, registrant: @registrant) - @mail = DomainMailer.registrant_pending_updated(@domain) + @mail = DomainMailer.pending_update_old_registrant_request(@domain) end it 'should not render email subject' do @@ -34,7 +34,7 @@ describe DomainMailer do @domain.registrant_verification_token = '123' @domain.registrant_verification_asked_at = Time.zone.now @domain.registrant = @new_registrant - @mail = DomainMailer.registrant_pending_updated(@domain) + @mail = DomainMailer.pending_update_old_registrant_request(@domain) end it 'should render email subject' do From 00d42ef3c4c98422fb0418ab729a287178da9434 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 28 Jul 2015 15:59:14 +0300 Subject: [PATCH 19/25] Email notification when pending update rejected #2786 --- app/jobs/domain_update_confirm_job.rb | 1 + app/mailers/domain_mailer.rb | 13 +++++++++++++ app/models/domain.rb | 6 ++++++ ...ected_new_registrant_notification.html.erb | 19 +++++++++++++++++++ ...ected_new_registrant_notification.text.erb | 19 +++++++++++++++++++ config/locales/en.yml | 1 + 6 files changed, 59 insertions(+) create mode 100644 app/views/mailers/domain_mailer/pending_update_rejected_new_registrant_notification.html.erb create mode 100644 app/views/mailers/domain_mailer/pending_update_rejected_new_registrant_notification.text.erb diff --git a/app/jobs/domain_update_confirm_job.rb b/app/jobs/domain_update_confirm_job.rb index 2310eaad4..9fd21f22e 100644 --- a/app/jobs/domain_update_confirm_job.rb +++ b/app/jobs/domain_update_confirm_job.rb @@ -8,6 +8,7 @@ class DomainUpdateConfirmJob < Que::Job domain.apply_pending_update! domain.clean_pendings! when RegistrantVerification::REJECTED + DomainMailer.pending_update_rejected_new_registrant_notification(domain).deliver_now domain.clean_pendings! end destroy # it's best to destroy the job in the same transaction diff --git a/app/mailers/domain_mailer.rb b/app/mailers/domain_mailer.rb index 822d4a22f..00b5cfb8d 100644 --- a/app/mailers/domain_mailer.rb +++ b/app/mailers/domain_mailer.rb @@ -57,6 +57,19 @@ class DomainMailer < ApplicationMailer name: @domain.name)} [#{@domain.name}]") end + def pending_update_rejected_new_registrant_notification(domain) + @domain = domain + # no delivery off control, driggered by que, no epp request + + @new_registrant_email = @domain.pending_json[:new_registrant_email] + @new_registrant_name = @domain.pending_json[:new_registrant_name] + + return if whitelist_blocked?(@new_registrant_email) + mail(to: @new_registrant_email, + subject: "#{I18n.t(:pending_update_rejected_new_registrant_notification_subject, + name: @domain.name)} [#{@domain.name}]") + end + def pending_deleted(domain) @domain = domain return if delivery_off?(@domain) diff --git a/app/models/domain.rb b/app/models/domain.rb index d77587d40..98d1e5697 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -359,6 +359,9 @@ class Domain < ActiveRecord::Base token = registrant_verification_token asked_at = registrant_verification_asked_at changes_cache = changes + new_registrant_id = registrant.id + new_registrant_email = registrant.email + new_registrant_name = registrant.name DomainMailer.pending_update_old_registrant_request(self).deliver_now DomainMailer.pending_update_new_registrant_notification(self).deliver_now @@ -370,6 +373,9 @@ class Domain < ActiveRecord::Base self.registrant_verification_asked_at = asked_at self.statuses = [DomainStatus::PENDING_UPDATE] pending_json[:domain] = changes_cache + pending_json[:new_registrant_id] = new_registrant_id + pending_json[:new_registrant_email] = new_registrant_email + pending_json[:new_registrant_name] = new_registrant_name end # rubocop: disable Metrics/CyclomaticComplexity diff --git a/app/views/mailers/domain_mailer/pending_update_rejected_new_registrant_notification.html.erb b/app/views/mailers/domain_mailer/pending_update_rejected_new_registrant_notification.html.erb new file mode 100644 index 000000000..94672f176 --- /dev/null +++ b/app/views/mailers/domain_mailer/pending_update_rejected_new_registrant_notification.html.erb @@ -0,0 +1,19 @@ +Tere, +

+Domeeni <%= @domain.name %> registreerija <%= @new_registrant_name %> on domeeni registreerija vahetamise taotluse tagasi lükanud. +

+Küsimuste korral palun võtke ühendust registripidajaga <%= @domain.registrar_name %>, kelle kontaktid leiate http://internet.ee/registripidajad/akrediteeritud-registripidajad +

+Lugupidamisega,
+Eesti Interneti SA +

+
+

+Hi, +

+Registrant change was declined for the domain <%= @domain.name %>. +

+Please contact to your registrar <%= @domain.registrar_name %> if you have any questions. +

+Best Regards,
+Estonian Internet Foundation diff --git a/app/views/mailers/domain_mailer/pending_update_rejected_new_registrant_notification.text.erb b/app/views/mailers/domain_mailer/pending_update_rejected_new_registrant_notification.text.erb new file mode 100644 index 000000000..afdf06325 --- /dev/null +++ b/app/views/mailers/domain_mailer/pending_update_rejected_new_registrant_notification.text.erb @@ -0,0 +1,19 @@ +Tere, + +Domeeni <%= @domain.name %> registreerija <%= @new_registrant_name %> on domeeni registreerija vahetamise taotluse tagasi lükanud. + +Küsimuste korral palun võtke ühendust registripidajaga <%= @domain.registrar_name %>, kelle kontaktid leiate http://internet.ee/registripidajad/akrediteeritud-registripidajad + +Lugupidamisega +Eesti Interneti SA + +-------------------------------------- + +Hi, + +Registrant change was declined for the domain <%= @domain.name %>. + +Please contact to your registrar <%= @domain.registrar_name %> if you have any questions. + +Best Regards, +Estonian Internet Foundation diff --git a/config/locales/en.yml b/config/locales/en.yml index f083a40e3..837ee6b35 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -779,6 +779,7 @@ en: object_status_prohibits_operation: 'Object status prohibits operation' pending_update_old_registrant_request_subject: "Kinnitustaotlus domeeni %{name} registreerija vahetuseks / Application for approval for registrant chache of %{name}" pending_update_new_registrant_notification_subject: "Domeeni %{name} registreerija vahetus protseduur on algatatud / %{name} registrant change" + pending_update_rejected_new_registrant_notification_subject: "Domeeni %{name} registreerija vahetuse taotlus tagasi lükatud / %{name} registrant change declined" domain_pending_deleted_subject: "Kinnitustaotlus domeeni %{name} kustutamiseks .ee registrist / Application for approval for deletion of %{name}" whois: WHOIS login_failed_check_id_card: 'Log in failed, check ID card' From 8a92591df714ea9513e1963eb56d6555d5a5a353 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 28 Jul 2015 17:32:14 +0300 Subject: [PATCH 20/25] Added multiple domain emails #2786 --- app/jobs/domain_update_confirm_job.rb | 2 +- app/mailers/domain_mailer.rb | 45 +++++- app/models/domain.rb | 5 +- app/models/epp/domain.rb | 4 +- ...d_notification_for_new_registrant.html.erb | 19 +++ ...d_notification_for_new_registrant.text.erb | 19 +++ ..._notification_for_new_registrant.html.erb} | 0 ..._notification_for_new_registrant.text.erb} | 0 ..._notification_for_new_registrant.html.erb} | 0 ..._notification_for_new_registrant.text.erb} | 0 ...pdate_request_for_old_registrant.html.erb} | 0 ...pdate_request_for_old_registrant.text.erb} | 0 ..._notification_for_new_registrant.html.erb} | 0 ..._notification_for_new_registrant.text.erb} | 0 ...d_notification_for_old_registrant.html.erb | 21 +++ ...d_notification_for_old_registrant.text.erb | 21 +++ config/locales/en.yml | 10 +- spec/mailers/domain_mailer_spec.rb | 144 ++++++++++++++---- 18 files changed, 243 insertions(+), 47 deletions(-) create mode 100644 app/views/mailers/domain_mailer/pending_update_expired_notification_for_new_registrant.html.erb create mode 100644 app/views/mailers/domain_mailer/pending_update_expired_notification_for_new_registrant.text.erb rename app/views/mailers/domain_mailer/{pending_update_new_registrant_notification.html.erb => pending_update_notification_for_new_registrant.html.erb} (100%) rename app/views/mailers/domain_mailer/{pending_update_new_registrant_notification.text.erb => pending_update_notification_for_new_registrant.text.erb} (100%) rename app/views/mailers/domain_mailer/{pending_update_rejected_new_registrant_notification.html.erb => pending_update_rejected_notification_for_new_registrant.html.erb} (100%) rename app/views/mailers/domain_mailer/{pending_update_rejected_new_registrant_notification.text.erb => pending_update_rejected_notification_for_new_registrant.text.erb} (100%) rename app/views/mailers/domain_mailer/{pending_update_old_registrant_request.html.erb => pending_update_request_for_old_registrant.html.erb} (100%) rename app/views/mailers/domain_mailer/{pending_update_old_registrant_request.text.erb => pending_update_request_for_old_registrant.text.erb} (100%) rename app/views/mailers/domain_mailer/{registrant_updated.html.erb => registrant_updated_notification_for_new_registrant.html.erb} (100%) rename app/views/mailers/domain_mailer/{registrant_updated.text.erb => registrant_updated_notification_for_new_registrant.text.erb} (100%) create mode 100644 app/views/mailers/domain_mailer/registrant_updated_notification_for_old_registrant.html.erb create mode 100644 app/views/mailers/domain_mailer/registrant_updated_notification_for_old_registrant.text.erb diff --git a/app/jobs/domain_update_confirm_job.rb b/app/jobs/domain_update_confirm_job.rb index 9fd21f22e..ab57e0a45 100644 --- a/app/jobs/domain_update_confirm_job.rb +++ b/app/jobs/domain_update_confirm_job.rb @@ -8,7 +8,7 @@ class DomainUpdateConfirmJob < Que::Job domain.apply_pending_update! domain.clean_pendings! when RegistrantVerification::REJECTED - DomainMailer.pending_update_rejected_new_registrant_notification(domain).deliver_now + DomainMailer.pending_update_rejected_notification_for_new_registrant(domain).deliver_now domain.clean_pendings! end destroy # it's best to destroy the job in the same transaction diff --git a/app/mailers/domain_mailer.rb b/app/mailers/domain_mailer.rb index 00b5cfb8d..eb724a222 100644 --- a/app/mailers/domain_mailer.rb +++ b/app/mailers/domain_mailer.rb @@ -1,5 +1,5 @@ class DomainMailer < ApplicationMailer - def pending_update_old_registrant_request(domain) + def pending_update_request_for_old_registrant(domain) @domain = domain return if delivery_off?(@domain) @@ -20,11 +20,11 @@ class DomainMailer < ApplicationMailer return if whitelist_blocked?(@old_registrant.email) mail(to: @old_registrant.email, - subject: "#{I18n.t(:pending_update_old_registrant_request_subject, + subject: "#{I18n.t(:pending_update_request_for_old_registrant_subject, name: @domain.name)} [#{@domain.name}]") end - def pending_update_new_registrant_notification(domain) + def pending_update_notification_for_new_registrant(domain) @domain = domain return if delivery_off?(@domain) @@ -43,21 +43,33 @@ class DomainMailer < ApplicationMailer return if whitelist_blocked?(@new_registrant.email) mail(to: @new_registrant.email, - subject: "#{I18n.t(:pending_update_new_registrant_notification_subject, + subject: "#{I18n.t(:pending_update_notification_for_new_registrant_subject, name: @domain.name)} [#{@domain.name}]") end - def registrant_updated(domain) + def registrant_updated_notification_for_new_registrant(domain) @domain = domain return if delivery_off?(@domain) return if whitelist_blocked?(@domain.registrant_email) mail(to: @domain.registrant_email, - subject: "#{I18n.t(:domain_registrant_updated, + subject: "#{I18n.t(:registrant_updated_notification_for_new_registrant_subject, name: @domain.name)} [#{@domain.name}]") end - def pending_update_rejected_new_registrant_notification(domain) + def registrant_updated_notification_for_old_registrant(domain) + @domain = domain + return if delivery_off?(@domain) + + @old_registrant_email = domain.registrant_email # Nb! before applying pending updates + + return if whitelist_blocked?(@old_registrant_email) + mail(to: @old_registrant_email, + subject: "#{I18n.t(:registrant_updated_notification_for_old_registrant_subject, + name: @domain.name)} [#{@domain.name}]") + end + + def pending_update_rejected_notification_for_new_registrant(domain) @domain = domain # no delivery off control, driggered by que, no epp request @@ -66,7 +78,24 @@ class DomainMailer < ApplicationMailer return if whitelist_blocked?(@new_registrant_email) mail(to: @new_registrant_email, - subject: "#{I18n.t(:pending_update_rejected_new_registrant_notification_subject, + subject: "#{I18n.t(:pending_update_rejected_notification_for_new_registrant_subject, + name: @domain.name)} [#{@domain.name}]") + end + + def pending_update_expired_notification_for_new_registrant(domain) + @domain = domain + # no delivery off control, driggered by cron, no epp request + + @new_registrant_email = @domain.pending_json[:new_registrant_email] + @new_registrant_name = @domain.pending_json[:new_registrant_name] + + return if whitelist_blocked?(@new_registrant_email) + if @new_registrant_email.blank? + logger.info "EMAIL NOT DELIVERED: no registrant email [pending_update_expired_notification_for_new_registrant]" + return + end + mail(to: @new_registrant_email, + subject: "#{I18n.t(:pending_update_expired_notification_for_new_registrant_subject, name: @domain.name)} [#{@domain.name}]") end diff --git a/app/models/domain.rb b/app/models/domain.rb index 98d1e5697..014faf0c5 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -198,6 +198,7 @@ class Domain < ActiveRecord::Base next end count += 1 + DomainMailer.pending_update_expired_notification_for_new_registrant(domain).deliver_now domain.clean_pendings! STDOUT << "#{Time.zone.now.utc} Domain.clean_expired_pendings: ##{domain.id}\n" unless Rails.env.test? end @@ -363,8 +364,8 @@ class Domain < ActiveRecord::Base new_registrant_email = registrant.email new_registrant_name = registrant.name - DomainMailer.pending_update_old_registrant_request(self).deliver_now - DomainMailer.pending_update_new_registrant_notification(self).deliver_now + DomainMailer.pending_update_request_for_old_registrant(self).deliver_now + DomainMailer.pending_update_notification_for_new_registrant(self).deliver_now reload # revert back to original diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index cd2a6bf82..cc5dba270 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -420,6 +420,7 @@ class Epp::Domain < Domain # rubocop: enable Metrics/AbcSize def apply_pending_update! + old_registrant_email = DomainMailer.registrant_updated_notification_for_old_registrant(self) preclean_pendings user = ApiUser.find(pending_json['current_user_id']) frame = Nokogiri::XML(pending_json['frame']) @@ -428,7 +429,8 @@ class Epp::Domain < Domain return unless update(frame, user, false) clean_pendings! self.deliver_emails = true # turn on email delivery for epp - DomainMailer.registrant_updated(self).deliver_now + DomainMailer.registrant_updated_notification_for_new_registrant(self).deliver_now + old_registrant_email.deliver_now end def apply_pending_delete! diff --git a/app/views/mailers/domain_mailer/pending_update_expired_notification_for_new_registrant.html.erb b/app/views/mailers/domain_mailer/pending_update_expired_notification_for_new_registrant.html.erb new file mode 100644 index 000000000..a8bf8723d --- /dev/null +++ b/app/views/mailers/domain_mailer/pending_update_expired_notification_for_new_registrant.html.erb @@ -0,0 +1,19 @@ +Tere, +

+Domeeni <%= @domain.name %> registreerija <%= @domain.registrant_name %> ei kinnitanud tähtaegselt registreerija vahetuse taotlust. Domeeni <%= @domain.name %> registreerija vahetus on sellest tulenevalt tühistatud. +

+Küsimuste korral palun võtke ühendust registripidajaga <%= @domain.registrar_name %>, kelle kontaktid leiate http://internet.ee/registripidajad/akrediteeritud-registripidajad +

+Lugupidamisega
+Eesti Interneti SA +

+
+

+Hi, +

+Domain registrant change has been expired for the domain <%= @domain.name %>. +

+Please contact to your registrar <%= @domain.registrar_name %> if you have any questions. +

+Best Regards,
+Estonian Internet Foundation diff --git a/app/views/mailers/domain_mailer/pending_update_expired_notification_for_new_registrant.text.erb b/app/views/mailers/domain_mailer/pending_update_expired_notification_for_new_registrant.text.erb new file mode 100644 index 000000000..020a9da65 --- /dev/null +++ b/app/views/mailers/domain_mailer/pending_update_expired_notification_for_new_registrant.text.erb @@ -0,0 +1,19 @@ +Tere, + +Domeeni <%= @domain.name %> registreerija <%= @domain.registrant_name %> ei kinnitanud tähtaegselt registreerija vahetuse taotlust. Domeeni <%= @domain.name %> registreerija vahetus on sellest tulenevalt tühistatud. + +Küsimuste korral palun võtke ühendust registripidajaga <%= @domain.registrar_name %>, kelle kontaktid leiate http://internet.ee/registripidajad/akrediteeritud-registripidajad + +Lugupidamisega +Eesti Interneti SA + +-------------------------------------- + +Hi, + +Domain registrant change has been expired for the domain <%= @domain.name %>. + +Please contact to your registrar <%= @domain.registrar_name %> if you have any questions. + +Best Regards, +Estonian Internet Foundation diff --git a/app/views/mailers/domain_mailer/pending_update_new_registrant_notification.html.erb b/app/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.html.erb similarity index 100% rename from app/views/mailers/domain_mailer/pending_update_new_registrant_notification.html.erb rename to app/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.html.erb diff --git a/app/views/mailers/domain_mailer/pending_update_new_registrant_notification.text.erb b/app/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.text.erb similarity index 100% rename from app/views/mailers/domain_mailer/pending_update_new_registrant_notification.text.erb rename to app/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.text.erb diff --git a/app/views/mailers/domain_mailer/pending_update_rejected_new_registrant_notification.html.erb b/app/views/mailers/domain_mailer/pending_update_rejected_notification_for_new_registrant.html.erb similarity index 100% rename from app/views/mailers/domain_mailer/pending_update_rejected_new_registrant_notification.html.erb rename to app/views/mailers/domain_mailer/pending_update_rejected_notification_for_new_registrant.html.erb diff --git a/app/views/mailers/domain_mailer/pending_update_rejected_new_registrant_notification.text.erb b/app/views/mailers/domain_mailer/pending_update_rejected_notification_for_new_registrant.text.erb similarity index 100% rename from app/views/mailers/domain_mailer/pending_update_rejected_new_registrant_notification.text.erb rename to app/views/mailers/domain_mailer/pending_update_rejected_notification_for_new_registrant.text.erb diff --git a/app/views/mailers/domain_mailer/pending_update_old_registrant_request.html.erb b/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb similarity index 100% rename from app/views/mailers/domain_mailer/pending_update_old_registrant_request.html.erb rename to app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb diff --git a/app/views/mailers/domain_mailer/pending_update_old_registrant_request.text.erb b/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb similarity index 100% rename from app/views/mailers/domain_mailer/pending_update_old_registrant_request.text.erb rename to app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb diff --git a/app/views/mailers/domain_mailer/registrant_updated.html.erb b/app/views/mailers/domain_mailer/registrant_updated_notification_for_new_registrant.html.erb similarity index 100% rename from app/views/mailers/domain_mailer/registrant_updated.html.erb rename to app/views/mailers/domain_mailer/registrant_updated_notification_for_new_registrant.html.erb diff --git a/app/views/mailers/domain_mailer/registrant_updated.text.erb b/app/views/mailers/domain_mailer/registrant_updated_notification_for_new_registrant.text.erb similarity index 100% rename from app/views/mailers/domain_mailer/registrant_updated.text.erb rename to app/views/mailers/domain_mailer/registrant_updated_notification_for_new_registrant.text.erb diff --git a/app/views/mailers/domain_mailer/registrant_updated_notification_for_old_registrant.html.erb b/app/views/mailers/domain_mailer/registrant_updated_notification_for_old_registrant.html.erb new file mode 100644 index 000000000..bdfda76dc --- /dev/null +++ b/app/views/mailers/domain_mailer/registrant_updated_notification_for_old_registrant.html.erb @@ -0,0 +1,21 @@ +Tere, +

+Domeeni <%= @domain.name %> registreerija vahetuse taotlus on kinnitatud ning andmed registris uuendatud. +

+Uued registreerija:
+Nimi: <%= @domain.registrant_name %> +

+Lugupidamisega
+Eesti Interneti SA +

+
+

+Hi, +

+Process for changing registrant of the domain <%= @domain.name %> has been approved and the data in the registry is updated. +

+New registrant:
+Name: <%= @domain.registrant_name %> +

+Best Regards,
+Estonian Internet Foundation diff --git a/app/views/mailers/domain_mailer/registrant_updated_notification_for_old_registrant.text.erb b/app/views/mailers/domain_mailer/registrant_updated_notification_for_old_registrant.text.erb new file mode 100644 index 000000000..08fb37fe0 --- /dev/null +++ b/app/views/mailers/domain_mailer/registrant_updated_notification_for_old_registrant.text.erb @@ -0,0 +1,21 @@ +Tere, + +Domeeni <%= @domain.name %> registreerija vahetuse taotlus on kinnitatud ning andmed registris uuendatud. + +Uued registreerija: +Nimi: <%= @domain.registrant_name %> + +Lugupidamisega +Eesti Interneti SA + +-------------------------------------- + +Hi, + +Process for changing registrant of the domain <%= @domain.name %> has been approved and the data in the registry is updated. + +New registrant: +Name: <%= @domain.registrant_name %> + +Best Regards, +Estonian Internet Foundation diff --git a/config/locales/en.yml b/config/locales/en.yml index 837ee6b35..98f759105 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -777,9 +777,12 @@ en: 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' object_status_prohibits_operation: 'Object status prohibits operation' - pending_update_old_registrant_request_subject: "Kinnitustaotlus domeeni %{name} registreerija vahetuseks / Application for approval for registrant chache of %{name}" - pending_update_new_registrant_notification_subject: "Domeeni %{name} registreerija vahetus protseduur on algatatud / %{name} registrant change" - pending_update_rejected_new_registrant_notification_subject: "Domeeni %{name} registreerija vahetuse taotlus tagasi lükatud / %{name} registrant change declined" + pending_update_request_for_old_registrant_subject: "Kinnitustaotlus domeeni %{name} registreerija vahetuseks / Application for approval for registrant chache of %{name}" + pending_update_notification_for_new_registrant_subject: "Domeeni %{name} registreerija vahetus protseduur on algatatud / %{name} registrant change" + pending_update_rejected_notification_for_new_registrant_subject: "Domeeni %{name} registreerija vahetuse taotlus tagasi lükatud / %{name} registrant change declined" + pending_update_expired_notification_for_new_registrant_subject: "Domeeni %{name} registreerija vahetuse taotlus on tühistatud / %{name} registrant change cancelled" + registrant_updated_notification_for_new_registrant_subject: 'Domeeni %{name} registreerija vahetus teostatud / Registrant change of %{name} has been finished.' + registrant_updated_notification_for_old_registrant_subject: 'Domeeni %{name} registreerija vahetus teostatud / Registrant change of %{name} has been finished.' domain_pending_deleted_subject: "Kinnitustaotlus domeeni %{name} kustutamiseks .ee registrist / Application for approval for deletion of %{name}" whois: WHOIS login_failed_check_id_card: 'Log in failed, check ID card' @@ -874,7 +877,6 @@ en: no_transfers_found: 'No transfers found' parameter_value_range_error: 'Parameter value range error: %{key}' payment_received: 'Payment received' - domain_registrant_updated: 'Domeeni %{name} registreerija vahetus teostatud / Registrant change of %{name} has been finished.' api_user_not_found: 'API user not found' domain_already_belongs_to_the_querying_registrar: 'Domain already belongs to the querying registrar' notes: Notes diff --git a/spec/mailers/domain_mailer_spec.rb b/spec/mailers/domain_mailer_spec.rb index a78e4d030..f1765d308 100644 --- a/spec/mailers/domain_mailer_spec.rb +++ b/spec/mailers/domain_mailer_spec.rb @@ -1,11 +1,11 @@ require 'rails_helper' describe DomainMailer do - describe 'registrant change request for old registrant when delivery turned off' do + describe 'pending update request for an old registrant when delivery turned off' do before :all do @registrant = Fabricate(:registrant, email: 'test@example.com') @domain = Fabricate(:domain, registrant: @registrant) - @mail = DomainMailer.pending_update_old_registrant_request(@domain) + @mail = DomainMailer.pending_update_request_for_old_registrant(@domain) end it 'should not render email subject' do @@ -25,7 +25,7 @@ describe DomainMailer do end end - describe 'registrant change request for old registrant' do + describe 'pending update request for an old registrant' do before :all do @registrant = Fabricate(:registrant, email: 'test@example.com') @new_registrant = Fabricate(:registrant, email: 'test@example.org') @@ -34,7 +34,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_old_registrant_request(@domain) + @mail = DomainMailer.pending_update_request_for_old_registrant(@domain) end it 'should render email subject' do @@ -58,7 +58,7 @@ describe DomainMailer do end end - describe 'registrant change notification for new registrant' do + describe 'pending upadte notification for a new registrant' do before :all do @registrant = Fabricate(:registrant, email: 'old@example.com') @new_registrant = Fabricate(:registrant, email: 'new@example.org') @@ -67,7 +67,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_new_registrant_notification(@domain) + @mail = DomainMailer.pending_update_notification_for_new_registrant(@domain) end it 'should render email subject' do @@ -87,6 +87,113 @@ describe DomainMailer do end end + describe 'pending update notification for a new registrant' do + before :all do + @registrant = Fabricate(:registrant, email: 'old@example.com') + @new_registrant = Fabricate(:registrant, email: 'new@example.org') + @domain = Fabricate(:domain, registrant: @registrant) + @domain.deliver_emails = true + @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) + end + + it 'should render email subject' do + @mail.subject.should =~ /protseduur on algatatud/ + end + + it 'should have sender email' do + @mail.from.should == ["noreply@internet.ee"] + end + + it 'should send confirm email to new registrant email' do + @mail.to.should == ["new@example.org"] + end + + it 'should render body' do + @mail.body.encoded.should =~ /vahendusel on algatatud/ + end + end + + describe 'pending update rejected notification for a new registrant' do + before :all do + @registrant = Fabricate(:registrant, email: 'old@example.com') + @new_registrant = Fabricate(:registrant, email: 'new@example.org') + @domain = Fabricate(:domain, registrant: @registrant) + @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) + end + + it 'should render email subject' do + @mail.subject.should =~ /vahetuse taotlus tagasi lükatud/ + end + + it 'should have sender email' do + @mail.from.should == ["noreply@internet.ee"] + end + + it 'should send confirm email to new registrant email' do + @mail.to.should == ["new@example.org"] + end + + it 'should render body' do + @mail.body.encoded.should =~ /Registrant change was declined/ + end + end + + describe 'registrant updated notification for a new registrant' do + before :all 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) + end + + it 'should render email subject' do + @mail.subject.should =~ /registreerija vahetus teostatud/ + end + + it 'should have sender email' do + @mail.from.should == ["noreply@internet.ee"] + end + + it 'should send to registrant email' do + @mail.to.should == ["test@example.com"] + end + + it 'should render body' do + @mail.body.encoded.should =~ /registreerija vahetuse taotlus on kinnitatud/ + end + end + + describe 'registrant updated notification for a old registrant' do + before :all 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) + end + + it 'should render email subject' do + @mail.subject.should =~ /registreerija vahetus teostatud/ + end + + it 'should have sender email' do + @mail.from.should == ["noreply@internet.ee"] + end + + it 'should send to registrant email' do + @mail.to.should == ["test@example.com"] + end + + it 'should render body' do + @mail.body.encoded.should =~ /registreerija vahetuse taotlus on kinnitatud/ + end + end + describe 'domain pending delete notification when delivery turned off' do before :all do @registrant = Fabricate(:registrant, email: 'test@example.com') @@ -141,29 +248,4 @@ describe DomainMailer do @mail.body.encoded.should =~ %r{registrant\/domain_delete_con} # somehowe delete_confirms not matching end end - - describe 'registrant successfully changed confirmation' do - before :all do - @registrant = Fabricate(:registrant, email: 'test@example.com') - @domain = Fabricate(:domain, registrant: @registrant) - @domain.deliver_emails = true - @mail = DomainMailer.registrant_updated(@domain) - end - - it 'should render email subject' do - @mail.subject.should =~ /registreerija vahetus teostatud/ - end - - it 'should have sender email' do - @mail.from.should == ["noreply@internet.ee"] - end - - it 'should send to registrant email' do - @mail.to.should == ["test@example.com"] - end - - it 'should render body' do - @mail.body.encoded.should =~ /registreerija vahetuse taotlus on kinnitatud/ - end - end end From acb9f2ee087cf4d31891fdb00a1602ee5bc62498 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 28 Jul 2015 17:49:35 +0300 Subject: [PATCH 21/25] Added domain delete rejection notification #2786 --- app/jobs/domain_delete_confirm_job.rb | 1 + app/mailers/domain_mailer.rb | 20 ++++++++++++++ ...ding_delete_rejected_notification.html.erb | 15 +++++++++++ ...ding_delete_rejected_notification.text.erb | 15 +++++++++++ config/locales/en.yml | 1 + spec/mailers/domain_mailer_spec.rb | 27 +++++++++++++++++++ 6 files changed, 79 insertions(+) create mode 100644 app/views/mailers/domain_mailer/pending_delete_rejected_notification.html.erb create mode 100644 app/views/mailers/domain_mailer/pending_delete_rejected_notification.text.erb diff --git a/app/jobs/domain_delete_confirm_job.rb b/app/jobs/domain_delete_confirm_job.rb index 90a76e47b..153ef7012 100644 --- a/app/jobs/domain_delete_confirm_job.rb +++ b/app/jobs/domain_delete_confirm_job.rb @@ -8,6 +8,7 @@ class DomainDeleteConfirmJob < Que::Job domain.apply_pending_delete! domain.clean_pendings! when RegistrantVerification::REJECTED + DomainMailer.pending_delete_rejected_notification(domain).deliver_now domain.clean_pendings! end destroy # it's best to destroy the job in the same transaction diff --git a/app/mailers/domain_mailer.rb b/app/mailers/domain_mailer.rb index eb724a222..0e7614199 100644 --- a/app/mailers/domain_mailer.rb +++ b/app/mailers/domain_mailer.rb @@ -123,4 +123,24 @@ class DomainMailer < ApplicationMailer subject: "#{I18n.t(:domain_pending_deleted_subject, name: @domain.name)} [#{@domain.name}]") end + + def pending_delete_rejected_notification(domain) + @domain = domain + # no delivery off control, driggered by que, no epp request + + if @domain.registrant_verification_token.blank? + logger.warn "EMAIL NOT DELIVERED: registrant_verification_token is missing for #{@domain.name}" + return + end + + if @domain.registrant_verification_asked_at.blank? + logger.warn "EMAIL NOT DELIVERED: registrant_verification_asked_at is missing for #{@domain.name}" + return + end + + return if whitelist_blocked?(@domain.registrant.email) + mail(to: @domain.registrant.email, + subject: "#{I18n.t(:pending_delete_rejected_notification_subject, + name: @domain.name)} [#{@domain.name}]") + end end diff --git a/app/views/mailers/domain_mailer/pending_delete_rejected_notification.html.erb b/app/views/mailers/domain_mailer/pending_delete_rejected_notification.html.erb new file mode 100644 index 000000000..e89a02327 --- /dev/null +++ b/app/views/mailers/domain_mailer/pending_delete_rejected_notification.html.erb @@ -0,0 +1,15 @@ +Tere, +

+Domeeni <%= @domain.name %> kustutamise taotlus on registreerija <%= @domain.registrar_name %> poolt tagasi lükatud. +

+Lugupidamisega
+Eesti Interneti SA +

+
+

+Hi, +

+Domain <%= @domain.name %> deletion rejected. +

+Best Regards,
+Estonian Internet Foundation diff --git a/app/views/mailers/domain_mailer/pending_delete_rejected_notification.text.erb b/app/views/mailers/domain_mailer/pending_delete_rejected_notification.text.erb new file mode 100644 index 000000000..d3600a3c7 --- /dev/null +++ b/app/views/mailers/domain_mailer/pending_delete_rejected_notification.text.erb @@ -0,0 +1,15 @@ +Tere, + +Domeeni <%= @domain.name %> kustutamise taotlus on registreerija <%= @domain.registrar_name %> poolt tagasi lükatud. + +Lugupidamisega +Eesti Interneti SA + +-------------------------------------- + +Hi, + +Domain <%= @domain.name %> deletion rejected. + +Best Regards, +Estonian Internet Foundation diff --git a/config/locales/en.yml b/config/locales/en.yml index 98f759105..9defb35db 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -784,6 +784,7 @@ en: registrant_updated_notification_for_new_registrant_subject: 'Domeeni %{name} registreerija vahetus teostatud / Registrant change of %{name} has been finished.' registrant_updated_notification_for_old_registrant_subject: 'Domeeni %{name} registreerija vahetus teostatud / Registrant change of %{name} has been finished.' domain_pending_deleted_subject: "Kinnitustaotlus domeeni %{name} kustutamiseks .ee registrist / Application for approval for deletion of %{name}" + pending_delete_rejected_notification_subject: "Domeeni %{name} kustutamise taotlus tagasi lükatud / %{name) deletion declined" whois: WHOIS login_failed_check_id_card: 'Log in failed, check ID card' not_valid_domain_verification_title: Domain verification not available diff --git a/spec/mailers/domain_mailer_spec.rb b/spec/mailers/domain_mailer_spec.rb index f1765d308..44e6d0e42 100644 --- a/spec/mailers/domain_mailer_spec.rb +++ b/spec/mailers/domain_mailer_spec.rb @@ -248,4 +248,31 @@ describe DomainMailer do @mail.body.encoded.should =~ %r{registrant\/domain_delete_con} # somehowe delete_confirms not matching end end + + describe 'email pending delete notification' do + before :all do + @registrant = Fabricate(:registrant, email: 'test@example.com') + @domain = Fabricate(:domain, name: 'delete-pending-rejected.ee', registrant: @registrant) + @domain.deliver_emails = true + @domain.registrant_verification_token = '123' + @domain.registrant_verification_asked_at = Time.zone.now + @mail = DomainMailer.pending_delete_rejected_notification(@domain) + end + + it 'should render email subject' do + @mail.subject.should =~ /kustutamise taotlus tagasi lükatud/ + end + + it 'should have sender email' do + @mail.from.should == ["noreply@internet.ee"] + end + + it 'should send confirm email to old registrant email' do + @mail.to.should == ["test@example.com"] + end + + it 'should render body' do + @mail.body.encoded.should =~ /deletion rejected/ + end + end end From 5883452fa291b40b88fbafb230dbf8a9f8bcc695 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 28 Jul 2015 18:07:47 +0300 Subject: [PATCH 22/25] Added pending delete expired email #2786 --- app/mailers/domain_mailer.rb | 10 +++++++ app/models/domain.rb | 9 +++++- ...nding_delete_expired_notification.html.erb | 15 ++++++++++ ...nding_delete_expired_notification.text.erb | 15 ++++++++++ config/locales/en.yml | 1 + spec/mailers/domain_mailer_spec.rb | 29 ++++++++++++++++++- 6 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 app/views/mailers/domain_mailer/pending_delete_expired_notification.html.erb create mode 100644 app/views/mailers/domain_mailer/pending_delete_expired_notification.text.erb diff --git a/app/mailers/domain_mailer.rb b/app/mailers/domain_mailer.rb index 0e7614199..9b942504b 100644 --- a/app/mailers/domain_mailer.rb +++ b/app/mailers/domain_mailer.rb @@ -143,4 +143,14 @@ class DomainMailer < ApplicationMailer subject: "#{I18n.t(:pending_delete_rejected_notification_subject, name: @domain.name)} [#{@domain.name}]") end + + def pending_delete_expired_notification(domain) + @domain = domain + # no delivery off control, driggered by cron, no epp request + + return if whitelist_blocked?(@domain.registrant.email) + mail(to: @domain.registrant.email, + subject: "#{I18n.t(:pending_delete_expired_notification_subject, + name: @domain.name)} [#{@domain.name}]") + end end diff --git a/app/models/domain.rb b/app/models/domain.rb index 014faf0c5..b951e7f8e 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -184,6 +184,7 @@ class Domain < ActiveRecord::Base # rubocop: disable Metrics/AbcSize # rubocop: disable Metrics/CyclomaticComplexity + # rubocop: disable Metrics/PerceivedComplexity def clean_expired_pendings STDOUT << "#{Time.zone.now.utc} - Clean expired domain pendings\n" unless Rails.env.test? @@ -198,13 +199,19 @@ class Domain < ActiveRecord::Base next end count += 1 - DomainMailer.pending_update_expired_notification_for_new_registrant(domain).deliver_now + if domain.pending_update? + DomainMailer.pending_update_expired_notification_for_new_registrant(domain).deliver_now + end + if domain.pending_delete? + DomainMailer.pending_delete_expired_notification(domain).deliver_now + end domain.clean_pendings! STDOUT << "#{Time.zone.now.utc} Domain.clean_expired_pendings: ##{domain.id}\n" unless Rails.env.test? end STDOUT << "#{Time.zone.now.utc} - Successfully cancelled #{count} domain pendings\n" unless Rails.env.test? count end + # rubocop: enable Metrics/PerceivedComplexity # rubocop: enable Metrics/AbcSize # rubocop: enable Metrics/CyclomaticComplexity diff --git a/app/views/mailers/domain_mailer/pending_delete_expired_notification.html.erb b/app/views/mailers/domain_mailer/pending_delete_expired_notification.html.erb new file mode 100644 index 000000000..c5ed71c39 --- /dev/null +++ b/app/views/mailers/domain_mailer/pending_delete_expired_notification.html.erb @@ -0,0 +1,15 @@ +Tere, +

+Domeeni <%= @domain.name %> kustutamise taotlust ei kinnitatud tähtaegselt registreerija <%= @domain.registrant_name %> poolt. Domeeni <%= @domain.name %> kustutamine on sellest tulenevalt tühistatud. +

+Lugupidamisega
+Eesti Interneti SA +

+
+

+Hi, +

+Domain <%= @domain.name %> deletion cancelled. +

+Best Regards,
+Estonian Internet Foundation diff --git a/app/views/mailers/domain_mailer/pending_delete_expired_notification.text.erb b/app/views/mailers/domain_mailer/pending_delete_expired_notification.text.erb new file mode 100644 index 000000000..5ff510820 --- /dev/null +++ b/app/views/mailers/domain_mailer/pending_delete_expired_notification.text.erb @@ -0,0 +1,15 @@ +Tere, + +Domeeni <%= @domain.name %> kustutamise taotlust ei kinnitatud tähtaegselt registreerija <%= @domain.registrant_name %> poolt. Domeeni <%= @domain.name %> kustutamine on sellest tulenevalt tühistatud. + +Lugupidamisega +Eesti Interneti SA + +-------------------------------------- + +Hi, + +Domain <%= @domain.name %> deletion cancelled. + +Best Regards, +Estonian Internet Foundation diff --git a/config/locales/en.yml b/config/locales/en.yml index 9defb35db..bebe2bef0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -785,6 +785,7 @@ en: registrant_updated_notification_for_old_registrant_subject: 'Domeeni %{name} registreerija vahetus teostatud / Registrant change of %{name} has been finished.' domain_pending_deleted_subject: "Kinnitustaotlus domeeni %{name} kustutamiseks .ee registrist / Application for approval for deletion of %{name}" pending_delete_rejected_notification_subject: "Domeeni %{name} kustutamise taotlus tagasi lükatud / %{name) deletion declined" + pending_delete_expired_notification_subject: "Domeeni %{name} kustutamise taotlus on tühistatud / %{name} deletion cancelled" whois: WHOIS login_failed_check_id_card: 'Log in failed, check ID card' not_valid_domain_verification_title: Domain verification not available diff --git a/spec/mailers/domain_mailer_spec.rb b/spec/mailers/domain_mailer_spec.rb index 44e6d0e42..9d5172352 100644 --- a/spec/mailers/domain_mailer_spec.rb +++ b/spec/mailers/domain_mailer_spec.rb @@ -249,7 +249,7 @@ describe DomainMailer do end end - describe 'email pending delete notification' do + describe 'pending delete rejected notification' do before :all do @registrant = Fabricate(:registrant, email: 'test@example.com') @domain = Fabricate(:domain, name: 'delete-pending-rejected.ee', registrant: @registrant) @@ -275,4 +275,31 @@ describe DomainMailer do @mail.body.encoded.should =~ /deletion rejected/ end end + + describe 'pending delete rejected notification' do + before :all do + @registrant = Fabricate(:registrant, email: 'test@example.com') + @domain = Fabricate(:domain, name: 'delete-pending-expired.ee', registrant: @registrant) + @domain.deliver_emails = true + @domain.registrant_verification_token = '123' + @domain.registrant_verification_asked_at = Time.zone.now + @mail = DomainMailer.pending_delete_expired_notification(@domain) + end + + it 'should render email subject' do + @mail.subject.should =~ /deletion cancelled/ + end + + it 'should have sender email' do + @mail.from.should == ["noreply@internet.ee"] + end + + it 'should send confirm email to old registrant email' do + @mail.to.should == ["test@example.com"] + end + + it 'should render body' do + @mail.body.encoded.should =~ /deletion cancelled/ + end + end end From f89992d1203fe0aa667c7d071d319c7af1887365 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 28 Jul 2015 19:02:08 +0300 Subject: [PATCH 23/25] Added delete confirm email #2786 --- app/mailers/domain_mailer.rb | 9 ++++++ app/models/epp/domain.rb | 1 + .../delete_confirmation.html.erb | 15 +++++++++ .../delete_confirmation.text.erb | 15 +++++++++ config/locales/en.yml | 1 + spec/mailers/domain_mailer_spec.rb | 31 +++++++++++++++++-- 6 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 app/views/mailers/domain_mailer/delete_confirmation.html.erb create mode 100644 app/views/mailers/domain_mailer/delete_confirmation.text.erb diff --git a/app/mailers/domain_mailer.rb b/app/mailers/domain_mailer.rb index 9b942504b..1eb4341c9 100644 --- a/app/mailers/domain_mailer.rb +++ b/app/mailers/domain_mailer.rb @@ -153,4 +153,13 @@ class DomainMailer < ApplicationMailer subject: "#{I18n.t(:pending_delete_expired_notification_subject, name: @domain.name)} [#{@domain.name}]") end + + def delete_confirmation(domain) + @domain = domain + + return if whitelist_blocked?(@domain.registrant.email) + mail(to: @domain.registrant.email, + subject: "#{I18n.t(:delete_confirmation_subject, + name: @domain.name)} [#{@domain.name}]") + end end diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index cc5dba270..2cd3458a4 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -438,6 +438,7 @@ class Epp::Domain < Domain user = ApiUser.find(pending_json['current_user_id']) frame = Nokogiri::XML(pending_json['frame']) statuses.delete(DomainStatus::PENDING_DELETE) + DomainMailer.delete_confirmation(self).deliver_now clean_pendings! if epp_destroy(frame, user, false) end diff --git a/app/views/mailers/domain_mailer/delete_confirmation.html.erb b/app/views/mailers/domain_mailer/delete_confirmation.html.erb new file mode 100644 index 000000000..acc915787 --- /dev/null +++ b/app/views/mailers/domain_mailer/delete_confirmation.html.erb @@ -0,0 +1,15 @@ +Tere, +

+Domeeni <%= @domain.name %> kustutamise taotlus on registreerija poolt kinnitatud. Domeen <%= @domain.name %> on peatatud ja kustub registrist. +

+Lugupidamisega
+Eesti Interneti SA +

+
+

+Hi, +

+Domain <%= @domain.name %> deletion confirmed and will be deleted. +

+Best Regards,
+Estonian Internet Foundation diff --git a/app/views/mailers/domain_mailer/delete_confirmation.text.erb b/app/views/mailers/domain_mailer/delete_confirmation.text.erb new file mode 100644 index 000000000..a587b7f78 --- /dev/null +++ b/app/views/mailers/domain_mailer/delete_confirmation.text.erb @@ -0,0 +1,15 @@ +Tere, + +Domeeni <%= @domain.name %> kustutamise taotlus on registreerija poolt kinnitatud. Domeen <%= @domain.name %> on peatatud ja kustub registrist. + +Lugupidamisega +Eesti Interneti SA + +-------------------------------------- + +Hi, + +Domain <%= @domain.name %> deletion confirmed and will be deleted. + +Best Regards, +Estonian Internet Foundation diff --git a/config/locales/en.yml b/config/locales/en.yml index bebe2bef0..97a17e3da 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -786,6 +786,7 @@ en: domain_pending_deleted_subject: "Kinnitustaotlus domeeni %{name} kustutamiseks .ee registrist / Application for approval for deletion of %{name}" pending_delete_rejected_notification_subject: "Domeeni %{name} kustutamise taotlus tagasi lükatud / %{name) deletion declined" pending_delete_expired_notification_subject: "Domeeni %{name} kustutamise taotlus on tühistatud / %{name} deletion cancelled" + delete_confirmation_subject: "Domeeni %{name} kustutatud / %{name} deleted" whois: WHOIS login_failed_check_id_card: 'Log in failed, check ID card' not_valid_domain_verification_title: Domain verification not available diff --git a/spec/mailers/domain_mailer_spec.rb b/spec/mailers/domain_mailer_spec.rb index 9d5172352..bf06d4677 100644 --- a/spec/mailers/domain_mailer_spec.rb +++ b/spec/mailers/domain_mailer_spec.rb @@ -276,10 +276,10 @@ describe DomainMailer do end end - describe 'pending delete rejected notification' do + describe 'pending delete expired notification' do before :all do @registrant = Fabricate(:registrant, email: 'test@example.com') - @domain = Fabricate(:domain, name: 'delete-pending-expired.ee', registrant: @registrant) + @domain = Fabricate(:domain, name: 'pending-delete-expired.ee', registrant: @registrant) @domain.deliver_emails = true @domain.registrant_verification_token = '123' @domain.registrant_verification_asked_at = Time.zone.now @@ -302,4 +302,31 @@ describe DomainMailer do @mail.body.encoded.should =~ /deletion cancelled/ end end + + describe 'pending delete rejected notification' do + before :all do + @registrant = Fabricate(:registrant, email: 'test@example.com') + @domain = Fabricate(:domain, name: 'delete-confirmed.ee', registrant: @registrant) + @domain.deliver_emails = true + @domain.registrant_verification_token = '123' + @domain.registrant_verification_asked_at = Time.zone.now + @mail = DomainMailer.delete_confirmation(@domain) + end + + it 'should render email subject' do + @mail.subject.should =~ /deleted/ + end + + it 'should have sender email' do + @mail.from.should == ["noreply@internet.ee"] + end + + it 'should send confirm email to old registrant email' do + @mail.to.should == ["test@example.com"] + end + + it 'should render body' do + @mail.body.encoded.should =~ /confirmed and will be deleted/ + end + end end From 736848d70cb3f3116842404b9f94a198123d852b Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 28 Jul 2015 19:16:04 +0300 Subject: [PATCH 24/25] rubocop updates --- config/initializers/eis_custom_active_model.rb | 2 ++ config/initializers/eis_custom_active_record.rb | 1 + config/initializers/eis_custom_flash.rb | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/config/initializers/eis_custom_active_model.rb b/config/initializers/eis_custom_active_model.rb index f41a42325..ba5f29b06 100644 --- a/config/initializers/eis_custom_active_model.rb +++ b/config/initializers/eis_custom_active_model.rb @@ -1,4 +1,6 @@ # Log all active model user errors +# rubocop: disable Lint/AssignmentInCondition +# rubocop: disable Style/SignalException module ActiveModel class Errors def add(attribute, message = :invalid, options = {}) diff --git a/config/initializers/eis_custom_active_record.rb b/config/initializers/eis_custom_active_record.rb index 546f5a4ae..60dcebeb9 100644 --- a/config/initializers/eis_custom_active_record.rb +++ b/config/initializers/eis_custom_active_record.rb @@ -1,4 +1,5 @@ # Log all user issues raised by active record +# rubocop: disable Metrics/LineLength class ActiveRecord::Base after_validation do |m| Rails.logger.info "USER MSG: ACTIVERECORD: #{m.class} ##{m.id} #{m.errors.full_messages} #{m.errors['epp_errors']}" if m.errors.present? diff --git a/config/initializers/eis_custom_flash.rb b/config/initializers/eis_custom_flash.rb index ed5832e85..4e4d359b5 100644 --- a/config/initializers/eis_custom_flash.rb +++ b/config/initializers/eis_custom_flash.rb @@ -1,6 +1,10 @@ # Log all flash messages +# rubocop: disable Metrics/CyclomaticComplexity +# rubocop: disable Metrics/LineLength module ActionDispatch class Flash + # rubocop: disable Metrics/PerceivedComplexity + # rubocop: disable Style/MultilineOperationIndentation def call(env) @app.call(env) ensure From f2b1705a1e97556fcb7f679eae6e5aefb8ac3661 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 28 Jul 2015 22:09:46 +0300 Subject: [PATCH 25/25] Rubocop update --- app/controllers/admin/pricelists_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/pricelists_controller.rb b/app/controllers/admin/pricelists_controller.rb index ccbe3166f..8037f57f6 100644 --- a/app/controllers/admin/pricelists_controller.rb +++ b/app/controllers/admin/pricelists_controller.rb @@ -4,7 +4,8 @@ class Admin::PricelistsController < AdminController def index @q = Pricelist.search(params[:q]) - @q.sorts = ['category asc', 'duration asc', 'operation_category asc', 'valid_from desc', 'valid_to asc'] if @q.sorts.empty? + @q.sorts = ['category asc', 'duration asc', 'operation_category asc', + 'valid_from desc', 'valid_to asc'] if @q.sorts.empty? @pricelists = @q.result.page(params[:page]) end