Merge remote-tracking branch 'origin/master' into repp-domains

This commit is contained in:
Karl Erik Õunapuu 2021-01-11 16:01:55 +02:00
commit 70759cb51b
No known key found for this signature in database
GPG key ID: C9DD647298A34764
24 changed files with 331 additions and 28 deletions

View file

@ -0,0 +1,27 @@
# frozen_string_literal: true
module Admin
class MassActionsController < BaseController
before_action :authorize_admin
# GET /admin/mass_actions
def index; end
# POST /admin/mass_actions
def create
res = MassAction.process(params[:mass_action], params[:entry_list].path)
notice = if res
"#{params[:mass_action]} completed for #{res[:ok]}.\n" \
"Failed: #{res[:fail]}"
else
"Dataset integrity validation failed for #{params[:mass_action]}"
end
redirect_to(admin_mass_actions_path, notice: notice)
end
def authorize_admin
authorize! :manage, :mass_actions
end
end
end

View file

@ -48,18 +48,25 @@ class Registrar
parsed_response = JSON.parse(response.body, symbolize_names: true)
if response.code == '200'
notices = [t('.replaced')]
notices << "#{t('.affected_domains')}: " \
"#{parsed_response[:data][:affected_domains].join(', ')}"
flash[:notice] = notices.join(', ')
redirect_to registrar_domains_url
redirect_to(registrar_domains_url,
flash: { notice: compose_notice_message(parsed_response) })
else
@api_errors = parsed_response[:message]
render file: 'registrar/bulk_change/new', locals: { active_tab: :nameserver }
end
end
def compose_notice_message(res)
notices = ["#{t('.replaced')}. #{t('.affected_domains')}: " \
"#{res[:data][:affected_domains].join(', ')}"]
if res[:data][:skipped_domains]
notices << "#{t('.skipped_domains')}: #{res[:data][:skipped_domains].join(', ')}"
end
notices.join(', ')
end
def domain_list_from_csv
return [] if params[:puny_file].blank?

View file

@ -5,25 +5,31 @@ module Repp
before_action :verify_nameserver_existance, only: %i[update]
def update
domains = params[:data][:domains] || []
affected = current_user.registrar
.replace_nameservers(hostname,
hostname_params[:data][:attributes],
domains: domains)
affected, errored = current_user.registrar
.replace_nameservers(hostname,
hostname_params[:data][:attributes],
domains: domains_from_params)
render_success(data: data_format_for_success(affected))
render_success(data: data_format_for_success(affected, errored))
rescue ActiveRecord::RecordInvalid => e
handle_errors(e.record)
end
private
def data_format_for_success(affected_domains)
def domains_from_params
return [] unless params[:data][:domains]
params[:data][:domains].map(&:downcase)
end
def data_format_for_success(affected_domains, errored_domains)
{
type: 'nameserver',
id: params[:data][:attributes][:hostname],
attributes: params[:data][:attributes],
affected_domains: affected_domains,
skipped_domains: errored_domains,
}
end