diff --git a/.codeclimate.yml b/.codeclimate.yml index 2324522fc..31da9b9cb 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -16,8 +16,10 @@ plugins: enabled: true config: languages: - - ruby - - javascript + ruby: + mass_threshold: 100 + javascript: + mass_threshold: 100 eslint: enabled: true channel: eslint-5 diff --git a/app/controllers/registrar/admin_contacts_controller.rb b/app/controllers/registrar/admin_contacts_controller.rb new file mode 100644 index 000000000..55cfbae9e --- /dev/null +++ b/app/controllers/registrar/admin_contacts_controller.rb @@ -0,0 +1,19 @@ +class Registrar + class AdminContactsController < BulkChangeController + BASE_URL = URI.parse("#{ENV['repp_url']}domains/admin_contacts").freeze + ACTIVE_TAB = :admin_contact + + def update + authorize! :manage, :repp + + uri = BASE_URL + request = form_request(uri) + response = do_request(request, uri) + start_notice = t('.replaced') + + process_response(response: response, + start_notice: start_notice, + active_tab: ACTIVE_TAB) + end + end +end diff --git a/app/controllers/registrar/bulk_change_controller.rb b/app/controllers/registrar/bulk_change_controller.rb index b11883d6a..74bbf89e8 100644 --- a/app/controllers/registrar/bulk_change_controller.rb +++ b/app/controllers/registrar/bulk_change_controller.rb @@ -26,6 +26,15 @@ class Registrar private + def form_request(uri) + request = Net::HTTP::Patch.new(uri) + request.set_form_data(current_contact_id: params[:current_contact_id], + new_contact_id: params[:new_contact_id]) + request.basic_auth(current_registrar_user.username, + current_registrar_user.plain_text_password) + request + end + def process_response(response:, start_notice: '', active_tab:) parsed_response = JSON.parse(response.body, symbolize_names: true) diff --git a/app/controllers/registrar/tech_contacts_controller.rb b/app/controllers/registrar/tech_contacts_controller.rb index 3cddb5f36..cc9238730 100644 --- a/app/controllers/registrar/tech_contacts_controller.rb +++ b/app/controllers/registrar/tech_contacts_controller.rb @@ -7,14 +7,8 @@ class Registrar authorize! :manage, :repp uri = BASE_URL - request = Net::HTTP::Patch.new(uri) - request.set_form_data(current_contact_id: params[:current_contact_id], - new_contact_id: params[:new_contact_id]) - request.basic_auth(current_registrar_user.username, - current_registrar_user.plain_text_password) - + request = form_request(uri) response = do_request(request, uri) - start_notice = t('.replaced') process_response(response: response, diff --git a/app/views/registrar/bulk_change/_admin_contact_form.html.erb b/app/views/registrar/bulk_change/_admin_contact_form.html.erb new file mode 100644 index 000000000..d8b4beb55 --- /dev/null +++ b/app/views/registrar/bulk_change/_admin_contact_form.html.erb @@ -0,0 +1,60 @@ +<%= form_tag registrar_admin_contacts_path, method: :patch, class: 'form-horizontal' do %> + <% if @error %> +
+ <%= @error %> +
+ <% end %> + +
+
+ <%= label_tag :current_contact_id, t('.current_contact_id') %> +
+ +
+ <%= text_field_tag :current_contact_id, params[:current_contact_id], + list: :contacts, + required: true, + autofocus: true, + class: 'form-control' %> +
+
+ +
+
+ <%= label_tag :new_contact_id, t('.new_contact_id') %> +
+ +
+ <%= text_field_tag :new_contact_id, params[:new_contact_id], + list: :contacts, + required: true, + class: 'form-control' %> +
+
+ +
+
+ +
+
+ +
+
+ <%= t '.help_btn' %> +
+
+ <%= t '.help' %> +
+
+
+
+<% end %> + + + <% available_contacts.each do |data| %> + + <% end %> + diff --git a/app/views/registrar/bulk_change/new.html.erb b/app/views/registrar/bulk_change/new.html.erb index e61270b6d..f3095a53d 100644 --- a/app/views/registrar/bulk_change/new.html.erb +++ b/app/views/registrar/bulk_change/new.html.erb @@ -12,6 +12,10 @@ <%= t '.technical_contact' %> +
  • + <%= t '.admin_contact' %> +
  • +
  • <%= t '.nameserver' %>
  • @@ -31,6 +35,11 @@ <%= render 'tech_contact_form', available_contacts: available_contacts %> +
    + <%= render 'admin_contact_form', available_contacts: available_contacts %> +
    +
    <%= render 'nameserver_form' %>
    diff --git a/config/locales/registrar/admin_contacts.en.yml b/config/locales/registrar/admin_contacts.en.yml new file mode 100644 index 000000000..9265a6d10 --- /dev/null +++ b/config/locales/registrar/admin_contacts.en.yml @@ -0,0 +1,6 @@ +en: + registrar: + admin_contacts: + update: + replaced: Admin contacts have been successfully replaced. + replaced: Technical contacts have been successfully replaced. diff --git a/config/locales/registrar/bulk_change.en.yml b/config/locales/registrar/bulk_change.en.yml index 58d5fce97..6bd7fd84c 100644 --- a/config/locales/registrar/bulk_change.en.yml +++ b/config/locales/registrar/bulk_change.en.yml @@ -18,6 +18,16 @@ en: Replace technical contact specified in "current contact ID" with the one in "new contact ID" on any domain registered under this registrar + admin_contact_form: + current_contact_id: Current admin contact ID + new_contact_id: New admin contact ID + submit_btn: Replace admin contacts + help_btn: Toggle help + help: >- + Replace admin contact specified in "current contact ID" with the one in "new + contact ID" on any domain registered under this registrar. Contact idents must + be the same + nameserver_form: ip_hint: One IP per line replace_btn: Replace nameserver diff --git a/config/routes.rb b/config/routes.rb index 16102f2b6..2c9590477 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -137,6 +137,7 @@ Rails.application.routes.draw do resource :bulk_change, controller: :bulk_change, only: :new post '/bulk_renew/new', to: 'bulk_change#bulk_renew', as: :bulk_renew resource :tech_contacts, only: :update + resource :admin_contacts, only: :update resource :nameservers, only: :update resources :contacts, constraints: {:id => /[^\/]+(?=#{ ActionController::Renderers::RENDERERS.map{|e| "\\.#{e}\\z"}.join("|") })|[^\/]+/} do member do