diff --git a/.reek b/.reek index 933847410..060f76785 100644 --- a/.reek +++ b/.reek @@ -246,6 +246,7 @@ 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 eb7577e02..b8ba84bba 100644 --- a/app/assets/javascripts/registrant-manifest.coffee +++ b/app/assets/javascripts/registrant-manifest.coffee @@ -1,7 +1,13 @@ #= 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 7962ffcae..c59a5e951 100644 --- a/app/assets/stylesheets/forms.scss +++ b/app/assets/stylesheets/forms.scss @@ -5,7 +5,3 @@ 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 75eafe582..154645065 100644 --- a/app/assets/stylesheets/registrant-manifest.sass +++ b/app/assets/stylesheets/registrant-manifest.sass @@ -5,7 +5,6 @@ //= 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 7cde44a86..fbd0eff13 100644 --- a/app/controllers/registrant/domains_controller.rb +++ b/app/controllers/registrant/domains_controller.rb @@ -1,12 +1,13 @@ 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 @@ -14,15 +15,19 @@ 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') @@ -47,12 +52,6 @@ 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 @@ -83,4 +82,5 @@ class Registrant::DomainsController < RegistrantController "#{ENV['registrant_url']}/registrant/domain_delete_confirms" end end -end + +end \ No newline at end of file diff --git a/app/controllers/registrant/sessions_controller.rb b/app/controllers/registrant/sessions_controller.rb index 2ab7e0dde..e1523c919 100644 --- a/app/controllers/registrant/sessions_controller.rb +++ b/app/controllers/registrant/sessions_controller.rb @@ -31,6 +31,12 @@ 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 2e7c06cc8..f73a5cfe8 100644 --- a/app/models/business_registry_cache.rb +++ b/app/models/business_registry_cache.rb @@ -19,17 +19,24 @@ authentication using electronic ID. Association through a business organisation =end class BusinessRegistryCache < ActiveRecord::Base - def associated_domain_ids - contact_ids = Contact.where(ident_type: 'org', ident: associated_businesses, ident_country_code: ident_country_code).pluck(:id) + + # 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 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 @@ -62,5 +69,15 @@ 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 3e55242b9..2eba33ea5 100644 --- a/app/views/layouts/registrant/application.haml +++ b/app/views/layouts/registrant/application.haml @@ -2,14 +2,17 @@ %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' - = javascript_include_tag 'registrant-manifest' + = stylesheet_link_tag 'registrant-manifest', media: 'all', 'data-turbolinks-track' => true + = javascript_include_tag 'registrant-manifest', 'data-turbolinks-track' => true = favicon_link_tag 'favicon.ico' %body / Fixed navbar @@ -46,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/_domain.html.erb b/app/views/registrant/domains/_domain.html.erb deleted file mode 100644 index b3bf4d334..000000000 --- a/app/views/registrant/domains/_domain.html.erb +++ /dev/null @@ -1,6 +0,0 @@ - - <%= 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 new file mode 100644 index 000000000..056abd885 --- /dev/null +++ b/app/views/registrant/domains/index.haml @@ -0,0 +1,84 @@ += 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 deleted file mode 100644 index 43a9122eb..000000000 --- a/app/views/registrant/domains/index.html.erb +++ /dev/null @@ -1,111 +0,0 @@ - - -
-
- <%= 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 new file mode 100644 index 000000000..4d524b785 --- /dev/null +++ b/app/views/registrant/domains/show.haml @@ -0,0 +1,17 @@ += 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 deleted file mode 100644 index 32dc2584a..000000000 --- a/app/views/registrant/domains/show.html.erb +++ /dev/null @@ -1,46 +0,0 @@ -<%= 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 be0a1c638..efbe514e5 100644 --- a/config/locales/registrant/domains.en.yml +++ b/config/locales/registrant/domains.en.yml @@ -2,9 +2,7 @@ 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 242028cbb..9a513b434 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, only: %i[index show] do + resources :domains do collection do get :download_list end @@ -107,6 +107,7 @@ 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 deleted file mode 100644 index 0047c532e..000000000 --- a/db/migrate/20180112080312_remove_domain_contacts_contact_type.rb +++ /dev/null @@ -1,5 +0,0 @@ -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 deleted file mode 100644 index 5c6ff341c..000000000 --- a/db/migrate/20180112084221_add_domain_contacts_contact_id_fk.rb +++ /dev/null @@ -1,5 +0,0 @@ -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 deleted file mode 100644 index e3a84a688..000000000 --- a/db/migrate/20180112084442_add_domain_contacts_domain_id_fk.rb +++ /dev/null @@ -1,5 +0,0 @@ -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 d2000ab98..d823ae27c 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -884,6 +884,7 @@ 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, @@ -4473,22 +4474,6 @@ 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: - -- @@ -5075,9 +5060,3 @@ 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 b6216a3b0..a4b16517f 100644 --- a/doc/models_complete.svg +++ b/doc/models_complete.svg @@ -812,6 +812,7 @@ id :integer contact_id :integer domain_id :integer +contact_type :string created_at :datetime updated_at :datetime contact_code_cache :string @@ -1065,6 +1066,7 @@ id :integer contact_id :integer domain_id :integer +contact_type :string created_at :datetime updated_at :datetime contact_code_cache :string @@ -1343,6 +1345,7 @@ 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 deleted file mode 100644 index c55c98e0d..000000000 --- a/test/fixtures/business_registry_caches.yml +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 0300ef2b6..000000000 --- a/test/fixtures/contacts.yml +++ /dev/null @@ -1,20 +0,0 @@ -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 deleted file mode 100644 index 3e1d01d62..000000000 --- a/test/fixtures/domain_contacts.yml +++ /dev/null @@ -1,4 +0,0 @@ -two_jane: - domain: two - contact: jane - type: AdminDomainContact diff --git a/test/fixtures/domains.yml b/test/fixtures/domains.yml deleted file mode 100644 index 46a1e44e0..000000000 --- a/test/fixtures/domains.yml +++ /dev/null @@ -1,14 +0,0 @@ -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 856788de9..860f06c13 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -14,7 +14,3 @@ 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 deleted file mode 100644 index 6a1a76e39..000000000 --- a/test/integration/registrant/domains_test.rb +++ /dev/null @@ -1,25 +0,0 @@ -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