mirror of
https://github.com/internetee/registry.git
synced 2025-06-12 23:54:44 +02:00
Add CSV validator to mass action
This commit is contained in:
parent
4566b39435
commit
4e18545105
2 changed files with 27 additions and 5 deletions
|
@ -10,10 +10,14 @@ module Admin
|
|||
# POST /admin/mass_actions
|
||||
def create
|
||||
res = MassAction.process(params[:mass_action], params[:entry_list].path)
|
||||
backlog = "#{params[:mass_action]} completed for #{res[:ok]}.\n" \
|
||||
notice = if res
|
||||
"#{params[:mass_action]} completed for #{res[:ok]}.\n" \
|
||||
"Failed: objects: #{res[:fail]}"
|
||||
else
|
||||
"Dataset integrity validation failed for #{params[:mass_action]}"
|
||||
end
|
||||
|
||||
redirect_to(admin_mass_actions_path, notice: backlog)
|
||||
redirect_to(admin_mass_actions_path, notice: notice)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,13 +1,18 @@
|
|||
class MassAction
|
||||
def self.process(action_type, entries)
|
||||
return process_force_delete(entries) if action_type == 'force_delete'
|
||||
entries = CSV.read(entries, headers: true)
|
||||
case action_type
|
||||
when 'force_delete'
|
||||
return false unless force_delete_entries_valid?(entries)
|
||||
|
||||
process_force_delete(entries)
|
||||
end
|
||||
rescue StandardError
|
||||
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
|
||||
|
@ -18,4 +23,17 @@ class MassAction
|
|||
|
||||
log
|
||||
end
|
||||
|
||||
def self.force_delete_entries_valid?(entries)
|
||||
valid = true
|
||||
entries.each do |e|
|
||||
unless e['domain_name'].present? && %w[IDENT_BURIED EMAIL PHONE].include?(e['delete_reason'])
|
||||
valid = false
|
||||
end
|
||||
end
|
||||
|
||||
valid
|
||||
rescue StandardError
|
||||
false
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue