From 5e39af41e321cce686d0072c05929e879143392a Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 11 Jan 2018 15:25:03 +0200 Subject: [PATCH 01/26] Remove test-dependent code --- app/controllers/registrant/sessions_controller.rb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/controllers/registrant/sessions_controller.rb b/app/controllers/registrant/sessions_controller.rb index e1523c919..2ab7e0dde 100644 --- a/app/controllers/registrant/sessions_controller.rb +++ b/app/controllers/registrant/sessions_controller.rb @@ -31,12 +31,6 @@ class Registrant::SessionsController < Devise::SessionsController client = Digidoc::Client.new(endpoint) client.logger = Rails.application.config.logger unless Rails.env.test? - if Rails.env.test? && phone == "123" - @user = ApiUser.find_by(identity_code: "14212128025") - sign_in(@user, event: :authentication) - return redirect_to registrant_root_url - end - # country_codes = {'+372' => 'EST'} response = client.authenticate( phone: "+372#{phone}", From 294ff638b14f0784253c53ef217e07c3062c3b41 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 11 Jan 2018 15:49:39 +0200 Subject: [PATCH 02/26] Remove unused routes --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 9a513b434..ffb618410 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -99,7 +99,7 @@ Rails.application.routes.draw do namespace :registrant do root 'domains#index' - resources :domains do + resources :domains, only: %i[index show] do collection do get :download_list end From 7fe3e2765a75256b46613a256df5476c3d99ca01 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 11 Jan 2018 15:53:13 +0200 Subject: [PATCH 03/26] Reformat code --- .../registrant/domains_controller.rb | 26 +++++++++---------- config/routes.rb | 1 - 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/app/controllers/registrant/domains_controller.rb b/app/controllers/registrant/domains_controller.rb index fbd0eff13..8aa86aff5 100644 --- a/app/controllers/registrant/domains_controller.rb +++ b/app/controllers/registrant/domains_controller.rb @@ -1,13 +1,12 @@ class Registrant::DomainsController < RegistrantController - def index - authorize! :view, :registrant_domains - params[:q] ||= {} - normalize_search_parameters do - @q = domains.search(params[:q]) - @domains = @q.result.page(params[:page]) - end - @domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i > 0 + authorize! :view, :registrant_domains + params[:q] ||= {} + normalize_search_parameters do + @q = domains.search(params[:q]) + @domains = @q.result.page(params[:page]) + end + @domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i > 0 end def show @@ -23,11 +22,11 @@ class Registrant::DomainsController < RegistrantController authorize! :view, :registrant_domains dom = domains.find(params[:id]) if (dom.statuses.include?(DomainStatus::PENDING_UPDATE) || dom.statuses.include?(DomainStatus::PENDING_DELETE_CONFIRMATION)) && - dom.pending_json.present? + dom.pending_json.present? - @domain = dom - confirm_path = get_confirm_path(dom.statuses) - @verification_url = "#{confirm_path}/#{@domain.id}?token=#{@domain.registrant_verification_token}" + @domain = dom + confirm_path = get_confirm_path(dom.statuses) + @verification_url = "#{confirm_path}/#{@domain.id}?token=#{@domain.registrant_verification_token}" else flash[:warning] = I18n.t('available_verification_url_not_found') @@ -82,5 +81,4 @@ class Registrant::DomainsController < RegistrantController "#{ENV['registrant_url']}/registrant/domain_delete_confirms" end end - -end \ No newline at end of file +end diff --git a/config/routes.rb b/config/routes.rb index ffb618410..242028cbb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -107,7 +107,6 @@ Rails.application.routes.draw do member do get 'domain_verification_url' end - end # resources :invoices do From 5533b4f891959baa395910b880ccf7028825ed84 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 11 Jan 2018 15:55:15 +0200 Subject: [PATCH 04/26] Encapsulate methods --- app/controllers/registrant/domains_controller.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/registrant/domains_controller.rb b/app/controllers/registrant/domains_controller.rb index 8aa86aff5..7cde44a86 100644 --- a/app/controllers/registrant/domains_controller.rb +++ b/app/controllers/registrant/domains_controller.rb @@ -14,10 +14,6 @@ class Registrant::DomainsController < RegistrantController authorize! :read, @domain end - def set_domain - @domain = domains.find(params[:id]) - end - def domain_verification_url authorize! :view, :registrant_domains dom = domains.find(params[:id]) @@ -51,6 +47,12 @@ class Registrant::DomainsController < RegistrantController end end + private + + def set_domain + @domain = domains.find(params[:id]) + end + def domains ident_cc, ident = @current_user.registrant_ident.split '-' begin From 51a80ce748425ba3ee1b39b75be0849bc4c7d7ff Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 11 Jan 2018 16:07:19 +0200 Subject: [PATCH 05/26] Remove inline coffeescript --- app/views/registrant/domains/index.haml | 9 +-------- config/locales/registrant/domains.en.yml | 1 + 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/app/views/registrant/domains/index.haml b/app/views/registrant/domains/index.haml index 056abd885..c0daa60df 100644 --- a/app/views/registrant/domains/index.haml +++ b/app/views/registrant/domains/index.haml @@ -30,8 +30,7 @@   %span.glyphicon.glyphicon-search   - %button.btn.btn-default.js-reset-form - = t(:clear_fields) + = link_to(t('.reset_btn'), registrant_domains_path, class: 'btn btn-default') .row .col-md-3 .btn-group{:role => "group"} @@ -76,9 +75,3 @@ .col-md-6.text-right .pagination = t(:result_count, count: @domains.total_count) - -:coffee - $(".js-reset-form").on "click", (e) -> - e.preventDefault(); - window.location = "#{registrant_domains_path}" - diff --git a/config/locales/registrant/domains.en.yml b/config/locales/registrant/domains.en.yml index efbe514e5..d426e24fe 100644 --- a/config/locales/registrant/domains.en.yml +++ b/config/locales/registrant/domains.en.yml @@ -3,6 +3,7 @@ en: domains: index: registrant: Registrant + reset_btn: Reset download_list: registrant: Registrant From 1fb601694e574bb03f01913d44da47c6615d9b32 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 11 Jan 2018 16:09:29 +0200 Subject: [PATCH 06/26] Convert HAML to ERB --- app/views/registrant/domains/index.haml | 77 ------------ app/views/registrant/domains/index.html.erb | 122 ++++++++++++++++++++ app/views/registrant/domains/show.haml | 17 --- app/views/registrant/domains/show.html.erb | 46 ++++++++ 4 files changed, 168 insertions(+), 94 deletions(-) delete mode 100644 app/views/registrant/domains/index.haml create mode 100644 app/views/registrant/domains/index.html.erb delete mode 100644 app/views/registrant/domains/show.haml create mode 100644 app/views/registrant/domains/show.html.erb diff --git a/app/views/registrant/domains/index.haml b/app/views/registrant/domains/index.haml deleted file mode 100644 index c0daa60df..000000000 --- a/app/views/registrant/domains/index.haml +++ /dev/null @@ -1,77 +0,0 @@ -= render 'shared/title', name: t(:domains) - -.row - .col-md-12 - = search_form_for [:registrant, @q], html: { style: 'margin-bottom: 0;', class: 'js-form', autocomplete: 'off' } do |f| - .row - .col-md-3 - .form-group - = f.label :name - = f.search_field :name_matches, value: params[:q][:name_matches], class: 'form-control', placeholder: t(:name) - .col-md-3 - .form-group - = f.label t(:registrant_ident) - = f.search_field :registrant_ident_eq, class: 'form-control', placeholder: t(:registrant_ident) - .row - .col-md-3 - .form-group - = f.label t(:valid_to_from) - = f.search_field :valid_to_gteq, value: params[:q][:valid_to_gteq], class: 'form-control js-datepicker', placeholder: t(:valid_to_from) - .col-md-3 - .form-group - = f.label t(:valid_to_until) - = f.search_field :valid_to_lteq, value: params[:q][:valid_to_lteq], class: 'form-control js-datepicker', placeholder: t(:valid_to_until) - .col-md-3 - .form-group - = label_tag t(:results_per_page) - = text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page) - .col-md-3{style: 'padding-top: 25px;'} - %button.btn.btn-primary -   - %span.glyphicon.glyphicon-search -   - = link_to(t('.reset_btn'), registrant_domains_path, class: 'btn btn-default') - .row - .col-md-3 - .btn-group{:role => "group"} - %button.btn.btn-default.dropdown-toggle{"aria-expanded" => "false", "aria-haspopup" => "true", "data-toggle" => "dropdown", :type => "button"} - Download - %span.caret - %ul.dropdown-menu - %li= link_to 'PDF', download_list_registrant_domains_path(q: params[:q], format: "pdf") - %li= link_to 'CSV', download_list_registrant_domains_path(q: params[:q], format: "csv") - .col-md-3 - .col-md-3 - .col-md-3 - - - -%hr -.row - .col-md-12 - .table-responsive - %table.table.table-hover.table-bordered.table-condensed - %thead - %tr - %th{class: 'col-xs-2'} - = sort_link(@q, 'name') - %th{class: 'col-xs-2'} - = sort_link(@q, 'registrant_name', t('.registrant')) - %th{class: 'col-xs-2'} - = sort_link(@q, 'valid_to', t(:valid_to)) - %th{class: 'col-xs-2'} - = sort_link(@q, 'registrar_name', t(:registrar_name)) - %tbody - - @domains.each do |x| - %tr - %td= link_to(x, registrant_domain_path(x)) - %td= link_to(x.registrant.name, registrant_contact_path(x.registrant)) if x.registrant - %td= l(x.valid_to, format: :short) - %td= link_to(x.registrar, registrant_registrar_path(x.registrar)) if x.registrar - - .row - .col-md-6 - = paginate @domains - .col-md-6.text-right - .pagination - = t(:result_count, count: @domains.total_count) diff --git a/app/views/registrant/domains/index.html.erb b/app/views/registrant/domains/index.html.erb new file mode 100644 index 000000000..d39ed5a33 --- /dev/null +++ b/app/views/registrant/domains/index.html.erb @@ -0,0 +1,122 @@ +<%= render 'shared/title', name: t(:domains) %> +
+
+ <%= search_form_for [:registrant, @q], html: { style: 'margin-bottom: 0;', class: 'js-form', autocomplete: 'off' } do |f| %> +
+
+
+ <%= f.label :name %> + <%= f.search_field :name_matches, value: params[:q][:name_matches], class: 'form-control', placeholder: t(:name) %> +
+
+
+
+ <%= f.label t(:registrant_ident) %> + <%= f.search_field :registrant_ident_eq, class: 'form-control', placeholder: t(:registrant_ident) %> +
+
+
+
+
+
+ <%= f.label t(:valid_to_from) %> + <%= f.search_field :valid_to_gteq, value: params[:q][:valid_to_gteq], class: 'form-control js-datepicker', placeholder: t(:valid_to_from) %> +
+
+
+
+ <%= f.label t(:valid_to_until) %> + <%= f.search_field :valid_to_lteq, value: params[:q][:valid_to_lteq], class: 'form-control js-datepicker', placeholder: t(:valid_to_until) %> +
+
+
+
+ <%= label_tag t(:results_per_page) %> + <%= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page) %> +
+
+
+ + <%= link_to(t('.reset_btn'), registrant_domains_path, class: 'btn btn-default') %> +
+
+
+
+
+ + +
+
+
+
+
+
+ <% end %> +
+
+
+
+
+
+ + + + + + + + + + + <% @domains.each do |x| %> + + + + + + +
+ <% end %> + +
+ <%= sort_link(@q, 'name') %> + + <%= sort_link(@q, 'registrant_name', t('.registrant')) %> + + <%= sort_link(@q, 'valid_to', t(:valid_to)) %> + + <%= sort_link(@q, 'registrar_name', t(:registrar_name)) %> +
+ <%= link_to(x, registrant_domain_path(x)) %> + + <%= link_to(x.registrant.name, registrant_contact_path(x.registrant)) if x.registrant %> + + <%= l(x.valid_to, format: :short) %> + + <%= link_to(x.registrar, registrant_registrar_path(x.registrar)) if x.registrar %> +
+
+
+
+ <%= paginate @domains %> +
+
+ +
+
diff --git a/app/views/registrant/domains/show.haml b/app/views/registrant/domains/show.haml deleted file mode 100644 index 4d524b785..000000000 --- a/app/views/registrant/domains/show.haml +++ /dev/null @@ -1,17 +0,0 @@ -= render 'shared/title', name: @domain.name - -.row - .col-md-6= render 'registrant/domains/partials/general' - .col-md-6= render 'registrant/domains/partials/owner' -.row - .col-md-12= render 'registrant/domains/partials/tech_contacts' -.row - .col-md-12= render 'registrant/domains/partials/admin_contacts' -.row - .col-md-12= render 'registrant/domains/partials/statuses' -.row - .col-md-12= render 'registrant/domains/partials/nameservers' -.row - .col-md-12= render 'registrant/domains/partials/dnskeys' -.row - .col-md-12= render 'registrant/domains/partials/keyrelays' diff --git a/app/views/registrant/domains/show.html.erb b/app/views/registrant/domains/show.html.erb new file mode 100644 index 000000000..32dc2584a --- /dev/null +++ b/app/views/registrant/domains/show.html.erb @@ -0,0 +1,46 @@ +<%= render 'shared/title', name: @domain.name %> + +
+
+ <%= render 'registrant/domains/partials/general' %> +
+
+ <%= render 'registrant/domains/partials/owner' %> +
+
+ +
+
+ <%= render 'registrant/domains/partials/tech_contacts' %> +
+
+ +
+
+ <%= render 'registrant/domains/partials/admin_contacts' %> +
+
+ +
+
+ <%= render 'registrant/domains/partials/statuses' %> +
+
+ +
+
+ <%= render 'registrant/domains/partials/nameservers' %> +
+
+ +
+
+ <%= render 'registrant/domains/partials/dnskeys' %> +
+
+ +
+
+ <%= render 'registrant/domains/partials/keyrelays' %> +
+
From 3d13456e2999df9da3061e3391ce614b7d5aaf9f Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 11 Jan 2018 16:50:49 +0200 Subject: [PATCH 07/26] Remove unused CSS class --- app/views/registrant/domains/index.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/registrant/domains/index.html.erb b/app/views/registrant/domains/index.html.erb index d39ed5a33..6c8b3c579 100644 --- a/app/views/registrant/domains/index.html.erb +++ b/app/views/registrant/domains/index.html.erb @@ -1,7 +1,7 @@ <%= render 'shared/title', name: t(:domains) %>
- <%= search_form_for [:registrant, @q], html: { style: 'margin-bottom: 0;', class: 'js-form', autocomplete: 'off' } do |f| %> + <%= search_form_for [:registrant, @q], html: { style: 'margin-bottom: 0;', autocomplete: 'off' } do |f| %>
From 8744445cd25370aa67a0c66a6a79b5a9cc68451a Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 11 Jan 2018 17:00:21 +0200 Subject: [PATCH 08/26] Fix invalid HTML --- app/views/layouts/registrant/application.haml | 2 +- app/views/registrant/domains/index.html.erb | 15 +++++++++------ config/locales/registrant/domains.en.yml | 1 + 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/views/layouts/registrant/application.haml b/app/views/layouts/registrant/application.haml index 2eba33ea5..f0a3a58aa 100644 --- a/app/views/layouts/registrant/application.haml +++ b/app/views/layouts/registrant/application.haml @@ -49,7 +49,7 @@ %footer.footer .container - %row + .row .col-md-6 = image_tag 'eis-logo-et.png' .col-md-6.text-right diff --git a/app/views/registrant/domains/index.html.erb b/app/views/registrant/domains/index.html.erb index 6c8b3c579..427b00b93 100644 --- a/app/views/registrant/domains/index.html.erb +++ b/app/views/registrant/domains/index.html.erb @@ -1,17 +1,20 @@ -<%= render 'shared/title', name: t(:domains) %> + +
- <%= search_form_for [:registrant, @q], html: { style: 'margin-bottom: 0;', autocomplete: 'off' } do |f| %> + <%= search_form_for [:registrant, @q], html: { autocomplete: 'off' } do |f| %>
- <%= f.label :name %> + <%= f.label :name, for: nil %> <%= f.search_field :name_matches, value: params[:q][:name_matches], class: 'form-control', placeholder: t(:name) %>
- <%= f.label t(:registrant_ident) %> + <%= f.label t(:registrant_ident), for: nil %> <%= f.search_field :registrant_ident_eq, class: 'form-control', placeholder: t(:registrant_ident) %>
@@ -19,13 +22,13 @@
- <%= f.label t(:valid_to_from) %> + <%= f.label t(:valid_to_from), for: nil %> <%= f.search_field :valid_to_gteq, value: params[:q][:valid_to_gteq], class: 'form-control js-datepicker', placeholder: t(:valid_to_from) %>
- <%= f.label t(:valid_to_until) %> + <%= f.label t(:valid_to_until), for: nil %> <%= f.search_field :valid_to_lteq, value: params[:q][:valid_to_lteq], class: 'form-control js-datepicker', placeholder: t(:valid_to_until) %>
diff --git a/config/locales/registrant/domains.en.yml b/config/locales/registrant/domains.en.yml index d426e24fe..be0a1c638 100644 --- a/config/locales/registrant/domains.en.yml +++ b/config/locales/registrant/domains.en.yml @@ -2,6 +2,7 @@ en: registrant: domains: index: + header: Domains registrant: Registrant reset_btn: Reset From 3ab2df06ee9665cc079a3fee8b800e1fe32e5505 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 11 Jan 2018 17:12:00 +0200 Subject: [PATCH 09/26] Include forms in registrant CSS --- app/assets/stylesheets/forms.scss | 4 ++++ app/assets/stylesheets/registrant-manifest.sass | 1 + 2 files changed, 5 insertions(+) diff --git a/app/assets/stylesheets/forms.scss b/app/assets/stylesheets/forms.scss index c59a5e951..7962ffcae 100644 --- a/app/assets/stylesheets/forms.scss +++ b/app/assets/stylesheets/forms.scss @@ -5,3 +5,7 @@ input[type=number]::-webkit-inner-spin-button { input[type=number] { -moz-appearance: textfield; } + +.search-form .actions { + padding-top: 25px; +} diff --git a/app/assets/stylesheets/registrant-manifest.sass b/app/assets/stylesheets/registrant-manifest.sass index 154645065..75eafe582 100644 --- a/app/assets/stylesheets/registrant-manifest.sass +++ b/app/assets/stylesheets/registrant-manifest.sass @@ -5,6 +5,7 @@ //= require 'select2-bootstrap' @import shared/fonts @import shared/general +@import forms @import nprogress @import nprogress-bootstrap @import typeaheadjs From 666db8c1fcae60ece28edda0afa21f2a7e9dd65e Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 11 Jan 2018 17:12:30 +0200 Subject: [PATCH 10/26] Remove inline CSS --- app/views/registrant/domains/index.html.erb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/registrant/domains/index.html.erb b/app/views/registrant/domains/index.html.erb index 427b00b93..a5cb98049 100644 --- a/app/views/registrant/domains/index.html.erb +++ b/app/views/registrant/domains/index.html.erb @@ -4,7 +4,7 @@
- <%= search_form_for [:registrant, @q], html: { autocomplete: 'off' } do |f| %> + <%= search_form_for [:registrant, @q], html: { class: 'search-form', autocomplete: 'off' } do |f| %>
@@ -38,7 +38,8 @@ <%= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page) %>
-
+ +
From 1938c8e6cf6f3c5ea033aa0c589408de3f255872 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 12 Jan 2018 10:11:04 +0200 Subject: [PATCH 22/26] Remove unused DB column --- .../20180112080312_remove_domain_contacts_contact_type.rb | 5 +++++ db/structure.sql | 3 ++- doc/models_complete.svg | 3 --- 3 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20180112080312_remove_domain_contacts_contact_type.rb diff --git a/db/migrate/20180112080312_remove_domain_contacts_contact_type.rb b/db/migrate/20180112080312_remove_domain_contacts_contact_type.rb new file mode 100644 index 000000000..0047c532e --- /dev/null +++ b/db/migrate/20180112080312_remove_domain_contacts_contact_type.rb @@ -0,0 +1,5 @@ +class RemoveDomainContactsContactType < ActiveRecord::Migration + def change + remove_column :domain_contacts, :contact_type, :string + end +end diff --git a/db/structure.sql b/db/structure.sql index d823ae27c..d2bbcd59f 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -884,7 +884,6 @@ CREATE TABLE domain_contacts ( id integer NOT NULL, contact_id integer, domain_id integer, - contact_type character varying, created_at timestamp without time zone, updated_at timestamp without time zone, contact_code_cache character varying, @@ -5060,3 +5059,5 @@ INSERT INTO schema_migrations (version) VALUES ('20171121233843'); INSERT INTO schema_migrations (version) VALUES ('20171123035941'); +INSERT INTO schema_migrations (version) VALUES ('20180112080312'); + diff --git a/doc/models_complete.svg b/doc/models_complete.svg index a4b16517f..b6216a3b0 100644 --- a/doc/models_complete.svg +++ b/doc/models_complete.svg @@ -812,7 +812,6 @@ id :integer contact_id :integer domain_id :integer -contact_type :string created_at :datetime updated_at :datetime contact_code_cache :string @@ -1066,7 +1065,6 @@ id :integer contact_id :integer domain_id :integer -contact_type :string created_at :datetime updated_at :datetime contact_code_cache :string @@ -1345,7 +1343,6 @@ id :integer contact_id :integer domain_id :integer -contact_type :string created_at :datetime updated_at :datetime contact_code_cache :string From 233bbd752efacff89fec1227437321362dafeb62 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 12 Jan 2018 10:49:19 +0200 Subject: [PATCH 23/26] Add "domain_contacts" DB table foreign keys --- ...84221_add_domain_contacts_contact_id_fk.rb | 5 +++++ ...084442_add_domain_contacts_domain_id_fk.rb | 5 +++++ db/structure.sql | 20 +++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 db/migrate/20180112084221_add_domain_contacts_contact_id_fk.rb create mode 100644 db/migrate/20180112084442_add_domain_contacts_domain_id_fk.rb diff --git a/db/migrate/20180112084221_add_domain_contacts_contact_id_fk.rb b/db/migrate/20180112084221_add_domain_contacts_contact_id_fk.rb new file mode 100644 index 000000000..5c6ff341c --- /dev/null +++ b/db/migrate/20180112084221_add_domain_contacts_contact_id_fk.rb @@ -0,0 +1,5 @@ +class AddDomainContactsContactIdFk < ActiveRecord::Migration + def change + add_foreign_key :domain_contacts, :contacts, name: 'domain_contacts_contact_id_fk' + end +end diff --git a/db/migrate/20180112084442_add_domain_contacts_domain_id_fk.rb b/db/migrate/20180112084442_add_domain_contacts_domain_id_fk.rb new file mode 100644 index 000000000..e3a84a688 --- /dev/null +++ b/db/migrate/20180112084442_add_domain_contacts_domain_id_fk.rb @@ -0,0 +1,5 @@ +class AddDomainContactsDomainIdFk < ActiveRecord::Migration + def change + add_foreign_key :domain_contacts, :domains, name: 'domain_contacts_domain_id_fk' + end +end diff --git a/db/structure.sql b/db/structure.sql index d2bbcd59f..d2000ab98 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -4473,6 +4473,22 @@ ALTER TABLE ONLY contacts ADD CONSTRAINT contacts_registrar_id_fk FOREIGN KEY (registrar_id) REFERENCES registrars(id); +-- +-- Name: domain_contacts_contact_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY domain_contacts + ADD CONSTRAINT domain_contacts_contact_id_fk FOREIGN KEY (contact_id) REFERENCES contacts(id); + + +-- +-- Name: domain_contacts_domain_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY domain_contacts + ADD CONSTRAINT domain_contacts_domain_id_fk FOREIGN KEY (domain_id) REFERENCES domains(id); + + -- -- Name: domains_registrant_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: - -- @@ -5061,3 +5077,7 @@ INSERT INTO schema_migrations (version) VALUES ('20171123035941'); INSERT INTO schema_migrations (version) VALUES ('20180112080312'); +INSERT INTO schema_migrations (version) VALUES ('20180112084221'); + +INSERT INTO schema_migrations (version) VALUES ('20180112084442'); + From a183eb400bbbf6b390a7501b1ea5424bc8210b22 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sat, 13 Jan 2018 12:52:11 +0200 Subject: [PATCH 24/26] Remove unused code --- .reek | 1 - app/models/business_registry_cache.rb | 10 ---------- 2 files changed, 11 deletions(-) diff --git a/.reek b/.reek index 060f76785..933847410 100644 --- a/.reek +++ b/.reek @@ -246,7 +246,6 @@ DuplicateMethodCall: - Billing::Price#self.effective - Billing::Price#self.valid - BusinessRegistryCache#fetch_by_ident_and_cc - - BusinessRegistryCache#purge - Certificate#parse_metadata - Certificate#reload_apache - Certificate#revoke! diff --git a/app/models/business_registry_cache.rb b/app/models/business_registry_cache.rb index f73a5cfe8..8ec3e0786 100644 --- a/app/models/business_registry_cache.rb +++ b/app/models/business_registry_cache.rb @@ -69,15 +69,5 @@ class BusinessRegistryCache < ActiveRecord::Base def business_registry Soap::Arireg.new end - - def purge - STDOUT << "#{Time.zone.now.utc} - Starting Purge of old BusinessRegistry data from cache\n" unless Rails.env.test? - purged = 0 - BusinessRegistryCache.where('retrieved_on < ?', - Time.zone.now < Setting.days_to_keep_business_registry_cache.days).each do |br| - br.destroy and purged += 1 - end - STDOUT << "#{Time.zone.now.utc} - Finished purging #{purged} old BusinessRegistry cache items\n" unless Rails.env.test? - end end end From 67082374ff9587dfd006238f5beac372dabfa928 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sun, 14 Jan 2018 20:48:03 +0200 Subject: [PATCH 25/26] Show domains where current registrant user acts as a registrant #663 --- app/models/business_registry_cache.rb | 15 ++++--------- test/fixtures/business_registry_caches.yml | 8 +++++++ test/fixtures/contacts.yml | 20 +++++++++++++++++ test/fixtures/domain_contacts.yml | 4 ++++ test/fixtures/domains.yml | 14 ++++++++++++ test/fixtures/registrars.yml | 3 +++ test/fixtures/users.yml | 4 ++++ test/integration/registrant/domains_test.rb | 25 +++++++++++++++++++++ 8 files changed, 82 insertions(+), 11 deletions(-) create mode 100644 test/fixtures/business_registry_caches.yml create mode 100644 test/fixtures/contacts.yml create mode 100644 test/fixtures/domain_contacts.yml create mode 100644 test/fixtures/domains.yml create mode 100644 test/integration/registrant/domains_test.rb diff --git a/app/models/business_registry_cache.rb b/app/models/business_registry_cache.rb index 8ec3e0786..2e7c06cc8 100644 --- a/app/models/business_registry_cache.rb +++ b/app/models/business_registry_cache.rb @@ -19,24 +19,17 @@ authentication using electronic ID. Association through a business organisation =end class BusinessRegistryCache < ActiveRecord::Base - - # 1. load domains by business - # 2. load domains by person - def associated_contacts - contact_ids = Contact.where(ident_type: 'org', ident: associated_businesses, ident_country_code: 'EE').pluck(:id) - contact_ids += Contact.where(ident_type: 'priv', ident: ident, ident_country_code: ident_country_code).pluck(:id) - contact_ids - end - def associated_domain_ids + contact_ids = Contact.where(ident_type: 'org', ident: associated_businesses, ident_country_code: ident_country_code).pluck(:id) + contact_ids += Contact.where(ident_type: 'priv', ident: ident, ident_country_code: ident_country_code).pluck(:id) domain_ids = [] - contact_ids = associated_contacts - unless contact_ids.blank? domain_ids = DomainContact.distinct.where(contact_id: contact_ids).pluck(:domain_id) end + domain_ids += Domain.where(registrant_id: contact_ids).pluck(:id) + domain_ids end diff --git a/test/fixtures/business_registry_caches.yml b/test/fixtures/business_registry_caches.yml new file mode 100644 index 000000000..c55c98e0d --- /dev/null +++ b/test/fixtures/business_registry_caches.yml @@ -0,0 +1,8 @@ +first: + ident: 1234 + ident_country_code: US + associated_businesses: + - 1234 + retrieved_on: 2010-07-05 10:30 + created_at: 2010-07-05 10:30 + updated_at: 2010-07-05 10:30 diff --git a/test/fixtures/contacts.yml b/test/fixtures/contacts.yml new file mode 100644 index 000000000..0300ef2b6 --- /dev/null +++ b/test/fixtures/contacts.yml @@ -0,0 +1,20 @@ +john: + name: John + ident: 1234 + ident_type: priv + ident_country_code: US + registrar: acme + +jane: + name: Jane + ident: 1234 + ident_type: priv + ident_country_code: US + registrar: acme + +acme_ltd: + name: Acme Ltd. + ident: 1234 + ident_type: org + registrar: acme + ident_country_code: US diff --git a/test/fixtures/domain_contacts.yml b/test/fixtures/domain_contacts.yml new file mode 100644 index 000000000..3e1d01d62 --- /dev/null +++ b/test/fixtures/domain_contacts.yml @@ -0,0 +1,4 @@ +two_jane: + domain: two + contact: jane + type: AdminDomainContact diff --git a/test/fixtures/domains.yml b/test/fixtures/domains.yml new file mode 100644 index 000000000..341f78d54 --- /dev/null +++ b/test/fixtures/domains.yml @@ -0,0 +1,14 @@ +one: + name: one.test + registrar: acme + registrant: john + +two: + name: two.test + registrar: acme + registrant: john + +three: + name: three.test + registrar: acme + registrant: acme_ltd diff --git a/test/fixtures/registrars.yml b/test/fixtures/registrars.yml index 52b2bbc00..960d47b13 100644 --- a/test/fixtures/registrars.yml +++ b/test/fixtures/registrars.yml @@ -10,6 +10,9 @@ DEFAULTS: &DEFAULTS valid: <<: *DEFAULTS +acme: + <<: *DEFAULTS + complete: <<: *DEFAULTS name: 2 diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 860f06c13..856788de9 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -14,3 +14,7 @@ admin: country_code: US roles: - admin + +registrant: + type: RegistrantUser + registrant_ident: US-1234 diff --git a/test/integration/registrant/domains_test.rb b/test/integration/registrant/domains_test.rb new file mode 100644 index 000000000..6a1a76e39 --- /dev/null +++ b/test/integration/registrant/domains_test.rb @@ -0,0 +1,25 @@ +require 'test_helper' + +class DomainsTest < ActionDispatch::IntegrationTest + def setup + login_as users(:registrant) + + Setting.days_to_keep_business_registry_cache = 1 + travel_to Time.zone.parse('2010-07-05') + end + + def test_shows_domains_where_current_user_is_registrant + visit registrant_domains_url + assert_text 'one.test' + end + + def test_shows_domains_where_current_user_is_contact_person + visit registrant_domains_url + assert_text 'two.test' + end + + def test_shows_domains_where_current_user_has_associated_organizations + visit registrant_domains_url + assert_text 'three.test' + end +end From b363358d79430d1a57a502208792d5ff86c41c38 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sun, 14 Jan 2018 21:01:19 +0200 Subject: [PATCH 26/26] Fix fixtures --- test/fixtures/domains.yml | 6 +++--- test/fixtures/registrars.yml | 3 --- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/test/fixtures/domains.yml b/test/fixtures/domains.yml index 341f78d54..46a1e44e0 100644 --- a/test/fixtures/domains.yml +++ b/test/fixtures/domains.yml @@ -1,14 +1,14 @@ one: name: one.test - registrar: acme + registrar: valid registrant: john two: name: two.test - registrar: acme + registrar: valid registrant: john three: name: three.test - registrar: acme + registrar: valid registrant: acme_ltd diff --git a/test/fixtures/registrars.yml b/test/fixtures/registrars.yml index 960d47b13..52b2bbc00 100644 --- a/test/fixtures/registrars.yml +++ b/test/fixtures/registrars.yml @@ -10,9 +10,6 @@ DEFAULTS: &DEFAULTS valid: <<: *DEFAULTS -acme: - <<: *DEFAULTS - complete: <<: *DEFAULTS name: 2