Fix tech contact / bulk transfer notifications

This commit is contained in:
Karl Erik Õunapuu 2020-12-22 19:05:06 +02:00
parent 903044263a
commit 8fffe6e736
No known key found for this signature in database
GPG key ID: C9DD647298A34764
5 changed files with 17 additions and 14 deletions

View file

@ -55,10 +55,12 @@ class Registrar
parsed_response = JSON.parse(response.body, symbolize_names: true) parsed_response = JSON.parse(response.body, symbolize_names: true)
if response.code == '200' if response.code == '200'
flash[:notice] = t '.transferred', count: parsed_response[:data].size failed = parsed_response[:data][:failed].each(&:domain_name).join(', ')
flash[:notice] = t('.transferred', success: parsed_response[:data][:success].size,
failed: failed)
redirect_to registrar_domains_url redirect_to registrar_domains_url
else else
@api_errors = parsed_response[:errors] @api_errors = parsed_response[:message]
render file: 'registrar/bulk_change/new', locals: { active_tab: :bulk_transfer } render file: 'registrar/bulk_change/new', locals: { active_tab: :bulk_transfer }
end end
else else

View file

@ -49,10 +49,10 @@ class Registrar
notices << "#{t('.skipped_domains')}: #{parsed_response[:data][:skipped_domains].join(', ')}" notices << "#{t('.skipped_domains')}: #{parsed_response[:data][:skipped_domains].join(', ')}"
end end
flash[:notice] = notices flash[:notice] = notices.join(', ')
redirect_to registrar_domains_url redirect_to registrar_domains_url
else else
@error = parsed_response[:message] @error = response.code == '404' ? 'Contact(s) not found' : parsed_response[:message]
render file: 'registrar/bulk_change/new', locals: { active_tab: :technical_contact } render file: 'registrar/bulk_change/new', locals: { active_tab: :technical_contact }
end end
end end

View file

@ -5,19 +5,20 @@ class TechDomainContact < DomainContact
skipped_domains = [] skipped_domains = []
tech_contacts = where(contact: current_contact) tech_contacts = where(contact: current_contact)
transaction do tech_contacts.each do |tech_contact|
tech_contacts.each do |tech_contact| if tech_contact.domain.discarded?
if tech_contact.domain.discarded? skipped_domains << tech_contact.domain.name
skipped_domains << tech_contact.domain.name next
next end
end begin
tech_contact.contact = new_contact tech_contact.contact = new_contact
tech_contact.save! tech_contact.save!
affected_domains << tech_contact.domain.name affected_domains << tech_contact.domain.name
rescue ActiveRecord::RecordNotUnique
skipped_domains << tech_contact.domain.name
end end
end end
return affected_domains.sort, skipped_domains.sort [affected_domains.sort, skipped_domains.sort]
end end
end end

View file

@ -1,7 +1,7 @@
<%= form_tag registrar_tech_contacts_path, method: :patch, class: 'form-horizontal' do %> <%= form_tag registrar_tech_contacts_path, method: :patch, class: 'form-horizontal' do %>
<% if @error %> <% if @error %>
<div class="alert alert-danger"> <div class="alert alert-danger">
<%= @error[:message] %> <%= @error %>
</div> </div>
<% end %> <% end %>

View file

@ -6,7 +6,7 @@ en:
create: create:
header: Domain transfer header: Domain transfer
transferred: "%{count} domains have been successfully transferred" transferred: "%{count} domains have been successfully transferred. Failed domains: %{failed}"
form: form:
submit_btn: Transfer submit_btn: Transfer