From 6077f6c36d67f0d5d93dd0611c966d47aad07435 Mon Sep 17 00:00:00 2001 From: Stas Date: Tue, 1 Dec 2015 15:21:40 +0200 Subject: [PATCH 01/70] 105842700-portal --- .../registrant/domains_controller.rb | 40 +++++++++++- .../registrant/registrars_controller.rb | 64 +++++++++++++++++++ .../registrant/sessions_controller.rb | 2 + .../registrant/whois_controller.rb | 4 ++ app/views/registrant/domains/index.haml | 61 ++++++++++++++---- .../domains/partials/_admin_contacts.haml | 22 +++++++ .../registrant/domains/partials/_dnskeys.haml | 25 ++++++++ .../registrant/domains/partials/_general.haml | 32 ++++++++++ .../domains/partials/_keyrelays.haml | 20 ++++++ .../domains/partials/_legal_documents.haml | 14 ++++ .../domains/partials/_nameservers.haml | 23 +++++++ .../registrant/domains/partials/_owner.haml | 19 ++++++ .../domains/partials/_statuses.haml | 18 ++++++ .../domains/partials/_tech_contacts.haml | 22 +++++++ app/views/registrant/domains/show.haml | 24 +++++++ app/views/registrant/whois/index.haml | 4 +- 16 files changed, 378 insertions(+), 16 deletions(-) create mode 100644 app/controllers/registrant/registrars_controller.rb create mode 100644 app/views/registrant/domains/partials/_admin_contacts.haml create mode 100644 app/views/registrant/domains/partials/_dnskeys.haml create mode 100644 app/views/registrant/domains/partials/_general.haml create mode 100644 app/views/registrant/domains/partials/_keyrelays.haml create mode 100644 app/views/registrant/domains/partials/_legal_documents.haml create mode 100644 app/views/registrant/domains/partials/_nameservers.haml create mode 100644 app/views/registrant/domains/partials/_owner.haml create mode 100644 app/views/registrant/domains/partials/_statuses.haml create mode 100644 app/views/registrant/domains/partials/_tech_contacts.haml create mode 100644 app/views/registrant/domains/show.haml diff --git a/app/controllers/registrant/domains_controller.rb b/app/controllers/registrant/domains_controller.rb index 4bba945a8..81e99cd54 100644 --- a/app/controllers/registrant/domains_controller.rb +++ b/app/controllers/registrant/domains_controller.rb @@ -1,5 +1,41 @@ class Registrant::DomainsController < RegistrantController + def index - authorize! :view, :registrant_domains + + authorize! :view, :registrant_domains + params[:q] ||= {} + + domains = Domain.includes(:registrar, :registrant).where(registrant_id: 76246) + + normalize_search_parameters do + @q = domains.search(params[:q]) + @domains = @q.result.page(params[:page]) end -end + @domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i > 0 + end + + def show + @domain = Domain.find(params[:id]) + @domain.valid? + end + + def set_domain + @domain = Domain.find(params[:id]) + end + + def normalize_search_parameters + + ca_cache = params[:q][:valid_to_lteq] + begin + end_time = params[:q][:valid_to_lteq].try(:to_date) + params[:q][:valid_to_lteq] = end_time.try(:end_of_day) + rescue + logger.warn('Invalid date') + end + + yield + + params[:q][:valid_to_lteq] = ca_cache + end + +end \ No newline at end of file diff --git a/app/controllers/registrant/registrars_controller.rb b/app/controllers/registrant/registrars_controller.rb new file mode 100644 index 000000000..ca34ed176 --- /dev/null +++ b/app/controllers/registrant/registrars_controller.rb @@ -0,0 +1,64 @@ +class Registrar::RegistrarsController < RegistrartController + load_and_authorize_resource + + + def search + render json: Registrar.search_by_query(params[:q]) + end + + def index + @q = Registrar.ordered.search(params[:q]) + @registrars = @q.result.page(params[:page]) + end + + def new + @registrar = Registrar.new + end + + def create + @registrar = Registrar.new(registrar_params) + + if @registrar.save + flash[:notice] = I18n.t('registrar_added') + redirect_to [:admin, @registrar] + else + flash.now[:alert] = I18n.t('failed_to_add_registrar') + render 'new' + end + end + + def edit; end + + def update + if @registrar.update(registrar_params) + flash[:notice] = I18n.t('registrar_updated') + redirect_to [:admin, @registrar] + else + flash.now[:alert] = I18n.t('failed_to_update_registrar') + render 'edit' + end + end + + def destroy + if @registrar.destroy + flash[:notice] = I18n.t('registrar_deleted') + redirect_to admin_registrars_path + else + flash.now[:alert] = I18n.t('failed_to_delete_registrar') + render 'show' + end + end + + private + + def set_registrar + @registrar = Registrar.find(params[:id]) + end + + def registrar_params + params.require(:registrar).permit( + :name, :reg_no, :vat_no, :street, :city, :state, :zip, :billing_address, + :country_code, :email, :phone, :billing_email, :code + ) + end +end diff --git a/app/controllers/registrant/sessions_controller.rb b/app/controllers/registrant/sessions_controller.rb index f0a292137..4acdbc613 100644 --- a/app/controllers/registrant/sessions_controller.rb +++ b/app/controllers/registrant/sessions_controller.rb @@ -2,6 +2,8 @@ class Registrant::SessionsController < Devise::SessionsController layout 'registrant/application' def login + @user = RegistrantUser.find_by_username('registrar1') + sign_in(@user, event: :authentication) end # rubocop: disable Metrics/AbcSize diff --git a/app/controllers/registrant/whois_controller.rb b/app/controllers/registrant/whois_controller.rb index 71d29dd76..b44a0bb67 100644 --- a/app/controllers/registrant/whois_controller.rb +++ b/app/controllers/registrant/whois_controller.rb @@ -1,5 +1,9 @@ class Registrant::WhoisController < RegistrantController def index authorize! :view, :registrant_whois + + if params[:domain_name].present? + @domain = WhoisRecord.find_by(name: params[:domain_name]); + end end end diff --git a/app/views/registrant/domains/index.haml b/app/views/registrant/domains/index.haml index 8b71cefca..5ce325efe 100644 --- a/app/views/registrant/domains/index.haml +++ b/app/views/registrant/domains/index.haml @@ -1,5 +1,42 @@ = 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) + .col-md-3 + .form-group + = f.label t(:nameserver_hostname) + = f.search_field :nameservers_hostname_eq, class: 'form-control', placeholder: t(:nameserver_hostname) + .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 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 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) + %hr .row .col-md-12 @@ -8,20 +45,20 @@ %thead %tr %th{class: 'col-xs-2'} - = t(:name) + = sort_link(@q, 'name') %th{class: 'col-xs-2'} - = t(:registrant) + = sort_link(@q, 'registrant_name', t(:registrant)) %th{class: 'col-xs-2'} - = t(:valid_to) + = sort_link(@q, 'valid_to', t(:valid_to)) %th{class: 'col-xs-2'} - = t(:registrar) + = sort_link(@q, 'registrar_name', t(:registrar)) %tbody - -# - @domains.each do |x| - -# %tr - -# %td= link_to(x, admin_domain_path(x)) - -# %td - -# - if x.registrant - -# = link_to(x.registrant, [:admin, x.registrant]) + - @domains.each do |x| + %tr + %td= link_to(x, registrant_domain_path(x)) + %td + - if x.registrant + = link_to(x.registrant, [:admin, x.registrant]) - -# %td= l(x.valid_to, format: :short) - -# %td= link_to(x.registrar, admin_registrar_path(x.registrar)) if x.registrar + %td= l(x.valid_to, format: :short) + %td= link_to(x.registrar, admin_registrar_path(x.registrar)) if x.registrar diff --git a/app/views/registrant/domains/partials/_admin_contacts.haml b/app/views/registrant/domains/partials/_admin_contacts.haml new file mode 100644 index 000000000..0db8f6e32 --- /dev/null +++ b/app/views/registrant/domains/partials/_admin_contacts.haml @@ -0,0 +1,22 @@ +- panel_class = @domain.errors.messages[:admin_contacts] ? 'panel-danger' : 'panel-default' +.panel{class: panel_class} + .panel-heading.clearfix + = t(:admin_contacts) + .table-responsive + %table.table.table-hover.table-bordered.table-condensed + %thead + %tr + %th{class: 'col-xs-4'}= t(:name) + %th{class: 'col-xs-4'}= t(:id) + %th{class: 'col-xs-4'}= t(:email) + %tbody + - @domain.admin_contacts.each do |ac| + %tr + %td= link_to(ac, admin_contact_path(ac)) + %td= ac.code + %td= ac.email + - if @domain.errors.messages[:admin_contacts] + %tfoot + - @domain.errors.messages[:admin_contacts].each do |x| + %tr + %td{colspan: 4}= x diff --git a/app/views/registrant/domains/partials/_dnskeys.haml b/app/views/registrant/domains/partials/_dnskeys.haml new file mode 100644 index 000000000..6d5759e65 --- /dev/null +++ b/app/views/registrant/domains/partials/_dnskeys.haml @@ -0,0 +1,25 @@ +- panel_class = @domain.errors.messages[:dnskeys] ? 'panel-danger' : 'panel-default' +#dnskeys.panel{class: panel_class} + .panel-heading.clearfix + = t(:dnskeys) + .table-responsive + %table.table.table-hover.table-bordered.table-condensed + %thead + %tr + %th{class: 'col-xs-1'}= t(:flag) + %th{class: 'col-xs-1'}= t(:protocol) + %th{class: 'col-xs-1'}= t(:algorithm) + %th{class: 'col-xs-9'}= t(:public_key) + %tbody + - @domain.dnskeys.each do |x| + %tr + %td= x.flags + %td= x.protocol + %td= x.alg + %td= x.public_key + - if @domain.errors.messages[:dnskeys] + %tfoot + - @domain.errors.messages[:dnskeys].each do |x| + %tr + %td{colspan: 4}= x + diff --git a/app/views/registrant/domains/partials/_general.haml b/app/views/registrant/domains/partials/_general.haml new file mode 100644 index 000000000..d433a1302 --- /dev/null +++ b/app/views/registrant/domains/partials/_general.haml @@ -0,0 +1,32 @@ +.panel.panel-default + .panel-heading + %h3.panel-title= t(:general) + .panel-body + %dl.dl-horizontal + %dt= t(:name) + %dd= @domain.name + + %dt= t(:registered_at) + %dd= l(@domain.registered_at) + + %dt= t(:registrar) + %dd= link_to(@domain.registrar, admin_registrar_path(@domain.registrar)) + + %dt= t(:password) + %dd + = text_field_tag :password, @domain.auth_info, readonly: true, class: 'partially-hidden' + + %dt= t(:valid_from) + %dd= l(@domain.valid_from) + + %dt= t(:valid_to) + %dd= l(@domain.valid_to) + + %dt= t(:outzone_at) + %dd= l(@domain.outzone_at) + + %dt= t(:delete_at) + %dd= l(@domain.delete_at) + + %dt= t(:force_delete_at) + %dd= l(@domain.force_delete_at) diff --git a/app/views/registrant/domains/partials/_keyrelays.haml b/app/views/registrant/domains/partials/_keyrelays.haml new file mode 100644 index 000000000..43d099383 --- /dev/null +++ b/app/views/registrant/domains/partials/_keyrelays.haml @@ -0,0 +1,20 @@ +.panel{class: 'panel-default'} + .panel-heading.clearfix + = t(:keyrelays) + .table-responsive + %table.table.table-hover.table-bordered.table-condensed + %thead + %tr + %th{class: 'col-xs-4'}= t(:uploaded_at) + %th{class: 'col-xs-3'}= t(:expiry) + %th{class: 'col-xs-2'}= t(:requester) + %th{class: 'col-xs-2'}= t(:accepter) + %th{class: 'col-xs-1'}= t(:status) + %tbody + - @domain.keyrelays.includes([:requester, :accepter]).order(pa_date: :desc).each do |x| + %tr + %td= link_to(x.pa_date, [:admin, x]) + %td= x.expiry + %td= link_to(x.requester, [:admin, x.requester]) + %td= link_to(x.accepter, [:admin, 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 new file mode 100644 index 000000000..900a9784a --- /dev/null +++ b/app/views/registrant/domains/partials/_legal_documents.haml @@ -0,0 +1,14 @@ +.panel.panel-default + .panel-heading.clearfix + = t(:legal_documents) + .table-responsive + %table.table.table-hover.table-bordered.table-condensed + %thead + %tr + %th{class: 'col-xs-8'}= t(:created_at) + %th{class: 'col-xs-4'}= t(:type) + %tbody + - legal_documents.each do |x| + %tr + %td= link_to(x.created_at, [:admin, x]) + %td= x.document_type diff --git a/app/views/registrant/domains/partials/_nameservers.haml b/app/views/registrant/domains/partials/_nameservers.haml new file mode 100644 index 000000000..db3ca759a --- /dev/null +++ b/app/views/registrant/domains/partials/_nameservers.haml @@ -0,0 +1,23 @@ +- panel_class = @domain.errors.messages[:nameservers] ? 'panel-danger' : 'panel-default' +#nameservers.panel{class: panel_class} + .panel-heading.clearfix + = t(:nameservers) + .table-responsive + %table.table.table-hover.table-bordered.table-condensed + %thead + %tr + %th{class: 'col-xs-4'}= t(:hostname) + %th{class: 'col-xs-4'}= t(:ipv4) + %th{class: 'col-xs-4'}= t(:ipv6) + %tbody + - @domain.nameservers.each do |x| + %tr + %td= x + %td= x.ipv4 + %td= x.ipv6 + - if @domain.errors.messages[:nameservers] + %tfoot + - @domain.errors.messages[:nameservers].each do |x| + %tr + %td{colspan: 3}= x + diff --git a/app/views/registrant/domains/partials/_owner.haml b/app/views/registrant/domains/partials/_owner.haml new file mode 100644 index 000000000..7f499f86b --- /dev/null +++ b/app/views/registrant/domains/partials/_owner.haml @@ -0,0 +1,19 @@ +.panel.panel-default + .panel-heading + %h3.panel-title= t(:registrant) + .panel-body + %dl.dl-horizontal + %dt= t(:name) + %dd= link_to(@domain.registrant, [:admin, @domain.registrant]) + + %dt= t(:id) + %dd= @domain.registrant_code + + %dt= t(:identity_code) + %dd= @domain.registrant_ident + + %dt= t(:email) + %dd= @domain.registrant_email + + %dt= t(:phone) + %dd= @domain.registrant_phone diff --git a/app/views/registrant/domains/partials/_statuses.haml b/app/views/registrant/domains/partials/_statuses.haml new file mode 100644 index 000000000..ab8e55e6c --- /dev/null +++ b/app/views/registrant/domains/partials/_statuses.haml @@ -0,0 +1,18 @@ +#domain_statuses.panel.panel-default + .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 + - @domain.statuses.each do |status| + %tr + %td + - if @domain.pending_json.present? && [DomainStatus::PENDING_UPDATE, DomainStatus::PENDING_DELETE].include?(status) + = link_to status, admin_domain_domain_versions_path(@domain.id) + - else + = status + %td= @domain.status_notes[status] diff --git a/app/views/registrant/domains/partials/_tech_contacts.haml b/app/views/registrant/domains/partials/_tech_contacts.haml new file mode 100644 index 000000000..20badbea8 --- /dev/null +++ b/app/views/registrant/domains/partials/_tech_contacts.haml @@ -0,0 +1,22 @@ +- panel_class = @domain.errors.messages[:tech_contacts] ? 'panel-danger' : 'panel-default' +#tech_contacts.panel{class: panel_class} + .panel-heading.clearfix + = t(:tech_contacts) + .table-responsive + %table.table.table-hover.table-bordered.table-condensed + %thead + %tr + %th{class: 'col-xs-4'}= t(:name) + %th{class: 'col-xs-4'}= t(:id) + %th{class: 'col-xs-4'}= t(:email) + %tbody + - @domain.tech_contacts.each do |tc| + %tr + %td= link_to(tc, admin_contact_path(tc)) + %td= tc.code + %td= tc.email + - if @domain.errors.messages[:tech_contacts] + %tfoot + - @domain.errors.messages[:tech_contacts].each do |x| + %tr + %td{colspan: 4}= x diff --git a/app/views/registrant/domains/show.haml b/app/views/registrant/domains/show.haml new file mode 100644 index 000000000..17a85b841 --- /dev/null +++ b/app/views/registrant/domains/show.haml @@ -0,0 +1,24 @@ +- content_for :actions do + = link_to(t(:edit_statuses), edit_admin_domain_path(@domain), class: 'btn btn-primary') + = link_to(t(:history), admin_domain_domain_versions_path(@domain.id), method: :get, class: 'btn btn-primary') + += render 'shared/title', name: @domain.name + +.row + .col-md-6= render 'admin/domains/partials/general' + .col-md-6= render 'admin/domains/partials/owner' +.row + .col-md-12= render 'admin/domains/partials/tech_contacts' +.row + .col-md-12= render 'admin/domains/partials/admin_contacts' +.row + .col-md-12= render 'admin/domains/partials/statuses' +.row + .col-md-12= render 'admin/domains/partials/nameservers' +.row + .col-md-12= render 'admin/domains/partials/dnskeys' +.row + .col-md-12= render 'admin/domains/partials/keyrelays' +.row + .col-md-12 + = render 'admin/domains/partials/legal_documents', legal_documents: @domain.legal_documents diff --git a/app/views/registrant/whois/index.haml b/app/views/registrant/whois/index.haml index 3e390eaf3..3d95af638 100644 --- a/app/views/registrant/whois/index.haml +++ b/app/views/registrant/whois/index.haml @@ -17,5 +17,5 @@ %span.glyphicon.glyphicon-search   %hr - - if @results - = @results + - if @domain + %pre= @domain.body \ No newline at end of file From da910bc6606967f65738a021e46941edec86922e Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Tue, 1 Dec 2015 18:15:27 +0200 Subject: [PATCH 02/70] Story#105842700 - Login user with ID card --- app/controllers/registrant/domains_controller.rb | 2 +- app/controllers/registrant/sessions_controller.rb | 13 +++---------- app/models/registrant_user.rb | 14 +++++++++++--- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/app/controllers/registrant/domains_controller.rb b/app/controllers/registrant/domains_controller.rb index 81e99cd54..cec5be34e 100644 --- a/app/controllers/registrant/domains_controller.rb +++ b/app/controllers/registrant/domains_controller.rb @@ -5,7 +5,7 @@ class Registrant::DomainsController < RegistrantController authorize! :view, :registrant_domains params[:q] ||= {} - domains = Domain.includes(:registrar, :registrant).where(registrant_id: 76246) + domains = current_user.domains normalize_search_parameters do @q = domains.search(params[:q]) diff --git a/app/controllers/registrant/sessions_controller.rb b/app/controllers/registrant/sessions_controller.rb index 4acdbc613..91589d510 100644 --- a/app/controllers/registrant/sessions_controller.rb +++ b/app/controllers/registrant/sessions_controller.rb @@ -2,21 +2,14 @@ class Registrant::SessionsController < Devise::SessionsController layout 'registrant/application' def login - @user = RegistrantUser.find_by_username('registrar1') - sign_in(@user, event: :authentication) end # rubocop: disable Metrics/AbcSize def id - if Rails.env.development? - sign_in(RegistrantUser.find_or_create_by_idc_data('test'), event: :authentication) - return redirect_to registrant_root_url - end + id_code, id_issuer = request.env['SSL_CLIENT_S_DN'], request.env['SSL_CLIENT_I_DN_O'] + id_code, id_issuer = 'test', RegistrantUser::ACCEPTED_ISSUER if Rails.env.development? - logger.error request.env['SSL_CLIENT_S_DN'] - logger.error request.env['SSL_CLIENT_S_DN'].encoding - logger.error request.env['SSL_CLIENT_I_DN_O'] - @user = RegistrantUser.find_or_create_by_idc_data(request.env['SSL_CLIENT_S_DN'], request.env['SSL_CLIENT_I_DN_O']) + @user = RegistrantUser.find_or_create_by_idc_data(id_code, id_issuer) if @user sign_in(@user, event: :authentication) redirect_to registrant_root_url diff --git a/app/models/registrant_user.rb b/app/models/registrant_user.rb index 9a69e8acb..6fac517af 100644 --- a/app/models/registrant_user.rb +++ b/app/models/registrant_user.rb @@ -1,4 +1,5 @@ class RegistrantUser < User + ACCEPTED_ISSUER = 'AS Sertifitseerimiskeskus' attr_accessor :idc_data def ability @@ -6,6 +7,15 @@ class RegistrantUser < User end delegate :can?, :cannot?, to: :ability + def ident + registrant_ident.to_s.split("-").last + end + + def domains + Domain.includes(:registrar, :registrant).where(contacts: {ident: ident}) + end + + def to_s username end @@ -13,11 +23,9 @@ class RegistrantUser < User class << self def find_or_create_by_idc_data(idc_data, issuer_organization) return false if idc_data.blank? - return false if issuer_organization != 'AS Sertifitseerimiskeskus' + return false if issuer_organization != ACCEPTED_ISSUER idc_data.force_encoding('UTF-8') - logger.error(idc_data) - logger.error(idc_data.encoding) identity_code = idc_data.scan(/serialNumber=(\d+)/).flatten.first country = idc_data.scan(/^\/C=(.{2})/).flatten.first first_name = idc_data.scan(%r{/GN=(.+)/serialNumber}).flatten.first From 2748f3be5527d061c5dabebf438ed16a738e2cd5 Mon Sep 17 00:00:00 2001 From: Stas Date: Sun, 6 Dec 2015 20:47:34 +0200 Subject: [PATCH 03/70] 105842700-download_list_added --- .../registrant/domains_controller.rb | 27 +++++--- .../registrant/registrars_controller.rb | 64 ++----------------- app/models/ability.rb | 4 +- app/models/domain.rb | 9 +++ .../registrant/domains/download_list.haml | 0 app/views/registrant/domains/index.haml | 35 ++++++++-- app/views/registrant/domains/show.haml | 21 +++--- app/views/registrant/registrars/index.haml | 22 +++++++ app/views/registrant/registrars/show.haml | 53 +++++++++++++++ config/application.rb | 2 + config/routes.rb | 14 ++++ 11 files changed, 163 insertions(+), 88 deletions(-) create mode 100644 app/views/registrant/domains/download_list.haml create mode 100644 app/views/registrant/registrars/index.haml create mode 100644 app/views/registrant/registrars/show.haml diff --git a/app/controllers/registrant/domains_controller.rb b/app/controllers/registrant/domains_controller.rb index cec5be34e..4fab83787 100644 --- a/app/controllers/registrant/domains_controller.rb +++ b/app/controllers/registrant/domains_controller.rb @@ -1,12 +1,9 @@ class Registrant::DomainsController < RegistrantController def index - authorize! :view, :registrant_domains params[:q] ||= {} - domains = current_user.domains - normalize_search_parameters do @q = domains.search(params[:q]) @domains = @q.result.page(params[:page]) @@ -16,15 +13,32 @@ class Registrant::DomainsController < RegistrantController def show @domain = Domain.find(params[:id]) - @domain.valid? + if !(current_user.domains.include?(@domain) || @domain.valid?) + redirect_to registrant_domains_path + end + authorize! :read, @domain end def set_domain @domain = Domain.find(params[:id]) end - def normalize_search_parameters + def download_list + authorize! :view, :registrant_domains + params[:q] ||= {} + domains = current_user.domains + normalize_search_parameters do + @q = domains.search(params[:q]) + @domains = @q + end + respond_to do |format| + format.html + format.csv { render text: @domains.to_csv } + end + end + + def normalize_search_parameters ca_cache = params[:q][:valid_to_lteq] begin end_time = params[:q][:valid_to_lteq].try(:to_date) @@ -32,10 +46,7 @@ class Registrant::DomainsController < RegistrantController rescue logger.warn('Invalid date') end - yield - params[:q][:valid_to_lteq] = ca_cache end - end \ No newline at end of file diff --git a/app/controllers/registrant/registrars_controller.rb b/app/controllers/registrant/registrars_controller.rb index ca34ed176..36ab9bb2a 100644 --- a/app/controllers/registrant/registrars_controller.rb +++ b/app/controllers/registrant/registrars_controller.rb @@ -1,64 +1,8 @@ -class Registrar::RegistrarsController < RegistrartController - load_and_authorize_resource +class Registrant::RegistrarsController < RegistrantController - - def search - render json: Registrar.search_by_query(params[:q]) - end - - def index - @q = Registrar.ordered.search(params[:q]) - @registrars = @q.result.page(params[:page]) - end - - def new - @registrar = Registrar.new - end - - def create - @registrar = Registrar.new(registrar_params) - - if @registrar.save - flash[:notice] = I18n.t('registrar_added') - redirect_to [:admin, @registrar] - else - flash.now[:alert] = I18n.t('failed_to_add_registrar') - render 'new' - end - end - - def edit; end - - def update - if @registrar.update(registrar_params) - flash[:notice] = I18n.t('registrar_updated') - redirect_to [:admin, @registrar] - else - flash.now[:alert] = I18n.t('failed_to_update_registrar') - render 'edit' - end - end - - def destroy - if @registrar.destroy - flash[:notice] = I18n.t('registrar_deleted') - redirect_to admin_registrars_path - else - flash.now[:alert] = I18n.t('failed_to_delete_registrar') - render 'show' - end - end - - private - - def set_registrar + def show @registrar = Registrar.find(params[:id]) - end - - def registrar_params - params.require(:registrar).permit( - :name, :reg_no, :vat_no, :street, :city, :state, :zip, :billing_address, - :country_code, :email, :phone, :billing_email, :code - ) + authorize! :read, @registrar + @registrar.valid? end end diff --git a/app/models/ability.rb b/app/models/ability.rb index cf98cb704..61f1edb2e 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -16,7 +16,7 @@ class Ability @user.roles.each { |role| send(role) } if @user.roles when 'ApiUser' @user.roles.each { |role| send(role) } if @user.roles - when 'RegistrantUser' + when 'RegistrantUser' static_registrant end @@ -117,9 +117,11 @@ class Ability end def static_registrant + customer_service can :manage, :registrant_domains can :manage, :registrant_whois can :manage, Depp::Domain + can :manage, Domain end def user diff --git a/app/models/domain.rb b/app/models/domain.rb index 9845e8ac8..ca988dc4d 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -774,5 +774,14 @@ class Domain < ActiveRecord::Base status_notes[status] = notes[i] end end + + def self.to_csv + CSV.generate do |csv| + csv << column_names + all.each do |domain| + csv << domain.attributes.values_at(*column_names) + end + end + end end # rubocop: enable Metrics/ClassLength diff --git a/app/views/registrant/domains/download_list.haml b/app/views/registrant/domains/download_list.haml new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/registrant/domains/index.haml b/app/views/registrant/domains/index.haml index 5ce325efe..b79b921bd 100644 --- a/app/views/registrant/domains/index.haml +++ b/app/views/registrant/domains/index.haml @@ -12,10 +12,6 @@ .form-group = f.label t(:registrant_ident) = f.search_field :registrant_ident_eq, class: 'form-control', placeholder: t(:registrant_ident) - .col-md-3 - .form-group - = f.label t(:nameserver_hostname) - = f.search_field :nameservers_hostname_eq, class: 'form-control', placeholder: t(:nameserver_hostname) .row .col-md-3 .form-group @@ -36,6 +32,20 @@   %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_domain_path(params[:q], format: "pdf") + %li= link_to 'CSV', download_list_registrant_domain_path(params[:q], format: "csv") + .col-md-3 + .col-md-3 + .col-md-3 + + %hr .row @@ -58,7 +68,20 @@ %td= link_to(x, registrant_domain_path(x)) %td - if x.registrant - = link_to(x.registrant, [:admin, x.registrant]) + = link_to(x.registrant, [:registrant, x.registrant]) if x.registrant %td= l(x.valid_to, format: :short) - %td= link_to(x.registrar, admin_registrar_path(x.registrar)) if x.registrar + %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/show.haml b/app/views/registrant/domains/show.haml index 17a85b841..50c0409b2 100644 --- a/app/views/registrant/domains/show.haml +++ b/app/views/registrant/domains/show.haml @@ -1,24 +1,19 @@ - content_for :actions do - = link_to(t(:edit_statuses), edit_admin_domain_path(@domain), class: 'btn btn-primary') - = link_to(t(:history), admin_domain_domain_versions_path(@domain.id), method: :get, class: 'btn btn-primary') + -#= link_to(t(:history), admin_domain_domain_versions_path(@domain.id), method: :get, class: 'btn btn-primary') = render 'shared/title', name: @domain.name .row - .col-md-6= render 'admin/domains/partials/general' - .col-md-6= render 'admin/domains/partials/owner' + .col-md-6= render 'registrant/domains/partials/general' .row - .col-md-12= render 'admin/domains/partials/tech_contacts' + .col-md-12= render 'registrant/domains/partials/tech_contacts' .row - .col-md-12= render 'admin/domains/partials/admin_contacts' + .col-md-12= render 'registrant/domains/partials/admin_contacts' .row - .col-md-12= render 'admin/domains/partials/statuses' + .col-md-12= render 'registrant/domains/partials/statuses' .row - .col-md-12= render 'admin/domains/partials/nameservers' + .col-md-12= render 'registrant/domains/partials/nameservers' .row - .col-md-12= render 'admin/domains/partials/dnskeys' + .col-md-12= render 'registrant/domains/partials/dnskeys' .row - .col-md-12= render 'admin/domains/partials/keyrelays' -.row - .col-md-12 - = render 'admin/domains/partials/legal_documents', legal_documents: @domain.legal_documents + .col-md-12= render 'registrant/domains/partials/keyrelays' diff --git a/app/views/registrant/registrars/index.haml b/app/views/registrant/registrars/index.haml new file mode 100644 index 000000000..a2604dbec --- /dev/null +++ b/app/views/registrant/registrars/index.haml @@ -0,0 +1,22 @@ +- content_for :actions do + = link_to(t(:new), new_admin_registrar_path, class: 'btn btn-primary') += render 'shared/title', name: t(:registrars) + +.row + .col-md-12 + .table-responsive + %table.table.table-hover.table-bordered.table-condensed + %thead + %tr + %th{class: 'col-xs-6'} + = sort_link(@q, 'name') + %th{class: 'col-xs-6'} + = sort_link(@q, 'reg_no', t(:reg_no)) + %tbody + - @registrars.each do |x| + %tr + %td= link_to(x, [:admin, x]) + %td= x.reg_no +.row + .col-md-12 + = paginate @registrars diff --git a/app/views/registrant/registrars/show.haml b/app/views/registrant/registrars/show.haml new file mode 100644 index 000000000..ed5c72b29 --- /dev/null +++ b/app/views/registrant/registrars/show.haml @@ -0,0 +1,53 @@ += render 'shared/title', name: @registrar.name + +- if @registrar.errors.any? + - @registrar.errors.each do |attr, err| + = err + %br +- if @registrar.errors.any? + %hr +.row + .col-md-6 + .panel.panel-default + .panel-heading + %h3.panel-title= t(:general) + .panel-body + %dl.dl-horizontal + %dt= t(:name) + %dd= @registrar.name + + %dt= t(:reg_no) + %dd= @registrar.reg_no + + %dt= t(:vat_no) + %dd= @registrar.vat_no + + %dt= t(:reference_no) + %dd= @registrar.reference_no + + %dt= t(:id) + %dd= @registrar.code + + .col-md-6 + .panel.panel-default + .panel-heading + %h3.panel-title= t(:contact) + .panel-body + %dl.dl-horizontal + %dt= t(:country) + %dd= @registrar.country + + %dt= t(:address) + %dd= @registrar.address + + %dt= t(:contact_phone) + %dd= @registrar.phone + + %dt= t(:contact_email) + %dd= @registrar.email + + %dt= t(:billing_address) + %dd= @registrar.billing_address + + %dt= t(:billing_email) + %dd= @registrar.billing_email diff --git a/config/application.rb b/config/application.rb index 7734cc6e9..2121039dc 100644 --- a/config/application.rb +++ b/config/application.rb @@ -7,6 +7,8 @@ require 'action_controller/railtie' require 'action_mailer/railtie' require 'action_view/railtie' require 'sprockets/railtie' +require 'csv' +require 'rails/all' # require "rails/test_unit/railtie" # Require the gems listed in Gemfile, including any gems diff --git a/config/routes.rb b/config/routes.rb index f5b81e8b5..8abef6c2c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -102,6 +102,12 @@ Rails.application.routes.draw do namespace :registrant do root 'domains#index' + resources :domains do + member do + get :download_list + end + end + # resources :invoices do # member do # get 'download_pdf' @@ -140,6 +146,14 @@ Rails.application.routes.draw do end end + resources :registrars do + resources :api_users + resources :white_ips + collection do + get :search + end + end + resources :whois # resources :contacts do # member do From cd8feaf55300e49e32244e40696218a9b4e2163b Mon Sep 17 00:00:00 2001 From: Stas Date: Mon, 7 Dec 2015 17:29:57 +0200 Subject: [PATCH 04/70] 105842700-file_generation_changed --- app/controllers/registrant/domains_controller.rb | 11 +++++++---- app/models/domain.rb | 5 +++++ app/views/registrant/domains/index.haml | 4 ++-- config/routes.rb | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/controllers/registrant/domains_controller.rb b/app/controllers/registrant/domains_controller.rb index 4fab83787..2e17f9039 100644 --- a/app/controllers/registrant/domains_controller.rb +++ b/app/controllers/registrant/domains_controller.rb @@ -32,11 +32,14 @@ class Registrant::DomainsController < RegistrantController @domains = @q end - respond_to do |format| - format.html - format.csv { render text: @domains.to_csv } + respond_to do |format| + format.csv { render text: @domains.result.to_csv } + format.pdf do + pdf = @domains.result.pdf(render_to_string('registrant/domains/download_list', layout: false)) + send_data pdf, filename: 'domains' + end + end end - end def normalize_search_parameters ca_cache = params[:q][:valid_to_lteq] diff --git a/app/models/domain.rb b/app/models/domain.rb index ca988dc4d..4d29d4032 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -783,5 +783,10 @@ class Domain < ActiveRecord::Base end end end + + def self.pdf(html) + kit = PDFKit.new(html) + kit.to_pdf + end end # rubocop: enable Metrics/ClassLength diff --git a/app/views/registrant/domains/index.haml b/app/views/registrant/domains/index.haml index b79b921bd..efc399ebf 100644 --- a/app/views/registrant/domains/index.haml +++ b/app/views/registrant/domains/index.haml @@ -39,8 +39,8 @@ Download %span.caret %ul.dropdown-menu - %li= link_to 'PDF', download_list_registrant_domain_path(params[:q], format: "pdf") - %li= link_to 'CSV', download_list_registrant_domain_path(params[:q], format: "csv") + %li= link_to 'PDF', download_list_registrant_domains_path(params[:q], format: "pdf") + %li= link_to 'CSV', download_list_registrant_domains_path(params[:q], format: "csv") .col-md-3 .col-md-3 .col-md-3 diff --git a/config/routes.rb b/config/routes.rb index 8abef6c2c..69e6c9680 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -103,7 +103,7 @@ Rails.application.routes.draw do root 'domains#index' resources :domains do - member do + collection do get :download_list end end From ce209b317d04347e16dbbd53b59b1bf3bf084d65 Mon Sep 17 00:00:00 2001 From: Stas Date: Wed, 9 Dec 2015 15:29:28 +0200 Subject: [PATCH 05/70] 105842700-redirect_fix_and template --- app/controllers/application_controller.rb | 2 +- .../registrant/domains_controller.rb | 2 +- .../registrant/domains/download_list.haml | 22 +++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 318923e3d..a79be9aca 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -32,7 +32,7 @@ class ApplicationController < ActionController::Base if registrar_request? registrar_root_url elsif registrant_request? - registrant_root_url + registrant_login_url elsif admin_request? admin_root_url end diff --git a/app/controllers/registrant/domains_controller.rb b/app/controllers/registrant/domains_controller.rb index 2e17f9039..eb5388662 100644 --- a/app/controllers/registrant/domains_controller.rb +++ b/app/controllers/registrant/domains_controller.rb @@ -36,7 +36,7 @@ class Registrant::DomainsController < RegistrantController format.csv { render text: @domains.result.to_csv } format.pdf do pdf = @domains.result.pdf(render_to_string('registrant/domains/download_list', layout: false)) - send_data pdf, filename: 'domains' + send_data pdf, filename: 'domains.pdf' end end end diff --git a/app/views/registrant/domains/download_list.haml b/app/views/registrant/domains/download_list.haml index e69de29bb..f8fc70fd9 100644 --- a/app/views/registrant/domains/download_list.haml +++ b/app/views/registrant/domains/download_list.haml @@ -0,0 +1,22 @@ +.col-md-12 + .table-responsive + %table.table.table-hover.table-bordered.table-condensed + %thead + %tr + %th{class: 'col-xs-2'} + =t(:name) + %th{class: 'col-xs-2'} + =t(:registrant) + %th{class: 'col-xs-2'} + =t(:valid_to) + %th{class: 'col-xs-2'} + =t(:registrar) + %tbody + - @domains.result.each do |x| + %tr + %td= x.name + %td= x.registrant + %td= l(x.valid_to, format: :short) + %td= x.registrar + .row + .col-md-6 From c315c1717809c67082a97223fdc512545163d849 Mon Sep 17 00:00:00 2001 From: Stas Date: Thu, 10 Dec 2015 15:56:29 +0200 Subject: [PATCH 06/70] 105842700-encoding_fix --- .../registrant/domains/download_list.haml | 48 +++++++++++-------- app/views/registrant/domains/index.haml | 4 +- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/app/views/registrant/domains/download_list.haml b/app/views/registrant/domains/download_list.haml index f8fc70fd9..40212812c 100644 --- a/app/views/registrant/domains/download_list.haml +++ b/app/views/registrant/domains/download_list.haml @@ -1,22 +1,28 @@ -.col-md-12 - .table-responsive - %table.table.table-hover.table-bordered.table-condensed - %thead - %tr - %th{class: 'col-xs-2'} - =t(:name) - %th{class: 'col-xs-2'} - =t(:registrant) - %th{class: 'col-xs-2'} - =t(:valid_to) - %th{class: 'col-xs-2'} - =t(:registrar) - %tbody - - @domains.result.each do |x| +!!! +%html + %head + %meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"} + %title Contacts + %body + .col-md-12 + .table-responsive + %table.table.table-hover.table-bordered.table-condensed + %thead %tr - %td= x.name - %td= x.registrant - %td= l(x.valid_to, format: :short) - %td= x.registrar - .row - .col-md-6 + %th{class: 'col-xs-2'} + =t(:name) + %th{class: 'col-xs-2'} + =t(:registrant) + %th{class: 'col-xs-2'} + =t(:valid_to) + %th{class: 'col-xs-2'} + =t(:registrar) + %tbody + - @domains.result.each do |x| + %tr + %td= x.name + %td= x.registrant + %td= l(x.valid_to, format: :short) + %td= x.registrar + .row + .col-md-6 diff --git a/app/views/registrant/domains/index.haml b/app/views/registrant/domains/index.haml index efc399ebf..776b7878d 100644 --- a/app/views/registrant/domains/index.haml +++ b/app/views/registrant/domains/index.haml @@ -39,8 +39,8 @@ Download %span.caret %ul.dropdown-menu - %li= link_to 'PDF', download_list_registrant_domains_path(params[:q], format: "pdf") - %li= link_to 'CSV', download_list_registrant_domains_path(params[:q], format: "csv") + %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 From d9f97a5f6a4432dd1c3ba12edfbcf66e1ac32056 Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Thu, 10 Dec 2015 16:02:12 +0200 Subject: [PATCH 07/70] Story #105846070 - configure cache setting for business data --- app/controllers/admin/settings_controller.rb | 1 + config/initializers/initial_settings.rb | 2 ++ 2 files changed, 3 insertions(+) diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb index 89ccd9ac6..cc49b3b61 100644 --- a/app/controllers/admin/settings_controller.rb +++ b/app/controllers/admin/settings_controller.rb @@ -59,6 +59,7 @@ class Admin::SettingsController < AdminController :transfer_wait_time, :invoice_number_min, :invoice_number_max, + :days_to_keep_business_registry_cache, :days_to_keep_invoices_active, :days_to_keep_overdue_invoices_active, :days_to_renew_domain_before_expire, diff --git a/config/initializers/initial_settings.rb b/config/initializers/initial_settings.rb index 812641a09..7c566db69 100644 --- a/config/initializers/initial_settings.rb +++ b/config/initializers/initial_settings.rb @@ -28,6 +28,8 @@ if con.present? && con.table_exists?('settings') Setting.save_default(:client_side_status_editing_enabled, false) + Setting.save_default(:days_to_keep_business_registry_cache, 2) + Setting.save_default(:invoice_number_min, 131050) Setting.save_default(:invoice_number_max, 149999) Setting.save_default(:days_to_keep_invoices_active, 30) From d012f282412a3b95631bba2909f88b2b09eede59 Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Thu, 10 Dec 2015 17:39:18 +0200 Subject: [PATCH 08/70] Story #105846070 - add configuration for Soap::Arireg --- config/application-example.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/config/application-example.yml b/config/application-example.yml index b08a1b007..59411a739 100644 --- a/config/application-example.yml +++ b/config/application-example.yml @@ -86,6 +86,16 @@ repp_url: 'https://repp.gitlab.eu/repp/v1/' # restful_whois_url: 'https://restful-whois.example.com' +# +# Estonian Business Registry +# +# config/secrets.yml --- arireg: {username, password} +arireg_username: 'kasutaja' +arireg_password: 'parool' +# config/environments/production.rb --- Soap::Arireg.wsdl, Soap::Arireg.host +arireg_wsdl: 'lib/schemas/testariport.wsdl' # https://demo-ariregxml.rik.ee:447/testariport/?wsdl +#arireg_wsdl: 'lib/schemas/ariport.wsdl' # https://ariregxml.rik.ee/ariport/?wsdl +arireg_host: 'https://demo-ariregxml.rik.ee:447' # https://ariregxml.rik.ee/ # # REGISTRAR AND REGISTRANT From 1ae25d2fff2ddac7efa712214770d85c3c27a318 Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Thu, 10 Dec 2015 18:01:19 +0200 Subject: [PATCH 09/70] Story #105846070 - add Arireg class for Soap query of business registry --- app/models/soap/arireg.rb | 141 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 app/models/soap/arireg.rb diff --git a/app/models/soap/arireg.rb b/app/models/soap/arireg.rb new file mode 100644 index 000000000..1e53f0261 --- /dev/null +++ b/app/models/soap/arireg.rb @@ -0,0 +1,141 @@ +# coding: utf-8 +require 'savon' +=begin + +Estonian Business registry provides information about registered companies via xml (SOAP over HTTPS). + +Note: + The SSL endpoint certificate is self signed. + +Documentation: + http://www.rik.ee/et/e-ariregister/xml-teenus + Specifications are in Eng and Est + User contract required + +Testing: + https://demo-ariregxml.rik.ee:447/testariport/?wsdl + http://demo-ariregxml.rik.ee:81 + https://demo-ariregxml.rik.ee:447 + +Live service: + https://ariregxml.rik.ee/ariport/?wsdl + https://ariregxml.rik.ee/ + +Implements Soap::Arireg # associated_businesses + 8. arireg.paringesindus_v4 + Rights of representation of all persons related to the company (newer) + http://www2.rik.ee/schemas/xtee/arireg/live/paringesindus_v4.xsd + expects personal id code, to fetch list of registered business id codes + returning {ident: person, ident_country_code: ... associated_businesses: [...id_codes...]} + +=end + +# do some SSL set up? +# ssl_version +# ssl_verify_mode +# ssl_cert_key_file +# ssl_cert_key +# ssl_cert_key_password +# ssl_cert_file +# ssl_cert +# ssl_ca_cert_file +# ssl_ca_cert + +module Soap + class Arireg + class << self + attr_accessor :wsdl, :host, :username, :password + end + + def initialize + if self.class.username.nil? + if Rails.application.secrets.key?(:arireg) + arireg = Rails.application.secrets[:arireg].with_indifferent_access + self.class.username = arireg[:username] + self.class.password = arireg[:password] + if self.class.wsdl.nil? # no override of config/environments/* ? + self.class.wsdl = arireg[:wsdl] + self.class.host = arireg[:host] + end + else + self.class.username = ENV['arireg_username'] + self.class.password = ENV['arireg_password'] + end + end + if self.class.wsdl.nil? + self.class.wsdl = ENV['arireg_wsdl'] + self.class.host = ENV['arireg_host'] + end + + # note Savon has error if https w/non-standard port, + # use non-standard force to pre-set endpoint + @client = Savon.client(wsdl: self.class.wsdl, + host: self.class.host, + endpoint: "#{self.class.host}/cgi-bin/consumer_proxy") + @session = nil + end + + # retrieve business id codes for business that a person has a legal role + def associated_businesses(ident, ident_cc = 'EST') + begin + response = @client.call :paringesindus_v4, message: body( + 'fyysilise_isiku_kood' => ident, + 'fyysilise_isiku_koodi_riik' => ident_cc + ) + content = extract response, :paringesindus_v4_response + unless content.blank? + if content[:ettevotjad].key? :item + business_ident = items(content, :ettevotjad).map do |item| + #puts "#{item[:ariregistri_kood]}\t#{item[:arinimi]}\t#{item[:staatus]} #{item[:oiguslik_vorm]}\t" + item[:ariregistri_kood] + end + { + ident: ident, + ident_country_code: ident_cc, + # ident_type: 'priv', + retrieved_on: Time.now, + associated_businesses: business_ident + } + end + end + rescue Savon::SOAPFault => fault + Rails.logger.error "#{fault} Äriregister arireg #{self.class.username} at #{self.class.host }" + nil + rescue HTTPI::SSLError => ssl_error + Rails.logger.error "#{ssl_error} at #{self.class.host}" + nil + end + end + + def debug + @client.globals.log_level :debug + @client.globals.log true + @client.globals.pretty_print_xml true + @client + end + + private + + # add required elements to request + def body(args) + if @session.nil? + args['ariregister_kasutajanimi'] = self.class.username + args['ariregister_parool'] = self.class.password + else + args['ariregister_sessioon'] = @session + end + {keha: args} + end + + def extract(response, element) + # response envelope body has again header/body under element; header is user and password returned + response.hash[:envelope][:body][element][:keha] + end + + def items(content, parent) + items = content[parent][:item] + items.is_a?(Array) ? items : [items] + end + + end +end From 4c4908e5a64fc51ba33c1f76a392706a0ea87f2c Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Thu, 10 Dec 2015 18:07:14 +0200 Subject: [PATCH 10/70] Story #105846070 - Arireg just log sock error, and give up --- app/models/soap/arireg.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/models/soap/arireg.rb b/app/models/soap/arireg.rb index 1e53f0261..e0a842cf1 100644 --- a/app/models/soap/arireg.rb +++ b/app/models/soap/arireg.rb @@ -104,6 +104,9 @@ module Soap rescue HTTPI::SSLError => ssl_error Rails.logger.error "#{ssl_error} at #{self.class.host}" nil + rescue SocketError => sock + Rails.logger.error "#{sock}" + nil end end From 49dd053453241284acdf21184c8e5d289aa6d586 Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Thu, 10 Dec 2015 18:46:16 +0200 Subject: [PATCH 11/70] Story #105846070 - Arireg change error handling, raise business logic error Soap::Arireg:NotAvailableError --- app/models/soap/arireg.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/models/soap/arireg.rb b/app/models/soap/arireg.rb index e0a842cf1..d35a175d3 100644 --- a/app/models/soap/arireg.rb +++ b/app/models/soap/arireg.rb @@ -42,7 +42,16 @@ Implements Soap::Arireg # associated_businesses # ssl_ca_cert module Soap + class Arireg + + class NotAvailableError < StandardError + def initialize(params) + params[:message] = "#{I18n.t(:business_registry_service_not_available)}" unless params.key? :message + super(params) + end + end + class << self attr_accessor :wsdl, :host, :username, :password end @@ -100,13 +109,13 @@ module Soap end rescue Savon::SOAPFault => fault Rails.logger.error "#{fault} Äriregister arireg #{self.class.username} at #{self.class.host }" - nil + raise NotAvailableError.new(exception: fault) rescue HTTPI::SSLError => ssl_error Rails.logger.error "#{ssl_error} at #{self.class.host}" - nil + raise NotAvailableError.new(exception: ssl_error) rescue SocketError => sock Rails.logger.error "#{sock}" - nil + raise NotAvailableError.new(exception: sock) end end From 310002f0066d4c41b27a057a28273be197d01129 Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Thu, 10 Dec 2015 18:54:55 +0200 Subject: [PATCH 12/70] Story #105846070 - add message text for Soap::Arireg:NotAvailableError --- config/locales/en.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 16e643b16..9d8f25a44 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -533,7 +533,8 @@ en: switch_to: Switch to admin_menu: Admin domain_transfer_was_approved: 'Domain transfer was approved, associated contacts were: %{contacts} and registrant was %{registrant}' - + business_registry_service_not_available: "Business Registry service Ärireg is not available" + # DEPP activemodel: errors: From 38c43d6279351326f9d5e08cfbc9ac0cf84c00c8 Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Thu, 10 Dec 2015 18:56:20 +0200 Subject: [PATCH 13/70] Story #105846070 - support for country code remapping will be required --- app/models/soap/arireg.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/models/soap/arireg.rb b/app/models/soap/arireg.rb index d35a175d3..3c3d6407a 100644 --- a/app/models/soap/arireg.rb +++ b/app/models/soap/arireg.rb @@ -89,7 +89,7 @@ module Soap begin response = @client.call :paringesindus_v4, message: body( 'fyysilise_isiku_kood' => ident, - 'fyysilise_isiku_koodi_riik' => ident_cc + 'fyysilise_isiku_koodi_riik' => country_code_3(ident_cc) ) content = extract response, :paringesindus_v4_response unless content.blank? @@ -138,7 +138,13 @@ module Soap end {keha: args} end - + + # TLA --- three letter acronym required not two letter acronyms, transform + def country_code_3(code) + # FIXME: need service class for this data + code.length == 3 ? code : {'EE' => 'EST', 'SE' => 'SWE', 'FI' => 'FIN', 'DK' => 'DEN'}[code] + end + def extract(response, element) # response envelope body has again header/body under element; header is user and password returned response.hash[:envelope][:body][element][:keha] From d60029d85ce5391d64e0fbd700abfd86d3bde69c Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Thu, 10 Dec 2015 19:08:04 +0200 Subject: [PATCH 14/70] Story #105846070 - BusinessRegistryCache to use Arireg service --- app/models/business_registry_cache.rb | 75 +++++++++++++++++++ ...9122816_create_business_registry_caches.rb | 13 ++++ 2 files changed, 88 insertions(+) create mode 100644 app/models/business_registry_cache.rb create mode 100644 db/migrate/20151209122816_create_business_registry_caches.rb diff --git a/app/models/business_registry_cache.rb b/app/models/business_registry_cache.rb new file mode 100644 index 000000000..b590853f5 --- /dev/null +++ b/app/models/business_registry_cache.rb @@ -0,0 +1,75 @@ + +=begin +The portal for registrants has to offer an overview of the domains the user is related to directly or through an organisation. +Personal relation is defined by matching the personal identification code associated with a domain and the one acquired on +authentication using electronic ID. Association through a business organisation requires a query to business registry. + + * when user logs in the personal identification code is sent to business registry (using XML service) + * business registry returns the list of business registry codes the user is a board member of + * the list is cached for two days (configurable) + * during that time no new queries are made to business registry for that personal identification code + and the cached organisation code listing is used + * user sees the listing of domains that are associated with him/her directly or through registered organisation + * UI of the portal displays the list of organisation codes and names used to fetch additional domains for the user + (currently by clicking on a username in top right corner of the screen). + Also time and date of the query to the business registry is displayed with the list of organisations. + * if the query to the business registry fails for any reason the list of + domains associated directly with the user is still displayed with an error message indicating a problem + with receiving current list business entities. Outdated list of organisations cannot be used. +=end + +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_ids.uniq! unless contact_ids.blank? + unless contact_ids.blank? + DomainContact.select(:domain_id).distinct.where("contact_id in (?)", contact_ids).pluck(:domain_id).try(:each) do |domain_id| + domains << Domain.find(domain_id) + end + end + domains + end + + class << self + + def fetch_associated_domains(ident_code, ident_cc) + cached = fetch_by_ident_and_cc(ident_code, ident_cc) + cached.associated_domains unless cached.blank? + end + + def fetch_by_ident_and_cc(ident_code, ident_cc) + cache = BusinessRegistryCache.find_by(ident: ident_code, ident_country_code: ident_cc) + # 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) + cache = nil # expired data is forbidden + data = business_registry.associated_businesses(ident_code, ident_cc) + unless data.nil? + cache = BusinessRegistryCache.new(data) + cache.save + end + cache + end + + def business_registry + # TODO: can this be cached and shared? + 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/db/migrate/20151209122816_create_business_registry_caches.rb b/db/migrate/20151209122816_create_business_registry_caches.rb new file mode 100644 index 000000000..3d7766a60 --- /dev/null +++ b/db/migrate/20151209122816_create_business_registry_caches.rb @@ -0,0 +1,13 @@ +class CreateBusinessRegistryCaches < ActiveRecord::Migration + def change + create_table :business_registry_caches do |t| + t.string :ident + t.string :ident_country_code + t.datetime :retrieved_on + t.string :associated_businesses, array: true + t.timestamps null: false + end + + add_index :business_registry_caches, :ident + end +end From a5e3c95b35dc2f426c3c8b8bd6730f97962b0a50 Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Thu, 10 Dec 2015 19:19:15 +0200 Subject: [PATCH 15/70] Story #105846070 - save local copies of the schema for Arireg ariport, to use in config --- lib/schemas/ariport.wsdl | 510 +++++++++++++++++++++++++++++++++++ lib/schemas/testariport.wsdl | 510 +++++++++++++++++++++++++++++++++++ 2 files changed, 1020 insertions(+) create mode 100644 lib/schemas/ariport.wsdl create mode 100644 lib/schemas/testariport.wsdl diff --git a/lib/schemas/ariport.wsdl b/lib/schemas/ariport.wsdl new file mode 100644 index 000000000..7525c9227 --- /dev/null +++ b/lib/schemas/ariport.wsdl @@ -0,0 +1,510 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Teenuste nimekiri + + + + + + + Adapteri test + + + + + + + Ettevõtjaga seotud dokumentide loetelu päring + + + + + + + Ettevõtja esmakannete päring + + + + + + + Ettevõtja muudatuste loetelu tasuline päring + + + + + + + Ettevotja rekvisiitide päring + + + + + + + Ettevotja rekvisiitide fail + + + + + + + Isikute otsing + + + + + + + Klassifikaatorite päring + + + + + + + Ettevõtja majandusaasta aruande päring + + + + + + + Ettevõtja majandusaasta aruande loetelu päring + + + + + + + Ettevõtja detailandmete päring v5 + + + + + + + E-notar: toimiku dokumendi sisu + + + + + + + Ettevõtja lihtandmete päring v5 + + + + + + + Ettevõtja lihtandmete päring tasuta + + + + + + + Esindusõiguste päring v3 + + + + + + + Esindusõiguste päring v4 + + + + + + + Visuaalse Äriregistri ettevõtete-isikute vaheliste seoste päring + + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + + + + + Äriregister_uus + + + + diff --git a/lib/schemas/testariport.wsdl b/lib/schemas/testariport.wsdl new file mode 100644 index 000000000..25e3818b2 --- /dev/null +++ b/lib/schemas/testariport.wsdl @@ -0,0 +1,510 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Teenuste nimekiri + + + + + + + Adapteri test + + + + + + + Ettevõtjaga seotud dokumentide loetelu päring + + + + + + + Ettevõtja esmakannete päring + + + + + + + Ettevõtja muudatuste loetelu tasuline päring + + + + + + + Ettevotja rekvisiitide päring + + + + + + + Ettevotja rekvisiitide fail + + + + + + + Isikute otsing + + + + + + + Klassifikaatorite päring + + + + + + + Ettevõtja majandusaasta aruande päring + + + + + + + Ettevõtja majandusaasta aruande loetelu päring + + + + + + + Ettevõtja detailandmete päring v5 + + + + + + + E-notar: toimiku dokumendi sisu + + + + + + + Ettevõtja lihtandmete päring v5 + + + + + + + Ettevõtja lihtandmete päring tasuta + + + + + + + Esindusõiguste päring v3 + + + + + + + Esindusõiguste päring v4 + + + + + + + Visuaalse Äriregistri ettevõtete-isikute vaheliste seoste päring + + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + v1 + + + + + + + + + + + + + + Äriregister_uus + + + + From cf1f9818b3ff9c4eae0d9f78d6f95d1538c1d41d Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Fri, 11 Dec 2015 14:41:57 +0200 Subject: [PATCH 16/70] Story #105846070 - enable user view, registrant shows user domains --- app/controllers/registrant/domains_controller.rb | 2 ++ app/views/registrant/domains/index.haml | 15 ++++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/controllers/registrant/domains_controller.rb b/app/controllers/registrant/domains_controller.rb index 4bba945a8..7a19eadd2 100644 --- a/app/controllers/registrant/domains_controller.rb +++ b/app/controllers/registrant/domains_controller.rb @@ -1,5 +1,7 @@ class Registrant::DomainsController < RegistrantController def index authorize! :view, :registrant_domains + ident_cc, ident = @current_user.registrant_ident.split '-' + @domains = BusinessRegistryCache.fetch_associated_domains ident, ident_cc end end diff --git a/app/views/registrant/domains/index.haml b/app/views/registrant/domains/index.haml index 8b71cefca..d9f1db882 100644 --- a/app/views/registrant/domains/index.haml +++ b/app/views/registrant/domains/index.haml @@ -16,12 +16,9 @@ %th{class: 'col-xs-2'} = t(:registrar) %tbody - -# - @domains.each do |x| - -# %tr - -# %td= link_to(x, admin_domain_path(x)) - -# %td - -# - if x.registrant - -# = link_to(x.registrant, [:admin, x.registrant]) - - -# %td= l(x.valid_to, format: :short) - -# %td= link_to(x.registrar, admin_registrar_path(x.registrar)) if x.registrar + - @domains.each do |x| + %tr + %td= x + %td= x.registrant + %td= l(x.valid_to, format: :short) + %td= x.registrar From c926aa41004ff6994af67df970ef13d0d7316321 Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Fri, 11 Dec 2015 15:28:22 +0200 Subject: [PATCH 17/70] Story #105846070 - update supported user countries for Arireg --- app/models/soap/arireg.rb | 61 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/app/models/soap/arireg.rb b/app/models/soap/arireg.rb index 3c3d6407a..397159a36 100644 --- a/app/models/soap/arireg.rb +++ b/app/models/soap/arireg.rb @@ -139,10 +139,13 @@ module Soap {keha: args} end - # TLA --- three letter acronym required not two letter acronyms, transform + # TLA --- three letter acronym required not two letter acronym, transform def country_code_3(code) - # FIXME: need service class for this data - code.length == 3 ? code : {'EE' => 'EST', 'SE' => 'SWE', 'FI' => 'FIN', 'DK' => 'DEN'}[code] + if code.length == 2 + code = CC2X3[code] + raise NotAvailableError.new(message: 'Unrecognized Country') if code.nil? + end + code end def extract(response, element) @@ -154,6 +157,56 @@ module Soap items = content[parent][:item] items.is_a?(Array) ? items : [items] end - + + CC2X3 = {"AF"=>"AFG", "AX"=>"ALA", "AL"=>"ALB", "DZ"=>"DZA", "AS"=>"ASM", + "AD"=>"AND", "AO"=>"AGO", "AI"=>"AIA", "AQ"=>"ATA", "AG"=>"ATG", + "AR"=>"ARG", "AM"=>"ARM", "AW"=>"ABW", "AU"=>"AUS", "AT"=>"AUT", + "AZ"=>"AZE", "BS"=>"BHS", "BH"=>"BHR", "BD"=>"BGD", "BB"=>"BRB", + "BY"=>"BLR", "BE"=>"BEL", "BZ"=>"BLZ", "BJ"=>"BEN", "BM"=>"BMU", + "BT"=>"BTN", "BO"=>"BOL", "BQ"=>"BES", "BA"=>"BIH", "BW"=>"BWA", + "BV"=>"BVT", "BR"=>"BRA", "IO"=>"IOT", "BN"=>"BRN", "BG"=>"BGR", + "BF"=>"BFA", "BI"=>"BDI", "CV"=>"CPV", "KH"=>"KHM", "CM"=>"CMR", + "CA"=>"CAN", "KY"=>"CYM", "CF"=>"CAF", "TD"=>"TCD", "CL"=>"CHL", + "CN"=>"CHN", "CX"=>"CXR", "CC"=>"CCK", "CO"=>"COL", "KM"=>"COM", + "CD"=>"COD", "CG"=>"COG", "CK"=>"COK", "CR"=>"CRI", "CI"=>"CIV", + "HR"=>"HRV", "CU"=>"CUB", "CW"=>"CUW", "CY"=>"CYP", "CZ"=>"CZE", + "DK"=>"DNK", "DJ"=>"DJI", "DM"=>"DMA", "DO"=>"DOM", "EC"=>"ECU", + "EG"=>"EGY", "SV"=>"SLV", "GQ"=>"GNQ", "ER"=>"ERI", "EE"=>"EST", + "ET"=>"ETH", "FK"=>"FLK", "FO"=>"FRO", "FJ"=>"FJI", "FI"=>"FIN", + "FR"=>"FRA", "GF"=>"GUF", "PF"=>"PYF", "TF"=>"ATF", "GA"=>"GAB", + "GM"=>"GMB", "GE"=>"GEO", "DE"=>"DEU", "GH"=>"GHA", "GI"=>"GIB", + "GR"=>"GRC", "GL"=>"GRL", "GD"=>"GRD", "GP"=>"GLP", "GU"=>"GUM", + "GT"=>"GTM", "GG"=>"GGY", "GN"=>"GIN", "GW"=>"GNB", "GY"=>"GUY", + "HT"=>"HTI", "HM"=>"HMD", "VA"=>"VAT", "HN"=>"HND", "HK"=>"HKG", + "HU"=>"HUN", "IS"=>"ISL", "IN"=>"IND", "ID"=>"IDN", "IR"=>"IRN", + "IQ"=>"IRQ", "IE"=>"IRL", "IM"=>"IMN", "IL"=>"ISR", "IT"=>"ITA", + "JM"=>"JAM", "JP"=>"JPN", "JE"=>"JEY", "JO"=>"JOR", "KZ"=>"KAZ", + "KE"=>"KEN", "KI"=>"KIR", "KP"=>"PRK", "KR"=>"KOR", "KW"=>"KWT", + "KG"=>"KGZ", "LA"=>"LAO", "LV"=>"LVA", "LB"=>"LBN", "LS"=>"LSO", + "LR"=>"LBR", "LY"=>"LBY", "LI"=>"LIE", "LT"=>"LTU", "LU"=>"LUX", + "MO"=>"MAC", "MK"=>"MKD", "MG"=>"MDG", "MW"=>"MWI", "MY"=>"MYS", + "MV"=>"MDV", "ML"=>"MLI", "MT"=>"MLT", "MH"=>"MHL", "MQ"=>"MTQ", + "MR"=>"MRT", "MU"=>"MUS", "YT"=>"MYT", "MX"=>"MEX", "FM"=>"FSM", + "MD"=>"MDA", "MC"=>"MCO", "MN"=>"MNG", "ME"=>"MNE", "MS"=>"MSR", + "MA"=>"MAR", "MZ"=>"MOZ", "MM"=>"MMR", "NA"=>"NAM", "NR"=>"NRU", + "NP"=>"NPL", "NL"=>"NLD", "NC"=>"NCL", "NZ"=>"NZL", "NI"=>"NIC", + "NE"=>"NER", "NG"=>"NGA", "NU"=>"NIU", "NF"=>"NFK", "MP"=>"MNP", + "NO"=>"NOR", "OM"=>"OMN", "PK"=>"PAK", "PW"=>"PLW", "PS"=>"PSE", + "PA"=>"PAN", "PG"=>"PNG", "PY"=>"PRY", "PE"=>"PER", "PH"=>"PHL", + "PN"=>"PCN", "PL"=>"POL", "PT"=>"PRT", "PR"=>"PRI", "QA"=>"QAT", + "RE"=>"REU", "RO"=>"ROU", "RU"=>"RUS", "RW"=>"RWA", "BL"=>"BLM", + "SH"=>"SHN", "KN"=>"KNA", "LC"=>"LCA", "MF"=>"MAF", "PM"=>"SPM", + "VC"=>"VCT", "WS"=>"WSM", "SM"=>"SMR", "ST"=>"STP", "SA"=>"SAU", + "SN"=>"SEN", "RS"=>"SRB", "SC"=>"SYC", "SL"=>"SLE", "SG"=>"SGP", + "SX"=>"SXM", "SK"=>"SVK", "SI"=>"SVN", "SB"=>"SLB", "SO"=>"SOM", + "ZA"=>"ZAF", "GS"=>"SGS", "SS"=>"SSD", "ES"=>"ESP", "LK"=>"LKA", + "SD"=>"SDN", "SR"=>"SUR", "SJ"=>"SJM", "SZ"=>"SWZ", "SE"=>"SWE", + "CH"=>"CHE", "SY"=>"SYR", "TW"=>"TWN", "TJ"=>"TJK", "TZ"=>"TZA", + "TH"=>"THA", "TL"=>"TLS", "TG"=>"TGO", "TK"=>"TKL", "TO"=>"TON", + "TT"=>"TTO", "TN"=>"TUN", "TR"=>"TUR", "TM"=>"TKM", "TC"=>"TCA", + "TV"=>"TUV", "UG"=>"UGA", "UA"=>"UKR", "AE"=>"ARE", "GB"=>"GBR", + "UM"=>"UMI", "US"=>"USA", "UY"=>"URY", "UZ"=>"UZB", "VU"=>"VUT", + "VE"=>"VEN", "VN"=>"VNM", "VG"=>"VGB", "VI"=>"VIR", "WF"=>"WLF", + "EH"=>"ESH", "YE"=>"YEM", "ZM"=>"ZMB", "ZW"=>"ZWE"} end end From 352c748258be99b9c59b0d33817c1f1739dc5cfd Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Fri, 11 Dec 2015 15:46:29 +0200 Subject: [PATCH 18/70] Story #105846070 - show error message to user when service not available --- app/controllers/registrant/domains_controller.rb | 7 ++++++- app/models/business_registry_cache.rb | 2 +- app/views/registrant/domains/index.haml | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/controllers/registrant/domains_controller.rb b/app/controllers/registrant/domains_controller.rb index 7a19eadd2..50aac75f3 100644 --- a/app/controllers/registrant/domains_controller.rb +++ b/app/controllers/registrant/domains_controller.rb @@ -2,6 +2,11 @@ class Registrant::DomainsController < RegistrantController def index authorize! :view, :registrant_domains ident_cc, ident = @current_user.registrant_ident.split '-' - @domains = BusinessRegistryCache.fetch_associated_domains ident, ident_cc + begin + @domains = BusinessRegistryCache.fetch_associated_domains ident, ident_cc + rescue Soap::Arireg::NotAvailableError => error + flash[:notice] = I18n.t(error.message[:message]) + @domains = [] + end end end diff --git a/app/models/business_registry_cache.rb b/app/models/business_registry_cache.rb index b590853f5..5d6010674 100644 --- a/app/models/business_registry_cache.rb +++ b/app/models/business_registry_cache.rb @@ -48,7 +48,7 @@ class BusinessRegistryCache < ActiveRecord::Base cache = BusinessRegistryCache.find_by(ident: ident_code, ident_country_code: ident_cc) # 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) - cache = nil # expired data is forbidden + cache = [] # expired data is forbidden data = business_registry.associated_businesses(ident_code, ident_cc) unless data.nil? cache = BusinessRegistryCache.new(data) diff --git a/app/views/registrant/domains/index.haml b/app/views/registrant/domains/index.haml index d9f1db882..f8c03b8af 100644 --- a/app/views/registrant/domains/index.haml +++ b/app/views/registrant/domains/index.haml @@ -16,7 +16,7 @@ %th{class: 'col-xs-2'} = t(:registrar) %tbody - - @domains.each do |x| + - @domains.try(:each) do |x| %tr %td= x %td= x.registrant From 2b186e9c933c0633950faa2d141b864adf9c1aac Mon Sep 17 00:00:00 2001 From: Stas Date: Fri, 11 Dec 2015 17:33:28 +0200 Subject: [PATCH 19/70] 105842700-translation_and_link_fix --- .../registrant/registrants_controller.rb | 8 ++ .../registrant/registrars_controller.rb | 1 - .../registrant/domains/partials/_general.haml | 2 +- app/views/registrant/registrants/index.haml | 112 ++++++++++++++++++ app/views/registrant/registrants/show.haml | 75 ++++++++++++ config/routes.rb | 2 + 6 files changed, 198 insertions(+), 2 deletions(-) create mode 100644 app/controllers/registrant/registrants_controller.rb create mode 100644 app/views/registrant/registrants/index.haml create mode 100644 app/views/registrant/registrants/show.haml diff --git a/app/controllers/registrant/registrants_controller.rb b/app/controllers/registrant/registrants_controller.rb new file mode 100644 index 000000000..adc1e0b82 --- /dev/null +++ b/app/controllers/registrant/registrants_controller.rb @@ -0,0 +1,8 @@ +class Registrant::RegistrantsController < RegistrantController + + def show + @contact = Registrant.find(params[:id]) + authorize! :read, @contact + @contact.valid? + end +end diff --git a/app/controllers/registrant/registrars_controller.rb b/app/controllers/registrant/registrars_controller.rb index 36ab9bb2a..d0630b73a 100644 --- a/app/controllers/registrant/registrars_controller.rb +++ b/app/controllers/registrant/registrars_controller.rb @@ -3,6 +3,5 @@ class Registrant::RegistrarsController < RegistrantController def show @registrar = Registrar.find(params[:id]) authorize! :read, @registrar - @registrar.valid? end end diff --git a/app/views/registrant/domains/partials/_general.haml b/app/views/registrant/domains/partials/_general.haml index d433a1302..d1a17c1cc 100644 --- a/app/views/registrant/domains/partials/_general.haml +++ b/app/views/registrant/domains/partials/_general.haml @@ -12,7 +12,7 @@ %dt= t(:registrar) %dd= link_to(@domain.registrar, admin_registrar_path(@domain.registrar)) - %dt= t(:password) + %dt= t(:authinfo_pw) %dd = text_field_tag :password, @domain.auth_info, readonly: true, class: 'partially-hidden' diff --git a/app/views/registrant/registrants/index.haml b/app/views/registrant/registrants/index.haml new file mode 100644 index 000000000..b8e7850e6 --- /dev/null +++ b/app/views/registrant/registrants/index.haml @@ -0,0 +1,112 @@ += render 'shared/title', name: t(:contacts) + +.row + .col-md-12 + = search_form_for [:admin, @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(:id) + = f.search_field :code_eq, class: 'form-control', placeholder: t(:id) + .col-md-3 + .form-group + = f.label t(:ident) + = f.search_field :ident_matches, class: 'form-control', placeholder: t(:ident) + .col-md-3 + .form-group + = label_tag t(:ident_type) + = select_tag '[q][ident_type_eq]', options_for_select(Contact::IDENT_TYPES, params[:q][:ident_type_eq]), { include_blank: true, placeholder: t(:choose), class: 'form-control selectize' } + .row + .col-md-3 + .form-group + = f.label t(:email) + = f.search_field :email_matches, class: 'form-control', placeholder: t(:email) + .col-md-3 + .form-group + = label_tag t(:country) + = select_tag '[q][country_code_eq]', SortedCountry.all_options(params[:q][:country_code_eq]), { include_blank: true, placeholder: t(:choose), class: 'form-control selectize' } + .col-md-3 + .form-group + = f.label t(:is_registrant) + %div + = f.check_box :registrant_domains_id_not_null + .col-md-3 + .form-group + = label_tag t(:contact_type) + = select_tag '[q][domain_contacts_type_in]', options_for_select([['admin', 'AdminDomainContact'], ['tech', 'TechDomainContact']], params[:q][:domain_contacts_type_in]), { multiple: true, placeholder: t(:choose), class: 'form-control js-combobox' } + .row + .col-md-3 + .form-group + = f.label t(:registrar) + = f.select :registrar_id_eq, Registrar.all.map { |x| [x, x.id] }, { include_blank: true }, class: 'form-control selectize', placeholder: t(:choose) + .col-md-3 + .form-group + = f.label t(:created_at_from) + = f.search_field :created_at_gteq, value: params[:q][:created_at_gteq], class: 'form-control datepicker', placeholder: t(:created_at_from) + .col-md-3 + .form-group + = f.label t(:created_at_until) + = f.search_field :created_at_lteq, value: params[:q][:created_at_lteq], class: 'form-control datepicker', placeholder: t(:created_at_until) + .col-md-3 + .form-group + = f.label t(:updated_at) + = f.search_field :updated_at_gteq, value: params[:q][:updated_at_gteq], class: 'form-control datepicker', placeholder: t(:updated_at) + .row + .col-md-6 + .form-group + = label_tag t(:status) + = select_tag :statuses_contains, options_for_select(Contact::STATUSES, params[:statuses_contains]), { multiple: true, placeholder: t(:choose), class: 'form-control js-combobox' } + .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) +%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', t(:name)) + %th{class: 'col-xs-2'} + = sort_link(@q, 'code', t(:id)) + %th{class: 'col-xs-2'} + = sort_link(@q, 'ident', t(:ident)) + %th{class: 'col-xs-2'} + = sort_link(@q, 'email', t(:created_at)) + %th{class: 'col-xs-2'} + = sort_link(@q, 'registrar_name', t(:registrar)) + %tbody + - @contacts.each do |contact| + %tr + %td= link_to(contact, admin_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)) + +.row + .col-md-6 + = paginate @contacts + .col-md-6.text-right + .pagination + = t(:result_count, count: @contacts.total_count) + +:coffee + $(".js-reset-form").on "click", (e) -> + e.preventDefault(); + window.location = "#{admin_contacts_path}" diff --git a/app/views/registrant/registrants/show.haml b/app/views/registrant/registrants/show.haml new file mode 100644 index 000000000..5b2a527ca --- /dev/null +++ b/app/views/registrant/registrants/show.haml @@ -0,0 +1,75 @@ += render 'shared/title', name: @contact.name + +.row + .col-md-6 + .panel.panel-default + .panel-heading + %h3.panel-title= t(:general) + .panel-body + %dl.dl-horizontal + %dt= t(:id) + %dd= @contact.code + + %dt= t(:authinfo_pw) + %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)) if @contact.registrar + + .col-md-6 + .panel.panel-default + .panel-heading + %h3.panel-title= t(:contact) + .panel-body + %dl.dl-horizontal + %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 \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 69e6c9680..922dbeaa5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -154,6 +154,8 @@ Rails.application.routes.draw do end end + resources :registrants + resources :whois # resources :contacts do # member do From 23d4547e2bb6072bfbf07d4c41e980cc8f1a58da Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Mon, 14 Dec 2015 13:04:46 +0200 Subject: [PATCH 20/70] Story #105846070 - update existing record if present --- app/models/business_registry_cache.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/models/business_registry_cache.rb b/app/models/business_registry_cache.rb index 5d6010674..5defd4183 100644 --- a/app/models/business_registry_cache.rb +++ b/app/models/business_registry_cache.rb @@ -48,11 +48,16 @@ class BusinessRegistryCache < ActiveRecord::Base cache = BusinessRegistryCache.find_by(ident: ident_code, ident_country_code: ident_cc) # 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) - cache = [] # expired data is forbidden - data = business_registry.associated_businesses(ident_code, ident_cc) - unless data.nil? - cache = BusinessRegistryCache.new(data) + 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 end cache end From 3d71a01280cd62c7edca72b69254656319ebee4e Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Mon, 14 Dec 2015 13:13:55 +0200 Subject: [PATCH 21/70] Story #105846070 - revert domains_controller and domains/index to allow merge --- app/controllers/registrant/domains_controller.rb | 7 ------- app/views/registrant/domains/index.haml | 15 +++++++++------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/app/controllers/registrant/domains_controller.rb b/app/controllers/registrant/domains_controller.rb index 50aac75f3..4bba945a8 100644 --- a/app/controllers/registrant/domains_controller.rb +++ b/app/controllers/registrant/domains_controller.rb @@ -1,12 +1,5 @@ class Registrant::DomainsController < RegistrantController def index authorize! :view, :registrant_domains - ident_cc, ident = @current_user.registrant_ident.split '-' - begin - @domains = BusinessRegistryCache.fetch_associated_domains ident, ident_cc - rescue Soap::Arireg::NotAvailableError => error - flash[:notice] = I18n.t(error.message[:message]) - @domains = [] - end end end diff --git a/app/views/registrant/domains/index.haml b/app/views/registrant/domains/index.haml index f8c03b8af..8b71cefca 100644 --- a/app/views/registrant/domains/index.haml +++ b/app/views/registrant/domains/index.haml @@ -16,9 +16,12 @@ %th{class: 'col-xs-2'} = t(:registrar) %tbody - - @domains.try(:each) do |x| - %tr - %td= x - %td= x.registrant - %td= l(x.valid_to, format: :short) - %td= x.registrar + -# - @domains.each do |x| + -# %tr + -# %td= link_to(x, admin_domain_path(x)) + -# %td + -# - if x.registrant + -# = link_to(x.registrant, [:admin, x.registrant]) + + -# %td= l(x.valid_to, format: :short) + -# %td= link_to(x.registrar, admin_registrar_path(x.registrar)) if x.registrar From e266c2274104b30b5db99e0a42c0c23dcde8f1e5 Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Mon, 14 Dec 2015 13:43:26 +0200 Subject: [PATCH 22/70] Story #105846070 - refactor local value to method --- app/controllers/registrant/domains_controller.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/registrant/domains_controller.rb b/app/controllers/registrant/domains_controller.rb index eb5388662..ea84a6aa3 100644 --- a/app/controllers/registrant/domains_controller.rb +++ b/app/controllers/registrant/domains_controller.rb @@ -3,7 +3,6 @@ class Registrant::DomainsController < RegistrantController def index authorize! :view, :registrant_domains params[:q] ||= {} - domains = current_user.domains normalize_search_parameters do @q = domains.search(params[:q]) @domains = @q.result.page(params[:page]) @@ -26,7 +25,6 @@ class Registrant::DomainsController < RegistrantController def download_list authorize! :view, :registrant_domains params[:q] ||= {} - domains = current_user.domains normalize_search_parameters do @q = domains.search(params[:q]) @domains = @q @@ -39,7 +37,11 @@ class Registrant::DomainsController < RegistrantController send_data pdf, filename: 'domains.pdf' end end - end + end + + def domains + current_user.domains + end def normalize_search_parameters ca_cache = params[:q][:valid_to_lteq] From 48ab1c7c7e6426b7c1da34e8b766ce97f1f6d421 Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Mon, 14 Dec 2015 13:50:11 +0200 Subject: [PATCH 23/70] Story #105846070 - include results from business registry if found --- app/controllers/registrant/domains_controller.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/registrant/domains_controller.rb b/app/controllers/registrant/domains_controller.rb index ea84a6aa3..addc157e3 100644 --- a/app/controllers/registrant/domains_controller.rb +++ b/app/controllers/registrant/domains_controller.rb @@ -40,7 +40,13 @@ class Registrant::DomainsController < RegistrantController end def domains - current_user.domains + ident_cc, ident = @current_user.registrant_ident.split '-' + begin + BusinessRegistryCache.fetch_associated_domains ident, ident_cc + rescue Soap::Arireg::NotAvailableError => error + flash[:notice] = I18n.t(error.message[:message]) + current_user.domains + end end def normalize_search_parameters From 9d2f23a71d16967696d7ee29eab874b30b8bc8ae Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Mon, 14 Dec 2015 14:08:52 +0200 Subject: [PATCH 24/70] Story #105846070 - use Domain.includes, replace Domain.find; return Relation rather than array. white space changes --- app/models/business_registry_cache.rb | 28 +++++++++++++-------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/app/models/business_registry_cache.rb b/app/models/business_registry_cache.rb index 5defd4183..9bc65d599 100644 --- a/app/models/business_registry_cache.rb +++ b/app/models/business_registry_cache.rb @@ -20,21 +20,19 @@ authentication using electronic ID. Association through a business organisation 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_ids.uniq! unless contact_ids.blank? - unless contact_ids.blank? - DomainContact.select(:domain_id).distinct.where("contact_id in (?)", contact_ids).pluck(:domain_id).try(:each) do |domain_id| - domains << Domain.find(domain_id) - end - end - domains + 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? + unless contact_ids.blank? + contact_ids.uniq! + domains = DomainContact.select(:domain_id).distinct.where("contact_id in (?)", contact_ids).pluck(:domain_id) + end + Domain.includes(:registrar, :registrant).where('id in (?)', domains) end class << self From 342de9a9c9edfa1ee875e9e9103104e4a06c2582 Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Mon, 14 Dec 2015 14:24:12 +0200 Subject: [PATCH 25/70] Story #105846070 - also return relation when business registry has no data --- app/models/business_registry_cache.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/business_registry_cache.rb b/app/models/business_registry_cache.rb index 9bc65d599..18555b1a5 100644 --- a/app/models/business_registry_cache.rb +++ b/app/models/business_registry_cache.rb @@ -39,7 +39,11 @@ class BusinessRegistryCache < ActiveRecord::Base def fetch_associated_domains(ident_code, ident_cc) cached = fetch_by_ident_and_cc(ident_code, ident_cc) - cached.associated_domains unless cached.blank? + if cached.blank? + Domain.includes(:registrar, :registrant).where(contacts: {ident: ident_code, ident_country_code: ident_cc}) + else + cached.associated_domains + end end def fetch_by_ident_and_cc(ident_code, ident_cc) From 47dcca06babd76599ec491949863bd1e70ccf5f0 Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Mon, 14 Dec 2015 14:40:01 +0200 Subject: [PATCH 26/70] Story #109818884 - set outzone_at when removing serverManualInZone --- app/models/domain.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/domain.rb b/app/models/domain.rb index 7858b3d36..57e4367b0 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -710,6 +710,8 @@ class Domain < ActiveRecord::Base case s when DomainStatus::PENDING_DELETE self.delete_at = nil + when DomainStatus::SERVER_MANUAL_INZONE # removal causes server hold to set + self.outzone_at = Time.zone.now if self.force_delete_at.present? # Handle any other special remove cases? # when DomainStatus::FORCE_DELETE unset_force_delete end From 8f29a2f94ae450231f2fb9aef1789cd5b8535d86 Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Mon, 14 Dec 2015 15:01:06 +0200 Subject: [PATCH 27/70] Story #105846070 - ensure that person search is limited to person contacts to avoid pollution --- app/models/business_registry_cache.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models/business_registry_cache.rb b/app/models/business_registry_cache.rb index 18555b1a5..6bd509101 100644 --- a/app/models/business_registry_cache.rb +++ b/app/models/business_registry_cache.rb @@ -40,7 +40,10 @@ class BusinessRegistryCache < ActiveRecord::Base 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: ident_code, ident_country_code: ident_cc}) + Domain.includes(:registrar, :registrant).where(contacts: { + ident_type: 'priv', + ident: ident_code, + ident_country_code: ident_cc}) else cached.associated_domains end From c8a1ec24ddb91b02c2ef3d6829b26553c9cd238d Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Mon, 14 Dec 2015 15:30:07 +0200 Subject: [PATCH 28/70] Story #105846070 - add more debug info for testers --- app/models/soap/arireg.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/soap/arireg.rb b/app/models/soap/arireg.rb index 397159a36..35517c3ef 100644 --- a/app/models/soap/arireg.rb +++ b/app/models/soap/arireg.rb @@ -95,7 +95,8 @@ module Soap unless content.blank? if content[:ettevotjad].key? :item business_ident = items(content, :ettevotjad).map do |item| - #puts "#{item[:ariregistri_kood]}\t#{item[:arinimi]}\t#{item[:staatus]} #{item[:oiguslik_vorm]}\t" + # 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 { @@ -123,6 +124,7 @@ module Soap @client.globals.log_level :debug @client.globals.log true @client.globals.pretty_print_xml true + @debug = true @client end From 13f50dec8cfb402d45ac4e6ce653cc9a7f086a50 Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Mon, 14 Dec 2015 16:02:45 +0200 Subject: [PATCH 29/70] Story #105846070 - ensure that show can also see all the users domains --- app/controllers/registrant/domains_controller.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/controllers/registrant/domains_controller.rb b/app/controllers/registrant/domains_controller.rb index addc157e3..445cc5d42 100644 --- a/app/controllers/registrant/domains_controller.rb +++ b/app/controllers/registrant/domains_controller.rb @@ -12,7 +12,7 @@ class Registrant::DomainsController < RegistrantController def show @domain = Domain.find(params[:id]) - if !(current_user.domains.include?(@domain) || @domain.valid?) + if !(domains.include?(@domain) || @domain.valid?) redirect_to registrant_domains_path end authorize! :read, @domain @@ -30,13 +30,13 @@ class Registrant::DomainsController < RegistrantController @domains = @q end - respond_to do |format| - format.csv { render text: @domains.result.to_csv } - format.pdf do - pdf = @domains.result.pdf(render_to_string('registrant/domains/download_list', layout: false)) - send_data pdf, filename: 'domains.pdf' - end + respond_to do |format| + format.csv { render text: @domains.result.to_csv } + format.pdf do + pdf = @domains.result.pdf(render_to_string('registrant/domains/download_list', layout: false)) + send_data pdf, filename: 'domains.pdf' end + end end def domains From 05c4aaf3f19a13fed0ddd6d517cfccede03e941e Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Mon, 14 Dec 2015 16:55:22 +0200 Subject: [PATCH 30/70] Story #105846070 - do not allow user to see other user's domains if their ident values have the same code --- app/models/registrant_user.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/models/registrant_user.rb b/app/models/registrant_user.rb index 6fac517af..f0222b2a6 100644 --- a/app/models/registrant_user.rb +++ b/app/models/registrant_user.rb @@ -12,10 +12,15 @@ class RegistrantUser < User end def domains - Domain.includes(:registrar, :registrant).where(contacts: {ident: ident}) + # TODO: move data to normal columns and drop registrant_ident + ident_cc, ident = @current_user.registrant_ident.split '-' + Domain.includes(:registrar, :registrant).where(contacts: { + ident_type: 'priv', + ident: ident, #identity_code, + ident_country_code: ident_cc #country_code + }) end - def to_s username end From 678852091b36f4563ac22b38d97f4964ec661e7a Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Thu, 7 Jan 2016 15:29:25 +0200 Subject: [PATCH 31/70] Stroy#110392672 - Contact domains update should be async --- app/jobs/regenerate_registrar_whoises_job.rb | 2 +- app/jobs/regenerate_whois_record_job.rb | 4 ++-- app/models/contact.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/jobs/regenerate_registrar_whoises_job.rb b/app/jobs/regenerate_registrar_whoises_job.rb index 10e13a038..68a76c8d3 100644 --- a/app/jobs/regenerate_registrar_whoises_job.rb +++ b/app/jobs/regenerate_registrar_whoises_job.rb @@ -4,7 +4,7 @@ class RegenerateRegistrarWhoisesJob < Que::Job registrar = Registrar.find(registrar_id) registrar.whois_records.select(:id).find_in_batches(batch_size: 20) do |group| - RegenerateWhoisRecordJob.enqueue group.map(&:id) + RegenerateWhoisRecordJob.enqueue group.map(&:id), :id end end end \ No newline at end of file diff --git a/app/jobs/regenerate_whois_record_job.rb b/app/jobs/regenerate_whois_record_job.rb index 6d79e2ea5..051247b7f 100644 --- a/app/jobs/regenerate_whois_record_job.rb +++ b/app/jobs/regenerate_whois_record_job.rb @@ -1,7 +1,7 @@ class RegenerateWhoisRecordJob < Que::Job - def run(ids) + def run(ids, attr = :id) ids.each do |id| - record = WhoisRecord.find_by(id: id) + record = WhoisRecord.find_by(attr => id) return unless record record.save diff --git a/app/models/contact.rb b/app/models/contact.rb index ccc44851d..39672e2c4 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -498,7 +498,7 @@ class Contact < ActiveRecord::Base end def update_related_whois_records - related_domain_descriptions.each{ |x, y| WhoisRecord.find_by(name: x).try(:save) } + RegenerateWhoisRecordJob.enqueue related_domain_descriptions.keys, :name end end From bd65eb64948fcd08c352db2fdbd6bb610d9d2e10 Mon Sep 17 00:00:00 2001 From: Stas Date: Tue, 12 Jan 2016 13:05:12 +0200 Subject: [PATCH 32/70] 110395650-separated_class_for_cron_jobs --- app/models/domain.rb | 128 ++++++++----------------------------- app/models/domain_cron.rb | 98 ++++++++++++++++++++++++++++ config/schedule.rb | 10 +-- spec/models/domain_spec.rb | 30 ++++----- 4 files changed, 143 insertions(+), 123 deletions(-) create mode 100644 app/models/domain_cron.rb diff --git a/app/models/domain.rb b/app/models/domain.rb index a9defdf50..5b3a6cd65 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -203,6 +203,31 @@ class Domain < ActiveRecord::Base statuses.include? DomainStatus::SERVER_TECH_CHANGE_PROHIBITED end + def self.clean_expired_pendings + DomainCron.send(__method__) + ActiveSupport::Deprecation.deprecate_methods(DomainCron, __method__) + end + + def self.start_expire_period + DomainCron.send(__method__) + ActiveSupport::Deprecation.deprecate_methods(DomainCron, __method__) + end + + def self.start_redemption_grace_period + DomainCron.send(__method__) + ActiveSupport::Deprecation.deprecate_methods(DomainCron, __method__) + end + + def self.start_delete_period + DomainCron.send(__method__) + ActiveSupport::Deprecation.deprecate_methods(DomainCron, __method__) + end + + def self.destroy_delete_candidates + DomainCron.send(__method__) + ActiveSupport::Deprecation.deprecate_methods(DomainCron, __method__) + end + class << self def convert_period_to_time(period, unit) return (period.to_i / 365).years if unit == 'd' @@ -221,109 +246,6 @@ class Domain < ActiveRecord::Base ) end - # rubocop: disable Metrics/AbcSize - # rubocop: disable Metrics/CyclomaticComplexity - # rubocop: disable Metrics/PerceivedComplexity - def clean_expired_pendings - STDOUT << "#{Time.zone.now.utc} - Clean expired domain pendings\n" unless Rails.env.test? - - expire_at = Setting.expire_pending_confirmation.hours.ago - count = 0 - expired_pending_domains = Domain.where('registrant_verification_asked_at <= ?', expire_at) - expired_pending_domains.each do |domain| - unless domain.pending_update? || domain.pending_delete? || domain.pending_delete_confirmation? - msg = "#{Time.zone.now.utc} - ISSUE: DOMAIN #{domain.id}: #{domain.name} IS IN EXPIRED PENDING LIST, " \ - "but no pendingDelete/pendingUpdate state present!\n" - STDOUT << msg unless Rails.env.test? - next - end - count += 1 - if domain.pending_update? - domain.send_mail :pending_update_expired_notification_for_new_registrant - end - if domain.pending_delete? || domain.pending_delete_confirmation? - DomainMailer.pending_delete_expired_notification(domain.id, true).deliver - end - domain.clean_pendings! - unless Rails.env.test? - STDOUT << "#{Time.zone.now.utc} Domain.clean_expired_pendings: ##{domain.id} (#{domain.name})\n" - end - end - STDOUT << "#{Time.zone.now.utc} - Successfully cancelled #{count} domain pendings\n" unless Rails.env.test? - count - end - # rubocop: enable Metrics/PerceivedComplexity - # rubocop: enable Metrics/AbcSize - # rubocop: enable Metrics/CyclomaticComplexity - - # rubocop: disable Metrics/LineLength - def start_expire_period - STDOUT << "#{Time.zone.now.utc} - Expiring domains\n" unless Rails.env.test? - - domains = Domain.where('valid_to <= ?', Time.zone.now) - domains.each do |domain| - next unless domain.expirable? - domain.set_graceful_expired - DomainMailer.expiration_reminder(domain.id).deliver - STDOUT << "#{Time.zone.now.utc} Domain.start_expire_period: ##{domain.id} (#{domain.name}) #{domain.changes}\n" unless Rails.env.test? - domain.save - end - - STDOUT << "#{Time.zone.now.utc} - Successfully expired #{domains.count} domains\n" unless Rails.env.test? - end - - def start_redemption_grace_period - STDOUT << "#{Time.zone.now.utc} - Setting server_hold to domains\n" unless Rails.env.test? - - d = Domain.where('outzone_at <= ?', Time.zone.now) - d.each do |domain| - next unless domain.server_holdable? - domain.statuses << DomainStatus::SERVER_HOLD - STDOUT << "#{Time.zone.now.utc} Domain.start_redemption_grace_period: ##{domain.id} (#{domain.name}) #{domain.changes}\n" unless Rails.env.test? - domain.save - end - - STDOUT << "#{Time.zone.now.utc} - Successfully set server_hold to #{d.count} domains\n" unless Rails.env.test? - end - - def start_delete_period - STDOUT << "#{Time.zone.now.utc} - Setting delete_candidate to domains\n" unless Rails.env.test? - - d = Domain.where('delete_at <= ?', Time.zone.now) - d.each do |domain| - next unless domain.delete_candidateable? - domain.statuses << DomainStatus::DELETE_CANDIDATE - STDOUT << "#{Time.zone.now.utc} Domain.start_delete_period: ##{domain.id} (#{domain.name}) #{domain.changes}\n" unless Rails.env.test? - domain.save - end - - return if Rails.env.test? - STDOUT << "#{Time.zone.now.utc} - Successfully set delete_candidate to #{d.count} domains\n" - end - - # rubocop:disable Rails/FindEach - # rubocop:disable Metrics/AbcSize - def destroy_delete_candidates - STDOUT << "#{Time.zone.now.utc} - Destroying domains\n" unless Rails.env.test? - - c = 0 - Domain.where("statuses @> '{deleteCandidate}'::varchar[]").each do |x| - WhoisRecord.where(domain_id: x.id).destroy_all - destroy_with_message x - STDOUT << "#{Time.zone.now.utc} Domain.destroy_delete_candidates: by deleteCandidate ##{x.id} (#{x.name})\n" unless Rails.env.test? - - c += 1 - end - - Domain.where('force_delete_at <= ?', Time.zone.now).each do |x| - WhoisRecord.where(domain_id: x.id).destroy_all - destroy_with_message x - STDOUT << "#{Time.zone.now.utc} Domain.destroy_delete_candidates: by force delete time ##{x.id} (#{x.name})\n" unless Rails.env.test? - c += 1 - end - - STDOUT << "#{Time.zone.now.utc} - Successfully destroyed #{c} domains\n" unless Rails.env.test? - end # rubocop: enable Metrics/AbcSize # rubocop:enable Rails/FindEach # rubocop: enable Metrics/LineLength diff --git a/app/models/domain_cron.rb b/app/models/domain_cron.rb new file mode 100644 index 000000000..3fd09dc1f --- /dev/null +++ b/app/models/domain_cron.rb @@ -0,0 +1,98 @@ +class DomainCron + + def self.clean_expired_pendings + STDOUT << "#{Time.zone.now.utc} - Clean expired domain pendings\n" unless Rails.env.test? + + expire_at = Setting.expire_pending_confirmation.hours.ago + count = 0 + expired_pending_domains = Domain.where('registrant_verification_asked_at <= ?', expire_at) + expired_pending_domains.each do |domain| + unless domain.pending_update? || domain.pending_delete? || domain.pending_delete_confirmation? + msg = "#{Time.zone.now.utc} - ISSUE: DOMAIN #{domain.id}: #{domain.name} IS IN EXPIRED PENDING LIST, " \ + "but no pendingDelete/pendingUpdate state present!\n" + STDOUT << msg unless Rails.env.test? + next + end + count += 1 + if domain.pending_update? + domain.send_mail :pending_update_expired_notification_for_new_registrant + end + if domain.pending_delete? || domain.pending_delete_confirmation? + DomainMailer.pending_delete_expired_notification(domain.id, true).deliver + end + domain.clean_pendings! + unless Rails.env.test? + STDOUT << "#{Time.zone.now.utc} Domain.clean_expired_pendings: ##{domain.id} (#{domain.name})\n" + end + end + STDOUT << "#{Time.zone.now.utc} - Successfully cancelled #{count} domain pendings\n" unless Rails.env.test? + count + end + + def self.start_expire_period + STDOUT << "#{Time.zone.now.utc} - Expiring domains\n" unless Rails.env.test? + + domains = Domain.where('valid_to <= ?', Time.zone.now) + domains.each do |domain| + next unless domain.expirable? + domain.set_graceful_expired + DomainMailer.expiration_reminder(domain.id).deliver + STDOUT << "#{Time.zone.now.utc} Domain.start_expire_period: ##{domain.id} (#{domain.name}) #{domain.changes}\n" unless Rails.env.test? + domain.save + end + + STDOUT << "#{Time.zone.now.utc} - Successfully expired #{domains.count} domains\n" unless Rails.env.test? + end + + def self.start_redemption_grace_period + STDOUT << "#{Time.zone.now.utc} - Setting server_hold to domains\n" unless Rails.env.test? + + d = Domain.where('outzone_at <= ?', Time.zone.now) + d.each do |domain| + next unless domain.server_holdable? + domain.statuses << DomainStatus::SERVER_HOLD + STDOUT << "#{Time.zone.now.utc} Domain.start_redemption_grace_period: ##{domain.id} (#{domain.name}) #{domain.changes}\n" unless Rails.env.test? + domain.save + end + + STDOUT << "#{Time.zone.now.utc} - Successfully set server_hold to #{d.count} domains\n" unless Rails.env.test? + end + + def self.start_delete_period + STDOUT << "#{Time.zone.now.utc} - Setting delete_candidate to domains\n" unless Rails.env.test? + + d = Domain.where('delete_at <= ?', Time.zone.now) + d.each do |domain| + next unless domain.delete_candidateable? + domain.statuses << DomainStatus::DELETE_CANDIDATE + STDOUT << "#{Time.zone.now.utc} Domain.start_delete_period: ##{domain.id} (#{domain.name}) #{domain.changes}\n" unless Rails.env.test? + domain.save + end + + return if Rails.env.test? + STDOUT << "#{Time.zone.now.utc} - Successfully set delete_candidate to #{d.count} domains\n" + end + + def self.destroy_delete_candidates + STDOUT << "#{Time.zone.now.utc} - Destroying domains\n" unless Rails.env.test? + + c = 0 + Domain.where("statuses @> '{deleteCandidate}'::varchar[]").each do |x| + WhoisRecord.where(domain_id: x.id).destroy_all + destroy_with_message x + STDOUT << "#{Time.zone.now.utc} Domain.destroy_delete_candidates: by deleteCandidate ##{x.id} (#{x.name})\n" unless Rails.env.test? + + c += 1 + end + + Domain.where('force_delete_at <= ?', Time.zone.now).each do |x| + WhoisRecord.where(domain_id: x.id).destroy_all + destroy_with_message x + STDOUT << "#{Time.zone.now.utc} Domain.destroy_delete_candidates: by force delete time ##{x.id} (#{x.name})\n" unless Rails.env.test? + c += 1 + end + + STDOUT << "#{Time.zone.now.utc} - Successfully destroyed #{c} domains\n" unless Rails.env.test? + end + +end diff --git a/config/schedule.rb b/config/schedule.rb index 5524f10ab..81f11c341 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -31,7 +31,7 @@ if @cron_group == 'registry' # end every :day, at: '12:20am' do - runner 'Domain.clean_expired_pendings' + runner 'DomainCron.clean_expired_pendings' end every 3.hours do @@ -39,19 +39,19 @@ if @cron_group == 'registry' end every 42.minutes do - runner 'Domain.destroy_delete_candidates' + runner 'DomainCron.destroy_delete_candidates' end every 45.minutes do - runner 'Domain.start_expire_period' + runner 'DomainCron.start_expire_period' end every 50.minutes do - runner 'Domain.start_delete_period' + runner 'DomainCron.start_delete_period' end every 52.minutes do - runner 'Domain.start_redemption_grace_period' + runner 'DomainCron.start_redemption_grace_period' end end diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index 9dd0f1a48..cddb9141b 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -140,20 +140,20 @@ describe Domain do domain.registrant_verification_asked_at = 30.days.ago domain.pending_delete! - Domain.clean_expired_pendings.should == 1 + DomainCron.clean_expired_pendings.should == 1 domain.reload.pending_delete?.should == false domain.pending_json.should == {} end it 'should expire domains' do - Domain.start_expire_period + DomainCron.start_expire_period @domain.statuses.include?(DomainStatus::EXPIRED).should == false old_valid_to = Time.zone.now - 10.days @domain.valid_to = old_valid_to @domain.save - Domain.start_expire_period + DomainCron.start_expire_period @domain.reload @domain.statuses.include?(DomainStatus::EXPIRED).should == true @domain.outzone_at.should be_within(5).of(old_valid_to + Setting.expire_warning_period.days) @@ -161,7 +161,7 @@ describe Domain do old_valid_to + Setting.expire_warning_period.days + Setting.redemption_grace_period.days ) - Domain.start_expire_period + DomainCron.start_expire_period @domain.reload @domain.statuses.include?(DomainStatus::EXPIRED).should == true end @@ -173,7 +173,7 @@ describe Domain do @domain.outzone_at, @domain.delete_at = nil, nil @domain.save - Domain.start_expire_period + DomainCron.start_expire_period @domain.reload @domain.statuses.include?(DomainStatus::EXPIRED).should == true @domain.outzone_at.should be_within(5).of(old_valid_to + Setting.expire_warning_period.days) @@ -183,7 +183,7 @@ describe Domain do end it 'should start redemption grace period' do - Domain.start_redemption_grace_period + DomainCron.start_redemption_grace_period @domain.reload @domain.statuses.include?(DomainStatus::SERVER_HOLD).should == false @@ -191,20 +191,20 @@ describe Domain do @domain.statuses << DomainStatus::SERVER_MANUAL_INZONE # this prohibits server_hold @domain.save - Domain.start_redemption_grace_period + DomainCron.start_redemption_grace_period @domain.reload @domain.statuses.include?(DomainStatus::SERVER_HOLD).should == false @domain.statuses = [] @domain.save - Domain.start_redemption_grace_period + DomainCron.start_redemption_grace_period @domain.reload @domain.statuses.include?(DomainStatus::SERVER_HOLD).should == true end it 'should start delete period' do - Domain.start_delete_period + DomainCron.start_delete_period @domain.reload @domain.statuses.include?(DomainStatus::DELETE_CANDIDATE).should == false @@ -212,13 +212,13 @@ describe Domain do @domain.statuses << DomainStatus::SERVER_DELETE_PROHIBITED # this prohibits delete_candidate @domain.save - Domain.start_delete_period + DomainCron.start_delete_period @domain.reload @domain.statuses.include?(DomainStatus::DELETE_CANDIDATE).should == false @domain.statuses = [] @domain.save - Domain.start_delete_period + DomainCron.start_delete_period @domain.reload @domain.statuses.include?(DomainStatus::DELETE_CANDIDATE).should == true @@ -234,7 +234,7 @@ describe Domain do Domain.count.should == 2 - Domain.start_delete_period + DomainCron.start_delete_period Domain.destroy_delete_candidates Domain.count.should == 0 @@ -391,7 +391,7 @@ describe Domain do end it 'should start redemption grace period' do - Domain.start_redemption_grace_period + DomainCron.start_redemption_grace_period @domain.reload @domain.statuses.include?(DomainStatus::SERVER_HOLD).should == false @@ -399,14 +399,14 @@ describe Domain do @domain.statuses << DomainStatus::SERVER_MANUAL_INZONE # this prohibits server_hold @domain.save - Domain.start_redemption_grace_period + DomainCron.start_redemption_grace_period @domain.reload @domain.statuses.include?(DomainStatus::SERVER_HOLD).should == false @domain.statuses = [] @domain.save - Domain.start_redemption_grace_period + DomainCron.start_redemption_grace_period @domain.reload @domain.statuses.include?(DomainStatus::SERVER_HOLD).should == true end From fe771af0aee0ad111abf11130024a892bfb6f72d Mon Sep 17 00:00:00 2001 From: Stas Date: Wed, 13 Jan 2016 18:32:35 +0200 Subject: [PATCH 33/70] 1098188884-outzone_clear --- app/models/domain.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/models/domain.rb b/app/models/domain.rb index 57e4367b0..0a223520a 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -704,6 +704,18 @@ class Domain < ActiveRecord::Base # special handling for admin changing status def admin_status_update(update) + #check for hold status + if self.statuses.include?( + DomainStatus::SERVER_HOLD) && + !update.include?(DomainStatus::SERVER_HOLD) + + if self.statuses.include?(DomainStatus::EXPIRED) + self.outzone_at = Time.zone.now + else + self.outzone_at = nil + end + end + # check for deleted status statuses.each do |s| unless update.include? s From 0b5fdcf3c2fe12d4f515494692d7ef20f1413541 Mon Sep 17 00:00:00 2001 From: Stas Date: Wed, 13 Jan 2016 19:08:10 +0200 Subject: [PATCH 34/70] 110395650-method_changes --- app/models/domain_cron.rb | 45 ++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/app/models/domain_cron.rb b/app/models/domain_cron.rb index 3fd09dc1f..9e2540c9c 100644 --- a/app/models/domain_cron.rb +++ b/app/models/domain_cron.rb @@ -15,10 +15,10 @@ class DomainCron end count += 1 if domain.pending_update? - domain.send_mail :pending_update_expired_notification_for_new_registrant + DomainMailer.pending_update_expired_notification_for_new_registrant(domain.id).deliver end if domain.pending_delete? || domain.pending_delete_confirmation? - DomainMailer.pending_delete_expired_notification(domain.id, true).deliver + DomainMailer.pending_delete_expired_notification(domain.id, deliver_emails).deliver end domain.clean_pendings! unless Rails.env.test? @@ -33,44 +33,55 @@ class DomainCron STDOUT << "#{Time.zone.now.utc} - Expiring domains\n" unless Rails.env.test? domains = Domain.where('valid_to <= ?', Time.zone.now) + marked = 0 + real = 0 domains.each do |domain| next unless domain.expirable? + real += 1 domain.set_graceful_expired - DomainMailer.expiration_reminder(domain.id).deliver STDOUT << "#{Time.zone.now.utc} Domain.start_expire_period: ##{domain.id} (#{domain.name}) #{domain.changes}\n" unless Rails.env.test? - domain.save + domain.save and marked += 1 end - STDOUT << "#{Time.zone.now.utc} - Successfully expired #{domains.count} domains\n" unless Rails.env.test? + STDOUT << "#{Time.zone.now.utc} - Successfully expired #{marked} of #{real} domains\n" unless Rails.env.test? end def self.start_redemption_grace_period STDOUT << "#{Time.zone.now.utc} - Setting server_hold to domains\n" unless Rails.env.test? d = Domain.where('outzone_at <= ?', Time.zone.now) + marked = 0 + real = 0 d.each do |domain| next unless domain.server_holdable? + real += 1 domain.statuses << DomainStatus::SERVER_HOLD STDOUT << "#{Time.zone.now.utc} Domain.start_redemption_grace_period: ##{domain.id} (#{domain.name}) #{domain.changes}\n" unless Rails.env.test? - domain.save + domain.save and marked += 1 end - STDOUT << "#{Time.zone.now.utc} - Successfully set server_hold to #{d.count} domains\n" unless Rails.env.test? + STDOUT << "#{Time.zone.now.utc} - Successfully set server_hold to #{marked} of #{real} domains\n" unless Rails.env.test? + marked end def self.start_delete_period - STDOUT << "#{Time.zone.now.utc} - Setting delete_candidate to domains\n" unless Rails.env.test? + begin + STDOUT << "#{Time.zone.now.utc} - Setting delete_candidate to domains\n" unless Rails.env.test? - d = Domain.where('delete_at <= ?', Time.zone.now) - d.each do |domain| - next unless domain.delete_candidateable? - domain.statuses << DomainStatus::DELETE_CANDIDATE - STDOUT << "#{Time.zone.now.utc} Domain.start_delete_period: ##{domain.id} (#{domain.name}) #{domain.changes}\n" unless Rails.env.test? - domain.save + d = Domain.where('delete_at <= ?', Time.zone.now) + marked = 0 + real = 0 + d.each do |domain| + next unless domain.delete_candidateable? + real += 1 + domain.statuses << DomainStatus::DELETE_CANDIDATE + STDOUT << "#{Time.zone.now.utc} Domain.start_delete_period: ##{domain.id} (#{domain.name}) #{domain.changes}\n" unless Rails.env.test? + domain.save and marked += 1 + end + ensure # the operator should see what was accomplished + STDOUT << "#{Time.zone.now.utc} - Finished setting delete_candidate - #{marked} out of #{real} successfully set\n" unless Rails.env.test? end - - return if Rails.env.test? - STDOUT << "#{Time.zone.now.utc} - Successfully set delete_candidate to #{d.count} domains\n" + marked end def self.destroy_delete_candidates From b111285334a7c41102fdb030e4f40c4c75e09f40 Mon Sep 17 00:00:00 2001 From: Stas Date: Mon, 18 Jan 2016 14:20:27 +0200 Subject: [PATCH 35/70] 111396946-templates_and_actions --- .../admin/reserved_domains_controller.rb | 38 ++++++++- app/views/admin/reserved_domains/_form.haml | 23 ++++++ app/views/admin/reserved_domains/index.haml | 82 ++++++++++++++++--- app/views/admin/reserved_domains/new.haml | 3 + 4 files changed, 132 insertions(+), 14 deletions(-) create mode 100644 app/views/admin/reserved_domains/_form.haml create mode 100644 app/views/admin/reserved_domains/new.haml diff --git a/app/controllers/admin/reserved_domains_controller.rb b/app/controllers/admin/reserved_domains_controller.rb index 402d33022..48677bea2 100644 --- a/app/controllers/admin/reserved_domains_controller.rb +++ b/app/controllers/admin/reserved_domains_controller.rb @@ -2,11 +2,43 @@ class Admin::ReservedDomainsController < AdminController load_and_authorize_resource def index - names = ReservedDomain.pluck(:name, :password).each_with_object({}){|domain, hash| hash[domain[0]] = domain[1]} - names.names = nil if names.blank? - @reserved_domains = names.to_yaml.gsub(/---.?\n/, '').gsub(/\.\.\..?\n/, '') + + params[:q] ||= {} + domains = ReservedDomain.all + @q = domains.search(params[:q]) + @domains = @q.result.page(params[:page]) + @domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i > 0 + end + def new + @domain = ReservedDomain.new + end + + def edit + authorize! :update, Depp::Domain + @data = @domain.info(params[:domain_name]) + @domain_params = Depp::Domain.construct_params_from_server_data(@data) + end + + def update + authorize! :update, Depp::Domain + @domain_params = params[:domain] + @data = @domain.update(@domain_params) + + if response_ok? + redirect_to info_registrar_domains_url(domain_name: @domain_params[:name]) + else + params[:domain_name] = @domain_params[:name] + render 'new' + end + end + + def delete + authorize! :delete, Depp::Domain + end + + def create @reserved_domains = params[:reserved_domains] diff --git a/app/views/admin/reserved_domains/_form.haml b/app/views/admin/reserved_domains/_form.haml new file mode 100644 index 000000000..bfbacbfd9 --- /dev/null +++ b/app/views/admin/reserved_domains/_form.haml @@ -0,0 +1,23 @@ += form_for([:admin, @domain], html: {class: 'form-horizontal'}) do |f| + = render 'shared/full_errors', object: @domain + + .row + .col-md-8 + .panel.panel-default + .panel-heading.clearfix + .pull-left= t(:general) + .panel-body + .form-group + .col-md-4.control-label + = f.label :name + .col-md-7 + = f.text_field(:name, class: 'form-control') + .form-group + .col-md-4.control-label + = f.label :password + .col-md-7 + = f.text_field(:password, class: 'form-control') +%hr + .row + .col-md-8.text-right + = button_tag(t(:save), class: 'btn btn-primary') diff --git a/app/views/admin/reserved_domains/index.haml b/app/views/admin/reserved_domains/index.haml index 15840ff93..808ad1480 100644 --- a/app/views/admin/reserved_domains/index.haml +++ b/app/views/admin/reserved_domains/index.haml @@ -1,14 +1,74 @@ - content_for :actions do - = link_to('#', class: 'btn btn-default', "data-container": "body", "data-title": t('list_format_is_in_yaml'), "data-content": "domain.ee: authinfopw
seconddomain.ee:
thirddomain.ee: authinfo3

#{t('if_auth_info_is_left_empty_it_will_be_auto_generated')}
#{t('each_domain_name_must_end_with_colon_sign')}", "data-placement": "left", "data-toggle": "popover", "data-html" => "true") do - %span.glyphicon.glyphicon-info-sign{"aria-hidden" => "true"} - + = link_to(t(:new), new_admin_reserved_domain_path, class: 'btn btn-primary') = render 'shared/title', name: t(:reserved_domains) -= form_tag([:admin, :reserved_domains]) do |f| - .row - .col-md-12 - = text_area_tag :reserved_domains, @reserved_domains, class: 'form-control', rows: 30 - %hr - .row - .col-md-12.text-right - %button.btn.btn-warning=t(:save) +.row + .col-md-12 + = search_form_for [:admin, @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(:created_at_from) + = f.search_field :created_at_gteq, value: params[:q][:created_at_gteq], class: 'form-control datepicker', placeholder: t(:created_at_from) + .col-md-3 + .form-group + = f.label t(:created_at_until) + = f.search_field :created_at_lteq, value: params[:q][:created_at_lteq], class: 'form-control datepicker', placeholder: t(:created_at_until) + .row + .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) +%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, 'password') + %th{class: 'col-xs-2'} + = sort_link(@q, 'created_at', t(:created_at)) + %th{class: 'col-xs-2'} + = sort_link(@q, 'updated_at', t(:updated_at)) + %th{class: 'col-xs-2'} + = t(:actions) + %tbody + - @domains.each do |x| + %tr + %td= x.name + %td= x.password + %td= l(x.created_at, format: :short) + %td= l(x.updated_at, format: :short) + %td + = link_to(t(:edit), edit_admin_reserved_domains_path(name: x.name), + class: 'btn btn-primary btn-xs') + = link_to(t(:renew), renew_admin_reserved_domains_path(name: x.name), + class: 'btn btn-default btn-xs') + = link_to(t(:delete), delete_admin_reserved_domains_path(name: x.name), + class: 'btn btn-default btn-xs') +.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 = "#{admin_reserved_domains_path}" diff --git a/app/views/admin/reserved_domains/new.haml b/app/views/admin/reserved_domains/new.haml new file mode 100644 index 000000000..937fdebde --- /dev/null +++ b/app/views/admin/reserved_domains/new.haml @@ -0,0 +1,3 @@ += render 'shared/title', name: t(:new_reserved_domain) + += render 'form' From 793bc359ea013d2a1f650bc8af54f12100288704 Mon Sep 17 00:00:00 2001 From: Stas Date: Wed, 20 Jan 2016 15:44:55 +0200 Subject: [PATCH 36/70] 111396946-methods --- .../admin/reserved_domains_controller.rb | 60 +------------------ app/views/admin/reserved_domains/index.haml | 8 +-- 2 files changed, 5 insertions(+), 63 deletions(-) diff --git a/app/controllers/admin/reserved_domains_controller.rb b/app/controllers/admin/reserved_domains_controller.rb index 48677bea2..4cb7ba51f 100644 --- a/app/controllers/admin/reserved_domains_controller.rb +++ b/app/controllers/admin/reserved_domains_controller.rb @@ -16,66 +16,10 @@ class Admin::ReservedDomainsController < AdminController end def edit - authorize! :update, Depp::Domain - @data = @domain.info(params[:domain_name]) - @domain_params = Depp::Domain.construct_params_from_server_data(@data) - end - - def update - authorize! :update, Depp::Domain - @domain_params = params[:domain] - @data = @domain.update(@domain_params) - - if response_ok? - redirect_to info_registrar_domains_url(domain_name: @domain_params[:name]) - else - params[:domain_name] = @domain_params[:name] - render 'new' - end + authorize! :update, ReservedDomain end def delete - authorize! :delete, Depp::Domain - end - - - def create - @reserved_domains = params[:reserved_domains] - - begin - params[:reserved_domains] = "---\n" if params[:reserved_domains].blank? - names = YAML.load(params[:reserved_domains]) - fail if names == false - rescue - flash.now[:alert] = I18n.t('invalid_yaml') - logger.warn 'Invalid YAML' - render :index and return - end - - result = true - ReservedDomain.transaction do - # removing old ones - existing = ReservedDomain.any_of_domains(names.keys).pluck(:id) - ReservedDomain.where.not(id: existing).destroy_all - - #updating and adding - names.each do |name, psw| - rec = ReservedDomain.find_or_initialize_by(name: name) - rec.password = psw - - unless rec.save - result = false - raise ActiveRecord::Rollback - end - end - end - - if result - flash[:notice] = I18n.t('record_updated') - redirect_to :back - else - flash.now[:alert] = I18n.t('failed_to_update_record') - render :index - end + authorize! :delete, ReservedDomain end end diff --git a/app/views/admin/reserved_domains/index.haml b/app/views/admin/reserved_domains/index.haml index 808ad1480..6ac65d14b 100644 --- a/app/views/admin/reserved_domains/index.haml +++ b/app/views/admin/reserved_domains/index.haml @@ -55,12 +55,10 @@ %td= l(x.created_at, format: :short) %td= l(x.updated_at, format: :short) %td - = link_to(t(:edit), edit_admin_reserved_domains_path(name: x.name), + = link_to(t(:edit), edit_admin_reserved_domain_path(id: x.id), + class: 'btn btn-primary btn-xs') + = link_to(t(:delete), delete_admin_reserved_domain_path(id: x.id), class: 'btn btn-primary btn-xs') - = link_to(t(:renew), renew_admin_reserved_domains_path(name: x.name), - class: 'btn btn-default btn-xs') - = link_to(t(:delete), delete_admin_reserved_domains_path(name: x.name), - class: 'btn btn-default btn-xs') .row .col-md-6 = paginate @domains From 9bc34ed9ef4da159ae0bd9e499810f67385f03a5 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Mon, 25 Jan 2016 14:37:43 +0200 Subject: [PATCH 37/70] Story#105846070 - save error to json obj --- app/controllers/registrant/domains_controller.rb | 3 ++- app/models/soap/arireg.rb | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/registrant/domains_controller.rb b/app/controllers/registrant/domains_controller.rb index 445cc5d42..c2c406de7 100644 --- a/app/controllers/registrant/domains_controller.rb +++ b/app/controllers/registrant/domains_controller.rb @@ -44,7 +44,8 @@ class Registrant::DomainsController < RegistrantController begin BusinessRegistryCache.fetch_associated_domains ident, ident_cc rescue Soap::Arireg::NotAvailableError => error - flash[:notice] = I18n.t(error.message[:message]) + flash[:notice] = I18n.t(error.json[:message]) + Rails.error.fatal("[EXCEPTION] #{error.to_s}") current_user.domains end end diff --git a/app/models/soap/arireg.rb b/app/models/soap/arireg.rb index 35517c3ef..5c8db3475 100644 --- a/app/models/soap/arireg.rb +++ b/app/models/soap/arireg.rb @@ -46,8 +46,11 @@ module Soap class Arireg class NotAvailableError < StandardError + attr_accessor :json def initialize(params) params[:message] = "#{I18n.t(:business_registry_service_not_available)}" unless params.key? :message + @json = params + super(params) end end From a6fdb5289a939ed24c89bac150e0cdd8ba1e985e Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Mon, 25 Jan 2016 14:55:39 +0200 Subject: [PATCH 38/70] Story#105846070 - save error to json obj --- app/controllers/registrant/domains_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/registrant/domains_controller.rb b/app/controllers/registrant/domains_controller.rb index c2c406de7..cc6f8742d 100644 --- a/app/controllers/registrant/domains_controller.rb +++ b/app/controllers/registrant/domains_controller.rb @@ -45,7 +45,7 @@ class Registrant::DomainsController < RegistrantController BusinessRegistryCache.fetch_associated_domains ident, ident_cc rescue Soap::Arireg::NotAvailableError => error flash[:notice] = I18n.t(error.json[:message]) - Rails.error.fatal("[EXCEPTION] #{error.to_s}") + Rails.logger.error.fatal("[EXCEPTION] #{error.to_s}") current_user.domains end end From 9b64989038da6a1a4ff9afdd155195e5bf4ae6f1 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Mon, 25 Jan 2016 14:57:23 +0200 Subject: [PATCH 39/70] Story#105846070 - save error to json obj --- app/controllers/registrant/domains_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/registrant/domains_controller.rb b/app/controllers/registrant/domains_controller.rb index cc6f8742d..bf7ce37bb 100644 --- a/app/controllers/registrant/domains_controller.rb +++ b/app/controllers/registrant/domains_controller.rb @@ -45,7 +45,7 @@ class Registrant::DomainsController < RegistrantController BusinessRegistryCache.fetch_associated_domains ident, ident_cc rescue Soap::Arireg::NotAvailableError => error flash[:notice] = I18n.t(error.json[:message]) - Rails.logger.error.fatal("[EXCEPTION] #{error.to_s}") + Rails.logger.fatal("[EXCEPTION] #{error.to_s}") current_user.domains end end From 79b435cef250983447d4885278817343c91c7dae Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Mon, 25 Jan 2016 15:09:33 +0200 Subject: [PATCH 40/70] Story#105846070 - load domains by registrant_ident --- app/models/registrant_user.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/models/registrant_user.rb b/app/models/registrant_user.rb index f0222b2a6..413ff1202 100644 --- a/app/models/registrant_user.rb +++ b/app/models/registrant_user.rb @@ -12,8 +12,7 @@ class RegistrantUser < User end def domains - # TODO: move data to normal columns and drop registrant_ident - ident_cc, ident = @current_user.registrant_ident.split '-' + ident_cc, ident = registrant_ident.to_s.split '-' Domain.includes(:registrar, :registrant).where(contacts: { ident_type: 'priv', ident: ident, #identity_code, From 216c4e9fa0fff907b57bca9c95eba017828877f6 Mon Sep 17 00:00:00 2001 From: Stas Date: Mon, 25 Jan 2016 17:53:38 +0200 Subject: [PATCH 41/70] 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 42/70] 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 43/70] 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 From 0b3079b8b5fed07630228429e38a3a0175ca5f80 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Mon, 25 Jan 2016 18:22:34 +0200 Subject: [PATCH 44/70] Story#105846070 - Admin can edit setting days_to_keep_business_registry_cache --- app/views/admin/settings/index.haml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/admin/settings/index.haml b/app/views/admin/settings/index.haml index ede30e979..855c29d23 100644 --- a/app/views/admin/settings/index.haml +++ b/app/views/admin/settings/index.haml @@ -50,6 +50,7 @@ = render 'setting_row', var: :transfer_wait_time = render 'setting_row', var: :ds_digest_type = render 'setting_row', var: :client_side_status_editing_enabled + = render 'setting_row', var: :days_to_keep_business_registry_cache = render 'setting_row', var: :api_ip_whitelist_enabled = render 'setting_row', var: :registrar_ip_whitelist_enabled = render 'setting_row', var: :request_confrimation_on_registrant_change_enabled From a4adb0fec0dd95d35b2442f2dd5d2e27d361d647 Mon Sep 17 00:00:00 2001 From: Stas Date: Tue, 26 Jan 2016 16:28:29 +0200 Subject: [PATCH 45/70] 109818884-outzone_date_change --- app/models/domain.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/domain.rb b/app/models/domain.rb index 0a223520a..42a65bcde 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -710,7 +710,8 @@ class Domain < ActiveRecord::Base !update.include?(DomainStatus::SERVER_HOLD) if self.statuses.include?(DomainStatus::EXPIRED) - self.outzone_at = Time.zone.now + #self.outzone_at = Time.zone.now + 1.day + self.outzone_at = self.valid_to else self.outzone_at = nil end From 1aa9123aa284348c19ce9550e07cc7016781e309 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Thu, 28 Jan 2016 14:13:06 +0200 Subject: [PATCH 46/70] Story#105846070 - add Ariregister's info messages --- app/models/soap/arireg.rb | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/app/models/soap/arireg.rb b/app/models/soap/arireg.rb index cd8e446b4..e040c24ad 100644 --- a/app/models/soap/arireg.rb +++ b/app/models/soap/arireg.rb @@ -90,11 +90,16 @@ module Soap # retrieve business id codes for business that a person has a legal role def associated_businesses(ident, ident_cc = 'EST') begin - response = @client.call :paringesindus_v4, message: body( - 'fyysilise_isiku_kood' => ident, - 'fyysilise_isiku_koodi_riik' => country_code_3(ident_cc) - ) + msg = body( + 'fyysilise_isiku_kood' => ident, + 'fyysilise_isiku_koodi_riik' => country_code_3(ident_cc) + ) + Rails.logger.info "[Ariregister] Request sent with data: #{msg.inspect}" + + response = @client.call :paringesindus_v4, message: msg content = extract response, :paringesindus_v4_response + Rails.logger.info "[Ariregister] Got response with data: #{content.inspect}" + if content.present? && content[:ettevotjad].key?(:item) business_ident = items(content, :ettevotjad).map{|item| item[:ariregistri_kood]} else @@ -109,13 +114,13 @@ module Soap associated_businesses: business_ident } rescue Savon::SOAPFault => fault - Rails.logger.error "#{fault} Äriregister arireg #{self.class.username} at #{self.class.host }" + Rails.logger.error "[Ariregister] #{fault} Äriregister arireg #{self.class.username} at #{self.class.host }" raise NotAvailableError.new(exception: fault) rescue HTTPI::SSLError => ssl_error - Rails.logger.error "#{ssl_error} at #{self.class.host}" + Rails.logger.error "[Ariregister] #{ssl_error} at #{self.class.host}" raise NotAvailableError.new(exception: ssl_error) rescue SocketError => sock - Rails.logger.error "#{sock}" + Rails.logger.error "[Ariregister] #{sock}" raise NotAvailableError.new(exception: sock) end end From 72478dbb437523a689fe6f26a3c06266d568d4d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Thu, 28 Jan 2016 15:05:53 +0200 Subject: [PATCH 47/70] Restored bank transaction sum check for Directo integration --- app/models/directo.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/directo.rb b/app/models/directo.rb index 5a719d0a7..11506331e 100644 --- a/app/models/directo.rb +++ b/app/models/directo.rb @@ -9,7 +9,7 @@ class Directo < ActiveRecord::Base xml.invoices { group.each do |invoice| next if invoice.account_activity.nil? || invoice.account_activity.bank_transaction.nil? - # next if invoice.account_activity.bank_transaction.sum.nil? || invoice.account_activity.bank_transaction.sum != invoice.sum_cache + next if invoice.account_activity.bank_transaction.sum.nil? || invoice.account_activity.bank_transaction.sum != invoice.sum_cache num = invoice.number mappers[num] = invoice From 4c8da0bb7ad1642d36afe1035ace94955c283f57 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Thu, 28 Jan 2016 16:16:38 +0200 Subject: [PATCH 48/70] Story#105846070 - remove password from Ariregister log --- app/models/soap/arireg.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/soap/arireg.rb b/app/models/soap/arireg.rb index e040c24ad..422a72dd9 100644 --- a/app/models/soap/arireg.rb +++ b/app/models/soap/arireg.rb @@ -90,13 +90,13 @@ module Soap # retrieve business id codes for business that a person has a legal role def associated_businesses(ident, ident_cc = 'EST') begin - msg = body( - 'fyysilise_isiku_kood' => ident, + msg = { + 'fyysilise_isiku_kood' => ident, 'fyysilise_isiku_koodi_riik' => country_code_3(ident_cc) - ) + } Rails.logger.info "[Ariregister] Request sent with data: #{msg.inspect}" - response = @client.call :paringesindus_v4, message: msg + response = @client.call :paringesindus_v4, message: body(msg) content = extract response, :paringesindus_v4_response Rails.logger.info "[Ariregister] Got response with data: #{content.inspect}" From d70c4b5d12a6d6d9ea1a55ef95f4e236be881d01 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Mon, 1 Feb 2016 12:03:47 +0200 Subject: [PATCH 49/70] Story#110395650 - destroy_with_message is also extracted to class as it's used only for cron job --- app/models/domain.rb | 13 ------------- app/models/domain_cron.rb | 21 +++++++++++++++++---- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/app/models/domain.rb b/app/models/domain.rb index da56741ae..513a40718 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -245,19 +245,6 @@ class Domain < ActiveRecord::Base { admin_contacts: :registrar } ) end - - # rubocop: enable Metrics/AbcSize - # rubocop:enable Rails/FindEach - # rubocop: enable Metrics/LineLength - def destroy_with_message(domain) - domain.destroy - bye_bye = domain.versions.last - domain.registrar.messages.create!( - body: "#{I18n.t(:domain_deleted)}: #{domain.name}", - attached_obj_id: bye_bye.id, - attached_obj_type: bye_bye.class.to_s # DomainVersion - ) - end end def name=(value) diff --git a/app/models/domain_cron.rb b/app/models/domain_cron.rb index 9e2540c9c..65e50a59c 100644 --- a/app/models/domain_cron.rb +++ b/app/models/domain_cron.rb @@ -20,7 +20,7 @@ class DomainCron if domain.pending_delete? || domain.pending_delete_confirmation? DomainMailer.pending_delete_expired_notification(domain.id, deliver_emails).deliver end - domain.clean_pendings! + domain.clean_pendings_lowlevel unless Rails.env.test? STDOUT << "#{Time.zone.now.utc} Domain.clean_expired_pendings: ##{domain.id} (#{domain.name})\n" end @@ -40,7 +40,7 @@ class DomainCron real += 1 domain.set_graceful_expired STDOUT << "#{Time.zone.now.utc} Domain.start_expire_period: ##{domain.id} (#{domain.name}) #{domain.changes}\n" unless Rails.env.test? - domain.save and marked += 1 + domain.save(validate: false) and marked += 1 end STDOUT << "#{Time.zone.now.utc} - Successfully expired #{marked} of #{real} domains\n" unless Rails.env.test? @@ -57,7 +57,7 @@ class DomainCron real += 1 domain.statuses << DomainStatus::SERVER_HOLD STDOUT << "#{Time.zone.now.utc} Domain.start_redemption_grace_period: ##{domain.id} (#{domain.name}) #{domain.changes}\n" unless Rails.env.test? - domain.save and marked += 1 + domain.save(validate: false) and marked += 1 end STDOUT << "#{Time.zone.now.utc} - Successfully set server_hold to #{marked} of #{real} domains\n" unless Rails.env.test? @@ -76,7 +76,7 @@ class DomainCron real += 1 domain.statuses << DomainStatus::DELETE_CANDIDATE STDOUT << "#{Time.zone.now.utc} Domain.start_delete_period: ##{domain.id} (#{domain.name}) #{domain.changes}\n" unless Rails.env.test? - domain.save and marked += 1 + domain.save(validate: false) and marked += 1 end ensure # the operator should see what was accomplished STDOUT << "#{Time.zone.now.utc} - Finished setting delete_candidate - #{marked} out of #{real} successfully set\n" unless Rails.env.test? @@ -106,4 +106,17 @@ class DomainCron STDOUT << "#{Time.zone.now.utc} - Successfully destroyed #{c} domains\n" unless Rails.env.test? end + # rubocop: enable Metrics/AbcSize + # rubocop:enable Rails/FindEach + # rubocop: enable Metrics/LineLength + def self.destroy_with_message(domain) + domain.destroy + bye_bye = domain.versions.last + domain.registrar.messages.create!( + body: "#{I18n.t(:domain_deleted)}: #{domain.name}", + attached_obj_id: bye_bye.id, + attached_obj_type: bye_bye.class.to_s # DomainVersion + ) + end + end From c38986adc3ab5d8e55b951f3ba78d3ece8c178ba Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Tue, 2 Feb 2016 12:00:14 +0200 Subject: [PATCH 50/70] Story#110395650 - messages are updated --- app/models/domain_cron.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/domain_cron.rb b/app/models/domain_cron.rb index 65e50a59c..74c09740e 100644 --- a/app/models/domain_cron.rb +++ b/app/models/domain_cron.rb @@ -22,7 +22,7 @@ class DomainCron end domain.clean_pendings_lowlevel unless Rails.env.test? - STDOUT << "#{Time.zone.now.utc} Domain.clean_expired_pendings: ##{domain.id} (#{domain.name})\n" + STDOUT << "#{Time.zone.now.utc} DomainCron.clean_expired_pendings: ##{domain.id} (#{domain.name})\n" end end STDOUT << "#{Time.zone.now.utc} - Successfully cancelled #{count} domain pendings\n" unless Rails.env.test? @@ -39,7 +39,7 @@ class DomainCron next unless domain.expirable? real += 1 domain.set_graceful_expired - STDOUT << "#{Time.zone.now.utc} Domain.start_expire_period: ##{domain.id} (#{domain.name}) #{domain.changes}\n" unless Rails.env.test? + STDOUT << "#{Time.zone.now.utc} DomainCron.start_expire_period: ##{domain.id} (#{domain.name}) #{domain.changes}\n" unless Rails.env.test? domain.save(validate: false) and marked += 1 end @@ -56,7 +56,7 @@ class DomainCron next unless domain.server_holdable? real += 1 domain.statuses << DomainStatus::SERVER_HOLD - STDOUT << "#{Time.zone.now.utc} Domain.start_redemption_grace_period: ##{domain.id} (#{domain.name}) #{domain.changes}\n" unless Rails.env.test? + STDOUT << "#{Time.zone.now.utc} DomainCron.start_redemption_grace_period: ##{domain.id} (#{domain.name}) #{domain.changes}\n" unless Rails.env.test? domain.save(validate: false) and marked += 1 end @@ -75,7 +75,7 @@ class DomainCron next unless domain.delete_candidateable? real += 1 domain.statuses << DomainStatus::DELETE_CANDIDATE - STDOUT << "#{Time.zone.now.utc} Domain.start_delete_period: ##{domain.id} (#{domain.name}) #{domain.changes}\n" unless Rails.env.test? + STDOUT << "#{Time.zone.now.utc} DomainCron.start_delete_period: ##{domain.id} (#{domain.name}) #{domain.changes}\n" unless Rails.env.test? domain.save(validate: false) and marked += 1 end ensure # the operator should see what was accomplished @@ -99,7 +99,7 @@ class DomainCron Domain.where('force_delete_at <= ?', Time.zone.now).each do |x| WhoisRecord.where(domain_id: x.id).destroy_all destroy_with_message x - STDOUT << "#{Time.zone.now.utc} Domain.destroy_delete_candidates: by force delete time ##{x.id} (#{x.name})\n" unless Rails.env.test? + STDOUT << "#{Time.zone.now.utc} DomainCron.destroy_delete_candidates: by force delete time ##{x.id} (#{x.name})\n" unless Rails.env.test? c += 1 end From 996e56c5cdf8ce7d64dd02c3e9cec641eb52cfc7 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Tue, 2 Feb 2016 12:41:34 +0200 Subject: [PATCH 51/70] Story#110395650 - calling instance, not class methods --- app/models/domain.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/domain.rb b/app/models/domain.rb index 513a40718..87f10bea5 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -204,28 +204,28 @@ class Domain < ActiveRecord::Base end def self.clean_expired_pendings + ActiveSupport::Deprecation.instance.deprecation_warning(DomainCron, __method__) DomainCron.send(__method__) - ActiveSupport::Deprecation.deprecate_methods(DomainCron, __method__) end def self.start_expire_period + ActiveSupport::Deprecation.instance.deprecation_warning(DomainCron, __method__) DomainCron.send(__method__) - ActiveSupport::Deprecation.deprecate_methods(DomainCron, __method__) end def self.start_redemption_grace_period + ActiveSupport::Deprecation.instance.deprecation_warning(DomainCron, __method__) DomainCron.send(__method__) - ActiveSupport::Deprecation.deprecate_methods(DomainCron, __method__) end def self.start_delete_period + ActiveSupport::Deprecation.instance.deprecation_warning(DomainCron, __method__) DomainCron.send(__method__) - ActiveSupport::Deprecation.deprecate_methods(DomainCron, __method__) end def self.destroy_delete_candidates + ActiveSupport::Deprecation.instance.deprecation_warning(DomainCron, __method__) DomainCron.send(__method__) - ActiveSupport::Deprecation.deprecate_methods(DomainCron, __method__) end class << self From 6a63feb5dd922c0d0a34da0604c34bda29d522e7 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Tue, 2 Feb 2016 13:37:08 +0200 Subject: [PATCH 52/70] Story#112043941 - adding more logs to find out when invoices are not sent --- app/models/directo.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/models/directo.rb b/app/models/directo.rb index 11506331e..591f450c0 100644 --- a/app/models/directo.rb +++ b/app/models/directo.rb @@ -3,13 +3,19 @@ class Directo < ActiveRecord::Base def self.send_receipts new_trans = Invoice.where(invoice_type: "DEB", in_directo: false).where.not(cancelled_at: nil) + Rails.logger.info("[DIRECTO] Will try to send #{new_trans.count} invoices") + new_trans.find_in_batches(batch_size: 10).each do |group| mappers = {} # need them as no direct connection between invoice builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml| xml.invoices { group.each do |invoice| - next if invoice.account_activity.nil? || invoice.account_activity.bank_transaction.nil? - next if invoice.account_activity.bank_transaction.sum.nil? || invoice.account_activity.bank_transaction.sum != invoice.sum_cache + + if invoice.account_activity.nil? || invoice.account_activity.bank_transaction.nil? || + invoice.account_activity.bank_transaction.sum.nil? || invoice.account_activity.bank_transaction.sum != invoice.sum_cache + Rails.logger.info("[DIRECTO] Invoice #{invoice.number} has been skipped") + next + end num = invoice.number mappers[num] = invoice From c24e27710346bf5fda66ebd6053334926c4537e4 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Tue, 2 Feb 2016 13:43:05 +0200 Subject: [PATCH 53/70] Story#110395650 - deprecation logs are shown in staging and production now as well --- config/environments/production.rb | 2 +- config/environments/staging.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index 58258e710..e47420a27 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -70,7 +70,7 @@ Rails.application.configure do config.i18n.fallbacks = true # Send deprecation notices to registered listeners. - config.active_support.deprecation = :notify + config.active_support.deprecation = :log # Disable automatic flushing of the log to improve performance. # config.autoflush_log = false diff --git a/config/environments/staging.rb b/config/environments/staging.rb index 0a5e3ecae..7ffc82641 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -70,7 +70,7 @@ Rails.application.configure do config.i18n.fallbacks = true # Send deprecation notices to registered listeners. - config.active_support.deprecation = :notify + config.active_support.deprecation = :log # Disable automatic flushing of the log to improve performance. # config.autoflush_log = false From 2ab5d8500a75b755de77037cd0c3fa574df168de Mon Sep 17 00:00:00 2001 From: Stas Date: Wed, 3 Feb 2016 15:55:39 +0200 Subject: [PATCH 54/70] 111396946-views_methods --- .../admin/blocked_domains_controller.rb | 46 +++++++++--- .../admin/reserved_domains_controller.rb | 47 +++++++++++- app/models/reserved_domain.rb | 7 +- app/views/admin/blocked_domains/_form.haml | 17 +++++ app/views/admin/blocked_domains/edit.haml | 3 + app/views/admin/blocked_domains/index.haml | 73 +++++++++++++++++-- app/views/admin/blocked_domains/new.haml | 3 + app/views/admin/reserved_domains/_form.haml | 3 +- app/views/admin/reserved_domains/edit.haml | 3 + app/views/admin/reserved_domains/index.haml | 4 +- app/views/admin/reserved_domains/new.haml | 2 +- config/locales/en.yml | 3 + config/routes.rb | 12 ++- 13 files changed, 194 insertions(+), 29 deletions(-) create mode 100644 app/views/admin/blocked_domains/_form.haml create mode 100644 app/views/admin/blocked_domains/edit.haml create mode 100644 app/views/admin/blocked_domains/new.haml create mode 100644 app/views/admin/reserved_domains/edit.haml diff --git a/app/controllers/admin/blocked_domains_controller.rb b/app/controllers/admin/blocked_domains_controller.rb index 2df3f90d9..c30b2dfb8 100644 --- a/app/controllers/admin/blocked_domains_controller.rb +++ b/app/controllers/admin/blocked_domains_controller.rb @@ -2,22 +2,46 @@ class Admin::BlockedDomainsController < AdminController load_and_authorize_resource def index - bd = BlockedDomain.first_or_initialize - @blocked_domains = bd.names.join("\n") + + params[:q] ||= {} + domains = BlockedDomain.all + @q = domains.search(params[:q]) + @domains = @q.result.page(params[:page]) + @domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i > 0 + + end + + def new + + @domain = BlockedDomain.new + end def create - names = params[:blocked_domains].split("\r\n").map(&:strip) - bd = BlockedDomain.first_or_create + abort - if bd.update(names: names) - flash[:notice] = I18n.t('record_updated') - redirect_to :back + end + + def delete + + if BlockedDomain.find(params[:id]).destroy + flash[:notice] = I18n.t('domain_deleted') + redirect_to admin_blocked_domains_path else - @blocked_domains = params[:blocked_domains] - flash.now[:alert] = I18n.t('failed_to_update_record') - render :index + flash.now[:alert] = I18n.t('failed_to_delete_domain') + redirect_to admin_blocked_domains_path end end -end + + + def blocked_params + params.require(:blocked_domain).permit(:name) + end + + private + + def set_domain + @domain = BlockedDomain.find(params[:id]) + end +end \ No newline at end of file diff --git a/app/controllers/admin/reserved_domains_controller.rb b/app/controllers/admin/reserved_domains_controller.rb index 4cb7ba51f..b0af2fb9f 100644 --- a/app/controllers/admin/reserved_domains_controller.rb +++ b/app/controllers/admin/reserved_domains_controller.rb @@ -1,5 +1,6 @@ class Admin::ReservedDomainsController < AdminController load_and_authorize_resource + before_action :set_domain, only: [:edit, :update] def index @@ -16,10 +17,52 @@ class Admin::ReservedDomainsController < AdminController end def edit - authorize! :update, ReservedDomain + end + + def create + + @domain = ReservedDomain.new(reserved_params) + + if @domain.save + flash[:notice] = I18n.t('domain_added') + redirect_to admin_reserved_domains_path + else + flash.now[:alert] = I18n.t('failed_to_add_domain') + render 'new' + end + + end + + def update + + if @domain.update(reserved_params) + flash[:notice] = I18n.t('domain_updated') + else + flash.now[:alert] = I18n.t('failed_to_update_domain') + end + render 'edit' + end def delete - authorize! :delete, ReservedDomain + + if ReservedDomain.find(params[:id]).destroy + flash[:notice] = I18n.t('domain_deleted') + redirect_to admin_reserved_domains_path + else + flash.now[:alert] = I18n.t('failed_to_delete_domain') + redirect_to admin_reserved_domains_path + end + + end + + private + + def reserved_params + params.require(:reserved_domain).permit(:name, :password) + end + + def set_domain + @domain = ReservedDomain.find(params[:id]) end end diff --git a/app/models/reserved_domain.rb b/app/models/reserved_domain.rb index 141fd7263..e141ab7ee 100644 --- a/app/models/reserved_domain.rb +++ b/app/models/reserved_domain.rb @@ -22,7 +22,12 @@ class ReservedDomain < ActiveRecord::Base def fill_empty_passwords - self.password = SecureRandom.hex unless self.password + + if self.password.empty? + + self.password = SecureRandom.hex + + end end def name= val diff --git a/app/views/admin/blocked_domains/_form.haml b/app/views/admin/blocked_domains/_form.haml new file mode 100644 index 000000000..996d52843 --- /dev/null +++ b/app/views/admin/blocked_domains/_form.haml @@ -0,0 +1,17 @@ += form_for([:admin, @domain], html: {class: 'form-horizontal'}) do |f| + = render 'shared/full_errors', object: @domain + + .row + .col-md-8 + .panel.panel-default + .panel-heading.clearfix + .pull-left= t(:general) + .panel-body + .form-group + .col-md-4.control-label + = f.label :name + .col-md-7 + = f.text_field(:name, class: 'form-control') + .row + .col-md-8.text-right + = button_tag(t(:save), class: 'btn btn-primary') diff --git a/app/views/admin/blocked_domains/edit.haml b/app/views/admin/blocked_domains/edit.haml new file mode 100644 index 000000000..51d77f0cc --- /dev/null +++ b/app/views/admin/blocked_domains/edit.haml @@ -0,0 +1,3 @@ += render 'shared/title', name: t(:edit_pw) + += render 'form' diff --git a/app/views/admin/blocked_domains/index.haml b/app/views/admin/blocked_domains/index.haml index bd5660193..5accae030 100644 --- a/app/views/admin/blocked_domains/index.haml +++ b/app/views/admin/blocked_domains/index.haml @@ -1,10 +1,67 @@ +- content_for :actions do + = link_to(t(:new), new_admin_blocked_domain_path, class: 'btn btn-primary') = render 'shared/title', name: t(:blocked_domains) -= form_tag([:admin, :blocked_domains]) do |f| - .row - .col-md-12 - = text_area_tag :blocked_domains, @blocked_domains, class: 'form-control', rows: 30 - %hr - .row - .col-md-12.text-right - %button.btn.btn-warning=t(:save) +.row + .col-md-12 + = search_form_for [:admin, @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(:created_at_from) + = f.search_field :created_at_gteq, value: params[:q][:created_at_gteq], class: 'form-control datepicker', placeholder: t(:created_at_from) + .col-md-3 + .form-group + = f.label t(:created_at_until) + = f.search_field :created_at_lteq, value: params[:q][:created_at_lteq], class: 'form-control datepicker', placeholder: t(:created_at_until) + .row + .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) +%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, 'created_at', t(:created_at)) + %th{class: 'col-xs-2'} + = sort_link(@q, 'updated_at', t(:updated_at)) + %th{class: 'col-xs-2'} + = t(:actions) + %tbody + - @domains.each do |x| + %tr + %td= x.name + %td= l(x.created_at, format: :short) + %td= l(x.updated_at, format: :short) + %td + = link_to(t(:delete), delete_admin_blocked_domain_path(id: x.id), + data: { confirm: t(:are_you_sure) }, class: 'btn btn-danger btn-xs') +.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 = "#{admin_blocked_domains_path}" diff --git a/app/views/admin/blocked_domains/new.haml b/app/views/admin/blocked_domains/new.haml new file mode 100644 index 000000000..4461eea40 --- /dev/null +++ b/app/views/admin/blocked_domains/new.haml @@ -0,0 +1,3 @@ += render 'shared/title', name: t(:add_blocked_domain) + += render 'form' diff --git a/app/views/admin/reserved_domains/_form.haml b/app/views/admin/reserved_domains/_form.haml index bfbacbfd9..2ba2431e9 100644 --- a/app/views/admin/reserved_domains/_form.haml +++ b/app/views/admin/reserved_domains/_form.haml @@ -11,13 +11,12 @@ .col-md-4.control-label = f.label :name .col-md-7 - = f.text_field(:name, class: 'form-control') + = f.text_field(:name, class: 'form-control', disabled: !f.object.new_record?) .form-group .col-md-4.control-label = f.label :password .col-md-7 = f.text_field(:password, class: 'form-control') -%hr .row .col-md-8.text-right = button_tag(t(:save), class: 'btn btn-primary') diff --git a/app/views/admin/reserved_domains/edit.haml b/app/views/admin/reserved_domains/edit.haml new file mode 100644 index 000000000..51d77f0cc --- /dev/null +++ b/app/views/admin/reserved_domains/edit.haml @@ -0,0 +1,3 @@ += render 'shared/title', name: t(:edit_pw) + += render 'form' diff --git a/app/views/admin/reserved_domains/index.haml b/app/views/admin/reserved_domains/index.haml index 6ac65d14b..06825b624 100644 --- a/app/views/admin/reserved_domains/index.haml +++ b/app/views/admin/reserved_domains/index.haml @@ -55,10 +55,10 @@ %td= l(x.created_at, format: :short) %td= l(x.updated_at, format: :short) %td - = link_to(t(:edit), edit_admin_reserved_domain_path(id: x.id), + = link_to(t(:edit_pw), edit_admin_reserved_domain_path(id: x.id), class: 'btn btn-primary btn-xs') = link_to(t(:delete), delete_admin_reserved_domain_path(id: x.id), - class: 'btn btn-primary btn-xs') + data: { confirm: t(:are_you_sure) }, class: 'btn btn-danger btn-xs') .row .col-md-6 = paginate @domains diff --git a/app/views/admin/reserved_domains/new.haml b/app/views/admin/reserved_domains/new.haml index 937fdebde..cd6e189f9 100644 --- a/app/views/admin/reserved_domains/new.haml +++ b/app/views/admin/reserved_domains/new.haml @@ -1,3 +1,3 @@ -= render 'shared/title', name: t(:new_reserved_domain) += render 'shared/title', name: t(:add_reserved_domain) = render 'form' diff --git a/config/locales/en.yml b/config/locales/en.yml index 2cc8b1387..bad2571e2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -930,3 +930,6 @@ en: if_auth_info_is_left_empty_it_will_be_auto_generated: 'If auth info is left empty, it will be auto generated.' each_domain_name_must_end_with_colon_sign: 'Each domain name must end with colon (:) sign.' expiration_remind_subject: 'The %{name} domain has expired' + add_reserved_domain: 'Add domain to reserved list' + add_blocked_domain: 'Add domain to blocked list' + edit_pw: 'Edit Pw' \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 9dd7faf7d..86bdccaa9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -204,8 +204,16 @@ Rails.application.routes.draw do resources :settings - resources :blocked_domains - resources :reserved_domains + resources :blocked_domains do + member do + get 'delete' + end + end + resources :reserved_domains do + member do + get 'delete' + end + end resources :registrars do resources :api_users From f31db65d2cd6562a671d7abe275d530a81e53b36 Mon Sep 17 00:00:00 2001 From: Stas Date: Wed, 3 Feb 2016 17:17:38 +0200 Subject: [PATCH 55/70] 111396946-validates --- app/controllers/admin/blocked_domains_controller.rb | 12 ++++++++++-- app/controllers/admin/reserved_domains_controller.rb | 6 +++--- app/models/blocked_domain.rb | 1 + app/models/reserved_domain.rb | 3 +++ app/views/admin/reserved_domains/_form.haml | 2 +- config/locales/en.yml | 3 ++- 6 files changed, 20 insertions(+), 7 deletions(-) diff --git a/app/controllers/admin/blocked_domains_controller.rb b/app/controllers/admin/blocked_domains_controller.rb index c30b2dfb8..a21e01fd1 100644 --- a/app/controllers/admin/blocked_domains_controller.rb +++ b/app/controllers/admin/blocked_domains_controller.rb @@ -19,7 +19,15 @@ class Admin::BlockedDomainsController < AdminController def create - abort + @domain = BlockedDomain.new(blocked_domain_params) + + if @domain.save + flash[:notice] = I18n.t('domain_added') + redirect_to admin_blocked_domains_path + else + flash.now[:alert] = I18n.t('failed_to_add_domain') + render 'new' + end end @@ -35,7 +43,7 @@ class Admin::BlockedDomainsController < AdminController end - def blocked_params + def blocked_domain_params params.require(:blocked_domain).permit(:name) end diff --git a/app/controllers/admin/reserved_domains_controller.rb b/app/controllers/admin/reserved_domains_controller.rb index b0af2fb9f..319a6275c 100644 --- a/app/controllers/admin/reserved_domains_controller.rb +++ b/app/controllers/admin/reserved_domains_controller.rb @@ -21,7 +21,7 @@ class Admin::ReservedDomainsController < AdminController def create - @domain = ReservedDomain.new(reserved_params) + @domain = ReservedDomain.new(reserved_domain_params) if @domain.save flash[:notice] = I18n.t('domain_added') @@ -35,7 +35,7 @@ class Admin::ReservedDomainsController < AdminController def update - if @domain.update(reserved_params) + if @domain.update(reserved_domain_params) flash[:notice] = I18n.t('domain_updated') else flash.now[:alert] = I18n.t('failed_to_update_domain') @@ -58,7 +58,7 @@ class Admin::ReservedDomainsController < AdminController private - def reserved_params + def reserved_domain_params params.require(:reserved_domain).permit(:name, :password) end diff --git a/app/models/blocked_domain.rb b/app/models/blocked_domain.rb index 2a646a74f..e433aae85 100644 --- a/app/models/blocked_domain.rb +++ b/app/models/blocked_domain.rb @@ -1,5 +1,6 @@ class BlockedDomain < ActiveRecord::Base include Versions +validates :name, domain_name: true, uniqueness: true after_initialize -> { self.names = [] if names.nil? } end diff --git a/app/models/reserved_domain.rb b/app/models/reserved_domain.rb index e141ab7ee..718d90bcf 100644 --- a/app/models/reserved_domain.rb +++ b/app/models/reserved_domain.rb @@ -3,6 +3,9 @@ class ReservedDomain < ActiveRecord::Base before_save :fill_empty_passwords before_save :generate_data before_destroy :remove_data + validates :name, domain_name: true, uniqueness: true + + class << self diff --git a/app/views/admin/reserved_domains/_form.haml b/app/views/admin/reserved_domains/_form.haml index 2ba2431e9..ec7492659 100644 --- a/app/views/admin/reserved_domains/_form.haml +++ b/app/views/admin/reserved_domains/_form.haml @@ -16,7 +16,7 @@ .col-md-4.control-label = f.label :password .col-md-7 - = f.text_field(:password, class: 'form-control') + = f.text_field(:password, placeholder: t(:optional), class: 'form-control') .row .col-md-8.text-right = button_tag(t(:save), class: 'btn btn-primary') diff --git a/config/locales/en.yml b/config/locales/en.yml index bad2571e2..2e36ec69d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -932,4 +932,5 @@ en: expiration_remind_subject: 'The %{name} domain has expired' add_reserved_domain: 'Add domain to reserved list' add_blocked_domain: 'Add domain to blocked list' - edit_pw: 'Edit Pw' \ No newline at end of file + edit_pw: 'Edit Pw' + optional: 'Optional' \ No newline at end of file From 0ce6b84ddffa9063e78c17eb137324f28ee76fe6 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Thu, 4 Feb 2016 15:54:58 +0200 Subject: [PATCH 56/70] Story#112050051 - fix invoice sorting in admin --- app/controllers/admin/invoices_controller.rb | 2 +- app/views/admin/invoices/index.haml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/admin/invoices_controller.rb b/app/controllers/admin/invoices_controller.rb index 5aa6d4438..709dc866a 100644 --- a/app/controllers/admin/invoices_controller.rb +++ b/app/controllers/admin/invoices_controller.rb @@ -23,7 +23,7 @@ class Admin::InvoicesController < AdminController def index @q = Invoice.includes(:account_activity).search(params[:q]) - @q.sorts = 'id desc' if @q.sorts.empty? + @q.sorts = 'number desc' if @q.sorts.empty? @invoices = @q.result.page(params[:page]) end diff --git a/app/views/admin/invoices/index.haml b/app/views/admin/invoices/index.haml index 75b6285a4..f2954f927 100644 --- a/app/views/admin/invoices/index.haml +++ b/app/views/admin/invoices/index.haml @@ -8,13 +8,13 @@ %thead %tr %th{class: 'col-xs-3'} - = sort_link(@q, 'invoice') + = sort_link(@q, :number) %th{class: 'col-xs-3'} - = sort_link(@q, 'buyer') + = sort_link(@q, :buyer_name, "Buyer") %th{class: 'col-xs-3'} - = sort_link(@q, 'due_date') + = sort_link(@q, :due_date) %th{class: 'col-xs-3'} - = sort_link(@q, 'receipt_date') + = sort_link(@q, :account_activity_created_at, "Receipt date") %tbody - @invoices.each do |x| %tr From db819447c6829158ee773f1468f64756686a7391 Mon Sep 17 00:00:00 2001 From: Stas Date: Thu, 4 Feb 2016 17:24:26 +0200 Subject: [PATCH 57/70] 111396946-order_and_style_changes --- app/controllers/admin/blocked_domains_controller.rb | 2 +- app/controllers/admin/reserved_domains_controller.rb | 2 +- app/views/admin/blocked_domains/index.haml | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/admin/blocked_domains_controller.rb b/app/controllers/admin/blocked_domains_controller.rb index a21e01fd1..49cc65675 100644 --- a/app/controllers/admin/blocked_domains_controller.rb +++ b/app/controllers/admin/blocked_domains_controller.rb @@ -4,7 +4,7 @@ class Admin::BlockedDomainsController < AdminController def index params[:q] ||= {} - domains = BlockedDomain.all + domains = BlockedDomain.all.order(:name) @q = domains.search(params[:q]) @domains = @q.result.page(params[:page]) @domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i > 0 diff --git a/app/controllers/admin/reserved_domains_controller.rb b/app/controllers/admin/reserved_domains_controller.rb index 319a6275c..7de8d9891 100644 --- a/app/controllers/admin/reserved_domains_controller.rb +++ b/app/controllers/admin/reserved_domains_controller.rb @@ -5,7 +5,7 @@ class Admin::ReservedDomainsController < AdminController def index params[:q] ||= {} - domains = ReservedDomain.all + domains = ReservedDomain.all.order(:name) @q = domains.search(params[:q]) @domains = @q.result.page(params[:page]) @domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i > 0 diff --git a/app/views/admin/blocked_domains/index.haml b/app/views/admin/blocked_domains/index.haml index 5accae030..ab5f79bc7 100644 --- a/app/views/admin/blocked_domains/index.haml +++ b/app/views/admin/blocked_domains/index.haml @@ -43,7 +43,7 @@ = sort_link(@q, 'created_at', t(:created_at)) %th{class: 'col-xs-2'} = sort_link(@q, 'updated_at', t(:updated_at)) - %th{class: 'col-xs-2'} + %th{class: 'col-xs-1'} = t(:actions) %tbody - @domains.each do |x| @@ -51,9 +51,9 @@ %td= x.name %td= l(x.created_at, format: :short) %td= l(x.updated_at, format: :short) - %td + %td{class: 'col-xs-1'} = link_to(t(:delete), delete_admin_blocked_domain_path(id: x.id), - data: { confirm: t(:are_you_sure) }, class: 'btn btn-danger btn-xs') + data: { confirm: t(:are_you_sure) }, class: 'btn btn-danger btn-xs center-block') .row .col-md-6 = paginate @domains From 2650ca1922f77ebba9af91e3d622df3cd9855e78 Mon Sep 17 00:00:00 2001 From: Stas Date: Thu, 4 Feb 2016 17:59:48 +0200 Subject: [PATCH 58/70] 111396946-style_change --- app/views/admin/blocked_domains/index.haml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/views/admin/blocked_domains/index.haml b/app/views/admin/blocked_domains/index.haml index ab5f79bc7..5f6ac69d0 100644 --- a/app/views/admin/blocked_domains/index.haml +++ b/app/views/admin/blocked_domains/index.haml @@ -51,9 +51,10 @@ %td= x.name %td= l(x.created_at, format: :short) %td= l(x.updated_at, format: :short) - %td{class: 'col-xs-1'} - = link_to(t(:delete), delete_admin_blocked_domain_path(id: x.id), - data: { confirm: t(:are_you_sure) }, class: 'btn btn-danger btn-xs center-block') + %td + %div{class: 'text-center'} + = link_to(t(:delete), delete_admin_blocked_domain_path(id: x.id), + data: { confirm: t(:are_you_sure) }, class: 'btn btn-danger btn-xs') .row .col-md-6 = paginate @domains From d5f4edbadec4f9928260ce02fe129d4c96d67d47 Mon Sep 17 00:00:00 2001 From: Stas Date: Fri, 5 Feb 2016 15:38:53 +0200 Subject: [PATCH 59/70] 109818884-plus_15_days_added --- app/models/domain.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/domain.rb b/app/models/domain.rb index 42a65bcde..a816d5601 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -711,7 +711,7 @@ class Domain < ActiveRecord::Base if self.statuses.include?(DomainStatus::EXPIRED) #self.outzone_at = Time.zone.now + 1.day - self.outzone_at = self.valid_to + self.outzone_at = self.valid_to + 15.day else self.outzone_at = nil end From db6f78ede42a4513f661f5b6a16881faf7b15b3c Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Mon, 8 Feb 2016 10:36:22 +0200 Subject: [PATCH 60/70] Story#112050051 - extend ransack to sort invoices by custom scopes --- app/models/invoice.rb | 12 +++++++++ app/views/admin/invoices/index.haml | 4 +-- config/initializers/eis_ransack.rb | 40 +++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 config/initializers/eis_ransack.rb diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 5c7dafe85..425202a4c 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -11,6 +11,18 @@ class Invoice < ActiveRecord::Base scope :unbinded, lambda { where('id NOT IN (SELECT invoice_id FROM account_activities where invoice_id IS NOT NULL)') } + scope :all_columns, ->{select("invoices.*")} + scope :sort_due_date_column, ->{all_columns.select("CASE WHEN invoices.cancelled_at is not null THEN + (invoices.cancelled_at + interval '100 year') ELSE + invoices.due_date END AS sort_due_date")} + scope :sort_by_sort_due_date_asc, ->{sort_due_date_column.order("sort_due_date ASC")} + scope :sort_by_sort_due_date_desc, ->{sort_due_date_column.order("sort_due_date DESC")} + scope :sort_receipt_date_column, ->{all_columns.includes(:account_activity).references(:account_activity).select(%Q{ + CASE WHEN account_activities.created_at is not null THEN account_activities.created_at + WHEN invoices.cancelled_at is not null THEN invoices.cancelled_at + interval '100 year' + ELSE NULL END AS sort_receipt_date })} + scope :sort_by_sort_receipt_date_asc, ->{sort_receipt_date_column.order("sort_receipt_date ASC")} + scope :sort_by_sort_receipt_date_desc, ->{sort_receipt_date_column.order("sort_receipt_date DESC")} attr_accessor :billing_email validates :billing_email, email_format: { message: :invalid }, allow_blank: true diff --git a/app/views/admin/invoices/index.haml b/app/views/admin/invoices/index.haml index f2954f927..4b34dba94 100644 --- a/app/views/admin/invoices/index.haml +++ b/app/views/admin/invoices/index.haml @@ -12,9 +12,9 @@ %th{class: 'col-xs-3'} = sort_link(@q, :buyer_name, "Buyer") %th{class: 'col-xs-3'} - = sort_link(@q, :due_date) + = sort_link(@q, :sort_due_date, "Due date") %th{class: 'col-xs-3'} - = sort_link(@q, :account_activity_created_at, "Receipt date") + = sort_link(@q, :sort_receipt_date, "Receipt date") %tbody - @invoices.each do |x| %tr diff --git a/config/initializers/eis_ransack.rb b/config/initializers/eis_ransack.rb new file mode 100644 index 000000000..c23791ef7 --- /dev/null +++ b/config/initializers/eis_ransack.rb @@ -0,0 +1,40 @@ +# A custom initializer that enables sorting via custom scopes in Ransack (like the same feature in MetaSearch) + +module Ransack + module Adapters + module ActiveRecord + class Context < ::Ransack::Context + + # Allows for sorting by custom scopes + # + # + # Define your custom scopes in your model, e. g. sort_by_title_asc and sort_by_title_desc + # (The scopes would sort by some calculated column or a column added via some crazy join, etc.) + # + # In your sort links refer to the scopes like to standard fields, e. g. + # <%= sort_link(@q, :title, 'Crazy calculated title') %> + def evaluate(search, opts = {}) + viz = Visitor.new + relation = @object.where(viz.accept(search.base)) + if search.sorts.any? + custom_scopes = search.sorts.select do |s| + custom_scope_name = :"sort_by_#{s.name}_#{s.dir}" + relation.respond_to?(custom_scope_name) + end + attribute_scopes = search.sorts - custom_scopes + + relation = relation.except(:order) + + custom_scopes.each do |s| + custom_scope_name = :"sort_by_#{s.name}_#{s.dir}" + relation = relation.public_send(custom_scope_name) + end + + relation = relation.reorder(viz.accept(attribute_scopes)) if attribute_scopes.any? + end + opts[:distinct] ? relation.distinct : relation + end + end + end + end +end \ No newline at end of file From 769e3f1a1f2db1e1e555b8dd5fc49184acf41791 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Mon, 15 Feb 2016 10:55:47 +0200 Subject: [PATCH 61/70] Story#110392672 - do not run RegenerateWhoisRecordJob on empty domains --- app/models/contact.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/contact.rb b/app/models/contact.rb index 3af8dcd0e..aa3819850 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -499,7 +499,8 @@ class Contact < ActiveRecord::Base end def update_related_whois_records - RegenerateWhoisRecordJob.enqueue related_domain_descriptions.keys, :name + ids = related_domain_descriptions.keys + RegenerateWhoisRecordJob.enqueue(ids, :name) if ids.present? end end From e963484277d26f377f52b4ae3effd806d3584577 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Mon, 15 Feb 2016 12:33:01 +0200 Subject: [PATCH 62/70] Story#105852786 - we should use when cancelled_at is nil --- app/models/directo.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/directo.rb b/app/models/directo.rb index 591f450c0..60e1ed029 100644 --- a/app/models/directo.rb +++ b/app/models/directo.rb @@ -2,7 +2,7 @@ class Directo < ActiveRecord::Base belongs_to :item, polymorphic: true def self.send_receipts - new_trans = Invoice.where(invoice_type: "DEB", in_directo: false).where.not(cancelled_at: nil) + new_trans = Invoice.where(invoice_type: "DEB", in_directo: false).where(cancelled_at: nil) Rails.logger.info("[DIRECTO] Will try to send #{new_trans.count} invoices") new_trans.find_in_batches(batch_size: 10).each do |group| From 8013701580eb0a610802121b1afb3765c0b75590 Mon Sep 17 00:00:00 2001 From: Stas Date: Mon, 15 Feb 2016 15:42:12 +0200 Subject: [PATCH 63/70] 109818884-rule_added_to_others --- app/models/domain.rb | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/app/models/domain.rb b/app/models/domain.rb index a816d5601..beee1d125 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -704,19 +704,6 @@ class Domain < ActiveRecord::Base # special handling for admin changing status def admin_status_update(update) - #check for hold status - if self.statuses.include?( - DomainStatus::SERVER_HOLD) && - !update.include?(DomainStatus::SERVER_HOLD) - - if self.statuses.include?(DomainStatus::EXPIRED) - #self.outzone_at = Time.zone.now + 1.day - self.outzone_at = self.valid_to + 15.day - else - self.outzone_at = nil - end - end - # check for deleted status statuses.each do |s| unless update.include? s @@ -725,8 +712,10 @@ class Domain < ActiveRecord::Base self.delete_at = nil when DomainStatus::SERVER_MANUAL_INZONE # removal causes server hold to set self.outzone_at = Time.zone.now if self.force_delete_at.present? - # Handle any other special remove cases? - # when DomainStatus::FORCE_DELETE unset_force_delete + when DomainStatus::DomainStatus::EXPIRED # removal causes server hold to set + self.outzone_at = self.valid_to + 15.day + when DomainStatus::DomainStatus::SERVER_HOLD # removal causes server hold to set + self.outzone_at = nil end end end From f9fe365e65c72adbb86a30e03895d196679c37e0 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Thu, 18 Feb 2016 12:26:21 +0200 Subject: [PATCH 64/70] Story#113066359 - add index to domain statuses --- db/migrate/20160218102355_index_domain_statuses.rb | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 db/migrate/20160218102355_index_domain_statuses.rb diff --git a/db/migrate/20160218102355_index_domain_statuses.rb b/db/migrate/20160218102355_index_domain_statuses.rb new file mode 100644 index 000000000..d7bb787cb --- /dev/null +++ b/db/migrate/20160218102355_index_domain_statuses.rb @@ -0,0 +1,5 @@ +class IndexDomainStatuses < ActiveRecord::Migration + def change + add_index :domains, :statuses, using: :gin + end +end From 88bf3f586b68e3d0dcc17c64b3081049f3433909 Mon Sep 17 00:00:00 2001 From: Stas Date: Mon, 22 Feb 2016 13:20:36 +0200 Subject: [PATCH 65/70] 113146419-request_trim_for_epp --- app/controllers/epp_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/epp_controller.rb b/app/controllers/epp_controller.rb index a0e7d7dce..49be47848 100644 --- a/app/controllers/epp_controller.rb +++ b/app/controllers/epp_controller.rb @@ -361,9 +361,10 @@ class EppController < ApplicationController if request_command == 'login' && frame.present? frame.gsub!(/pw>.+<\//, 'pw>[FILTERED]]+)>([^<])+<\/eis:legalDocument>/, "[FILTERED]") ApiLog::EppLog.create({ - request: frame, + request: trimmed_request, request_command: request_command, request_successful: epp_errors.empty?, request_object: params[:epp_object_type], From 15a7b75e830b0115e96b095e33ef43e3b1442b57 Mon Sep 17 00:00:00 2001 From: Stas Date: Thu, 25 Feb 2016 15:55:14 +0200 Subject: [PATCH 66/70] 1113146419-rake --- lib/tasks/legal_documents.rake | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 lib/tasks/legal_documents.rake diff --git a/lib/tasks/legal_documents.rake b/lib/tasks/legal_documents.rake new file mode 100644 index 000000000..49cfd1f5d --- /dev/null +++ b/lib/tasks/legal_documents.rake @@ -0,0 +1,18 @@ +namespace :epp do + + desc 'Import all' + task all: :environment do + Rake::Task['epp:trim_documents'].invoke + end + + desc 'Import registrars' + task trim_documents: :environment do + puts '-----> Running query' + sql = <<-SQL + UPDATE epp_logs SET request = regexp_replace(request, '', '[FILTERED]<\eis:legalDocument>'); + SQL + ActiveRecord::Base.establish_connection + ActiveRecord::Base.connection.execute(sql) + end +end + From cf7b9bcacf5a0b4eebce28797fcadafd1f3b7931 Mon Sep 17 00:00:00 2001 From: Stas Date: Thu, 25 Feb 2016 16:12:39 +0200 Subject: [PATCH 67/70] 113146419-rake --- lib/tasks/{legal_documents.rake => epp.rake} | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) rename lib/tasks/{legal_documents.rake => epp.rake} (72%) diff --git a/lib/tasks/legal_documents.rake b/lib/tasks/epp.rake similarity index 72% rename from lib/tasks/legal_documents.rake rename to lib/tasks/epp.rake index 49cfd1f5d..e03835dad 100644 --- a/lib/tasks/legal_documents.rake +++ b/lib/tasks/epp.rake @@ -1,18 +1,19 @@ namespace :epp do - desc 'Import all' + desc 'EPP actions' task all: :environment do Rake::Task['epp:trim_documents'].invoke end - desc 'Import registrars' + desc 'Trim logs' task trim_documents: :environment do puts '-----> Running query' sql = <<-SQL UPDATE epp_logs SET request = regexp_replace(request, '', '[FILTERED]<\eis:legalDocument>'); SQL - ActiveRecord::Base.establish_connection - ActiveRecord::Base.connection.execute(sql) + ApiLog::EppLog.connection.execute(sql) + + puts "-----> Query done" end end From 55ffd229f91adf5f28b356aed3b4b9d193789dea Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Thu, 25 Feb 2016 16:25:43 +0200 Subject: [PATCH 68/70] Story#112043941 - show in cron STDOUT log that Directo task has been finished --- app/models/directo.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/directo.rb b/app/models/directo.rb index 60e1ed029..ac516cdf3 100644 --- a/app/models/directo.rb +++ b/app/models/directo.rb @@ -3,6 +3,7 @@ class Directo < ActiveRecord::Base def self.send_receipts new_trans = Invoice.where(invoice_type: "DEB", in_directo: false).where(cancelled_at: nil) + counter = 0 Rails.logger.info("[DIRECTO] Will try to send #{new_trans.count} invoices") new_trans.find_in_batches(batch_size: 10).each do |group| @@ -16,6 +17,7 @@ class Directo < ActiveRecord::Base Rails.logger.info("[DIRECTO] Invoice #{invoice.number} has been skipped") next end + counter += 1 num = invoice.number mappers[num] = invoice @@ -42,6 +44,8 @@ class Directo < ActiveRecord::Base response = RestClient::Request.execute(url: ENV['directo_invoice_url'], method: :post, payload: {put: "1", what: "invoice", xmldata: data}, verify_ssl: false).to_s dump_result_to_db(mappers, response) end + + STDOUT << "Directo receipts sending finished. #{counter} of #{new_trans.count} are sent" end def self.dump_result_to_db mappers, xml From 4106492ed35d2346d80b2bfa7ee47f51e111e2e3 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Fri, 26 Feb 2016 15:23:34 +0200 Subject: [PATCH 69/70] Story#114552597 - name_in_wire_format uses puny code --- app/models/domain.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/domain.rb b/app/models/domain.rb index 3e0ff3e23..249f43fb2 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -501,7 +501,7 @@ class Domain < ActiveRecord::Base def name_in_wire_format res = '' - parts = name.split('.') + parts = name_puny.split('.') parts.each do |x| res += format('%02X', x.length) # length of label in hex res += x.each_byte.map { |b| format('%02X', b) }.join # label From e21643bd72458e880a25285363937530cc809301 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Tue, 1 Mar 2016 15:45:55 +0200 Subject: [PATCH 70/70] Story#112043941 - calculate total in right place --- app/models/directo.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/directo.rb b/app/models/directo.rb index ac516cdf3..66fada5d1 100644 --- a/app/models/directo.rb +++ b/app/models/directo.rb @@ -3,8 +3,9 @@ class Directo < ActiveRecord::Base def self.send_receipts new_trans = Invoice.where(invoice_type: "DEB", in_directo: false).where(cancelled_at: nil) - counter = 0 - Rails.logger.info("[DIRECTO] Will try to send #{new_trans.count} invoices") + total = new_trans.count + counter = 0 + Rails.logger.info("[DIRECTO] Will try to send #{total} invoices") new_trans.find_in_batches(batch_size: 10).each do |group| mappers = {} # need them as no direct connection between invoice @@ -45,7 +46,7 @@ class Directo < ActiveRecord::Base dump_result_to_db(mappers, response) end - STDOUT << "Directo receipts sending finished. #{counter} of #{new_trans.count} are sent" + STDOUT << "#{Time.zone.now.utc} - Directo receipts sending finished. #{counter} of #{total} are sent\n" end def self.dump_result_to_db mappers, xml