diff --git a/app/controllers/epp/domains_controller.rb b/app/controllers/epp/domains_controller.rb index 6050e9d5d..94a077758 100644 --- a/app/controllers/epp/domains_controller.rb +++ b/app/controllers/epp/domains_controller.rb @@ -35,7 +35,7 @@ class Epp::DomainsController < EppController if @domain.update(params[:parsed_frame], current_user) if @domain.epp_pending_update.present? - render_epp_response '/epp/shared/success_pending' + render_epp_response '/epp/domains/success_pending' else render_epp_response '/epp/domains/success' end @@ -56,9 +56,15 @@ class Epp::DomainsController < EppController @domain.attach_legal_document(Epp::Domain.parse_legal_document_from_frame(params[:parsed_frame])) @domain.save(validate: false) - handle_errors(@domain) and return unless @domain.destroy - - render_epp_response '/epp/domains/success' + if @domain.epp_destroy(params[:parsed_frame]) + if @domain.epp_pending_delete.present? + render_epp_response '/epp/domains/success_pending' + else + render_epp_response '/epp/domains/success' + end + else + handle_errors(@domain) + end end # rubocop:enbale Metrics/CyclomaticComplexity diff --git a/app/mailers/domain_mailer.rb b/app/mailers/domain_mailer.rb index b5cb8188e..c9e072395 100644 --- a/app/mailers/domain_mailer.rb +++ b/app/mailers/domain_mailer.rb @@ -1,5 +1,5 @@ class DomainMailer < ApplicationMailer - def registrant_updated(domain) + def registrant_pending_updated(domain) @domain = domain return if Rails.env.production? ? false : !TEST_EMAILS.include?(@domain.registrant_email) @@ -22,6 +22,32 @@ class DomainMailer < ApplicationMailer @verification_url = "#{confirm_path}/#{@domain.id}?token=#{@domain.registrant_verification_token}" mail(to: @old_registrant.email, - subject: "#{I18n.t(:domain_registrant_update_subject, name: @domain.name)} [#{@domain.name}]") + subject: "#{I18n.t(:domain_registrant_pending_updated_subject, name: @domain.name)} [#{@domain.name}]") + end + + def pending_deleted(domain) + @domain = domain + return if Rails.env.production? ? false : !TEST_EMAILS.include?(@domain.registrant_email) + + # turn on delivery on specific request only, thus rake tasks does not deliver anything + return if @domain.deliver_emails != true + + 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 + + @old_registrant = Registrant.find(@domain.registrant_id_was) + + confirm_path = "#{ENV['registrant_url']}/registrant/domain_delete_confirms" + @verification_url = "#{confirm_path}/#{@domain.id}?token=#{@domain.registrant_verification_token}" + + mail(to: @old_registrant.email, + 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 0855b21ed..bbff5c1de 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -117,7 +117,8 @@ class Domain < ActiveRecord::Base validate :validate_nameserver_ips - attr_accessor :registrant_typeahead, :update_me, :deliver_emails, :epp_pending_update + attr_accessor :registrant_typeahead, :update_me, :deliver_emails, + :epp_pending_update, :epp_pending_delete def subordinate_nameservers nameservers.select { |x| x.hostname.end_with?(name) } @@ -176,11 +177,11 @@ class Domain < ActiveRecord::Base def pending_update! return true if pending_update? - self.epp_pending_update = true # for handling epp errors correctly + self.epp_pending_update = true # for epp return true unless registrant_verification_asked? pending_json_cache = all_changes - DomainMailer.registrant_updated(self).deliver_now + DomainMailer.registrant_pending_updated(self).deliver_now reload # revert back to original @@ -206,6 +207,21 @@ class Domain < ActiveRecord::Base self.registrant_verification_token = SecureRandom.hex(42) end + def pending_delete? + (domain_statuses.pluck(:value) & %W( + #{DomainStatus::PENDING_DELETE} + )).present? + end + + def pending_delete! + return true if pending_delete? + self.epp_pending_delete = true # for epp + + return true unless registrant_verification_asked? + domain_statuses.create(value: DomainStatus::PENDING_DELETE) + DomainMailer.pending_deleted(self).deliver_now + end + ### VALIDATIONS ### def validate_nameserver_ips diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 05418b57e..3e2269287 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -4,7 +4,7 @@ class Epp::Domain < Domain before_validation :manage_permissions def manage_permissions - return unless pending_update? + return unless pending_update? || pending_delete? add_epp_error('2304', nil, nil, I18n.t(:object_status_prohibits_operation)) false end @@ -410,6 +410,16 @@ class Epp::Domain < Domain ) end + def epp_destroy(frame) + if frame.css('delete').attr('verified').to_s.downcase != 'yes' + registrant_verification_asked! + pending_delete! + true # aka 1001 pending_delete + else + destroy + end + end + ### RENEW ### def renew(cur_exp_date, period, unit = 'y') diff --git a/app/views/domain_mailer/pending_deleted.html.erb b/app/views/domain_mailer/pending_deleted.html.erb new file mode 100644 index 000000000..a6ba283e0 --- /dev/null +++ b/app/views/domain_mailer/pending_deleted.html.erb @@ -0,0 +1,25 @@ +Tere, +

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

+Muudatuse kinnitamiseks külastage palun allolevat võrgulehekülge, kontrollige uuesti üle muudatuse andmed ning vajutage nuppu kinnitan: +

+Taotlus on aktiivne <48> tundi ja lükatakse automaatselt tagasi kui te seda enne ise ei kinnita või tagasi lükka.
+<%= link_to @verification_url, @verification_url %> +

+Lugupidamisega
+Eesti Interneti SA +

+
+

+Hi, +

+Application for deletion of your domain <%= @domain.name %> has been filed. Please make sure that the application is correct. Incase of problems please turn to your registrar. Your registrar is <%= @domain.registrar_name %> +

+To confirm the update please visit this website, once again review the data and press approve:
+<%= link_to @verification_url, @verification_url %> +

+The application will remain in pending status for <48> hrs and will be automaticcally rejected if it is not approved nor rejected before. +

+Best Regards,
+Estonian Internet Foundation diff --git a/app/views/domain_mailer/pending_deleted.text.erb b/app/views/domain_mailer/pending_deleted.text.erb new file mode 100644 index 000000000..da9763c55 --- /dev/null +++ b/app/views/domain_mailer/pending_deleted.text.erb @@ -0,0 +1,25 @@ +Tere, + +Registrisse laekus taotlus domeeni <%= @domain.name %> kustutamiseks. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja poole. Teie registripidaja on <%= @domain.registrar_name %> + +Muudatuse kinnitamiseks külastage palun allolevat võrgulehekülge, kontrollige uuesti üle muudatuse andmed ning vajutage nuppu kinnitan: + +Taotlus on aktiivne <48> tundi ja lükatakse automaatselt tagasi kui te seda enne ise ei kinnita või tagasi lükka. +<%= link_to @verification_url, @verification_url %> + +Lugupidamisega +Eesti Interneti SA + +-------------------------------------- + +Hi, + +Application for deletion of your domain <%= @domain.name %> has been filed. Please make sure that the application is correct. Incase of problems please turn to your registrar. Your registrar is <%= @domain.registrar_name %> + +To confirm the update please visit this website, once again review the data and press approve: +<%= link_to @verification_url, @verification_url %> + +The application will remain in pending status for <48> hrs and will be automaticcally rejected if it is not approved nor rejected before. + +Best Regards, +Estonian Internet Foundation diff --git a/app/views/domain_mailer/registrant_updated.html.erb b/app/views/domain_mailer/registrant_pending_updated.html.erb similarity index 100% rename from app/views/domain_mailer/registrant_updated.html.erb rename to app/views/domain_mailer/registrant_pending_updated.html.erb diff --git a/app/views/domain_mailer/registrant_updated.text.erb b/app/views/domain_mailer/registrant_pending_updated.text.erb similarity index 95% rename from app/views/domain_mailer/registrant_updated.text.erb rename to app/views/domain_mailer/registrant_pending_updated.text.erb index 9b1dfd535..ca6609eac 100644 --- a/app/views/domain_mailer/registrant_updated.text.erb +++ b/app/views/domain_mailer/registrant_pending_updated.text.erb @@ -21,7 +21,7 @@ Muudatuse kinnitamiseks külastage palun allolevat võrgulehekülge, kontrollige Lugupidamisega Eesti Interneti SA ---------------------------------------------------------------------------------- +-------------------------------------- Hi, diff --git a/app/views/epp/shared/success_pending.xml.builder b/app/views/epp/shared/success_pending.xml.builder deleted file mode 100644 index 3d1783009..000000000 --- a/app/views/epp/shared/success_pending.xml.builder +++ /dev/null @@ -1,9 +0,0 @@ -xml.epp_head do - xml.response do - xml.result('code' => '1001') do - xml.msg 'Command completed successfully; action pending' - end - end - - xml << render('/epp/shared/trID') -end diff --git a/config/locales/en.yml b/config/locales/en.yml index 023041d06..62a461fc8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -765,7 +765,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_update_subject: "Kinnitustaotlus domeeni %{name} registreerija vahetuseks / Application for approval for registrant chache of %{name}" + domain_registrant_pending_updated_subject: "Kinnitustaotlus domeeni %{name} registreerija vahetuseks / Application for approval for registrant chache of %{name}" + 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' not_valid_domain_verification_title: Domain verification not available diff --git a/doc/epp/domain.md b/doc/epp/domain.md index 9d13f8df3..0d3eede4a 100644 --- a/doc/epp/domain.md +++ b/doc/epp/domain.md @@ -51,6 +51,7 @@ Domain name mapping protocol short version: 1 Domain name. Can contain unicode characters. 0-1 Attributes to change 0-1 Contact reference to the registrant + Optional attribute: verified="yes/no" 0-1 Objects to add 0-n Contact reference. Attribute: type="admin / tech" 0-n Status description. @@ -94,6 +95,7 @@ Domain name mapping protocol short version: ----------------------- ------- ----------------- 1 1 Attribute: xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" + Optional attribute: verified="yes/no" 1 Domain name. Can contain unicode characters. 1 1 Attribute: xmlns:eis="urn:ee:eis:xml:epp:eis-1.0" diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index d57c2445f..6d6788184 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -2091,10 +2091,10 @@ describe 'EPP Domain', epp: true do ] }), :xml) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' + response[:msg].should == 'Command completed successfully; action pending' + response[:result_code].should == '1001' - Domain.find_by(name: domain.name).should == nil + Domain.find_by(name: domain.name).should_not == nil end it 'does not delete domain with specific status' do diff --git a/spec/mailers/domain_mailer_spec.rb b/spec/mailers/domain_mailer_spec.rb index 4f0fc35de..29e89a366 100644 --- a/spec/mailers/domain_mailer_spec.rb +++ b/spec/mailers/domain_mailer_spec.rb @@ -5,7 +5,7 @@ describe DomainMailer do before :all do @registrant = Fabricate(:registrant, email: 'test@example.com') @domain = Fabricate(:domain, registrant: @registrant) - @mail = DomainMailer.registrant_updated(@domain) + @mail = DomainMailer.registrant_pending_updated(@domain) end it 'should not render email subject' do @@ -34,11 +34,11 @@ describe DomainMailer do @domain.registrant_verification_token = '123' @domain.registrant_verification_asked_at = Time.zone.now @domain.registrant = @new_registrant - @mail = DomainMailer.registrant_updated(@domain) + @mail = DomainMailer.registrant_pending_updated(@domain) end it 'should render email subject' do - @mail.subject.should =~ /Kinnitustaotlus domeeni/ + @mail.subject.should =~ /registreerija vahetuseks/ end it 'should have sender email' do @@ -57,4 +57,59 @@ describe DomainMailer do @mail.body.encoded.should =~ /registrant\/domain_update_confirms/ end end + + describe 'domain pending delete notification when delivery turned off' do + before :all do + @registrant = Fabricate(:registrant, email: 'test@example.com') + @domain = Fabricate(:domain, registrant: @registrant) + @mail = DomainMailer.pending_deleted(@domain) + end + + it 'should not render email subject' do + @mail.subject.should == nil + end + + it 'should not have sender email' do + @mail.from.should == nil + end + + it 'should not have reveiver email' do + @mail.to.should == nil + end + + it 'should not render body' do + @mail.body.should == '' + end + end + + describe 'email changed notification' do + before :all do + @registrant = Fabricate(:registrant, email: 'test@example.com') + @domain = Fabricate(:domain, name: 'delete-pending.ee', registrant: @registrant) + @domain.deliver_emails = true + @domain.registrant_verification_token = '123' + @domain.registrant_verification_asked_at = Time.zone.now + @mail = DomainMailer.pending_deleted(@domain) + end + + it 'should render email subject' do + @mail.subject.should =~ /kustutamiseks .ee registrist/ + 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 =~ /Registrisse laekus taotlus domeeni delete-pending.ee kustutamiseks/ + end + + it 'should render verification url' do + @mail.body.encoded.should =~ /registrant\/domain_delete_confirms/ + end + end end