mirror of
https://github.com/internetee/registry.git
synced 2025-06-11 15:14:47 +02:00
Add mass actions w/ force delete to admin
This commit is contained in:
parent
7a6568c34a
commit
c72ca8d157
8 changed files with 76 additions and 3 deletions
|
@ -0,0 +1,3 @@
|
||||||
|
$('input:file').on("change", function() {
|
||||||
|
$('input:submit').prop('disabled', !$(this).val());
|
||||||
|
});
|
19
app/controllers/admin/mass_actions_controller.rb
Normal file
19
app/controllers/admin/mass_actions_controller.rb
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Admin
|
||||||
|
class MassActionsController < BaseController
|
||||||
|
authorize_resource
|
||||||
|
|
||||||
|
# GET /admin/disputes
|
||||||
|
def index; end
|
||||||
|
|
||||||
|
# POST /admin/disputes
|
||||||
|
def create
|
||||||
|
res = MassAction.process(params[:mass_action], params[:entry_list].path)
|
||||||
|
backlog = "#{params[:mass_action]} done for #{res[:ok].join(',')}.\n" \
|
||||||
|
"Failed: objects: #{res[:fail].join(',')}"
|
||||||
|
|
||||||
|
redirect_to(admin_mass_actions_path, notice: backlog)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -109,6 +109,7 @@ class Ability
|
||||||
can :destroy, :pending
|
can :destroy, :pending
|
||||||
can :create, :zonefile
|
can :create, :zonefile
|
||||||
can :access, :settings_menu
|
can :access, :settings_menu
|
||||||
|
can :manage, MassAction
|
||||||
end
|
end
|
||||||
|
|
||||||
def static_registrant
|
def static_registrant
|
||||||
|
|
|
@ -42,12 +42,12 @@ module Concerns::Domain::ForceDelete # rubocop:disable Metrics/ModuleLength
|
||||||
force_delete_start + Setting.expire_warning_period.days <= valid_to
|
force_delete_start + Setting.expire_warning_period.days <= valid_to
|
||||||
end
|
end
|
||||||
|
|
||||||
def schedule_force_delete(type: :fast_track)
|
def schedule_force_delete(type: :fast_track, notify: false)
|
||||||
if discarded?
|
if discarded?
|
||||||
raise StandardError, 'Force delete procedure cannot be scheduled while a domain is discarded'
|
raise StandardError, 'Force delete procedure cannot be scheduled while a domain is discarded'
|
||||||
end
|
end
|
||||||
|
|
||||||
type == :fast_track ? force_delete_fast_track : force_delete_soft
|
type == :fast_track ? force_delete_fast_track : force_delete_soft(notify: notify)
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_force_delete_type(force_delete_type)
|
def add_force_delete_type(force_delete_type)
|
||||||
|
@ -65,7 +65,7 @@ module Concerns::Domain::ForceDelete # rubocop:disable Metrics/ModuleLength
|
||||||
save(validate: false)
|
save(validate: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
def force_delete_soft
|
def force_delete_soft(notify: false)
|
||||||
preserve_current_statuses_for_force_delete
|
preserve_current_statuses_for_force_delete
|
||||||
add_force_delete_statuses
|
add_force_delete_statuses
|
||||||
add_force_delete_type(:soft)
|
add_force_delete_type(:soft)
|
||||||
|
@ -73,6 +73,7 @@ module Concerns::Domain::ForceDelete # rubocop:disable Metrics/ModuleLength
|
||||||
stop_all_pending_actions
|
stop_all_pending_actions
|
||||||
allow_deletion
|
allow_deletion
|
||||||
save(validate: false)
|
save(validate: false)
|
||||||
|
notify_parties if notify
|
||||||
end
|
end
|
||||||
|
|
||||||
def clear_force_delete_data
|
def clear_force_delete_data
|
||||||
|
@ -148,4 +149,13 @@ module Concerns::Domain::ForceDelete # rubocop:disable Metrics/ModuleLength
|
||||||
def force_delete_fast_track_start_date
|
def force_delete_fast_track_start_date
|
||||||
Time.zone.today + Setting.expire_warning_period.days + Setting.redemption_grace_period.days
|
Time.zone.today + Setting.expire_warning_period.days + Setting.redemption_grace_period.days
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def notify_parties
|
||||||
|
self.template_name = registrant.org? ? 'legal_person' : 'private_person'
|
||||||
|
save(validate: false)
|
||||||
|
registrar.notifications.create!(text: I18n.t('force_delete_set_on_domain',
|
||||||
|
domain_name: name,
|
||||||
|
outzone_date: outzone_date,
|
||||||
|
purge_date: purge_date))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
21
app/models/mass_action.rb
Normal file
21
app/models/mass_action.rb
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
class MassAction
|
||||||
|
def self.process(action_type, entries)
|
||||||
|
return process_force_delete(entries) if action_type == 'force_delete'
|
||||||
|
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.process_force_delete(entries)
|
||||||
|
log = { ok: [], fail: [] }
|
||||||
|
entries = CSV.read(entries, headers: true)
|
||||||
|
entries.each do |e|
|
||||||
|
dn = Domain.find_by(name_puny: e['Domain name'])
|
||||||
|
log[:fail] << e['Domain name'] and next unless dn
|
||||||
|
|
||||||
|
dn.schedule_force_delete(type: :soft, notify: true)
|
||||||
|
log[:ok] << dn.name
|
||||||
|
end
|
||||||
|
|
||||||
|
log
|
||||||
|
end
|
||||||
|
end
|
|
@ -33,6 +33,7 @@
|
||||||
%li= link_to t('.blocked_domains'), admin_blocked_domains_path
|
%li= link_to t('.blocked_domains'), admin_blocked_domains_path
|
||||||
%li= link_to t('.reserved_domains'), admin_reserved_domains_path
|
%li= link_to t('.reserved_domains'), admin_reserved_domains_path
|
||||||
%li= link_to t('.disputed_domains'), admin_disputes_path
|
%li= link_to t('.disputed_domains'), admin_disputes_path
|
||||||
|
%li= link_to t('.mass_actions'), admin_mass_actions_path
|
||||||
%li= link_to t('.epp_log'), admin_epp_logs_path(created_after: 'today')
|
%li= link_to t('.epp_log'), admin_epp_logs_path(created_after: 'today')
|
||||||
%li= link_to t('.repp_log'), admin_repp_logs_path(created_after: 'today')
|
%li= link_to t('.repp_log'), admin_repp_logs_path(created_after: 'today')
|
||||||
%li= link_to t('.que'), '/admin/que'
|
%li= link_to t('.que'), '/admin/que'
|
||||||
|
|
17
app/views/admin/mass_actions/index.html.erb
Normal file
17
app/views/admin/mass_actions/index.html.erb
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<div class="page-header">
|
||||||
|
<h1>Mass actions</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading">Bulk Domain Force Delete</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<p>Triggers <b>soft</b> force delete procedure for uploaded domain list. List must be in <b>CSV</b> format. Each domain entry must be on separate line. Line must include <b>domain name</b> with <b>delete reason</b>, separated by comma.</p>
|
||||||
|
<p>Allowed delete reasons: <b>IDENT_BURIED</b> | <b>PHONE</b> | <b>EMAIL</b></p>
|
||||||
|
<%= form_tag admin_mass_actions_path, multipart: true do %>
|
||||||
|
<%= file_field_tag :entry_list, accept: 'text/csv' %>
|
||||||
|
<%= hidden_field_tag :mass_action, 'force_delete' %>
|
||||||
|
<br>
|
||||||
|
<%= submit_tag "Start force delete process", class: 'btn btn-danger', disabled: true %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</div>
|
|
@ -295,6 +295,7 @@ Rails.application.routes.draw do
|
||||||
resources :delayed_jobs
|
resources :delayed_jobs
|
||||||
resources :epp_logs
|
resources :epp_logs
|
||||||
resources :repp_logs
|
resources :repp_logs
|
||||||
|
resources :mass_actions, only: %i[index create]
|
||||||
|
|
||||||
authenticate :admin_user do
|
authenticate :admin_user do
|
||||||
mount Que::Web, at: 'que'
|
mount Que::Web, at: 'que'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue