Refactor domain force delete, add "death" force delete mailer template

#268
This commit is contained in:
Artur Beljajev 2017-01-23 04:16:59 +02:00
parent ae5ae9c60b
commit b7a999f536
23 changed files with 395 additions and 166 deletions

View file

@ -1,6 +1,7 @@
class Admin::DomainsController < AdminController class Admin::DomainsController < AdminController
load_and_authorize_resource load_and_authorize_resource
before_action :set_domain, only: [:show, :edit, :update, :zonefile] before_action :set_domain, only: [:show, :edit, :update, :zonefile]
helper_method :force_delete_templates
# rubocop: disable Metrics/PerceivedComplexity # rubocop: disable Metrics/PerceivedComplexity
# rubocop: disable Metrics/CyclomaticComplexity # rubocop: disable Metrics/CyclomaticComplexity
@ -59,22 +60,26 @@ class Admin::DomainsController < AdminController
end end
end end
def set_force_delete def schedule_force_delete
if @domain.set_force_delete raise 'Template param cannot be empty' if params[:template_name].blank?
flash[:notice] = I18n.t('domain_updated')
else @domain.transaction do
flash.now[:alert] = I18n.t('failed_to_update_domain') @domain.schedule_force_delete
@domain.registrar.messages.create!(body: I18n.t('force_delete_set_on_domain', domain_name: @domain.name))
DomainDeleteForcedEmailJob.enqueue(@domain.id, params[:template_name])
end end
redirect_to [:admin, @domain]
redirect_to edit_admin_domain_path(@domain), notice: t('.scheduled')
end end
def unset_force_delete def cancel_force_delete
if @domain.unset_force_delete if @domain.cancel_force_delete
flash[:notice] = I18n.t('domain_updated') flash[:notice] = t('.cancelled')
else else
flash.now[:alert] = I18n.t('failed_to_update_domain') flash.now[:alert] = I18n.t('failed_to_update_domain')
end end
redirect_to [:admin, @domain]
redirect_to edit_admin_domain_path(@domain)
end end
def versions def versions
@ -121,5 +126,8 @@ class Admin::DomainsController < AdminController
params[:q][:valid_to_lteq] = ca_cache params[:q][:valid_to_lteq] = ca_cache
end end
end
def force_delete_templates
%w(removed_company death)
end
end

View file

@ -1,11 +1,12 @@
class DomainDeleteForcedEmailJob < Que::Job class DomainDeleteForcedEmailJob < Que::Job
def run(domain_id) def run(domain_id, template_name)
domain = Domain.find(domain_id) domain = Domain.find(domain_id)
log(domain) log(domain)
DomainDeleteMailer.forced(domain: domain, DomainDeleteMailer.forced(domain: domain,
registrar: domain.registrar, registrar: domain.registrar,
registrant: domain.registrant).deliver_now registrant: domain.registrant,
template_name: template_name).deliver_now
end end
private private

View file

@ -8,12 +8,17 @@ class DomainDeleteMailer < ApplicationMailer
mail(to: registrant.email, subject: subject) mail(to: registrant.email, subject: subject)
end end
def forced(domain:, registrar:, registrant:) def forced(domain:, registrar:, registrant:, template_name:)
@domain = DomainPresenter.new(domain: domain, view: view_context) @domain = DomainPresenter.new(domain: domain, view: view_context)
@registrar = RegistrarPresenter.new(registrar: registrar, view: view_context) @registrar = RegistrarPresenter.new(registrar: registrar, view: view_context)
@registrant = RegistrantPresenter.new(registrant: registrant, view: view_context) @registrant = RegistrantPresenter.new(registrant: registrant, view: view_context)
mail(to: domain.primary_contact_emails) @force_delete_set_date = Time.zone.now
@redemption_grace_period = Setting.redemption_grace_period
mail(to: domain.primary_contact_emails,
template_path: 'mailers/domain_delete_mailer/forced',
template_name: template_name)
end end
private private

View file

@ -5,15 +5,11 @@ module Concerns::Domain::ForceDelete
alias_attribute :force_delete_time, :force_delete_at alias_attribute :force_delete_time, :force_delete_at
end end
def force_deletable? def force_delete_scheduled?
!statuses.include?(DomainStatus::FORCE_DELETE)
end
def force_delete?
statuses.include?(DomainStatus::FORCE_DELETE) statuses.include?(DomainStatus::FORCE_DELETE)
end end
def set_force_delete def schedule_force_delete
self.statuses_backup = statuses self.statuses_backup = statuses
statuses.delete(DomainStatus::CLIENT_DELETE_PROHIBITED) statuses.delete(DomainStatus::CLIENT_DELETE_PROHIBITED)
statuses.delete(DomainStatus::SERVER_DELETE_PROHIBITED) statuses.delete(DomainStatus::SERVER_DELETE_PROHIBITED)
@ -43,7 +39,7 @@ module Concerns::Domain::ForceDelete
save!(validate: false) save!(validate: false)
end end
def unset_force_delete def cancel_force_delete
s = [] s = []
s << DomainStatus::EXPIRED if statuses.include?(DomainStatus::EXPIRED) s << DomainStatus::EXPIRED if statuses.include?(DomainStatus::EXPIRED)
s << DomainStatus::SERVER_HOLD if statuses.include?(DomainStatus::SERVER_HOLD) s << DomainStatus::SERVER_HOLD if statuses.include?(DomainStatus::SERVER_HOLD)

View file

@ -136,7 +136,7 @@ class Domain < ActiveRecord::Base
validate :check_permissions, :unless => :is_admin validate :check_permissions, :unless => :is_admin
def check_permissions def check_permissions
return unless force_delete? return unless force_delete_scheduled?
errors.add(:base, I18n.t(:object_status_prohibits_operation)) errors.add(:base, I18n.t(:object_status_prohibits_operation))
false false
end end

View file

@ -38,6 +38,24 @@ class DomainPresenter
domain.nameserver_hostnames.join(', ') domain.nameserver_hostnames.join(', ')
end end
def force_delete_toggle_btn
if !domain.force_delete_scheduled?
view.content_tag(:a, view.t('admin.domains.force_delete_toggle_btn.schedule'),
class: 'btn btn-danger',
data: {
toggle: 'modal',
target: '.domain-edit-force-delete-dialog',
}
)
else
view.link_to(view.t('admin.domains.force_delete_toggle_btn.cancel'),
view.cancel_force_delete_admin_domain_path(domain),
method: :patch,
data: { confirm: view.t('admin.domains.force_delete_toggle_btn.cancel_confim') },
class: 'btn btn-primary')
end
end
private private
attr_reader :domain attr_reader :domain

View file

@ -1,5 +1,5 @@
class RegistrantPresenter class RegistrantPresenter
delegate :name, :ident, :email, :priv?, :street, :city, to: :registrant delegate :name, :ident, :email, :priv?, :street, :city, :id_code, to: :registrant
def initialize(registrant:, view:) def initialize(registrant:, view:)
@registrant = registrant @registrant = registrant

View file

@ -1,3 +1,34 @@
<div class="domain-edit-force-delete-dialog"> <div class="modal domain-edit-force-delete-dialog" tabindex="-1" role="dialog">
test <div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span></button>
<h4 class="modal-title"><%= t '.title' %></h4>
</div>
<div class="modal-body">
<div class="row">
<%= form_tag schedule_force_delete_admin_domain_path, method: :patch,
id: 'domain-force-delete-form', class: 'form-horizontal' do %>
<div class="form-group">
<label class="col-sm-2 control-label"><%= t '.template' %>:</label>
<div class="col-sm-9">
<%= select_tag 'template_name', options_for_select(templates), class: 'form-control' %>
</div>
</div>
<% end %>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal"><%= t '.close_btn' %></button>
<button type="submit" form="domain-force-delete-form" class="btn btn-danger">
<%= t '.submit_btn' %>
</button>
</div>
</div>
</div>
</div> </div>

View file

@ -1,17 +1,20 @@
<% content_for :actions do %> <% domain = DomainPresenter.new(domain: @domain, view: self) %>
<%= link_to t('.add_new_status_btn'), '#', class: 'btn btn-primary js-add-status' %>
<% if @domain.force_deletable? %> <div class="row">
<%= link_to(t('.force_delete_btn'), force_delete_admin_domain_path(@domain), <div class="col-sm-5">
method: :post, data: { confirm: t(:are_you_sure) }, class: 'btn btn-warning') %> <h1 class="text-center-xs">
<% else %> Edit: <%= domain.name %>
<%= link_to(t('.cancel_force_delete_btn'), cancel_force_delete_admin_domain_path(@domain), </h1>
method: :post, data: { confirm: t(:are_you_sure) }, class: 'btn btn-warning') %> </div>
<% end %> <div class="col-sm-7">
<h1 class="text-right text-center-xs">
<%= link_to t('.add_new_status_btn'), '#', class: 'btn btn-primary js-add-status' %>
<%= domain.force_delete_toggle_btn %>
<%= link_to t('.back_btn'), [:admin, @domain], class: 'btn btn-default' %>
</h1>
</div>
</div>
<hr>
<%= link_to t(:back_to_domain), [:admin, @domain], class: 'btn btn-default' %>
<% end %>
<%= render 'shared/title', name: "#{t(:edit)}: #{@domain.name}" %>
<%= render 'form' %> <%= render 'form' %>
<%= render 'force_delete_dialog' %> <%= render 'force_delete_dialog', templates: force_delete_templates %>

View file

@ -1,43 +1,57 @@
<p>Lugupeetud domeeni <%= @domain.name %> kontaktisik<br> <table width="600" cellspacing="0" cellpadding="0" border="0" align="center"><tbody>
.ee domeeniregistrisse on domeeni <%= @domain.name %> kohta kantud järgmised andmed:</p> <tr><td>
<table cellspacing="0" cellpadding="0" border="0" align="center" style="text-align: justify; line-height: 16px; font-size: 12px;"><tbody>
<tr><td>
<br />
<p><strong>Lugupeetud domeeni <%= @domain.name %> kontaktisik</strong></p>
<p>.ee domeeniregistrisse on domeeni <strong><%= @domain.name %></strong> kohta kantud järgmised andmed:</p>
<p>Registreerija nimi: <%= @registrant.name %><br> <p>Registreerija nimi: <%= @registrant.name %><br>
Isikukood: <%= @registrant.id_code %></p> Isikukood: <%= @registrant.id_code %></p>
<p>Eesti Interneti Sihtasutusele (EIS) on saanud teatavaks, et füüsiline isik isikukoodiga <%= @registrant.id_code %> on surnud ja sellest on möödunud vähemalt 6 kuud. <p>Eesti Interneti Sihtasutusele (EIS) on saanud teatavaks, et füüsiline isik isikukoodiga <%= @registrant.id_code %> on surnud ja sellest on möödunud vähemalt 6 kuud.</p>
Domeenireeglite punktist 6.6 tulenevalt on domeeni suhtes õigust omaval registreerijal võimalus esitada domeeni <%= @domain.name %> registripidajale [Registrars.name] domeeni üleandmise taotlus Domeenireeglite p 5.3.6.2 kohaselt. Taotlusele tuleb lisada pärimisõiguse tõend, mis asendavad Domeenireeglite punktis 5.3.6.3 sätestatud üleandva registreerija nõusolekut. Vastav dokumentatsioon tuleb esitada Registripidajale <%= @redemption_grace_period %> päeva jooksul. <p>Domeenireeglite punktist 6.6 tulenevalt on domeeni suhtes õigust omaval registreerijal võimalus esitada domeeni <%= @domain.name %> registripidajale <%= @registrar.name %> domeeni üleandmise taotlus Domeenireeglite p 5.3.6.2 kohaselt. Taotlusele tuleb lisada pärimisõiguse tõend, mis asendavad Domeenireeglite punktis 5.3.6.3 sätestatud üleandva registreerija nõusolekut. Vastav dokumentatsioon tuleb esitada Registripidajale <%= @redemption_grace_period %> päeva jooksul.</p>
Kuna käesoleval hetkel domeenil registreerijat pole, on EIS algatanud <%= l(@force_delete_set_date, format: :date) %> vastavalt Domeenireeglite (http://www.internet.ee/domeenid/) punktile 6.6 domeeni <%= @domain.name %> suhtes <%= @redemption_grace_period %> päeva pikkuse kustutusmenetluse. Kustutamise käigus jääb domeen internetis kättesaadavaks ja selle aja jooksul on võimalik teostada domeeni üleandmine. <p>Kuna käesoleval hetkel domeenil registreerijat pole, on EIS algatanud <%= l(@force_delete_set_date, format: :date) %> vastavalt Domeenireeglite (http://www.internet.ee/domeenid/) punktile 6.6 domeeni <%= @domain.name %> suhtes <%= @redemption_grace_period %> päeva pikkuse kustutusmenetluse. Kustutamise käigus jääb domeen internetis kättesaadavaks ja selle aja jooksul on võimalik teostada domeeni üleandmine.</p>
Kui üleandmine ei ole <%= @redemption_grace_period %> päeva jooksul toimunud, kustub domeen <%= @domain.name %> 24 tunni jooksul <%= @domain.force_delete_date %> juhuslikult valitud ajahetkel. Soovi korral on võimalik domeen pärast selle kustumist registrist “kes ees, see mees” põhimõttel uuesti registreerida. <p>Kui üleandmine ei ole <%= @redemption_grace_period %> päeva jooksul toimunud, kustub domeen <%= @domain.name %> 24 tunni jooksul <%= @domain.force_delete_date %> juhuslikult valitud ajahetkel. Soovi korral on võimalik domeen pärast selle kustumist registrist “kes ees, see mees” põhimõttel uuesti registreerida.</p>
Lisaküsimuste korral võtke palun ühendust oma registripidajaga:</p> <p>Lisaküsimuste korral võtke palun ühendust oma registripidajaga:</p>
<%= render 'mailers/shared/registrar/registrar.et.html', registrar: @registrar %> <%= render 'mailers/shared/registrar/registrar.et.html', registrar: @registrar %>
<hr>
<p><strong>Dear contact of <%= @domain.name %> domain</strong><br>
<p>Dear contact of <%= @domain.name %> domain<br> The following details for domain name <strong><%= @domain.name %></strong> have been entered into the Estonian Internet Foundation's (EIS) domain registry:</p>
The following details for domain name <%= @domain.name %> have been entered into the Estonian Internet Foundation's (EIS) domain registry:</p>
<p>Registrant's name: <%= @registrant.name %><br> <p>Registrant's name: <%= @registrant.name %><br>
Identification code: <%= @registrant.id_code %></p> Identification code: <%= @registrant.id_code %></p>
<p>EIS has learned that the natural person <%= @registrant.name %> with identification code <%= @registrant.id_code %> has been deceased and 6 months have passed from death. <p>EIS has learned that the natural person <%= @registrant.name %> with identification code <%= @registrant.id_code %> has been deceased and 6 months have passed from death.</p>
According to paragraph 6.6 of the Domain Regulation, the registrant holding a right to the domain name <%= @domain.name %> can submit a domain name transfer application to the registrar [Registrars.name] in accordance with paragraph 5.3.6.2 of the Domain Regulation. The application must be submitted together with succession evidence certifying the acquisition of the domain that will replace the consent of the surrendering registrant as laid down in paragraph 5.3.6.3 of the Domain Regulation. The relevant documents should be submitted to the registrar within <%= @redemption_grace_period %> day(s). <p>According to paragraph 6.6 of the Domain Regulation, the registrant holding a right to the domain name <%= @domain.name %> can submit a domain name transfer application to the registrar <%= @registrar.name %> in accordance with paragraph 5.3.6.2 of the Domain Regulation. The application must be submitted together with succession evidence certifying the acquisition of the domain that will replace the consent of the surrendering registrant as laid down in paragraph 5.3.6.3 of the Domain Regulation. The relevant documents should be submitted to the registrar within <%= @redemption_grace_period %> day(s).</p>
As a deceased natural person is not the registrant of a domain, the EIS started the deletion process of <%= @domain.name %> domain on <%= l(@force_delete_set_date, format: :date) %> according to the Domain Regulation (http://www.internet.ee/en/domains/), using the <%= @redemption_grace_period %>-day delete procedure. The domain will remain available on the Internet during the delete procedure and within this time can be transferred to new registrant. <p>As a deceased natural person is not the registrant of a domain, the EIS started the deletion process of <%= @domain.name %> domain on <%= l(@force_delete_set_date, format: :date) %> according to the Domain Regulation (http://www.internet.ee/en/domains/), using the <%= @redemption_grace_period %>-day delete procedure. The domain will remain available on the Internet during the delete procedure and within this time can be transferred to new registrant.</p>
If the transfer has not been made in <%= @redemption_grace_period %> day(s), the domain <%= @domain.name %> will be deleted at a randomly chosen moment within 24 hours on <%= @domain.force_delete_date %>. After deletion it is possible to reregister the domain on a "first come, first served" basis. <p>If the transfer has not been made in <%= @redemption_grace_period %> day(s), the domain <%= @domain.name %> will be deleted at a randomly chosen moment within 24 hours on <%= @domain.force_delete_date %>. After deletion it is possible to reregister the domain on a "first come, first served" basis.</p>
Should you have additional questions, please contact your registrar:</p> <p>Should you have additional questions, please contact your registrar:</p>
<%= render 'mailers/shared/registrar/registrar.en.html', registrar: @registrar %> <%= render 'mailers/shared/registrar/registrar.en.html', registrar: @registrar %>
<p>Lugupidamisega,<br> <br /><br />
Best Regards,<br>
<br><br> <table width="100%" cellspacing="0" cellpadding="0" border="0" align="center" style="text-align: justify; line-height: 16px; font-size: 12px;"><tbody>
Eesti Interneti Sihtasutus<br> <tr><td align="left" valign="top">
Estonian Internet Foundation</p> <p><strong>Lugupidamisega,<br />
Best Regards,</strong></p>
<p><i>Eesti Interneti Sihtasutus<br />
Estonian Internet Foundation</i></p>
</td><td></td></tr>
</tbody>
</table>
</td></tr>
</tbody></table></table>

View file

@ -6,7 +6,7 @@ Isikukood: <%= @registrant.id_code %>
Eesti Interneti Sihtasutusele (EIS) on saanud teatavaks, et füüsiline isik isikukoodiga <%= @registrant.id_code %> on surnud ja sellest on möödunud vähemalt 6 kuud. Eesti Interneti Sihtasutusele (EIS) on saanud teatavaks, et füüsiline isik isikukoodiga <%= @registrant.id_code %> on surnud ja sellest on möödunud vähemalt 6 kuud.
Domeenireeglite punktist 6.6 tulenevalt on domeeni suhtes õigust omaval registreerijal võimalus esitada domeeni <%= @domain.name %> registripidajale [Registrars.name] domeeni üleandmise taotlus Domeenireeglite p 5.3.6.2 kohaselt. Taotlusele tuleb lisada pärimisõiguse tõend, mis asendavad Domeenireeglite punktis 5.3.6.3 sätestatud üleandva registreerija nõusolekut. Vastav dokumentatsioon tuleb esitada Registripidajale <%= @redemption_grace_period %> päeva jooksul. Domeenireeglite punktist 6.6 tulenevalt on domeeni suhtes õigust omaval registreerijal võimalus esitada domeeni <%= @domain.name %> registripidajale <%= @registrar.name %> domeeni üleandmise taotlus Domeenireeglite p 5.3.6.2 kohaselt. Taotlusele tuleb lisada pärimisõiguse tõend, mis asendavad Domeenireeglite punktis 5.3.6.3 sätestatud üleandva registreerija nõusolekut. Vastav dokumentatsioon tuleb esitada Registripidajale <%= @redemption_grace_period %> päeva jooksul.
Kuna käesoleval hetkel domeenil registreerijat pole, on EIS algatanud <%= l(@force_delete_set_date, format: :date) %> vastavalt Domeenireeglite (http://www.internet.ee/domeenid/) punktile 6.6 domeeni <%= @domain.name %> suhtes <%= @redemption_grace_period %> päeva pikkuse kustutusmenetluse. Kustutamise käigus jääb domeen internetis kättesaadavaks ja selle aja jooksul on võimalik teostada domeeni üleandmine. Kuna käesoleval hetkel domeenil registreerijat pole, on EIS algatanud <%= l(@force_delete_set_date, format: :date) %> vastavalt Domeenireeglite (http://www.internet.ee/domeenid/) punktile 6.6 domeeni <%= @domain.name %> suhtes <%= @redemption_grace_period %> päeva pikkuse kustutusmenetluse. Kustutamise käigus jääb domeen internetis kättesaadavaks ja selle aja jooksul on võimalik teostada domeeni üleandmine.
@ -27,7 +27,7 @@ Identification code: <%= @registrant.id_code %>
EIS has learned that the natural person <%= @registrant.name %> with identification code <%= @registrant.id_code %> has been deceased and 6 months have passed from death. EIS has learned that the natural person <%= @registrant.name %> with identification code <%= @registrant.id_code %> has been deceased and 6 months have passed from death.
According to paragraph 6.6 of the Domain Regulation, the registrant holding a right to the domain name <%= @domain.name %> can submit a domain name transfer application to the registrar [Registrars.name] in accordance with paragraph 5.3.6.2 of the Domain Regulation. The application must be submitted together with succession evidence certifying the acquisition of the domain that will replace the consent of the surrendering registrant as laid down in paragraph 5.3.6.3 of the Domain Regulation. The relevant documents should be submitted to the registrar within <%= @redemption_grace_period %> day(s). According to paragraph 6.6 of the Domain Regulation, the registrant holding a right to the domain name <%= @domain.name %> can submit a domain name transfer application to the registrar <%= @registrar.name %> in accordance with paragraph 5.3.6.2 of the Domain Regulation. The application must be submitted together with succession evidence certifying the acquisition of the domain that will replace the consent of the surrendering registrant as laid down in paragraph 5.3.6.3 of the Domain Regulation. The relevant documents should be submitted to the registrar within <%= @redemption_grace_period %> day(s).
As a deceased natural person is not the registrant of a domain, the EIS started the deletion process of <%= @domain.name %> domain on <%= l(@force_delete_set_date, format: :date) %> according to the Domain Regulation (http://www.internet.ee/en/domains/), using the <%= @redemption_grace_period %>-day delete procedure. The domain will remain available on the Internet during the delete procedure and within this time can be transferred to new registrant. As a deceased natural person is not the registrant of a domain, the EIS started the deletion process of <%= @domain.name %> domain on <%= l(@force_delete_set_date, format: :date) %> according to the Domain Regulation (http://www.internet.ee/en/domains/), using the <%= @redemption_grace_period %>-day delete procedure. The domain will remain available on the Internet during the delete procedure and within this time can be transferred to new registrant.

View file

@ -6,6 +6,19 @@ en:
edit: edit:
add_new_status_btn: Add new status add_new_status_btn: Add new status
back_btn: Back to domain
force_delete_dialog:
title: Force delete
template: Template
close_btn: Close dialog
submit_btn: Force delete domain
schedule_force_delete:
scheduled: Force delete procedure has been scheduled
cancel_force_delete:
cancelled: Force delete procedure has been cancelled
versions: versions:
time: Time time: Time
@ -16,3 +29,8 @@ en:
outzone_time: Outzone time outzone_time: Outzone time
delete_time: Delete time delete_time: Delete time
force_delete_time: Force delete time force_delete_time: Force delete time
force_delete_toggle_btn:
schedule: Schedule force delete
cancel: Cancel force delete
cancel_confim: Are you sure you want cancel force delete procedure?

View file

@ -602,7 +602,6 @@ en:
new_domain: 'New domain' new_domain: 'New domain'
edit: 'Edit' edit: 'Edit'
delete: 'Delete' delete: 'Delete'
are_you_sure: 'Are you sure?'
renew: 'Renew' renew: 'Renew'
new: New new: New
renew_domain: 'Renew domain' renew_domain: 'Renew domain'
@ -844,8 +843,6 @@ en:
valid: Valid valid: Valid
category: Zone category: Zone
object_is_not_eligible_for_renewal: 'Object is not eligible for renewal' object_is_not_eligible_for_renewal: 'Object is not eligible for renewal'
set_force_delete: 'Set force delete'
unset_force_delete: 'Unset force delete'
domain_expiring: 'Domain expiring' domain_expiring: 'Domain expiring'
domain_validation_rules: 'Domain validation rules' domain_validation_rules: 'Domain validation rules'
bank_statement_desc: 'Import file row will match only when matching following attributes: <b><br>ref number<br>payment amount<br>invoice number (the first numerical value in comment field)</b>.' bank_statement_desc: 'Import file row will match only when matching following attributes: <b><br>ref number<br>payment amount<br>invoice number (the first numerical value in comment field)</b>.'
@ -914,7 +911,7 @@ en:
created_at_from: 'Created at from' created_at_from: 'Created at from'
created_at_until: 'Created at until' created_at_until: 'Created at until'
is_registrant: 'Is registrant' is_registrant: 'Is registrant'
force_delete_set_on_domain: 'Force delete set on domain %{domain}' force_delete_set_on_domain: 'Force delete set on domain %{domain_name}'
mail_templates: Mail Templates mail_templates: Mail Templates
new_mail_template: New mail template new_mail_template: New mail template
failure: "It was not saved" failure: "It was not saved"

View file

@ -202,9 +202,10 @@ Rails.application.routes.draw do
resources :domain_versions, controller: 'domains', action: 'versions' resources :domain_versions, controller: 'domains', action: 'versions'
resources :pending_updates resources :pending_updates
resources :pending_deletes resources :pending_deletes
member do member do
post 'set_force_delete' patch 'schedule_force_delete'
post 'unset_force_delete' patch 'cancel_force_delete'
end end
end end

View file

@ -10,5 +10,10 @@ FactoryGirl.define do
domain.admin_domain_contacts << FactoryGirl.build(:admin_domain_contact) domain.admin_domain_contacts << FactoryGirl.build(:admin_domain_contact)
domain.tech_domain_contacts << FactoryGirl.build(:tech_domain_contact) domain.tech_domain_contacts << FactoryGirl.build(:tech_domain_contact)
end end
factory :domain_without_force_delete do
force_delete_time nil
statuses []
end
end end
end end

View file

@ -0,0 +1,33 @@
require 'rails_helper'
RSpec.feature 'Force delete' do
context 'when domain has no force delete procedure' do
given!(:domain) { create(:domain_without_force_delete) }
scenario 'schedule' do
sign_in_to_admin_area
visit edit_admin_domain_url(domain)
click_link_or_button 'Force delete domain'
expect(page).to have_text('Force delete procedure has been scheduled')
end
end
context 'when domain has force delete procedure' do
given!(:domain) { create(:domain_without_force_delete) }
background do
domain.schedule_force_delete
end
scenario 'cancel' do
sign_in_to_admin_area
visit edit_admin_domain_url(domain)
click_link_or_button 'Cancel force delete'
expect(page).to have_text('Force delete procedure has been cancelled')
end
end
end

View file

@ -48,12 +48,16 @@ RSpec.describe DomainDeleteMailer do
describe '#forced' do describe '#forced' do
let(:domain) { instance_spy(Domain, name: 'test.com') } let(:domain) { instance_spy(Domain, name: 'test.com') }
let(:registrant) { instance_spy(Registrant) }
let(:template_name) { 'removed_company' }
let(:domain_presenter) { instance_spy(DomainPresenter) } let(:domain_presenter) { instance_spy(DomainPresenter) }
let(:registrar_presenter) { instance_spy(RegistrarPresenter) } let(:registrar_presenter) { instance_spy(RegistrarPresenter) }
let(:registrant_presenter) { instance_spy(RegistrantPresenter) } let(:registrant_presenter) { instance_spy(RegistrantPresenter) }
subject(:message) { described_class.forced(domain: domain, subject(:message) { described_class.forced(domain: domain,
registrar: 'registrar', registrar: 'registrar',
registrant: 'registrant') registrant: registrant,
template_name: template_name)
} }
before :example do before :example do
@ -75,8 +79,28 @@ RSpec.describe DomainDeleteMailer do
expect(message.subject).to eq('Kustutusmenetluse teade') expect(message.subject).to eq('Kustutusmenetluse teade')
end end
it 'sends message' do context 'when template is :death' do
expect { message.deliver_now }.to change { ActionMailer::Base.deliveries.count }.by(1) let(:template_name) { 'death' }
it 'sends message' do
expect { message.deliver_now }.to change { ActionMailer::Base.deliveries.count }.by(1)
end
end
context 'when registrant is private entity' do
let(:registrant) { build_stubbed(:registrant_private_entity) }
it 'sends message' do
expect { message.deliver_now }.to change { ActionMailer::Base.deliveries.count }.by(1)
end
end
context 'when registrant is legal entity' do
let(:registrant) { build_stubbed(:registrant_legal_entity) }
it 'sends message' do
expect { message.deliver_now }.to change { ActionMailer::Base.deliveries.count }.by(1)
end
end end
end end
end end

View file

@ -0,0 +1,98 @@
require 'rails_helper'
RSpec.describe Domain do
it { is_expected.to alias_attribute(:force_delete_time, :force_delete_at) }
before :example do
Fabricate(:zonefile_setting, origin: 'ee')
end
it 'should set force delete time' do
domain = Fabricate(:domain)
domain.statuses = ['ok']
domain.schedule_force_delete
domain.statuses.should match_array([
"serverForceDelete",
"pendingDelete",
"serverManualInzone",
"serverRenewProhibited",
"serverTransferProhibited",
"serverUpdateProhibited"
])
domain.cancel_force_delete
domain.statuses.should == ['ok']
domain.statuses = [
DomainStatus::CLIENT_DELETE_PROHIBITED,
DomainStatus::SERVER_DELETE_PROHIBITED,
DomainStatus::PENDING_UPDATE,
DomainStatus::PENDING_TRANSFER,
DomainStatus::PENDING_RENEW,
DomainStatus::PENDING_CREATE,
DomainStatus::CLIENT_HOLD,
DomainStatus::EXPIRED,
DomainStatus::SERVER_HOLD,
DomainStatus::DELETE_CANDIDATE
]
domain.save
domain.schedule_force_delete
domain.statuses.should match_array([
"clientHold",
"deleteCandidate",
"expired",
"serverForceDelete",
"pendingDelete",
"serverHold",
"serverRenewProhibited",
"serverTransferProhibited",
"serverUpdateProhibited"
])
domain.cancel_force_delete
domain.statuses.should match_array([
"clientDeleteProhibited",
"clientHold",
"deleteCandidate",
"expired",
"pendingCreate",
"pendingRenew",
"pendingTransfer",
"pendingUpdate",
"serverDeleteProhibited",
"serverHold"
])
end
it 'should should be manual in zone and held after force delete' do
domain = create(:domain)
Setting.redemption_grace_period = 1
domain.valid?
domain.outzone_at = Time.zone.now + 1.day # before redemption grace period
# what should this be?
# domain.server_holdable?.should be true
domain.statuses.include?(DomainStatus::SERVER_HOLD).should be false
domain.statuses.include?(DomainStatus::SERVER_MANUAL_INZONE).should be false
domain.schedule_force_delete
domain.server_holdable?.should be false
domain.statuses.include?(DomainStatus::SERVER_MANUAL_INZONE).should be true
domain.statuses.include?(DomainStatus::SERVER_HOLD).should be false
end
it 'should not allow update after force delete' do
domain = create(:domain)
domain.valid?
domain.pending_update_prohibited?.should be false
domain.update_prohibited?.should be false
domain.schedule_force_delete
domain.pending_update_prohibited?.should be true
domain.update_prohibited?.should be true
end
end

View file

@ -182,98 +182,6 @@ RSpec.describe Domain do
domain.statuses.include?(DomainStatus::SERVER_HOLD).should == false domain.statuses.include?(DomainStatus::SERVER_HOLD).should == false
end end
it 'should set force delete time' do
@domain.statuses = ['ok']
@domain.set_force_delete
@domain.statuses.should match_array([
"serverForceDelete",
"pendingDelete",
"serverManualInzone",
"serverRenewProhibited",
"serverTransferProhibited",
"serverUpdateProhibited"
])
fda = Time.zone.now + Setting.redemption_grace_period.days
@domain.registrar.messages.count.should == 1
m = @domain.registrar.messages.first
m.body.should == "Force delete set on domain #{@domain.name}"
@domain.unset_force_delete
@domain.statuses.should == ['ok']
@domain.statuses = [
DomainStatus::CLIENT_DELETE_PROHIBITED,
DomainStatus::SERVER_DELETE_PROHIBITED,
DomainStatus::PENDING_UPDATE,
DomainStatus::PENDING_TRANSFER,
DomainStatus::PENDING_RENEW,
DomainStatus::PENDING_CREATE,
DomainStatus::CLIENT_HOLD,
DomainStatus::EXPIRED,
DomainStatus::SERVER_HOLD,
DomainStatus::DELETE_CANDIDATE
]
@domain.save
@domain.set_force_delete
@domain.statuses.should match_array([
"clientHold",
"deleteCandidate",
"expired",
"serverForceDelete",
"pendingDelete",
"serverHold",
"serverRenewProhibited",
"serverTransferProhibited",
"serverUpdateProhibited"
])
@domain.unset_force_delete
@domain.statuses.should match_array([
"clientDeleteProhibited",
"clientHold",
"deleteCandidate",
"expired",
"pendingCreate",
"pendingRenew",
"pendingTransfer",
"pendingUpdate",
"serverDeleteProhibited",
"serverHold"
])
end
it 'should should be manual in zone and held after force delete' do
Setting.redemption_grace_period = 1
@domain.valid?
@domain.outzone_at = Time.zone.now + 1.day # before redemption grace period
# what should this be?
# @domain.server_holdable?.should be true
@domain.statuses.include?(DomainStatus::SERVER_HOLD).should be false
@domain.statuses.include?(DomainStatus::SERVER_MANUAL_INZONE).should be false
@domain.set_force_delete
@domain.server_holdable?.should be false
@domain.statuses.include?(DomainStatus::SERVER_MANUAL_INZONE).should be true
@domain.statuses.include?(DomainStatus::SERVER_HOLD).should be false
end
it 'should not allow update after force delete' do
@domain.valid?
@domain.pending_update_prohibited?.should be false
@domain.update_prohibited?.should be false
@domain.set_force_delete
@domain.pending_update_prohibited?.should be true
@domain.update_prohibited?.should be true
end
context 'with time period settings' do context 'with time period settings' do
before :example do before :example do
@save_days_to_renew = Setting.days_to_renew_domain_before_expire @save_days_to_renew = Setting.days_to_renew_domain_before_expire
@ -302,7 +210,7 @@ RSpec.describe Domain do
it 'should not allow to renew after force delete' do it 'should not allow to renew after force delete' do
Setting.redemption_grace_period = 1 Setting.redemption_grace_period = 1
@domain.set_force_delete @domain.schedule_force_delete
@domain.renewable?.should be false @domain.renewable?.should be false
end end
end end
@ -327,7 +235,7 @@ RSpec.describe Domain do
it 'should not allow to renew after force delete' do it 'should not allow to renew after force delete' do
Setting.redemption_grace_period = 1 Setting.redemption_grace_period = 1
@domain.set_force_delete @domain.schedule_force_delete
@domain.renewable?.should be false @domain.renewable?.should be false
end end
end end
@ -700,7 +608,6 @@ end
RSpec.describe Domain, db: false do RSpec.describe Domain, db: false do
it { is_expected.to alias_attribute(:on_hold_time, :outzone_at) } it { is_expected.to alias_attribute(:on_hold_time, :outzone_at) }
it { is_expected.to alias_attribute(:delete_time, :delete_at) } it { is_expected.to alias_attribute(:delete_time, :delete_at) }
it { is_expected.to alias_attribute(:force_delete_time, :force_delete_at) }
it { is_expected.to alias_attribute(:outzone_time, :outzone_at) } it { is_expected.to alias_attribute(:outzone_time, :outzone_at) }
describe 'nameserver validation', db: true do describe 'nameserver validation', db: true do

View file

@ -114,6 +114,40 @@ RSpec.describe DomainPresenter do
end end
end end
describe '#force_delete_toggle_btn' do
let(:domain) { build_stubbed(:domain) }
context 'when force delete is not scheduled' do
before :example do
expect(domain).to receive(:force_delete_scheduled?).and_return(false)
end
it 'returns schedule button' do
html = view.content_tag(:a, 'Schedule force delete',
class: 'btn btn-danger',
data: {
toggle: 'modal',
target: '.domain-edit-force-delete-dialog',
})
expect(presenter.force_delete_toggle_btn).to eq(html)
end
end
context 'when force delete is scheduled' do
before :example do
expect(domain).to receive(:force_delete_scheduled?).and_return(true)
end
it 'returns cancel button' do
html = link_to('Cancel force delete',
view.cancel_force_delete_admin_domain_path(domain),
method: :patch,
data: { confirm: 'Are you sure you want cancel force delete procedure?' },
class: 'btn btn-warning')
expect(presenter.force_delete_toggle_btn).to eq(html)
end
end
end
domain_delegatable_attributes = %i( domain_delegatable_attributes = %i(
name name

View file

@ -11,6 +11,7 @@ RSpec.describe RegistrantPresenter do
priv? priv?
street street
city city
id_code
) )
registrant_delegate_attributes.each do |attribute_name| registrant_delegate_attributes.each do |attribute_name|

View file

@ -0,0 +1,13 @@
require 'rails_helper'
RSpec.describe Admin::DomainsController do
describe 'routing' do
it 'routes to #schedule_force_delete' do
expect(patch: '/admin/domains/1/schedule_force_delete').to route_to('admin/domains#schedule_force_delete', id: '1')
end
it 'routes to #cancel_force_delete' do
expect(patch: '/admin/domains/1/cancel_force_delete').to route_to('admin/domains#cancel_force_delete', id: '1')
end
end
end

View file

@ -0,0 +1,22 @@
require 'rails_helper'
RSpec.describe 'admin/domains/edit' do
let(:domain) { build_stubbed(:domain) }
let(:domain_presenter) { DomainPresenter.new(domain: domain, view: view) }
before :example do
allow(DomainPresenter).to receive(:new).and_return(domain_presenter)
allow(view).to receive(:force_delete_templates)
assign(:domain, domain)
stub_template '_form' => ''
stub_template '_force_delete_dialog' => ''
end
it 'has force_delete_toggle_btn' do
expect(domain_presenter).to receive(:force_delete_toggle_btn).and_return('force_delete_toggle_btn')
render
expect(rendered).to have_content('force_delete_toggle_btn')
end
end