Added pending delete

This commit is contained in:
Priit Tark 2015-05-18 16:45:34 +03:00
parent 50d36cb654
commit 6f59824cd1
13 changed files with 184 additions and 27 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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')

View file

@ -0,0 +1,25 @@
Tere,
<br><br>
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 %>
<br><br>
Muudatuse kinnitamiseks külastage palun allolevat võrgulehekülge, kontrollige uuesti üle muudatuse andmed ning vajutage nuppu kinnitan:
<br><br>
Taotlus on aktiivne <48> tundi ja lükatakse automaatselt tagasi kui te seda enne ise ei kinnita või tagasi lükka.<br>
<%= link_to @verification_url, @verification_url %>
<br><br>
Lugupidamisega<br>
Eesti Interneti SA
<br><br>
<hr>
<br><br>
Hi,
<br><br>
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 %>
<br><br>
To confirm the update please visit this website, once again review the data and press approve:<br>
<%= link_to @verification_url, @verification_url %>
<br><br>
The application will remain in pending status for <48> hrs and will be automaticcally rejected if it is not approved nor rejected before.
<br><br>
Best Regards,<br>
Estonian Internet Foundation

View file

@ -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

View file

@ -21,7 +21,7 @@ Muudatuse kinnitamiseks külastage palun allolevat võrgulehekülge, kontrollige
Lugupidamisega
Eesti Interneti SA
---------------------------------------------------------------------------------
--------------------------------------
Hi,

View file

@ -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

View file

@ -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

View file

@ -51,6 +51,7 @@ Domain name mapping protocol short version:
<domain:name> 1 Domain name. Can contain unicode characters.
<domain:chg> 0-1 Attributes to change
<domain:registrant> 0-1 Contact reference to the registrant
Optional attribute: verified="yes/no"
<domain:add> 0-1 Objects to add
<domain:contact> 0-n Contact reference. Attribute: type="admin / tech"
<domain:status> 0-n Status description.
@ -94,6 +95,7 @@ Domain name mapping protocol short version:
----------------------- ------- -----------------
<delete> 1
<domain:delete> 1 Attribute: xmlns:domain="urn:ietf:params:xml:ns:domain-1.0"
Optional attribute: verified="yes/no"
<domain:name> 1 Domain name. Can contain unicode characters.
<extension> 1
<eis:extdata> 1 Attribute: xmlns:eis="urn:ee:eis:xml:epp:eis-1.0"

View file

@ -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

View file

@ -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