diff --git a/app/controllers/registrar/nameservers_controller.rb b/app/controllers/registrar/nameservers_controller.rb index 05e47e1dc..bb74015fd 100644 --- a/app/controllers/registrar/nameservers_controller.rb +++ b/app/controllers/registrar/nameservers_controller.rb @@ -2,27 +2,29 @@ class Registrar::NameserversController < RegistrarController load_and_authorize_resource def index - nameservers = current_user.registrar.nameservers + if can_replace_hostnames? + res = Nameserver.replace_hostname_ends( + current_user.registrar.domains.includes( + :registrant, :nameservers, :admin_domain_contacts, :tech_domain_contacts, :domain_statuses, + :versions, :admin_contacts, :tech_contacts, :whois_record, :dnskeys + ), + params[:q][:hostname_end], + params[:hostname_end_replacement] + ) + + if res + params[:q][:hostname_end] = params[:hostname_end_replacement] + params[:hostname_end_replacement] = nil + flash.now[:notice] = t('all_hostnames_replaced') + else + flash.now[:warning] = t('hostnames_partially_replaced') + end + end + + nameservers = current_user.registrar.nameservers.includes(:domain) @q = nameservers.search(params[:q]) @q.sorts = 'id desc' if @q.sorts.empty? @nameservers = @q.result.page(params[:page]) - - return unless can_replace_hostnames? - - res = Nameserver.replace_hostname_ends( - current_user.registrar.domains.includes( - :registrant, :nameservers, :admin_domain_contacts, :tech_domain_contacts, :domain_statuses, - :versions, :admin_contacts, :tech_contacts, :whois_record, :dnskeys - ), - params[:q][:hostname_end], - params[:hostname_end_replacement] - ) - - if res - flash.now[:notice] = t('all_hostnames_replaced') - else - flash.now[:warning] = t('hostnames_partially_replaced') - end end private diff --git a/app/models/nameserver.rb b/app/models/nameserver.rb index 20b554ea2..97d3ecb9a 100644 --- a/app/models/nameserver.rb +++ b/app/models/nameserver.rb @@ -45,14 +45,18 @@ class Nameserver < ActiveRecord::Base class << self def replace_hostname_ends(domains, old_end, new_end) + domains = domains.where('EXISTS( + select 1 from nameservers ns where ns.domain_id = domains.id AND ns.hostname LIKE ? + )', "%#{old_end}" + ) + res = true domains.each do |d| - nameservers = d.nameservers.where('hostname LIKE ?', "%#{old_end}") - next unless nameservers - ns_attrs = { nameservers_attributes: [] } - nameservers.each do |ns| + d.nameservers.each do |ns| + next unless ns.hostname.end_with?(old_end) + hn = ns.hostname.chomp(old_end) ns_attrs[:nameservers_attributes] << { id: ns.id, diff --git a/app/views/registrar/domains/index.haml b/app/views/registrar/domains/index.haml index 677ffe111..294f53432 100644 --- a/app/views/registrar/domains/index.haml +++ b/app/views/registrar/domains/index.haml @@ -1,7 +1,8 @@ - content_for :actions do - = link_to(t(:new), new_registrar_domain_path, class: 'btn btn-primary') + = link_to(t(:new), new_registrar_domain_path, class: 'btn btn-default') = link_to(t(:transfer), transfer_registrar_domains_path, class: 'btn btn-default') = link_to(t(:keyrelay), registrar_keyrelay_path, class: 'btn btn-default') + = link_to(t(:nameservers), registrar_nameservers_path, class: 'btn btn-default') = render 'shared/title', name: t(:domains) .row @@ -12,7 +13,7 @@ = text_field_tag :domain_name, params[:domain_name], class: 'form-control', placeholder: t('domain_name'), autocomplete: 'off', autofocus: true .col-md-1.text-right.text-center-xs .form-group - %button.btn.btn-primary + %button.btn.btn-default   %span.glyphicon.glyphicon-search   @@ -37,7 +38,7 @@ = Time.zone.parse(x['valid_to']).try(:to_date) %td = link_to(t(:edit), edit_registrar_domains_path(domain_name: x['name']), - class: 'btn btn-primary btn-xs') + class: 'btn btn-default btn-xs') = link_to(t(:renew), renew_registrar_domains_path(domain_name: x['name']), class: 'btn btn-default btn-xs') = link_to(t(:delete), delete_registrar_domains_path(domain_name: x['name']), diff --git a/app/views/registrar/nameservers/index.haml b/app/views/registrar/nameservers/index.haml index 8fdb29592..2c1b1b8d4 100644 --- a/app/views/registrar/nameservers/index.haml +++ b/app/views/registrar/nameservers/index.haml @@ -1,6 +1,5 @@ -/ - content_for :actions do -/ = link_to(t(:add_deposit), new_registrar_deposit_path, class: 'btn btn-primary') -/ = link_to(t(:account_activity), registrar_account_activities_path, class: 'btn btn-default') +- content_for :actions do + = link_to(t(:back_to_domains), registrar_domains_path, class: 'btn btn-default') = render 'shared/title', name: t(:nameservers) .row @@ -20,10 +19,13 @@   %span.glyphicon.glyphicon-search   - %button.btn.btn-default{name: 'replace'} - = t(:replace) %button.btn.btn-default.js-reset-form = t(:clear_fields) + %button.btn.btn-primary{name: 'replace'} + = t(:replace) + .row + .col-md-12 + %p.help-block= t('hostnames_will_be_replaced_only_if_domain_validates_with_the_new_nameserver') %hr .row .col-md-12 @@ -31,9 +33,10 @@ %table.table.table-hover.table-condensed %thead %tr - %th{class: 'col-xs-4'}= t(:hostname) - %th{class: 'col-xs-4'}= t(:ipv4) - %th{class: 'col-xs-4'}= t(:ipv6) + %th{class: 'col-xs-3'}= t(:hostname) + %th{class: 'col-xs-3'}= t(:ipv4) + %th{class: 'col-xs-3'}= t(:ipv6) + %th{class: 'col-xs-3'}= t(:domain) %tbody - @nameservers.each do |x| %tr @@ -46,9 +49,10 @@ %td= x.hostname %td= x.ipv4 %td= x.ipv4 + %td= link_to(x.domain, info_registrar_domains_url(domain_name: x.domain.name)) .row .col-md-12 - / = paginate @nameservers + = paginate @nameservers :coffee $(".js-reset-form").on "click", (e) -> diff --git a/config/locales/en.yml b/config/locales/en.yml index 531c4bfa0..bc273f25d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -753,3 +753,5 @@ en: hostnames_replaced: 'Hostnames replaced' all_hostnames_replaced: 'All hostnames replaced' hostnames_partially_replaced: 'Hostnames partially replaced' + hostnames_will_be_replaced_only_if_domain_validates_with_the_new_nameserver: 'Hostnames will be replaced only if domain validates with the new nameserver' + back_to_domains: 'Back to domains'