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/assets/javascripts/registrant-manifest.coffee b/app/assets/javascripts/registrant-manifest.coffee index b8ba84bba..eb7577e02 100644 --- a/app/assets/javascripts/registrant-manifest.coffee +++ b/app/assets/javascripts/registrant-manifest.coffee @@ -1,13 +1,7 @@ #= require jquery #= require jquery_ujs -#= require jquery.validate -#= require jquery.validate.additional-methods -#= require turbolinks #= require bootstrap-sprockets -#= require jquery.nested_attributes -#= require shared/jquery.validate.bootstrap #= require jquery-ui/datepicker #= require select2 #= require datepicker #= require shared/general -#= require registrar/application 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 diff --git a/app/controllers/registrant/domains_controller.rb b/app/controllers/registrant/domains_controller.rb index fbd0eff13..7cde44a86 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 @@ -15,19 +14,15 @@ 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]) 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') @@ -52,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 @@ -82,5 +83,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/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}", diff --git a/app/models/business_registry_cache.rb b/app/models/business_registry_cache.rb index f73a5cfe8..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 @@ -69,15 +62,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 diff --git a/app/views/layouts/registrant/application.haml b/app/views/layouts/registrant/application.haml index 2eba33ea5..3e55242b9 100644 --- a/app/views/layouts/registrant/application.haml +++ b/app/views/layouts/registrant/application.haml @@ -2,17 +2,14 @@ %html{lang: I18n.locale.to_s} %head %meta{charset: "utf-8"}/ - %meta{content: "IE=edge", "http-equiv" => "X-UA-Compatible"}/ %meta{content: "width=device-width, initial-scale=1", name: "viewport"}/ - %meta{content: "Full stack top-level domain (TLD) management.", name: "description"}/ - %meta{content: "Gitlab LTD", name: "author"}/ - if content_for? :head_title = yield :head_title - else %title= t(:registrant_head_title) = csrf_meta_tags - = stylesheet_link_tag 'registrant-manifest', media: 'all', 'data-turbolinks-track' => true - = javascript_include_tag 'registrant-manifest', 'data-turbolinks-track' => true + = stylesheet_link_tag 'registrant-manifest', media: 'all' + = javascript_include_tag 'registrant-manifest' = favicon_link_tag 'favicon.ico' %body / Fixed navbar @@ -49,7 +46,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/_domain.html.erb b/app/views/registrant/domains/_domain.html.erb new file mode 100644 index 000000000..b3bf4d334 --- /dev/null +++ b/app/views/registrant/domains/_domain.html.erb @@ -0,0 +1,6 @@ + + <%= link_to domain, registrant_domain_path(domain) %> + <%= link_to domain.registrant.name, registrant_contact_path(domain.registrant) %> + <%= l domain.expire_time %> + <%= link_to domain.registrar, registrant_registrar_path(domain.registrar) %> + diff --git a/app/views/registrant/domains/index.haml b/app/views/registrant/domains/index.haml deleted file mode 100644 index 056abd885..000000000 --- a/app/views/registrant/domains/index.haml +++ /dev/null @@ -1,84 +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 -   - %button.btn.btn-default.js-reset-form - = t(:clear_fields) - .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) - -:coffee - $(".js-reset-form").on "click", (e) -> - e.preventDefault(); - window.location = "#{registrant_domains_path}" - diff --git a/app/views/registrant/domains/index.html.erb b/app/views/registrant/domains/index.html.erb new file mode 100644 index 000000000..43a9122eb --- /dev/null +++ b/app/views/registrant/domains/index.html.erb @@ -0,0 +1,111 @@ + + +
+
+ <%= search_form_for [:registrant, @q], html: { class: 'search-form', autocomplete: 'off' } do |f| %> +
+
+
+ <%= 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), for: nil %> + <%= f.search_field :registrant_ident_eq, class: 'form-control', placeholder: t(:registrant_ident) %> +
+
+
+
+
+
+ <%= 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), for: nil %> + <%= 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 %> +
+
+
+
+
+
+ + + + + + + + + + + + <%= render @domains %> + +
+ <%= 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)) %> +
+
+
+
+ <%= 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' %> +
+
diff --git a/config/locales/registrant/domains.en.yml b/config/locales/registrant/domains.en.yml index efbe514e5..be0a1c638 100644 --- a/config/locales/registrant/domains.en.yml +++ b/config/locales/registrant/domains.en.yml @@ -2,7 +2,9 @@ en: registrant: domains: index: + header: Domains registrant: Registrant + reset_btn: Reset download_list: registrant: Registrant diff --git a/config/routes.rb b/config/routes.rb index 9a513b434..242028cbb 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 @@ -107,7 +107,6 @@ Rails.application.routes.draw do member do get 'domain_verification_url' end - end # resources :invoices do 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/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 d823ae27c..d2000ab98 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, @@ -4474,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: - -- @@ -5060,3 +5075,9 @@ INSERT INTO schema_migrations (version) VALUES ('20171121233843'); 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'); + 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 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..46a1e44e0 --- /dev/null +++ b/test/fixtures/domains.yml @@ -0,0 +1,14 @@ +one: + name: one.test + registrar: valid + registrant: john + +two: + name: two.test + registrar: valid + registrant: john + +three: + name: three.test + registrar: valid + registrant: acme_ltd 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