From 216c4e9fa0fff907b57bca9c95eba017828877f6 Mon Sep 17 00:00:00 2001 From: Stas Date: Mon, 25 Jan 2016 17:53:38 +0200 Subject: [PATCH 1/3] 105842700-routes_fix --- .../registrant/contacts_controller.rb | 8 ++++ .../contacts/partials/_address.haml | 23 ++++++++++ .../contacts/partials/_domains.haml | 30 +++++++++++++ .../contacts/partials/_general.haml | 45 +++++++++++++++++++ .../registrant/contacts/partials/_search.haml | 6 +++ .../contacts/partials/_statuses.haml | 21 +++++++++ app/views/registrant/contacts/show.haml | 12 +++++ .../domains/partials/_admin_contacts.haml | 2 +- .../registrant/domains/partials/_general.haml | 2 +- .../domains/partials/_keyrelays.haml | 6 +-- .../domains/partials/_legal_documents.haml | 2 +- .../registrant/domains/partials/_owner.haml | 2 +- .../domains/partials/_tech_contacts.haml | 2 +- app/views/registrant/domains/show.haml | 4 +- app/views/registrant/registrants/index.haml | 8 ++-- app/views/registrant/registrars/index.haml | 5 +-- config/routes.rb | 1 + 17 files changed, 161 insertions(+), 18 deletions(-) create mode 100644 app/controllers/registrant/contacts_controller.rb create mode 100644 app/views/registrant/contacts/partials/_address.haml create mode 100644 app/views/registrant/contacts/partials/_domains.haml create mode 100644 app/views/registrant/contacts/partials/_general.haml create mode 100644 app/views/registrant/contacts/partials/_search.haml create mode 100644 app/views/registrant/contacts/partials/_statuses.haml create mode 100644 app/views/registrant/contacts/show.haml diff --git a/app/controllers/registrant/contacts_controller.rb b/app/controllers/registrant/contacts_controller.rb new file mode 100644 index 000000000..d3a0ddff8 --- /dev/null +++ b/app/controllers/registrant/contacts_controller.rb @@ -0,0 +1,8 @@ +class Registrant::ContactsController < RegistrantController + + def show + @contact = Contact.find(params[:id]) + authorize! :read, @contact + @contact.valid? + end +end \ No newline at end of file diff --git a/app/views/registrant/contacts/partials/_address.haml b/app/views/registrant/contacts/partials/_address.haml new file mode 100644 index 000000000..9c0f548e3 --- /dev/null +++ b/app/views/registrant/contacts/partials/_address.haml @@ -0,0 +1,23 @@ +.panel.panel-default + .panel-heading + %h3.panel-title= t(:address) + .panel-body + %dl.dl-horizontal + - if @contact.org_name.present? + %dt= t(:org_name) + %dd= @contact.org_name + + %dt= t(:street) + %dd= @contact.street.to_s.gsub("\n", '
').html_safe + + %dt= t(:city) + %dd= @contact.city + + %dt= t(:zip) + %dd= @contact.zip + + %dt= t(:state) + %dd= @contact.state + + %dt= t(:country) + %dd= @contact.country diff --git a/app/views/registrant/contacts/partials/_domains.haml b/app/views/registrant/contacts/partials/_domains.haml new file mode 100644 index 000000000..d0180532d --- /dev/null +++ b/app/views/registrant/contacts/partials/_domains.haml @@ -0,0 +1,30 @@ +- domains = contact.all_domains(page: params[:domain_page], per: 20, params: params) +#contacts.panel.panel-default + .panel-heading + .pull-left + = t(:domains) + .pull-right + = form_tag request.path, method: :get do + = select_tag :domain_filter, options_for_select(%w(Registrant AdminDomainContact TechDomainContact), selected: params[:domain_filter]), + include_blank: true, class: 'form-control2 selectize2' + %button.btn.btn-primary + %span.glyphicon.glyphicon-search + .clearfix + + .table-responsive + %table.table.table-hover.table-bordered.table-condensed + %thead + %tr + %th{class: 'col-xs-3'}=custom_sort_link t(:domain_name), :name + %th{class: 'col-xs-3'}=custom_sort_link t(:registrar), :registrar_name + %th{class: 'col-xs-3'}=custom_sort_link t(:valid_to), :valid_to + %th{class: 'col-xs-3'}= t(:roles) + %tbody + - domains.each do |x| + %tr + %td= link_to(x.name, [:registrant, x]) + %td= link_to(x.registrar, [:registrant, x.registrar]) + %td= l(x.valid_to, format: :short) + %td= x.roles.join(", ") + += paginate domains, param_name: :domain_page \ No newline at end of file diff --git a/app/views/registrant/contacts/partials/_general.haml b/app/views/registrant/contacts/partials/_general.haml new file mode 100644 index 000000000..36192cb2c --- /dev/null +++ b/app/views/registrant/contacts/partials/_general.haml @@ -0,0 +1,45 @@ +.panel.panel-default + .panel-heading + %h3.panel-title= t(:general) + .panel-body + %dl.dl-horizontal + %dt= t(:id) + %dd= @contact.code + + %dt= t(:password) + %dd + = text_field_tag :auth_info, @contact.auth_info, readonly: true, class: 'partially-hidden' + + %br + + %dt= t(:ident) + %dd= ident_for(@contact) + + %dt= t(:email) + %dd= @contact.email + + %dt= t(:phone) + %dd= @contact.phone + + - if @contact.fax + %dt= t(:fax) + %dd= @contact.fax + + %br + + %dt= t(:created) + %dd + = l(@contact.created_at, format: :short) + by + = creator_link(@contact) + + %dt= t(:updated) + %dd + = l(@contact.updated_at, format: :short) + by + = updator_link(@contact) + + %dt= t(:registrar) + %dd + - if @contact.registrar.present? + = link_to(@contact.registrar, registrant_registrar_path(@contact.registrar)) diff --git a/app/views/registrant/contacts/partials/_search.haml b/app/views/registrant/contacts/partials/_search.haml new file mode 100644 index 000000000..4a723bf6b --- /dev/null +++ b/app/views/registrant/contacts/partials/_search.haml @@ -0,0 +1,6 @@ += search_form_for [:registrant, @q] do |f| + = f.search_field :name_cont + = f.submit do + %span.glyphicon.glyphicon-search + + diff --git a/app/views/registrant/contacts/partials/_statuses.haml b/app/views/registrant/contacts/partials/_statuses.haml new file mode 100644 index 000000000..c39075754 --- /dev/null +++ b/app/views/registrant/contacts/partials/_statuses.haml @@ -0,0 +1,21 @@ +- panel_class = contact.errors.messages[:statuses] ? 'panel-danger' : 'panel-default' +#contact_statuses.panel{class: panel_class} + .panel-heading.clearfix + = t(:statuses) + .table-responsive + %table.table.table-hover.table-bordered.table-condensed + %thead + %tr + %th{class: 'col-xs-6'}= t(:status) + %th{class: 'col-xs-6'}= t(:notes) + %tbody + - contact.statuses.each do |status| + %tr + %td= status + %td= contact.status_notes[status] + + - if contact.errors.messages[:statuses] + %tfoot + - @domain.errors.messages[:statuses].each do |s| + %tr + %td{colspan: 4}= s diff --git a/app/views/registrant/contacts/show.haml b/app/views/registrant/contacts/show.haml new file mode 100644 index 000000000..57915e9ff --- /dev/null +++ b/app/views/registrant/contacts/show.haml @@ -0,0 +1,12 @@ +- content_for :actions do + = render 'shared/title', name: @contact.name + +.row + .col-md-6= render 'registrant/contacts/partials/general' + .col-md-6= render 'registrant/contacts/partials/address' +.row + .col-md-12= render 'registrant/contacts/partials/statuses', contact: @contact +.row + .col-md-12= render 'registrant/contacts/partials/domains', contact: @contact + + diff --git a/app/views/registrant/domains/partials/_admin_contacts.haml b/app/views/registrant/domains/partials/_admin_contacts.haml index 0db8f6e32..5e49d3fbc 100644 --- a/app/views/registrant/domains/partials/_admin_contacts.haml +++ b/app/views/registrant/domains/partials/_admin_contacts.haml @@ -12,7 +12,7 @@ %tbody - @domain.admin_contacts.each do |ac| %tr - %td= link_to(ac, admin_contact_path(ac)) + %td= link_to(ac, registrant_contact_path(ac)) %td= ac.code %td= ac.email - if @domain.errors.messages[:admin_contacts] diff --git a/app/views/registrant/domains/partials/_general.haml b/app/views/registrant/domains/partials/_general.haml index d1a17c1cc..d80c1ce6a 100644 --- a/app/views/registrant/domains/partials/_general.haml +++ b/app/views/registrant/domains/partials/_general.haml @@ -10,7 +10,7 @@ %dd= l(@domain.registered_at) %dt= t(:registrar) - %dd= link_to(@domain.registrar, admin_registrar_path(@domain.registrar)) + %dd= link_to(@domain.registrar, registrant_registrar_path(@domain.registrar)) %dt= t(:authinfo_pw) %dd diff --git a/app/views/registrant/domains/partials/_keyrelays.haml b/app/views/registrant/domains/partials/_keyrelays.haml index 43d099383..d2d39f6ba 100644 --- a/app/views/registrant/domains/partials/_keyrelays.haml +++ b/app/views/registrant/domains/partials/_keyrelays.haml @@ -13,8 +13,8 @@ %tbody - @domain.keyrelays.includes([:requester, :accepter]).order(pa_date: :desc).each do |x| %tr - %td= link_to(x.pa_date, [:admin, x]) + %td= link_to(x.pa_date, [:registrar, x]) %td= x.expiry - %td= link_to(x.requester, [:admin, x.requester]) - %td= link_to(x.accepter, [:admin, x.accepter]) + %td= link_to(x.requester, [:registrar, x.requester]) + %td= link_to(x.accepter, [:registrar, x.accepter]) %td= x.status diff --git a/app/views/registrant/domains/partials/_legal_documents.haml b/app/views/registrant/domains/partials/_legal_documents.haml index 900a9784a..7d740977b 100644 --- a/app/views/registrant/domains/partials/_legal_documents.haml +++ b/app/views/registrant/domains/partials/_legal_documents.haml @@ -10,5 +10,5 @@ %tbody - legal_documents.each do |x| %tr - %td= link_to(x.created_at, [:admin, x]) + %td= link_to(x.created_at, [:registrar, x]) %td= x.document_type diff --git a/app/views/registrant/domains/partials/_owner.haml b/app/views/registrant/domains/partials/_owner.haml index 7f499f86b..a7c678d56 100644 --- a/app/views/registrant/domains/partials/_owner.haml +++ b/app/views/registrant/domains/partials/_owner.haml @@ -4,7 +4,7 @@ .panel-body %dl.dl-horizontal %dt= t(:name) - %dd= link_to(@domain.registrant, [:admin, @domain.registrant]) + %dd= link_to(@domain.registrant, [:registrar, @domain.registrant]) %dt= t(:id) %dd= @domain.registrant_code diff --git a/app/views/registrant/domains/partials/_tech_contacts.haml b/app/views/registrant/domains/partials/_tech_contacts.haml index 20badbea8..12844a41e 100644 --- a/app/views/registrant/domains/partials/_tech_contacts.haml +++ b/app/views/registrant/domains/partials/_tech_contacts.haml @@ -12,7 +12,7 @@ %tbody - @domain.tech_contacts.each do |tc| %tr - %td= link_to(tc, admin_contact_path(tc)) + %td= link_to(tc, registrant_contact_path(tc)) %td= tc.code %td= tc.email - if @domain.errors.messages[:tech_contacts] diff --git a/app/views/registrant/domains/show.haml b/app/views/registrant/domains/show.haml index 50c0409b2..0c1ceb48e 100644 --- a/app/views/registrant/domains/show.haml +++ b/app/views/registrant/domains/show.haml @@ -1,7 +1,5 @@ - content_for :actions do - -#= link_to(t(:history), admin_domain_domain_versions_path(@domain.id), method: :get, class: 'btn btn-primary') - -= render 'shared/title', name: @domain.name + = render 'shared/title', name: @domain.name .row .col-md-6= render 'registrant/domains/partials/general' diff --git a/app/views/registrant/registrants/index.haml b/app/views/registrant/registrants/index.haml index b8e7850e6..11838d1b2 100644 --- a/app/views/registrant/registrants/index.haml +++ b/app/views/registrant/registrants/index.haml @@ -2,7 +2,7 @@ .row .col-md-12 - = search_form_for [:admin, @q], html: { style: 'margin-bottom: 0;', class: 'js-form', autocomplete: 'off' } do |f| + = search_form_for [:registrar, @q], html: { style: 'margin-bottom: 0;', class: 'js-form', autocomplete: 'off' } do |f| .row .col-md-3 .form-group @@ -91,13 +91,13 @@ %tbody - @contacts.each do |contact| %tr - %td= link_to(contact, admin_contact_path(contact)) + %td= link_to(contact, registrar_contact_path(contact)) %td= contact.code %td= ident_for(contact) %td= l(contact.created_at, format: :short) %td - if contact.registrar - = link_to(contact.registrar, admin_registrar_path(contact.registrar)) + = link_to(contact.registrar, registrar_registrar_path(contact.registrar)) .row .col-md-6 @@ -109,4 +109,4 @@ :coffee $(".js-reset-form").on "click", (e) -> e.preventDefault(); - window.location = "#{admin_contacts_path}" + window.location = "#{registrar_contacts_path}" diff --git a/app/views/registrant/registrars/index.haml b/app/views/registrant/registrars/index.haml index a2604dbec..0489bcf52 100644 --- a/app/views/registrant/registrars/index.haml +++ b/app/views/registrant/registrars/index.haml @@ -1,6 +1,5 @@ - content_for :actions do - = link_to(t(:new), new_admin_registrar_path, class: 'btn btn-primary') -= render 'shared/title', name: t(:registrars) + = render 'shared/title', name: t(:registrars) .row .col-md-12 @@ -15,7 +14,7 @@ %tbody - @registrars.each do |x| %tr - %td= link_to(x, [:admin, x]) + %td= link_to(x, [:registrar, x]) %td= x.reg_no .row .col-md-12 diff --git a/config/routes.rb b/config/routes.rb index 9a91027cc..6b3cbe00a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -155,6 +155,7 @@ Rails.application.routes.draw do end resources :registrants + resources :contacts resources :whois # resources :contacts do From addf9638d27f55c6aa04f8f0de50ef1d1eb5f6ff Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Mon, 25 Jan 2016 17:59:13 +0200 Subject: [PATCH 2/3] Story#105846070 - if I don't have orgs in Ariregister, then cache that answer as well --- app/models/business_registry_cache.rb | 40 +++++++++++++-------------- app/models/soap/arireg.rb | 27 ++++++++---------- 2 files changed, 31 insertions(+), 36 deletions(-) diff --git a/app/models/business_registry_cache.rb b/app/models/business_registry_cache.rb index 6bd509101..e287358b6 100644 --- a/app/models/business_registry_cache.rb +++ b/app/models/business_registry_cache.rb @@ -23,16 +23,16 @@ class BusinessRegistryCache < ActiveRecord::Base def associated_domains domains = [] contact_ids = associated_businesses.map do |bic| - Contact.select(:id).where("ident = ? AND ident_type = 'org' AND ident_country_code = 'EE'", bic).pluck(:id) - end - contact_ids = Contact.select(:id).where("ident = ? AND ident_type = 'priv' AND ident_country_code = ?", - ident, ident_country_code).pluck(:id) + contact_ids - contact_ids.flatten!.compact! unless contact_ids.blank? + Contact.where("ident = ? AND ident_type = 'org' AND ident_country_code = 'EE'", bic).pluck(:id) + end.flatten + contact_ids += Contact.where("ident = ? AND ident_type = 'priv' AND ident_country_code = ?", + ident, ident_country_code).pluck(:id) + unless contact_ids.blank? - contact_ids.uniq! - domains = DomainContact.select(:domain_id).distinct.where("contact_id in (?)", contact_ids).pluck(:domain_id) + domains = DomainContact.select(:domain_id).distinct.where(contact_id: contact_ids).pluck(:domain_id) end - Domain.includes(:registrar, :registrant).where('id in (?)', domains) + + Domain.includes(:registrar, :registrant).where(id: domains) end class << self @@ -50,25 +50,23 @@ class BusinessRegistryCache < ActiveRecord::Base end def fetch_by_ident_and_cc(ident_code, ident_cc) - cache = BusinessRegistryCache.find_by(ident: ident_code, ident_country_code: ident_cc) + cache = BusinessRegistryCache.first_or_initialize(ident: ident_code, ident_country_code: ident_cc) + msg_start = "[Ariregister] #{ident_cc}-#{ident_code}:" + # fetch new data if cache is expired - return cache if cache.present? && cache.retrieved_on > (Time.zone.now - Setting.days_to_keep_business_registry_cache.days) - businesses = business_registry.associated_businesses(ident_code, ident_cc) - unless businesses.nil? - if cache.blank? - cache = BusinessRegistryCache.new(businesses) - else - cache.update businesses - end - cache.save - else - cache = [] # expired data is forbidden + if cache.retrieved_on && cache.retrieved_on > (Time.zone.now - Setting.days_to_keep_business_registry_cache.days) + Rails.logger.info("#{msg_start} Info loaded from cache") + return cache end + + cache.attributes = business_registry.associated_businesses(ident_code, ident_cc) + Rails.logger.info("#{msg_start} Info loaded from server") + + cache.save cache end def business_registry - # TODO: can this be cached and shared? Soap::Arireg.new end diff --git a/app/models/soap/arireg.rb b/app/models/soap/arireg.rb index 5c8db3475..cd8e446b4 100644 --- a/app/models/soap/arireg.rb +++ b/app/models/soap/arireg.rb @@ -95,22 +95,19 @@ module Soap 'fyysilise_isiku_koodi_riik' => country_code_3(ident_cc) ) content = extract response, :paringesindus_v4_response - unless content.blank? - if content[:ettevotjad].key? :item - business_ident = items(content, :ettevotjad).map do |item| - # debug helps users gather data for testing - puts "#{item[:ariregistri_kood]}\t#{item[:arinimi]}\t#{item[:staatus]} #{item[:oiguslik_vorm]}\t" if @debug - item[:ariregistri_kood] - end - { - ident: ident, - ident_country_code: ident_cc, - # ident_type: 'priv', - retrieved_on: Time.now, - associated_businesses: business_ident - } - end + if content.present? && content[:ettevotjad].key?(:item) + business_ident = items(content, :ettevotjad).map{|item| item[:ariregistri_kood]} + else + business_ident = [] end + + { + ident: ident, + ident_country_code: ident_cc, + # ident_type: 'priv', + retrieved_on: Time.now, + associated_businesses: business_ident + } rescue Savon::SOAPFault => fault Rails.logger.error "#{fault} Äriregister arireg #{self.class.username} at #{self.class.host }" raise NotAvailableError.new(exception: fault) From f0558ae0bfb66b4a680a851882a500bc1fc203b7 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Mon, 25 Jan 2016 18:15:18 +0200 Subject: [PATCH 3/3] Story#105846070 - more rails way how to load relations --- app/models/business_registry_cache.rb | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/app/models/business_registry_cache.rb b/app/models/business_registry_cache.rb index e287358b6..5ca1e002c 100644 --- a/app/models/business_registry_cache.rb +++ b/app/models/business_registry_cache.rb @@ -20,37 +20,28 @@ authentication using electronic ID. Association through a business organisation class BusinessRegistryCache < ActiveRecord::Base + # 1. load domains by business + # 2. load domains by person def associated_domains domains = [] - contact_ids = associated_businesses.map do |bic| - Contact.where("ident = ? AND ident_type = 'org' AND ident_country_code = 'EE'", bic).pluck(:id) - end.flatten - contact_ids += Contact.where("ident = ? AND ident_type = 'priv' AND ident_country_code = ?", - ident, ident_country_code).pluck(:id) + + 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) unless contact_ids.blank? - domains = DomainContact.select(:domain_id).distinct.where(contact_id: contact_ids).pluck(:domain_id) + domains = DomainContact.distinct.where(contact_id: contact_ids).pluck(:domain_id) end Domain.includes(:registrar, :registrant).where(id: domains) end class << self - def fetch_associated_domains(ident_code, ident_cc) - cached = fetch_by_ident_and_cc(ident_code, ident_cc) - if cached.blank? - Domain.includes(:registrar, :registrant).where(contacts: { - ident_type: 'priv', - ident: ident_code, - ident_country_code: ident_cc}) - else - cached.associated_domains - end + fetch_by_ident_and_cc(ident_code, ident_cc).associated_domains end def fetch_by_ident_and_cc(ident_code, ident_cc) - cache = BusinessRegistryCache.first_or_initialize(ident: ident_code, ident_country_code: ident_cc) + cache = BusinessRegistryCache.where(ident: ident_code, ident_country_code: ident_cc).first_or_initialize msg_start = "[Ariregister] #{ident_cc}-#{ident_code}:" # fetch new data if cache is expired