diff --git a/app/controllers/admin/domains_controller.rb b/app/controllers/admin/domains_controller.rb index f7914353e..97d358f7b 100644 --- a/app/controllers/admin/domains_controller.rb +++ b/app/controllers/admin/domains_controller.rb @@ -1,6 +1,7 @@ class Admin::DomainsController < AdminController load_and_authorize_resource before_action :set_domain, only: [:show, :edit, :update, :zonefile] + helper_method :force_delete_templates # rubocop: disable Metrics/PerceivedComplexity # rubocop: disable Metrics/CyclomaticComplexity @@ -59,22 +60,26 @@ class Admin::DomainsController < AdminController end end - def set_force_delete - if @domain.set_force_delete - flash[:notice] = I18n.t('domain_updated') - else - flash.now[:alert] = I18n.t('failed_to_update_domain') + def schedule_force_delete + raise 'Template param cannot be empty' if params[:template_name].blank? + + @domain.transaction do + @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 - redirect_to [:admin, @domain] + + redirect_to edit_admin_domain_path(@domain), notice: t('.scheduled') end - def unset_force_delete - if @domain.unset_force_delete - flash[:notice] = I18n.t('domain_updated') + def cancel_force_delete + if @domain.cancel_force_delete + flash[:notice] = t('.cancelled') else flash.now[:alert] = I18n.t('failed_to_update_domain') end - redirect_to [:admin, @domain] + + redirect_to edit_admin_domain_path(@domain) end def versions @@ -121,5 +126,8 @@ class Admin::DomainsController < AdminController params[:q][:valid_to_lteq] = ca_cache end -end + def force_delete_templates + %w(removed_company death) + end +end diff --git a/app/jobs/domain_delete_forced_email_job.rb b/app/jobs/domain_delete_forced_email_job.rb index 1ddd95bb9..c9ba13a6f 100644 --- a/app/jobs/domain_delete_forced_email_job.rb +++ b/app/jobs/domain_delete_forced_email_job.rb @@ -1,11 +1,12 @@ class DomainDeleteForcedEmailJob < Que::Job - def run(domain_id) + def run(domain_id, template_name) domain = Domain.find(domain_id) log(domain) DomainDeleteMailer.forced(domain: domain, registrar: domain.registrar, - registrant: domain.registrant).deliver_now + registrant: domain.registrant, + template_name: template_name).deliver_now end private diff --git a/app/mailers/domain_delete_mailer.rb b/app/mailers/domain_delete_mailer.rb index c8703e0ac..d6a1dac09 100644 --- a/app/mailers/domain_delete_mailer.rb +++ b/app/mailers/domain_delete_mailer.rb @@ -8,12 +8,17 @@ class DomainDeleteMailer < ApplicationMailer mail(to: registrant.email, subject: subject) end - def forced(domain:, registrar:, registrant:) + def forced(domain:, registrar:, registrant:, template_name:) @domain = DomainPresenter.new(domain: domain, view: view_context) @registrar = RegistrarPresenter.new(registrar: registrar, 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 private diff --git a/app/models/concerns/domain/force_delete.rb b/app/models/concerns/domain/force_delete.rb index fa44bc589..96f1a94b3 100644 --- a/app/models/concerns/domain/force_delete.rb +++ b/app/models/concerns/domain/force_delete.rb @@ -5,15 +5,11 @@ module Concerns::Domain::ForceDelete alias_attribute :force_delete_time, :force_delete_at end - def force_deletable? - !statuses.include?(DomainStatus::FORCE_DELETE) - end - - def force_delete? + def force_delete_scheduled? statuses.include?(DomainStatus::FORCE_DELETE) end - def set_force_delete + def schedule_force_delete self.statuses_backup = statuses statuses.delete(DomainStatus::CLIENT_DELETE_PROHIBITED) statuses.delete(DomainStatus::SERVER_DELETE_PROHIBITED) @@ -43,7 +39,7 @@ module Concerns::Domain::ForceDelete save!(validate: false) end - def unset_force_delete + def cancel_force_delete s = [] s << DomainStatus::EXPIRED if statuses.include?(DomainStatus::EXPIRED) s << DomainStatus::SERVER_HOLD if statuses.include?(DomainStatus::SERVER_HOLD) diff --git a/app/models/domain.rb b/app/models/domain.rb index 0117c16d1..bca5942ac 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -136,7 +136,7 @@ class Domain < ActiveRecord::Base validate :check_permissions, :unless => :is_admin def check_permissions - return unless force_delete? + return unless force_delete_scheduled? errors.add(:base, I18n.t(:object_status_prohibits_operation)) false end diff --git a/app/presenters/domain_presenter.rb b/app/presenters/domain_presenter.rb index 2d0cfd791..1836ef3b5 100644 --- a/app/presenters/domain_presenter.rb +++ b/app/presenters/domain_presenter.rb @@ -38,6 +38,24 @@ class DomainPresenter domain.nameserver_hostnames.join(', ') 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 attr_reader :domain diff --git a/app/presenters/registrant_presenter.rb b/app/presenters/registrant_presenter.rb index f7fcb3094..37c640fc3 100644 --- a/app/presenters/registrant_presenter.rb +++ b/app/presenters/registrant_presenter.rb @@ -1,5 +1,5 @@ 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:) @registrant = registrant diff --git a/app/views/admin/domains/_force_delete_dialog.html.erb b/app/views/admin/domains/_force_delete_dialog.html.erb index 68deaac26..3452883f2 100644 --- a/app/views/admin/domains/_force_delete_dialog.html.erb +++ b/app/views/admin/domains/_force_delete_dialog.html.erb @@ -1,3 +1,34 @@ -
- test + diff --git a/app/views/admin/domains/edit.html.erb b/app/views/admin/domains/edit.html.erb index 809285e7e..9c65c33d3 100644 --- a/app/views/admin/domains/edit.html.erb +++ b/app/views/admin/domains/edit.html.erb @@ -1,17 +1,20 @@ -<% content_for :actions do %> - <%= link_to t('.add_new_status_btn'), '#', class: 'btn btn-primary js-add-status' %> +<% domain = DomainPresenter.new(domain: @domain, view: self) %> - <% if @domain.force_deletable? %> - <%= link_to(t('.force_delete_btn'), force_delete_admin_domain_path(@domain), - method: :post, data: { confirm: t(:are_you_sure) }, class: 'btn btn-warning') %> - <% else %> - <%= link_to(t('.cancel_force_delete_btn'), cancel_force_delete_admin_domain_path(@domain), - method: :post, data: { confirm: t(:are_you_sure) }, class: 'btn btn-warning') %> - <% end %> +
+
+

+ Edit: <%= domain.name %> +

+
+
+

+ <%= 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' %> +

+
+
+
- <%= link_to t(:back_to_domain), [:admin, @domain], class: 'btn btn-default' %> -<% end %> - -<%= render 'shared/title', name: "#{t(:edit)}: #{@domain.name}" %> <%= render 'form' %> -<%= render 'force_delete_dialog' %> +<%= render 'force_delete_dialog', templates: force_delete_templates %> diff --git a/app/views/mailers/domain_delete_mailer/forced/death.html.erb b/app/views/mailers/domain_delete_mailer/forced/death.html.erb index 36ef3693d..aeb1583fe 100644 --- a/app/views/mailers/domain_delete_mailer/forced/death.html.erb +++ b/app/views/mailers/domain_delete_mailer/forced/death.html.erb @@ -1,43 +1,57 @@ -

Lugupeetud domeeni <%= @domain.name %> kontaktisik
-.ee domeeniregistrisse on domeeni <%= @domain.name %> kohta kantud järgmised andmed:

+ +
+ + +
+
+ +

Lugupeetud domeeni <%= @domain.name %> kontaktisik

+

.ee domeeniregistrisse on domeeni <%= @domain.name %> kohta kantud järgmised andmed:

Registreerija nimi: <%= @registrant.name %>
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.

-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. +

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.

-Lisaküsimuste korral võtke palun ühendust oma registripidajaga:

+

Lisaküsimuste korral võtke palun ühendust oma registripidajaga:

<%= render 'mailers/shared/registrar/registrar.et.html', registrar: @registrar %> +
- -

Dear contact of <%= @domain.name %> domain
-The following details for domain name <%= @domain.name %> have been entered into the Estonian Internet Foundation's (EIS) domain registry:

+

Dear contact of <%= @domain.name %> domain
+The following details for domain name <%= @domain.name %> have been entered into the Estonian Internet Foundation's (EIS) domain registry:

Registrant's name: <%= @registrant.name %>
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.

-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. +

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.

-Should you have additional questions, please contact your registrar:

+

Should you have additional questions, please contact your registrar:

<%= render 'mailers/shared/registrar/registrar.en.html', registrar: @registrar %> -

Lugupidamisega,
-Best Regards,
-

-Eesti Interneti Sihtasutus
-Estonian Internet Foundation

+

+ + + + +
+

Lugupidamisega,
+ Best Regards,

+

Eesti Interneti Sihtasutus
+ Estonian Internet Foundation

+
+
diff --git a/app/views/mailers/domain_delete_mailer/forced/death.text.erb b/app/views/mailers/domain_delete_mailer/forced/death.text.erb index 96393d5f3..58939070f 100644 --- a/app/views/mailers/domain_delete_mailer/forced/death.text.erb +++ b/app/views/mailers/domain_delete_mailer/forced/death.text.erb @@ -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. -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. @@ -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. -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. diff --git a/config/locales/admin/domains.en.yml b/config/locales/admin/domains.en.yml index ce37f7ea6..ae0626ffb 100644 --- a/config/locales/admin/domains.en.yml +++ b/config/locales/admin/domains.en.yml @@ -6,6 +6,19 @@ en: edit: 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: time: Time @@ -16,3 +29,8 @@ en: outzone_time: Outzone time delete_time: 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? diff --git a/config/locales/en.yml b/config/locales/en.yml index f75324218..d266cdfdf 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -602,7 +602,6 @@ en: new_domain: 'New domain' edit: 'Edit' delete: 'Delete' - are_you_sure: 'Are you sure?' renew: 'Renew' new: New renew_domain: 'Renew domain' @@ -844,8 +843,6 @@ en: valid: Valid category: Zone 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_validation_rules: 'Domain validation rules' bank_statement_desc: 'Import file row will match only when matching following attributes:
ref number
payment amount
invoice number (the first numerical value in comment field)
.' @@ -914,7 +911,7 @@ en: created_at_from: 'Created at from' created_at_until: 'Created at until' 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 new_mail_template: New mail template failure: "It was not saved" diff --git a/config/routes.rb b/config/routes.rb index c4f1cf32c..8b52e7091 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -202,9 +202,10 @@ Rails.application.routes.draw do resources :domain_versions, controller: 'domains', action: 'versions' resources :pending_updates resources :pending_deletes + member do - post 'set_force_delete' - post 'unset_force_delete' + patch 'schedule_force_delete' + patch 'cancel_force_delete' end end diff --git a/spec/factories/domain.rb b/spec/factories/domain.rb index 534670ce0..edbd2274c 100644 --- a/spec/factories/domain.rb +++ b/spec/factories/domain.rb @@ -10,5 +10,10 @@ FactoryGirl.define do domain.admin_domain_contacts << FactoryGirl.build(:admin_domain_contact) domain.tech_domain_contacts << FactoryGirl.build(:tech_domain_contact) end + + factory :domain_without_force_delete do + force_delete_time nil + statuses [] + end end end diff --git a/spec/features/admin/domains/force_delete_spec.rb b/spec/features/admin/domains/force_delete_spec.rb new file mode 100644 index 000000000..1d3b926a6 --- /dev/null +++ b/spec/features/admin/domains/force_delete_spec.rb @@ -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 diff --git a/spec/mailers/domain_delete_mailer_spec.rb b/spec/mailers/domain_delete_mailer_spec.rb index 5a2f775c1..ce4bbce93 100644 --- a/spec/mailers/domain_delete_mailer_spec.rb +++ b/spec/mailers/domain_delete_mailer_spec.rb @@ -48,12 +48,16 @@ RSpec.describe DomainDeleteMailer do describe '#forced' do 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(:registrar_presenter) { instance_spy(RegistrarPresenter) } let(:registrant_presenter) { instance_spy(RegistrantPresenter) } subject(:message) { described_class.forced(domain: domain, registrar: 'registrar', - registrant: 'registrant') + registrant: registrant, + template_name: template_name) } before :example do @@ -75,8 +79,28 @@ RSpec.describe DomainDeleteMailer do expect(message.subject).to eq('Kustutusmenetluse teade') end - it 'sends message' do - expect { message.deliver_now }.to change { ActionMailer::Base.deliveries.count }.by(1) + context 'when template is :death' do + 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 diff --git a/spec/models/concerns/domain/force_delete_spec.rb b/spec/models/concerns/domain/force_delete_spec.rb new file mode 100644 index 000000000..3e0563366 --- /dev/null +++ b/spec/models/concerns/domain/force_delete_spec.rb @@ -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 diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index 555cf48e1..6e224080f 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -182,98 +182,6 @@ RSpec.describe Domain do domain.statuses.include?(DomainStatus::SERVER_HOLD).should == false 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 before :example do @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 Setting.redemption_grace_period = 1 - @domain.set_force_delete + @domain.schedule_force_delete @domain.renewable?.should be false end end @@ -327,7 +235,7 @@ RSpec.describe Domain do it 'should not allow to renew after force delete' do Setting.redemption_grace_period = 1 - @domain.set_force_delete + @domain.schedule_force_delete @domain.renewable?.should be false end end @@ -700,7 +608,6 @@ end RSpec.describe Domain, db: false do 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(:force_delete_time, :force_delete_at) } it { is_expected.to alias_attribute(:outzone_time, :outzone_at) } describe 'nameserver validation', db: true do diff --git a/spec/presenters/domain_presenter_spec.rb b/spec/presenters/domain_presenter_spec.rb index 2209c01aa..5b3a14e12 100644 --- a/spec/presenters/domain_presenter_spec.rb +++ b/spec/presenters/domain_presenter_spec.rb @@ -114,6 +114,40 @@ RSpec.describe DomainPresenter do 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( name diff --git a/spec/presenters/registrant_presenter_spec.rb b/spec/presenters/registrant_presenter_spec.rb index 894dd40d5..5db6cb0da 100644 --- a/spec/presenters/registrant_presenter_spec.rb +++ b/spec/presenters/registrant_presenter_spec.rb @@ -11,6 +11,7 @@ RSpec.describe RegistrantPresenter do priv? street city + id_code ) registrant_delegate_attributes.each do |attribute_name| diff --git a/spec/routing/admin/domains_routing_spec.rb b/spec/routing/admin/domains_routing_spec.rb new file mode 100644 index 000000000..ce1da8d57 --- /dev/null +++ b/spec/routing/admin/domains_routing_spec.rb @@ -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 diff --git a/spec/views/admin/domains/edit.html.erb_spec.rb b/spec/views/admin/domains/edit.html.erb_spec.rb new file mode 100644 index 000000000..b3cc5d834 --- /dev/null +++ b/spec/views/admin/domains/edit.html.erb_spec.rb @@ -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