From 2e8558a93d8dc531f35051c755bb7afe092da6e2 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Mon, 19 Apr 2021 13:47:16 +0300 Subject: [PATCH 01/61] implement get all list notifications repp endpoint --- .../v1/registrar/notifications_controller.rb | 26 +++++++++++++++++++ config/routes.rb | 6 ++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/app/controllers/repp/v1/registrar/notifications_controller.rb b/app/controllers/repp/v1/registrar/notifications_controller.rb index 4e00a9321..1108d434e 100644 --- a/app/controllers/repp/v1/registrar/notifications_controller.rb +++ b/app/controllers/repp/v1/registrar/notifications_controller.rb @@ -18,6 +18,20 @@ module Repp render_success(data: data) end + api :GET, '/repp/v1/registrar/notifications/all_notifications' + desc 'Get the all unread poll messages' + def all_notifications + records = current_user.unread_notifications.order('created_at DESC').all + @notification = records.limit(limit).offset(offset) + # rubocop:disable Style/AndOr + render_success(data: nil) and return unless @notification + # rubocop:enable Style/AndOr + + data = @notification.as_json(only: %i[id text attached_obj_id attached_obj_type]) + + render_success(data: data) + end + api :GET, '/repp/v1/registrar/notifications/:notification_id' desc 'Get a specific poll message' def show @@ -45,6 +59,18 @@ module Repp def set_notification @notification = current_user.unread_notifications.find(params[:id]) end + + def limit + index_params[:limit] || 200 + end + + def offset + index_params[:offset] || 0 + end + + def index_params + params.permit(:limit, :offset) + end end end end diff --git a/config/routes.rb b/config/routes.rb index 4e78b7c0f..48186070b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -54,7 +54,11 @@ Rails.application.routes.draw do resources :auctions, only: %i[index] resources :retained_domains, only: %i[index] namespace :registrar do - resources :notifications, only: [:index, :show, :update] + resources :notifications, only: [:index, :show, :update] do + collection do + get '/all_notifications', to: 'notifications#all_notifications' + end + end resources :nameservers do collection do put '/', to: 'nameservers#update' From d5af1a7fb651e5fed6e9b1ab4fd81dbd5c01dce5 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Mon, 19 Apr 2021 14:10:00 +0300 Subject: [PATCH 02/61] added test --- .../repp/v1/registrar/notifications_controller.rb | 2 +- .../repp/v1/registrar/notifications_test.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/controllers/repp/v1/registrar/notifications_controller.rb b/app/controllers/repp/v1/registrar/notifications_controller.rb index 1108d434e..23be6d7b7 100644 --- a/app/controllers/repp/v1/registrar/notifications_controller.rb +++ b/app/controllers/repp/v1/registrar/notifications_controller.rb @@ -63,7 +63,7 @@ module Repp def limit index_params[:limit] || 200 end - + def offset index_params[:offset] || 0 end diff --git a/test/integration/repp/v1/registrar/notifications_test.rb b/test/integration/repp/v1/registrar/notifications_test.rb index 9fafca443..2677d393b 100644 --- a/test/integration/repp/v1/registrar/notifications_test.rb +++ b/test/integration/repp/v1/registrar/notifications_test.rb @@ -9,6 +9,17 @@ class ReppV1RegistrarNotificationsTest < ActionDispatch::IntegrationTest @auth_headers = { 'Authorization' => token } end + def test_all_unreaded_poll_messages + notification = @user.registrar.notifications.where(read: false).order(created_at: :desc).all + get "/repp/v1/registrar/notifications/all_notifications", headers: @auth_headers + json = JSON.parse(response.body, symbolize_names: true) + + assert_response :ok + assert_equal notification.count, json[:data].count + assert_equal json[:data].first[:text], notification.first.text + assert_equal json[:data].last[:text], notification.last.text + end + def test_gets_latest_unread_poll_message notification = @user.registrar.notifications.where(read: false).order(created_at: :desc).first get "/repp/v1/registrar/notifications", headers: @auth_headers From 8f3f5f7302f83099edb8940287b0a339f77ffdd9 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Tue, 20 Apr 2021 14:10:58 +0300 Subject: [PATCH 03/61] added test for transaction with binded invoice which already paid --- test/tasks/invoices/process_payments_test.rb | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/tasks/invoices/process_payments_test.rb b/test/tasks/invoices/process_payments_test.rb index eeaf411cc..3f0cd49e6 100644 --- a/test/tasks/invoices/process_payments_test.rb +++ b/test/tasks/invoices/process_payments_test.rb @@ -13,6 +13,8 @@ class ProcessPaymentsTaskTest < ActiveSupport::TestCase total: payment_amount, currency: @payment_currency, reference_no: @payment_reference_number) + @account_activity = account_activities(:one) + Setting.registry_iban = beneficiary_iban Lhv::ConnectApi.class_eval do @@ -29,6 +31,29 @@ class ProcessPaymentsTaskTest < ActiveSupport::TestCase end end + def test_cannot_create_new_invoice_if_transaction_binded_to_paid_invoice + @invoice.update(total: 10) + assert_not @invoice.paid? + + @account_activity.update(activity_type: "add_credit", bank_transaction: nil) + @invoice.update(account_activity: @account_activity, total: 10) + assert @invoice.paid? + + transaction = BankTransaction.new + transaction.description = "Invoice no. #{@invoice.number}" + transaction.sum = 10 + transaction.reference_no = @invoice.reference_no + transaction.save + assert transaction.valid? + + assert_no_difference 'AccountActivity.count' do + assert_no_difference 'Invoice.count' do + Invoice.create_from_transaction!(transaction) unless transaction.autobindable? + transaction.autobind_invoice + end + end + end + def test_doubles_are_valid assert Lhv::ConnectApi.method_defined?(:credit_debit_notification_messages) assert Lhv::ConnectApi::Messages::CreditDebitNotification.method_defined?(:bank_account_iban) From 40368aaa625e6aed05d83b45a0d3e69075136ee5 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Wed, 21 Apr 2021 10:47:03 +0300 Subject: [PATCH 04/61] added non canceled method for check paid invoices --- app/models/bank_transaction.rb | 10 ++++++++++ lib/tasks/invoices/process_payments.rake | 6 ++++-- test/tasks/invoices/process_payments_test.rb | 12 +++++++++--- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/models/bank_transaction.rb b/app/models/bank_transaction.rb index 24bf51e0c..8fe0d86b5 100644 --- a/app/models/bank_transaction.rb +++ b/app/models/bank_transaction.rb @@ -27,6 +27,16 @@ class BankTransaction < ApplicationRecord .find_by(total: sum) end + def non_canceled? + paid_invoices = registrar.invoices + .order(created_at: :asc) + .non_cancelled + .where(total: sum) + return true if paid_invoices.any?(&:paid?) + + false + end + def registrar @registrar ||= Invoice.find_by(reference_no: parsed_ref_number)&.buyer end diff --git a/lib/tasks/invoices/process_payments.rake b/lib/tasks/invoices/process_payments.rake index edf6609b9..4ce9587f7 100644 --- a/lib/tasks/invoices/process_payments.rake +++ b/lib/tasks/invoices/process_payments.rake @@ -39,9 +39,11 @@ namespace :invoices do reference_no: incoming_transaction.payment_reference_number, description: incoming_transaction.payment_description } transaction = bank_statement.bank_transactions.create!(transaction_attributes) - Invoice.create_from_transaction!(transaction) unless transaction.autobindable? - transaction.autobind_invoice + unless transaction.non_canceled? + Invoice.create_from_transaction!(transaction) unless transaction.autobindable? + transaction.autobind_invoice + end end end else diff --git a/test/tasks/invoices/process_payments_test.rb b/test/tasks/invoices/process_payments_test.rb index 3f0cd49e6..2d993fd7a 100644 --- a/test/tasks/invoices/process_payments_test.rb +++ b/test/tasks/invoices/process_payments_test.rb @@ -14,6 +14,7 @@ class ProcessPaymentsTaskTest < ActiveSupport::TestCase currency: @payment_currency, reference_no: @payment_reference_number) @account_activity = account_activities(:one) + @account = accounts(:cash) Setting.registry_iban = beneficiary_iban @@ -48,8 +49,13 @@ class ProcessPaymentsTaskTest < ActiveSupport::TestCase assert_no_difference 'AccountActivity.count' do assert_no_difference 'Invoice.count' do - Invoice.create_from_transaction!(transaction) unless transaction.autobindable? - transaction.autobind_invoice + assert_no_difference -> {@account.balance} do + unless transaction.non_canceled? + Invoice.create_from_transaction!(transaction) unless transaction.autobindable? + transaction.autobind_invoice + @account.reload + end + end end end end @@ -114,7 +120,7 @@ class ProcessPaymentsTaskTest < ActiveSupport::TestCase run_task end - assert_changes -> { registrar.invoices.count } do + assert_no_changes -> { registrar.invoices.count } do run_task end end From a1c38fb1cc32c9e4e8e9fc1289d9b03f8460076b Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Wed, 21 Apr 2021 14:04:47 +0300 Subject: [PATCH 05/61] refactoring --- test/tasks/invoices/process_payments_test.rb | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/test/tasks/invoices/process_payments_test.rb b/test/tasks/invoices/process_payments_test.rb index 2d993fd7a..8eca261ab 100644 --- a/test/tasks/invoices/process_payments_test.rb +++ b/test/tasks/invoices/process_payments_test.rb @@ -33,28 +33,16 @@ class ProcessPaymentsTaskTest < ActiveSupport::TestCase end def test_cannot_create_new_invoice_if_transaction_binded_to_paid_invoice - @invoice.update(total: 10) assert_not @invoice.paid? @account_activity.update(activity_type: "add_credit", bank_transaction: nil) - @invoice.update(account_activity: @account_activity, total: 10) + @invoice.update(account_activity: @account_activity, total: @payment_amount) assert @invoice.paid? - transaction = BankTransaction.new - transaction.description = "Invoice no. #{@invoice.number}" - transaction.sum = 10 - transaction.reference_no = @invoice.reference_no - transaction.save - assert transaction.valid? - assert_no_difference 'AccountActivity.count' do assert_no_difference 'Invoice.count' do assert_no_difference -> {@account.balance} do - unless transaction.non_canceled? - Invoice.create_from_transaction!(transaction) unless transaction.autobindable? - transaction.autobind_invoice - @account.reload - end + capture_io { run_task } end end end From af8bc4155607918f43c7b3d159034a737b7abf20 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Thu, 22 Apr 2021 11:49:30 +0300 Subject: [PATCH 06/61] implement paid cancel --- app/controllers/admin/invoices_controller.rb | 17 +++++++++++++++++ app/views/admin/invoices/show.haml | 4 ++++ config/locales/en.yml | 4 ++++ config/routes.rb | 4 ++++ 4 files changed, 29 insertions(+) diff --git a/app/controllers/admin/invoices_controller.rb b/app/controllers/admin/invoices_controller.rb index c9f1d0c46..43a1b1ee1 100644 --- a/app/controllers/admin/invoices_controller.rb +++ b/app/controllers/admin/invoices_controller.rb @@ -20,6 +20,23 @@ module Admin end end + def cancel_paid + invoice_id = params[:invoice_id] + invoice = Invoice.find(invoice_id) + + account_activity = AccountActivity.find_by(invoice_id: invoice_id) + account_activity_dup = account_activity.dup + account_activity_dup.sum = -account_activity.sum + + if account_activity_dup.save and invoice.update(cancelled_at: Time.zone.today) + flash[:notice] = t(:payment_was_cancelled) + redirect_to admin_invoices_path + else + flash[:alert] = t(:failed_to_payment_cancel) + redirect_to admin_invoices_path + end + end + def index @q = Invoice.includes(:account_activity).search(params[:q]) @q.sorts = 'number desc' if @q.sorts.empty? diff --git a/app/views/admin/invoices/show.haml b/app/views/admin/invoices/show.haml index d0450469f..b121c8337 100644 --- a/app/views/admin/invoices/show.haml +++ b/app/views/admin/invoices/show.haml @@ -6,6 +6,10 @@ %h1.text-right.text-center-xs - if @invoice.unpaid? = link_to(t(:payment_received), new_admin_bank_statement_path(invoice_id: @invoice.id), class: 'btn btn-default') + + - if @invoice.paid? and !@invoice.cancelled? + = link_to(t(:cancel_payment), cancel_paid_admin_invoices_path(invoice_id: @invoice.id), method: 'post', data: { confirm: t(:are_you_sure) }, class: 'btn btn-warning') + = link_to(t('.download_btn'), download_admin_invoice_path(@invoice), class: 'btn btn-default') = link_to(t('.deliver_btn'), new_admin_invoice_delivery_path(@invoice), class: 'btn btn-default') - if @invoice.cancellable? diff --git a/config/locales/en.yml b/config/locales/en.yml index 97c968996..1d5a469a2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -293,6 +293,9 @@ en: record_deleted: 'Record deleted' failed_to_delete_record: 'Failed to delete record' + payment_was_cancelled: 'Payment was cancelled' + failed_to_payment_cancel: 'Failed to payment cancel' + authentication_error: 'Authentication error' sign_in_cancelled: "Sign in cancelled" @@ -601,6 +604,7 @@ en: no_transfers_found: 'No transfers found' parameter_value_range_error: 'Parameter value range error: %{key}' payment_received: 'Payment received' + cancel_payment: 'Cancel Payment' api_user_not_found: 'API user not found' notes: Notes active_price_for_this_operation_is: 'Active price for this operation is %{price}' diff --git a/config/routes.rb b/config/routes.rb index 4e78b7c0f..9a8f50b41 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -231,6 +231,10 @@ Rails.application.routes.draw do end resources :invoices, except: %i[edit update destroy] do + collection do + # get ':id/cancel_paid', to: 'invoices#cancel_paid', as: 'get_cancel_paid' + post ':id/cancel_paid', to: 'invoices#cancel_paid', as: 'cancel_paid' + end resource :delivery, controller: 'invoices/delivery', only: %i[new create] member do From 895fa22702d7f48fab4ceaaf0d3d5e7153ca8e7e Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Thu, 22 Apr 2021 12:45:00 +0300 Subject: [PATCH 07/61] added test --- app/controllers/admin/invoices_controller.rb | 2 +- config/routes.rb | 1 - test/integration/admin_area/invoices_test.rb | 17 +++++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/invoices_controller.rb b/app/controllers/admin/invoices_controller.rb index 43a1b1ee1..cf17d78a1 100644 --- a/app/controllers/admin/invoices_controller.rb +++ b/app/controllers/admin/invoices_controller.rb @@ -26,7 +26,7 @@ module Admin account_activity = AccountActivity.find_by(invoice_id: invoice_id) account_activity_dup = account_activity.dup - account_activity_dup.sum = -account_activity.sum + account_activity_dup.sum = -account_activity.sum.to_i if account_activity_dup.save and invoice.update(cancelled_at: Time.zone.today) flash[:notice] = t(:payment_was_cancelled) diff --git a/config/routes.rb b/config/routes.rb index 9a8f50b41..a6a9f5ab3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -232,7 +232,6 @@ Rails.application.routes.draw do resources :invoices, except: %i[edit update destroy] do collection do - # get ':id/cancel_paid', to: 'invoices#cancel_paid', as: 'get_cancel_paid' post ':id/cancel_paid', to: 'invoices#cancel_paid', as: 'cancel_paid' end resource :delivery, controller: 'invoices/delivery', only: %i[new create] diff --git a/test/integration/admin_area/invoices_test.rb b/test/integration/admin_area/invoices_test.rb index 2aa17201d..01c1a29d7 100644 --- a/test/integration/admin_area/invoices_test.rb +++ b/test/integration/admin_area/invoices_test.rb @@ -4,6 +4,23 @@ class AdminAreaInvoicesIntegrationTest < ApplicationIntegrationTest setup do @invoice = invoices(:one) sign_in users(:admin) + + @account = accounts(:cash) + @registrar = registrars(:bestnames) + end + + def test_cancel_paid_invoice + @invoice.account_activity.update(sum: 10) + assert @invoice.paid? + + assert_equal @registrar.balance, 100 + + assert_no_difference 'Invoice.count' do + assert_difference 'AccountActivity.count' do + post cancel_paid_admin_invoices_path(id: @invoice.id) + "?invoice_id=#{@invoice.id}" + end + end + assert_equal @registrar.balance, 90 end def test_create_new_invoice From 28d156055545a1e797e6c7ecbb4da98bd4213574 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Thu, 22 Apr 2021 12:59:27 +0300 Subject: [PATCH 08/61] refactoring --- app/controllers/admin/invoices_controller.rb | 16 +++++++++------- app/models/bank_transaction.rb | 2 -- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/controllers/admin/invoices_controller.rb b/app/controllers/admin/invoices_controller.rb index cf17d78a1..e0b0a6d80 100644 --- a/app/controllers/admin/invoices_controller.rb +++ b/app/controllers/admin/invoices_controller.rb @@ -24,17 +24,12 @@ module Admin invoice_id = params[:invoice_id] invoice = Invoice.find(invoice_id) - account_activity = AccountActivity.find_by(invoice_id: invoice_id) - account_activity_dup = account_activity.dup - account_activity_dup.sum = -account_activity.sum.to_i - - if account_activity_dup.save and invoice.update(cancelled_at: Time.zone.today) + if account_activity_with_negative_sum(invoice) flash[:notice] = t(:payment_was_cancelled) - redirect_to admin_invoices_path else flash[:alert] = t(:failed_to_payment_cancel) - redirect_to admin_invoices_path end + redirect_to admin_invoices_path end def index @@ -60,5 +55,12 @@ module Admin def deposit_params params.require(:deposit).permit(:amount, :description, :registrar_id) end + + def account_activity_with_negative_sum(invoice) + account_activity = AccountActivity.find_by(invoice_id: invoice.id) + account_activity_dup = account_activity.dup + account_activity_dup.sum = -account_activity.sum.to_i + account_activity_dup.save && invoice.update(cancelled_at: Time.zone.today) + end end end diff --git a/app/models/bank_transaction.rb b/app/models/bank_transaction.rb index 8fe0d86b5..ab76010ee 100644 --- a/app/models/bank_transaction.rb +++ b/app/models/bank_transaction.rb @@ -33,8 +33,6 @@ class BankTransaction < ApplicationRecord .non_cancelled .where(total: sum) return true if paid_invoices.any?(&:paid?) - - false end def registrar From 1294a05870cde0c56ca9d678fea3d73eac7bbbe2 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Thu, 22 Apr 2021 14:15:43 +0300 Subject: [PATCH 09/61] refactoring: separate methods from bank_transaction model to concern --- app/models/bank_transaction.rb | 19 +--------- .../concerns/transaction_paid_invoices.rb | 37 +++++++++++++++++++ test/tasks/invoices/process_payments_test.rb | 18 ++++++++- 3 files changed, 54 insertions(+), 20 deletions(-) create mode 100644 app/models/concerns/transaction_paid_invoices.rb diff --git a/app/models/bank_transaction.rb b/app/models/bank_transaction.rb index ab76010ee..734075ac3 100644 --- a/app/models/bank_transaction.rb +++ b/app/models/bank_transaction.rb @@ -1,5 +1,6 @@ class BankTransaction < ApplicationRecord include Versions + include TransactionPaidInvoices belongs_to :bank_statement has_one :account_activity @@ -17,24 +18,6 @@ class BankTransaction < ApplicationRecord account_activity.invoice end - def invoice - return unless registrar - - @invoice ||= registrar.invoices - .order(created_at: :asc) - .unpaid - .non_cancelled - .find_by(total: sum) - end - - def non_canceled? - paid_invoices = registrar.invoices - .order(created_at: :asc) - .non_cancelled - .where(total: sum) - return true if paid_invoices.any?(&:paid?) - end - def registrar @registrar ||= Invoice.find_by(reference_no: parsed_ref_number)&.buyer end diff --git a/app/models/concerns/transaction_paid_invoices.rb b/app/models/concerns/transaction_paid_invoices.rb new file mode 100644 index 000000000..19d632c1d --- /dev/null +++ b/app/models/concerns/transaction_paid_invoices.rb @@ -0,0 +1,37 @@ +module TransactionPaidInvoices + extend ActiveSupport::Concern + + def invoice + return unless registrar + + @invoice ||= registrar.invoices + .order(created_at: :asc) + .unpaid + .non_cancelled + .find_by(total: sum) + end + + def non_canceled? + paid_invoices = registrar.invoices + .order(created_at: :asc) + .non_cancelled + .where(total: sum) + paid_invoices.any? do |invoice| + return true if invoice.paid? && fresh_admin_paid_invoice(invoice) + end + end + + private + + def fresh_admin_paid_invoice(invoice) + check_for_date_paid_invoice(invoice) && does_invoice_created_by_admin?(invoice) + end + + def check_for_date_paid_invoice(invoice) + invoice.account_activity.created_at > Time.zone.today - 2.days + end + + def does_invoice_created_by_admin?(invoice) + invoice.account_activity.creator_str&.include? 'Admin' + end +end diff --git a/test/tasks/invoices/process_payments_test.rb b/test/tasks/invoices/process_payments_test.rb index 8eca261ab..29f76ea7c 100644 --- a/test/tasks/invoices/process_payments_test.rb +++ b/test/tasks/invoices/process_payments_test.rb @@ -35,7 +35,7 @@ class ProcessPaymentsTaskTest < ActiveSupport::TestCase def test_cannot_create_new_invoice_if_transaction_binded_to_paid_invoice assert_not @invoice.paid? - @account_activity.update(activity_type: "add_credit", bank_transaction: nil) + @account_activity.update(activity_type: "add_credit", bank_transaction: nil, created_at: Time.zone.today - 1.day, creator_str: 'AdminUser') @invoice.update(account_activity: @account_activity, total: @payment_amount) assert @invoice.paid? @@ -48,6 +48,20 @@ class ProcessPaymentsTaskTest < ActiveSupport::TestCase end end + def test_if_invoice_is_overdue_than_48_hours + assert_not @invoice.paid? + + @account_activity.update(activity_type: "add_credit", bank_transaction: nil, created_at: Time.zone.today - 3.days, creator_str: 'AdminUser') + @invoice.update(account_activity: @account_activity, total: @payment_amount) + assert @invoice.paid? + + assert_difference 'AccountActivity.count' do + assert_difference 'Invoice.count' do + capture_io { run_task } + end + end + end + def test_doubles_are_valid assert Lhv::ConnectApi.method_defined?(:credit_debit_notification_messages) assert Lhv::ConnectApi::Messages::CreditDebitNotification.method_defined?(:bank_account_iban) @@ -108,7 +122,7 @@ class ProcessPaymentsTaskTest < ActiveSupport::TestCase run_task end - assert_no_changes -> { registrar.invoices.count } do + assert_changes -> { registrar.invoices.count } do run_task end end From ba9a485542156af2d40612b9fce1163086d2856b Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Mon, 26 Apr 2021 17:17:13 +0500 Subject: [PATCH 10/61] Add test to check response on /error/ epp endpoint --- test/integration/epp/base_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/integration/epp/base_test.rb b/test/integration/epp/base_test.rb index 2d19a6fa8..3e40ac525 100644 --- a/test/integration/epp/base_test.rb +++ b/test/integration/epp/base_test.rb @@ -34,6 +34,13 @@ class EppBaseTest < EppTestCase end end + def test_additional_error + get '/epp/error', params: { frame: valid_request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + + assert_epp_response :unknown_command + end + def test_validates_request_xml invalid_xml = <<-XML From c0917d4978f99871d38d9f50badd7847f1cf4e6c Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Mon, 26 Apr 2021 16:05:52 +0300 Subject: [PATCH 11/61] changed error code --- app/controllers/epp/base_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/epp/base_controller.rb b/app/controllers/epp/base_controller.rb index f12bd1bd2..3943d741b 100644 --- a/app/controllers/epp/base_controller.rb +++ b/app/controllers/epp/base_controller.rb @@ -8,7 +8,7 @@ module Epp before_action :ensure_session_id_passed before_action :generate_svtrid before_action :latin_only - before_action :validate_against_schema + # before_action :validate_against_schema before_action :validate_request before_action :enforce_epp_session_timeout, if: :signed_in? before_action :iptables_counter_update, if: :signed_in? @@ -113,7 +113,6 @@ module Epp end end end - @errors.uniq! render_epp_response '/epp/error' From e76f8da61819eaf066651a4735eed9b80c1794ba Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Tue, 27 Apr 2021 15:25:56 +0300 Subject: [PATCH 12/61] refactoring test --- app/controllers/epp/base_controller.rb | 4 +++- test/integration/epp/base_test.rb | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/controllers/epp/base_controller.rb b/app/controllers/epp/base_controller.rb index 3943d741b..820fe9098 100644 --- a/app/controllers/epp/base_controller.rb +++ b/app/controllers/epp/base_controller.rb @@ -8,7 +8,7 @@ module Epp before_action :ensure_session_id_passed before_action :generate_svtrid before_action :latin_only - # before_action :validate_against_schema + before_action :validate_against_schema before_action :validate_request before_action :enforce_epp_session_timeout, if: :signed_in? before_action :iptables_counter_update, if: :signed_in? @@ -23,6 +23,8 @@ module Epp rescue_from ActiveRecord::RecordNotFound, with: :respond_with_object_does_not_exist_error before_action :set_paper_trail_whodunnit + skip_before_action :validate_against_schema + protected def respond_with_command_failed_error(exception) diff --git a/test/integration/epp/base_test.rb b/test/integration/epp/base_test.rb index 3e40ac525..41fb186fe 100644 --- a/test/integration/epp/base_test.rb +++ b/test/integration/epp/base_test.rb @@ -41,6 +41,19 @@ class EppBaseTest < EppTestCase assert_epp_response :unknown_command end + def test_error_with_unknown_command + invalid_xml = <<-XML + + + + XML + + get '/epp/error', params: { frame: invalid_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + + assert_epp_response :unknown_command + end + def test_validates_request_xml invalid_xml = <<-XML @@ -50,7 +63,7 @@ class EppBaseTest < EppTestCase post valid_command_path, params: { frame: invalid_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } - assert_epp_response :syntax_error + assert_epp_response :required_parameter_missing end def test_anonymous_user From 3b11f0bc20935cfef355e16e94324b547d470931 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Mon, 15 Mar 2021 13:18:56 +0200 Subject: [PATCH 13/61] Test: Added test for legal doc sizes --- .../epp/domain/create/base_test.rb | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/test/integration/epp/domain/create/base_test.rb b/test/integration/epp/domain/create/base_test.rb index 35ef38179..fa04fc707 100644 --- a/test/integration/epp/domain/create/base_test.rb +++ b/test/integration/epp/domain/create/base_test.rb @@ -46,6 +46,109 @@ class EppDomainCreateBaseTest < EppTestCase assert_epp_response :parameter_value_syntax_error end + def test_too_small_legal_document + name = "new.#{dns_zones(:one).origin}" + contact = contacts(:john) + registrant = contact.becomes(Registrant) + + request_xml = <<-XML + + + + + + #{name} + #{registrant.code} + + + + + #{'test' * 2} + + + + + XML + assert_no_difference 'Domain.count' do + post epp_create_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + end + + assert_epp_response :parameter_value_policy_error + end + + def test_too_big_legal_document + name = "new.#{dns_zones(:one).origin}" + contact = contacts(:john) + registrant = contact.becomes(Registrant) + + # 8388608 bites == 8 mb + bignum_legaldoc = 't' * 8388608 + bignum_legaldoc+= "t" + + request_xml = <<-XML + + + + + + #{name} + #{registrant.code} + + + + + #{bignum_legaldoc} + + + + + XML + + assert_no_difference 'Domain.count' do + post epp_create_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + end + + assert_epp_response :parameter_value_policy_error + end + + def test_upper_limit_of_value_legal_document + name = "new.#{dns_zones(:one).origin}" + contact = contacts(:john) + registrant = contact.becomes(Registrant) + + # 8388608 bites == 8 mb + bignum_legaldoc = 't' * 8388608 + + request_xml = <<-XML + + + + + + #{name} + #{registrant.code} + + + + + #{bignum_legaldoc} + + + + + XML + + assert_difference 'Domain.count' do + post epp_create_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + end + + assert_epp_response :completed_successfully + end + + def test_not_registers_domain_without_legaldoc now = Time.zone.parse('2010-07-05') From 9f21b1704cd3eacb62f9d2157a2dcf584c0d932b Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Thu, 18 Mar 2021 15:12:30 +0500 Subject: [PATCH 14/61] Change error type if legaldoc file is more than 8 MB --- app/controllers/epp/base_controller.rb | 8 +++++++- test/integration/epp/domain/create/base_test.rb | 15 +++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/controllers/epp/base_controller.rb b/app/controllers/epp/base_controller.rb index 99c0ead35..ff711c490 100644 --- a/app/controllers/epp/base_controller.rb +++ b/app/controllers/epp/base_controller.rb @@ -23,6 +23,8 @@ module Epp rescue_from ActiveRecord::RecordNotFound, with: :respond_with_object_does_not_exist_error before_action :set_paper_trail_whodunnit + EIGHT_MEGABYTES = 8_388_608 + protected def respond_with_command_failed_error(exception) @@ -62,13 +64,17 @@ module Epp return if %w[hello error].include?(params[:action]) schema.validate(params[:nokogiri_frame]).each do |error| epp_errors << { - code: 2001, + code: error_code(error), msg: error } end handle_errors and return if epp_errors.any? end + def error_code(error) + error.str1.present? && error.str1.size > EIGHT_MEGABYTES ? 2306 : 2001 + end + def schema EPP_ALL_SCHEMA end diff --git a/test/integration/epp/domain/create/base_test.rb b/test/integration/epp/domain/create/base_test.rb index fa04fc707..777f01abc 100644 --- a/test/integration/epp/domain/create/base_test.rb +++ b/test/integration/epp/domain/create/base_test.rb @@ -73,7 +73,7 @@ class EppDomainCreateBaseTest < EppTestCase post epp_create_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end - + assert_epp_response :parameter_value_policy_error end @@ -82,9 +82,8 @@ class EppDomainCreateBaseTest < EppTestCase contact = contacts(:john) registrant = contact.becomes(Registrant) - # 8388608 bites == 8 mb - bignum_legaldoc = 't' * 8388608 - bignum_legaldoc+= "t" + # 8388608 bytes == 8 mb + bignum_legaldoc = 't' * (8388608 + 1) request_xml = <<-XML @@ -109,7 +108,7 @@ class EppDomainCreateBaseTest < EppTestCase post epp_create_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end - + assert_epp_response :parameter_value_policy_error end @@ -118,7 +117,7 @@ class EppDomainCreateBaseTest < EppTestCase contact = contacts(:john) registrant = contact.becomes(Registrant) - # 8388608 bites == 8 mb + # 8388608 bytes == 8 mb bignum_legaldoc = 't' * 8388608 request_xml = <<-XML @@ -139,12 +138,12 @@ class EppDomainCreateBaseTest < EppTestCase XML - + assert_difference 'Domain.count' do post epp_create_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end - + assert_epp_response :completed_successfully end From 31a463c58714f0cd75de6f8ad5a1618bbc2b4f02 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Thu, 18 Mar 2021 15:22:02 +0500 Subject: [PATCH 15/61] Move size constant to LegalDocument class --- app/controllers/epp/base_controller.rb | 4 +--- app/models/legal_document.rb | 1 + test/integration/epp/domain/create/base_test.rb | 6 ++---- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/app/controllers/epp/base_controller.rb b/app/controllers/epp/base_controller.rb index ff711c490..205b7f844 100644 --- a/app/controllers/epp/base_controller.rb +++ b/app/controllers/epp/base_controller.rb @@ -23,8 +23,6 @@ module Epp rescue_from ActiveRecord::RecordNotFound, with: :respond_with_object_does_not_exist_error before_action :set_paper_trail_whodunnit - EIGHT_MEGABYTES = 8_388_608 - protected def respond_with_command_failed_error(exception) @@ -72,7 +70,7 @@ module Epp end def error_code(error) - error.str1.present? && error.str1.size > EIGHT_MEGABYTES ? 2306 : 2001 + error.str1.present? && error.str1.size > LegalDocument::MAX_BODY_SIZE ? 2306 : 2001 end def schema diff --git a/app/models/legal_document.rb b/app/models/legal_document.rb index 377a9fdde..24b965996 100644 --- a/app/models/legal_document.rb +++ b/app/models/legal_document.rb @@ -1,6 +1,7 @@ class LegalDocument < ApplicationRecord include EppErrors MIN_BODY_SIZE = (1.37 * 3.kilobytes).ceil + MAX_BODY_SIZE = 8.megabytes if ENV['legal_document_types'].present? TYPES = ENV['legal_document_types'].split(',').map(&:strip) diff --git a/test/integration/epp/domain/create/base_test.rb b/test/integration/epp/domain/create/base_test.rb index 777f01abc..5308de519 100644 --- a/test/integration/epp/domain/create/base_test.rb +++ b/test/integration/epp/domain/create/base_test.rb @@ -82,8 +82,7 @@ class EppDomainCreateBaseTest < EppTestCase contact = contacts(:john) registrant = contact.becomes(Registrant) - # 8388608 bytes == 8 mb - bignum_legaldoc = 't' * (8388608 + 1) + bignum_legaldoc = 't' * (LegalDocument::MAX_BODY_SIZE + 1) request_xml = <<-XML @@ -117,8 +116,7 @@ class EppDomainCreateBaseTest < EppTestCase contact = contacts(:john) registrant = contact.becomes(Registrant) - # 8388608 bytes == 8 mb - bignum_legaldoc = 't' * 8388608 + bignum_legaldoc = 't' * LegalDocument::MAX_BODY_SIZE request_xml = <<-XML From 0f58e475131808e534045ba67da1540e794dd182 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Fri, 19 Mar 2021 15:35:55 +0500 Subject: [PATCH 16/61] Fix test to have file at Base64, fix size validation --- app/controllers/epp/base_controller.rb | 6 +----- app/models/legal_document.rb | 13 +++++++++---- config/locales/en.yml | 3 ++- test/integration/epp/domain/create/base_test.rb | 4 +++- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/controllers/epp/base_controller.rb b/app/controllers/epp/base_controller.rb index 205b7f844..99c0ead35 100644 --- a/app/controllers/epp/base_controller.rb +++ b/app/controllers/epp/base_controller.rb @@ -62,17 +62,13 @@ module Epp return if %w[hello error].include?(params[:action]) schema.validate(params[:nokogiri_frame]).each do |error| epp_errors << { - code: error_code(error), + code: 2001, msg: error } end handle_errors and return if epp_errors.any? end - def error_code(error) - error.str1.present? && error.str1.size > LegalDocument::MAX_BODY_SIZE ? 2306 : 2001 - end - def schema EPP_ALL_SCHEMA end diff --git a/app/models/legal_document.rb b/app/models/legal_document.rb index 24b965996..eba250991 100644 --- a/app/models/legal_document.rb +++ b/app/models/legal_document.rb @@ -21,14 +21,19 @@ class LegalDocument < ApplicationRecord def epp_code_map { - '2306' => [ - [:body, :length] - ] + '2306' => [ + %i[body length_more_than], + %i[body length_less_than], + ] } end def val_body_length - errors.add(:body, :length) if body.nil? || body.size < MIN_BODY_SIZE + if body.nil? || body.size < MIN_BODY_SIZE + errors.add(:body, :length_more_than) + elsif body.size > MAX_BODY_SIZE + errors.add(:body, :length_less_than) + end end def save_to_filesystem diff --git a/config/locales/en.yml b/config/locales/en.yml index 97c968996..f5800127e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -138,7 +138,8 @@ en: legal_document: attributes: body: - length: 'Parameter value policy error: legalDocument size should be more than 3kB' + length_more_than: 'Parameter value policy error: legalDocument size should be more than 3kB' + length_less_than: 'Parameter value policy error: legalDocument size should be less than 8mB' attributes: diff --git a/test/integration/epp/domain/create/base_test.rb b/test/integration/epp/domain/create/base_test.rb index 5308de519..5069ddf41 100644 --- a/test/integration/epp/domain/create/base_test.rb +++ b/test/integration/epp/domain/create/base_test.rb @@ -82,7 +82,7 @@ class EppDomainCreateBaseTest < EppTestCase contact = contacts(:john) registrant = contact.becomes(Registrant) - bignum_legaldoc = 't' * (LegalDocument::MAX_BODY_SIZE + 1) + bignum_legaldoc = Base64.encode64('t' * (LegalDocument::MAX_BODY_SIZE + 1)).gsub(/\n/,"") request_xml = <<-XML @@ -109,6 +109,8 @@ class EppDomainCreateBaseTest < EppTestCase end assert_epp_response :parameter_value_policy_error + error_description = 'legalDocument size should be less than 8mB' + assert response.body.include? error_description end def test_upper_limit_of_value_legal_document From c52c66933913c46f1335dfa463f6abc53c1a35d7 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Wed, 28 Apr 2021 14:02:31 +0500 Subject: [PATCH 17/61] Fix error code/message --- app/models/legal_document.rb | 2 +- config/locales/en.yml | 4 ++-- test/integration/epp/domain/create/base_test.rb | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/models/legal_document.rb b/app/models/legal_document.rb index eba250991..07c50c5dc 100644 --- a/app/models/legal_document.rb +++ b/app/models/legal_document.rb @@ -21,7 +21,7 @@ class LegalDocument < ApplicationRecord def epp_code_map { - '2306' => [ + '2308' => [ %i[body length_more_than], %i[body length_less_than], ] diff --git a/config/locales/en.yml b/config/locales/en.yml index f5800127e..a909dfcf4 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -138,8 +138,8 @@ en: legal_document: attributes: body: - length_more_than: 'Parameter value policy error: legalDocument size should be more than 3kB' - length_less_than: 'Parameter value policy error: legalDocument size should be less than 8mB' + length_more_than: 'Parameter value policy error: Legaldoc size is less than minimum allowed size of 3kB' + length_less_than: 'Parameter value policy error: Legaldoc size exceeds maximum allowed size of 8mB' attributes: diff --git a/test/integration/epp/domain/create/base_test.rb b/test/integration/epp/domain/create/base_test.rb index 5069ddf41..59a8ddf77 100644 --- a/test/integration/epp/domain/create/base_test.rb +++ b/test/integration/epp/domain/create/base_test.rb @@ -74,7 +74,7 @@ class EppDomainCreateBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end - assert_epp_response :parameter_value_policy_error + assert_epp_response :data_management_policy_violation end def test_too_big_legal_document @@ -108,8 +108,8 @@ class EppDomainCreateBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end - assert_epp_response :parameter_value_policy_error - error_description = 'legalDocument size should be less than 8mB' + assert_epp_response :data_management_policy_violation + error_description = 'Legaldoc size exceeds maximum allowed size of 8mB' assert response.body.include? error_description end From b3e27b37b5013cb8e1a366aa03cd192fb28f4d19 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Wed, 28 Apr 2021 16:53:06 +0300 Subject: [PATCH 18/61] change status from cancelled to unpaid --- app/controllers/admin/invoices_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/invoices_controller.rb b/app/controllers/admin/invoices_controller.rb index e0b0a6d80..42c3b5e48 100644 --- a/app/controllers/admin/invoices_controller.rb +++ b/app/controllers/admin/invoices_controller.rb @@ -60,7 +60,10 @@ module Admin account_activity = AccountActivity.find_by(invoice_id: invoice.id) account_activity_dup = account_activity.dup account_activity_dup.sum = -account_activity.sum.to_i - account_activity_dup.save && invoice.update(cancelled_at: Time.zone.today) + account_activity_dup.save + account_activity.update(invoice_id: nil) + account_activity_dup.update(invoice_id: nil) + account_activity.save && account_activity_dup.save end end end From 2d911e53c34a057576ea19755bacf37919b2808e Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Thu, 29 Apr 2021 09:51:10 +0300 Subject: [PATCH 19/61] added method which note cancelled payment orders --- app/controllers/admin/invoices_controller.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/controllers/admin/invoices_controller.rb b/app/controllers/admin/invoices_controller.rb index 42c3b5e48..bd54ffd0b 100644 --- a/app/controllers/admin/invoices_controller.rb +++ b/app/controllers/admin/invoices_controller.rb @@ -63,7 +63,13 @@ module Admin account_activity_dup.save account_activity.update(invoice_id: nil) account_activity_dup.update(invoice_id: nil) + mark_cancelled_payment_order(invoice) account_activity.save && account_activity_dup.save end + + def mark_cancelled_payment_order(invoice) + payment_order = invoice.payment_orders.last + payment_order.update(notes: 'Cancelled') + end end end From d6795fc0b2e7903dda1cbce87d899299a674711d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Thu, 29 Apr 2021 21:12:19 +0300 Subject: [PATCH 20/61] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a6ccc6a77..18ff4300e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +29.04.2021 +* Admin is able to cancel invoice payments [#1937](https://github.com/internetee/registry/issues/1937) + 26.04.2021 * Disputed status is removed on registrant change and status added to schema [#1927](https://github.com/internetee/registry/issues/1927) * Bounce list record is removed one there are no active contacts with the address [#1912](https://github.com/internetee/registry/issues/1912) From ce1630bc2f07d5713b252d42e9642dcd37e7aaba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Thu, 29 Apr 2021 21:14:20 +0300 Subject: [PATCH 21/61] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18ff4300e..73c0d7367 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ 29.04.2021 * Admin is able to cancel invoice payments [#1937](https://github.com/internetee/registry/issues/1937) +* Bump nokogiri to 1.11.3 [#1920](https://github.com/internetee/registry/pull/1920) 26.04.2021 * Disputed status is removed on registrant change and status added to schema [#1927](https://github.com/internetee/registry/issues/1927) From 64d4f4d0bc261354805e6a837dcaa011e7e6f5cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Fri, 30 Apr 2021 18:16:38 +0300 Subject: [PATCH 22/61] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73c0d7367..91197eb57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +30.04.2021 +* Fixed error message on oversized legaldocs [#1880](https://github.com/internetee/registry/issues/1880) + 29.04.2021 * Admin is able to cancel invoice payments [#1937](https://github.com/internetee/registry/issues/1937) * Bump nokogiri to 1.11.3 [#1920](https://github.com/internetee/registry/pull/1920) From e8ea94da36c2da9d504d069c6dc4faeb207613d2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 May 2021 05:02:32 +0000 Subject: [PATCH 23/61] Bump nokogiri from 1.11.0 to 1.11.3 Bumps [nokogiri](https://github.com/sparklemotion/nokogiri) from 1.11.0 to 1.11.3. - [Release notes](https://github.com/sparklemotion/nokogiri/releases) - [Changelog](https://github.com/sparklemotion/nokogiri/blob/main/CHANGELOG.md) - [Commits](https://github.com/sparklemotion/nokogiri/compare/v1.11.0...v1.11.3) Signed-off-by: dependabot[bot] --- Gemfile | 2 +- Gemfile.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 85d62654c..1355b8daa 100644 --- a/Gemfile +++ b/Gemfile @@ -25,7 +25,7 @@ gem 'validates_email_format_of', '1.6.3' # validates email against RFC 2822 and # 0.7.3 is the latest for Rails 4.2, however, it is absent on Rubygems server # https://github.com/huacnlee/rails-settings-cached/issues/165 -gem 'nokogiri', '~> 1.11.0' +gem 'nokogiri', '~> 1.11.3' # style gem 'bootstrap-sass', '~> 3.4' diff --git a/Gemfile.lock b/Gemfile.lock index dd41719ad..63319d370 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -307,10 +307,10 @@ GEM ruby2_keywords (~> 0.0.1) netrc (0.11.0) nio4r (2.5.7) - nokogiri (1.11.0) + nokogiri (1.11.3) mini_portile2 (~> 2.5.0) racc (~> 1.4) - nokogiri (1.11.0-x86_64-linux) + nokogiri (1.11.3-x86_64-linux) racc (~> 1.4) nori (2.6.0) omniauth (1.9.1) @@ -547,7 +547,7 @@ DEPENDENCIES mimemagic (= 0.3.10) minitest (~> 5.14) money-rails - nokogiri (~> 1.11.0) + nokogiri (~> 1.11.3) omniauth omniauth-rails_csrf_protection omniauth-tara! From 39b6348cf6ec6fd6d8d37cb398fad856c18d563f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 May 2021 05:04:28 +0000 Subject: [PATCH 24/61] Bump bootsnap from 1.7.3 to 1.7.4 Bumps [bootsnap](https://github.com/Shopify/bootsnap) from 1.7.3 to 1.7.4. - [Release notes](https://github.com/Shopify/bootsnap/releases) - [Changelog](https://github.com/Shopify/bootsnap/blob/master/CHANGELOG.md) - [Commits](https://github.com/Shopify/bootsnap/compare/v1.7.3...v1.7.4) Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index dd41719ad..f28953d48 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -164,7 +164,7 @@ GEM aws-eventstream (~> 1, >= 1.0.2) bcrypt (3.1.16) bindata (2.4.8) - bootsnap (1.7.3) + bootsnap (1.7.4) msgpack (~> 1.0) bootstrap-sass (3.4.1) autoprefixer-rails (>= 5.2.1) From 87ea96b11438e4d0c5137fce79a579a7d6d520fd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 May 2021 05:05:41 +0000 Subject: [PATCH 25/61] Bump truemail from 2.3.4 to 2.4.0 Bumps [truemail](https://github.com/truemail-rb/truemail) from 2.3.4 to 2.4.0. - [Release notes](https://github.com/truemail-rb/truemail/releases) - [Changelog](https://github.com/truemail-rb/truemail/blob/master/CHANGELOG.md) - [Commits](https://github.com/truemail-rb/truemail/compare/v2.3.4...v2.4.0) Signed-off-by: dependabot[bot] --- Gemfile | 2 +- Gemfile.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 85d62654c..86a57545a 100644 --- a/Gemfile +++ b/Gemfile @@ -20,7 +20,7 @@ gem 'paper_trail', '~> 12.0' gem 'pg', '1.2.3' # 1.8 is for Rails < 5.0 gem 'ransack', '~> 2.3' -gem 'truemail', '~> 2.3' # validates email by regexp, mail server existence and address existence +gem 'truemail', '~> 2.4' # validates email by regexp, mail server existence and address existence gem 'validates_email_format_of', '1.6.3' # validates email against RFC 2822 and RFC 3696 # 0.7.3 is the latest for Rails 4.2, however, it is absent on Rubygems server diff --git a/Gemfile.lock b/Gemfile.lock index dd41719ad..0ddf9124a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -461,7 +461,7 @@ GEM thor (1.1.0) thread_safe (0.3.6) tilt (2.0.10) - truemail (2.3.4) + truemail (2.4.0) simpleidn (~> 0.2.1) tzinfo (1.2.9) thread_safe (~> 0.1) @@ -568,7 +568,7 @@ DEPENDENCIES sidekiq simplecov (= 0.17.1) simpleidn (= 0.2.1) - truemail (~> 2.3) + truemail (~> 2.4) uglifier validates_email_format_of (= 1.6.3) webdrivers From a82eac54de3337cadba94e86cd8e502358d807f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Mon, 3 May 2021 09:47:53 +0300 Subject: [PATCH 26/61] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91197eb57..a1caa14b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +03.05.2021 +* Imporved error handling on invalid XML over EPP [#1952](https://github.com/internetee/registry/pull/1952) + 30.04.2021 * Fixed error message on oversized legaldocs [#1880](https://github.com/internetee/registry/issues/1880) From 26db6a80781949d0a958cd0845b29db24c379fe3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 May 2021 10:18:36 +0000 Subject: [PATCH 27/61] Bump mimemagic from 0.3.10 to 0.4.3 Bumps [mimemagic](https://github.com/mimemagicrb/mimemagic) from 0.3.10 to 0.4.3. - [Release notes](https://github.com/mimemagicrb/mimemagic/releases) - [Changelog](https://github.com/mimemagicrb/mimemagic/blob/master/CHANGELOG.md) - [Commits](https://github.com/mimemagicrb/mimemagic/compare/v0.3.10...v0.4.3) Signed-off-by: dependabot[bot] --- Gemfile | 2 +- Gemfile.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index bd71ca91e..9b90c30bb 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,7 @@ gem 'apipie-rails', '~> 0.5.18' gem 'bootsnap', '>= 1.1.0', require: false gem 'iso8601', '0.12.1' # for dates and times gem 'mime-types-data' -gem 'mimemagic', '0.3.10' +gem 'mimemagic', '0.4.3' gem 'rails', '~> 6.0' gem 'rest-client' gem 'uglifier' diff --git a/Gemfile.lock b/Gemfile.lock index 6779b9472..116f8bd9b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -286,7 +286,7 @@ GEM mime-types (3.3.1) mime-types-data (~> 3.2015) mime-types-data (3.2021.0225) - mimemagic (0.3.10) + mimemagic (0.4.3) nokogiri (~> 1) rake mini_mime (1.1.0) @@ -544,7 +544,7 @@ DEPENDENCIES kaminari lhv! mime-types-data - mimemagic (= 0.3.10) + mimemagic (= 0.4.3) minitest (~> 5.14) money-rails nokogiri (~> 1.11.3) From ffa9b715b0610bb4061b0d48b96198d907bf193d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Mon, 3 May 2021 16:42:42 +0300 Subject: [PATCH 28/61] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1caa14b4..98ef533f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ 03.05.2021 * Imporved error handling on invalid XML over EPP [#1952](https://github.com/internetee/registry/pull/1952) +* Bump nokogiri to 1.11.3 [#1961](https://github.com/internetee/registry/pull/1961) +* Bump bootsnap to 1.7.4 [#1963](https://github.com/internetee/registry/pull/1963) +* Bump truemail to 2.4.0 [#1964](https://github.com/internetee/registry/pull/1964) 30.04.2021 * Fixed error message on oversized legaldocs [#1880](https://github.com/internetee/registry/issues/1880) From dffa6470d8b01b7d105e30271b5968d9a5250559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Mon, 3 May 2021 16:44:25 +0300 Subject: [PATCH 29/61] Update CHANGELOG.md --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98ef533f0..dfd9b669e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,5 @@ 03.05.2021 * Imporved error handling on invalid XML over EPP [#1952](https://github.com/internetee/registry/pull/1952) -* Bump nokogiri to 1.11.3 [#1961](https://github.com/internetee/registry/pull/1961) * Bump bootsnap to 1.7.4 [#1963](https://github.com/internetee/registry/pull/1963) * Bump truemail to 2.4.0 [#1964](https://github.com/internetee/registry/pull/1964) From 759254d95482fa29515a7d17e62470654c852348 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Tue, 4 May 2021 14:37:50 +0300 Subject: [PATCH 30/61] change response message --- .../repp/v1/registrar/notifications_controller.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/repp/v1/registrar/notifications_controller.rb b/app/controllers/repp/v1/registrar/notifications_controller.rb index 23be6d7b7..b2406a52d 100644 --- a/app/controllers/repp/v1/registrar/notifications_controller.rb +++ b/app/controllers/repp/v1/registrar/notifications_controller.rb @@ -22,6 +22,7 @@ module Repp desc 'Get the all unread poll messages' def all_notifications records = current_user.unread_notifications.order('created_at DESC').all + @notification = records.limit(limit).offset(offset) # rubocop:disable Style/AndOr render_success(data: nil) and return unless @notification @@ -29,7 +30,10 @@ module Repp data = @notification.as_json(only: %i[id text attached_obj_id attached_obj_type]) - render_success(data: data) + default_count = 200 + + message = "Command completed successfully. The total notifications are #{records.count}. Returns only #{@notification.count}. Limit by default is #{limit}. To change the amount of data returned, use the parameters limit and offset in url." + render_success(data: data, message: message) end api :GET, '/repp/v1/registrar/notifications/:notification_id' From 62177078c26e4117568b853cc3a5d25484d7eda0 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Tue, 4 May 2021 14:42:09 +0300 Subject: [PATCH 31/61] refactoring --- .../repp/v1/registrar/notifications_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/repp/v1/registrar/notifications_controller.rb b/app/controllers/repp/v1/registrar/notifications_controller.rb index b2406a52d..1185a1a73 100644 --- a/app/controllers/repp/v1/registrar/notifications_controller.rb +++ b/app/controllers/repp/v1/registrar/notifications_controller.rb @@ -30,9 +30,9 @@ module Repp data = @notification.as_json(only: %i[id text attached_obj_id attached_obj_type]) - default_count = 200 - - message = "Command completed successfully. The total notifications are #{records.count}. Returns only #{@notification.count}. Limit by default is #{limit}. To change the amount of data returned, use the parameters limit and offset in url." + message = 'Command completed successfully.'\ + " Returning #{@notification.count} out of #{records.count}."\ + ' Use URL parameters :limit and :offset to list other messages if needed.' render_success(data: data, message: message) end From 83f3e14330b6a6050e3aa4e6a4a4f651cf244107 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 May 2021 05:03:54 +0000 Subject: [PATCH 32/61] Bump rails from 6.0.3.6 to 6.1.3.1 Bumps [rails](https://github.com/rails/rails) from 6.0.3.6 to 6.1.3.1. - [Release notes](https://github.com/rails/rails/releases) - [Commits](https://github.com/rails/rails/compare/v6.0.3.6...v6.1.3.1) Signed-off-by: dependabot[bot] --- Gemfile.lock | 127 ++++++++++++++++++++++++++------------------------- 1 file changed, 65 insertions(+), 62 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 116f8bd9b..166895691 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -76,65 +76,69 @@ GIT GEM remote: https://rubygems.org/ specs: - actioncable (6.0.3.6) - actionpack (= 6.0.3.6) + actioncable (6.1.3.1) + actionpack (= 6.1.3.1) + activesupport (= 6.1.3.1) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (6.0.3.6) - actionpack (= 6.0.3.6) - activejob (= 6.0.3.6) - activerecord (= 6.0.3.6) - activestorage (= 6.0.3.6) - activesupport (= 6.0.3.6) + actionmailbox (6.1.3.1) + actionpack (= 6.1.3.1) + activejob (= 6.1.3.1) + activerecord (= 6.1.3.1) + activestorage (= 6.1.3.1) + activesupport (= 6.1.3.1) mail (>= 2.7.1) - actionmailer (6.0.3.6) - actionpack (= 6.0.3.6) - actionview (= 6.0.3.6) - activejob (= 6.0.3.6) + actionmailer (6.1.3.1) + actionpack (= 6.1.3.1) + actionview (= 6.1.3.1) + activejob (= 6.1.3.1) + activesupport (= 6.1.3.1) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (6.0.3.6) - actionview (= 6.0.3.6) - activesupport (= 6.0.3.6) - rack (~> 2.0, >= 2.0.8) + actionpack (6.1.3.1) + actionview (= 6.1.3.1) + activesupport (= 6.1.3.1) + rack (~> 2.0, >= 2.0.9) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.0.3.6) - actionpack (= 6.0.3.6) - activerecord (= 6.0.3.6) - activestorage (= 6.0.3.6) - activesupport (= 6.0.3.6) + actiontext (6.1.3.1) + actionpack (= 6.1.3.1) + activerecord (= 6.1.3.1) + activestorage (= 6.1.3.1) + activesupport (= 6.1.3.1) nokogiri (>= 1.8.5) - actionview (6.0.3.6) - activesupport (= 6.0.3.6) + actionview (6.1.3.1) + activesupport (= 6.1.3.1) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) active_interaction (4.0.0) activemodel (>= 5, < 7) - activejob (6.0.3.6) - activesupport (= 6.0.3.6) + activejob (6.1.3.1) + activesupport (= 6.1.3.1) globalid (>= 0.3.6) - activemodel (6.0.3.6) - activesupport (= 6.0.3.6) - activerecord (6.0.3.6) - activemodel (= 6.0.3.6) - activesupport (= 6.0.3.6) + activemodel (6.1.3.1) + activesupport (= 6.1.3.1) + activerecord (6.1.3.1) + activemodel (= 6.1.3.1) + activesupport (= 6.1.3.1) activerecord-import (1.0.8) activerecord (>= 3.2) - activestorage (6.0.3.6) - actionpack (= 6.0.3.6) - activejob (= 6.0.3.6) - activerecord (= 6.0.3.6) + activestorage (6.1.3.1) + actionpack (= 6.1.3.1) + activejob (= 6.1.3.1) + activerecord (= 6.1.3.1) + activesupport (= 6.1.3.1) marcel (~> 1.0.0) - activesupport (6.0.3.6) + mini_mime (~> 1.0.2) + activesupport (6.1.3.1) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - zeitwerk (~> 2.2, >= 2.2.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) addressable (2.7.0) public_suffix (>= 2.0.2, < 5.0) aes_key_wrap (1.1.0) @@ -289,7 +293,7 @@ GEM mimemagic (0.4.3) nokogiri (~> 1) rake - mini_mime (1.1.0) + mini_mime (1.0.3) mini_portile2 (2.5.1) minitest (5.14.4) monetize (1.9.4) @@ -358,32 +362,32 @@ GEM rack rack-test (1.1.0) rack (>= 1.0, < 3) - rails (6.0.3.6) - actioncable (= 6.0.3.6) - actionmailbox (= 6.0.3.6) - actionmailer (= 6.0.3.6) - actionpack (= 6.0.3.6) - actiontext (= 6.0.3.6) - actionview (= 6.0.3.6) - activejob (= 6.0.3.6) - activemodel (= 6.0.3.6) - activerecord (= 6.0.3.6) - activestorage (= 6.0.3.6) - activesupport (= 6.0.3.6) - bundler (>= 1.3.0) - railties (= 6.0.3.6) + rails (6.1.3.1) + actioncable (= 6.1.3.1) + actionmailbox (= 6.1.3.1) + actionmailer (= 6.1.3.1) + actionpack (= 6.1.3.1) + actiontext (= 6.1.3.1) + actionview (= 6.1.3.1) + activejob (= 6.1.3.1) + activemodel (= 6.1.3.1) + activerecord (= 6.1.3.1) + activestorage (= 6.1.3.1) + activesupport (= 6.1.3.1) + bundler (>= 1.15.0) + railties (= 6.1.3.1) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) rails-html-sanitizer (1.3.0) loofah (~> 2.3) - railties (6.0.3.6) - actionpack (= 6.0.3.6) - activesupport (= 6.0.3.6) + railties (6.1.3.1) + actionpack (= 6.1.3.1) + activesupport (= 6.1.3.1) method_source rake (>= 0.8.7) - thor (>= 0.20.3, < 2.0) + thor (~> 1.0) rake (13.0.3) ransack (2.4.2) activerecord (>= 5.2.4) @@ -459,12 +463,11 @@ GEM httpclient (>= 2.4) temple (0.8.2) thor (1.1.0) - thread_safe (0.3.6) tilt (2.0.10) truemail (2.4.0) simpleidn (~> 0.2.1) - tzinfo (1.2.9) - thread_safe (~> 0.1) + tzinfo (2.0.4) + concurrent-ruby (~> 1.0) uglifier (4.2.0) execjs (>= 0.3.0, < 3) unf (0.1.4) @@ -558,7 +561,7 @@ DEPENDENCIES puma que que-web - rails (~> 6.0) + rails (~> 6.1) ransack (~> 2.3) rest-client rexml From 39bbe6e06dcf994c44772837bfa704d18c596db5 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Mon, 3 May 2021 13:40:42 +0500 Subject: [PATCH 33/61] Refactor deprecated in rails 6.1 issues --- .../admin/admin_users_controller.rb | 2 +- app/helpers/sorted_country_helper.rb | 32 ++++++++ app/models/sorted_country.rb | 40 ---------- app/views/admin/admin_users/_form.haml | 6 +- app/views/admin/contacts/index.haml | 2 +- .../admin/registrars/form/_address.html.erb | 4 +- .../registrar/contacts/_search_form.html.erb | 2 +- .../registrar/contacts/form/_address.haml | 2 +- .../registrar/contacts/form/_general.haml | 2 +- db/structure.sql | 80 +++++++++++++++++++ 10 files changed, 122 insertions(+), 50 deletions(-) create mode 100644 app/helpers/sorted_country_helper.rb delete mode 100644 app/models/sorted_country.rb diff --git a/app/controllers/admin/admin_users_controller.rb b/app/controllers/admin/admin_users_controller.rb index 8e72fd274..3d0c4280b 100644 --- a/app/controllers/admin/admin_users_controller.rb +++ b/app/controllers/admin/admin_users_controller.rb @@ -34,7 +34,7 @@ module Admin params[:admin_user].delete(:password) if params[:admin_user][:password].blank? params[:admin_user].delete(:password_confirmation) if params[:admin_user][:password_confirmation].blank? - if @admin_user.update_attributes(admin_user_params) + if @admin_user.update(admin_user_params) flash[:notice] = I18n.t('record_updated') redirect_to [:admin, @admin_user] else diff --git a/app/helpers/sorted_country_helper.rb b/app/helpers/sorted_country_helper.rb new file mode 100644 index 000000000..af08210be --- /dev/null +++ b/app/helpers/sorted_country_helper.rb @@ -0,0 +1,32 @@ +module SortedCountryHelper + def all_country_options(selected = nil) + quick_options = options_for_select(quick_list, selected: selected) + + # no double select + selected = quick_list.map(&:second).include?(selected) ? '' : selected + + all_options = options_for_select([['---', '---']] + all_sorted_truncated, + selected: selected, disabled: ['---']) + quick_options + all_options + end + + def quick_list + [ + %w[Estonia EE], + %w[Finland FI], + %w[Latvia LV], + %w[Lithuania LT], + ['Russian Federation', 'RU'], + %w[Sweden SE], + ['United States', 'US'], + ] + end + + def all_sorted + Country.all.sort_by(&:name) + end + + def all_sorted_truncated + all_sorted.map { |country| [country.name.truncate(26), country.alpha2] } + end +end diff --git a/app/models/sorted_country.rb b/app/models/sorted_country.rb deleted file mode 100644 index 7b27adacb..000000000 --- a/app/models/sorted_country.rb +++ /dev/null @@ -1,40 +0,0 @@ -class SortedCountry - class << self - include ActionView::Helpers - - def all_options(selected = nil) - quick_options = options_for_select(quick_list, selected: selected) - - # no double select - selected = quick_list.map(&:second).include?(selected) ? '' : selected - - all_options = options_for_select([['---', '---']] + all_sorted_truncated, - selected: selected, disabled: ['---']) - quick_options + all_options - end - - private - - def quick_list - @quick_list ||= - [ - %w[Estonia EE], - %w[Finland FI], - %w[Latvia LV], - %w[Lithuania LT], - ['Russian Federation', 'RU'], - %w[Sweden SE], - ['United States', 'US'] - ] - end - - def all_sorted - @all_sorted ||= Country.all.sort_by(&:name) - end - - def all_sorted_truncated - @all_sorted_truncated ||= - all_sorted.map { |country| [country.name.truncate(26), country.alpha2] } - end - end -end diff --git a/app/views/admin/admin_users/_form.haml b/app/views/admin/admin_users/_form.haml index ddee458ba..d23ff40cb 100644 --- a/app/views/admin/admin_users/_form.haml +++ b/app/views/admin/admin_users/_form.haml @@ -35,14 +35,14 @@ .col-md-4.control-label = f.label :country_code, t(:country), class: 'required' .col-md-8 - = f.select :country_code, SortedCountry.all_options(f.object.country_code), {}, required: true, class: 'form-control' + = f.select :country_code, ApplicationController.helpers.all_country_options(f.object.country_code), {}, required: true, class: 'form-control' %hr .form-group .col-md-4.control-label = f.label :role, nil, class: 'required' .col-md-8 - = select_tag 'admin_user[roles][]', - options_for_select(AdminUser::ROLES.map {|x| [t(x), x] }, + = select_tag 'admin_user[roles][]', + options_for_select(AdminUser::ROLES.map {|x| [t(x), x] }, @admin_user.roles.try(:first)), class: 'form-control selectize' %hr diff --git a/app/views/admin/contacts/index.haml b/app/views/admin/contacts/index.haml index cbd11d3fc..7da4f4ab7 100644 --- a/app/views/admin/contacts/index.haml +++ b/app/views/admin/contacts/index.haml @@ -28,7 +28,7 @@ .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' } + = select_tag '[q][country_code_eq]', ApplicationController.helpers.all_country_options(params[:q][:country_code_eq]), { include_blank: true, placeholder: t(:choose), class: 'form-control selectize' } .col-md-6 .form-group = label_tag t(:contact_type) diff --git a/app/views/admin/registrars/form/_address.html.erb b/app/views/admin/registrars/form/_address.html.erb index ccac2b03e..4d52aa591 100644 --- a/app/views/admin/registrars/form/_address.html.erb +++ b/app/views/admin/registrars/form/_address.html.erb @@ -49,7 +49,7 @@
<%= f.select :address_country_code, - SortedCountry.all_options(f.object.address_country_code), {}, + ApplicationController.helpers.all_country_options(f.object.address_country_code), {}, required: true, class: 'form-control' %> <%= t '.country_hint' %>
@@ -59,4 +59,4 @@ - \ No newline at end of file + diff --git a/app/views/registrar/contacts/_search_form.html.erb b/app/views/registrar/contacts/_search_form.html.erb index e15ff1880..73c1281e0 100644 --- a/app/views/registrar/contacts/_search_form.html.erb +++ b/app/views/registrar/contacts/_search_form.html.erb @@ -40,7 +40,7 @@
<%= 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' } %> + <%= select_tag '[q][country_code_eq]', ApplicationController.helpers.all_country_options(params[:q][:country_code_eq]), { include_blank: true, placeholder: t(:choose), class: 'form-control selectize' } %>
diff --git a/app/views/registrar/contacts/form/_address.haml b/app/views/registrar/contacts/form/_address.haml index 1d9ae5869..7789c2891 100644 --- a/app/views/registrar/contacts/form/_address.haml +++ b/app/views/registrar/contacts/form/_address.haml @@ -31,6 +31,6 @@ = f.label :country_code, t(:country) + '*' .col-md-7 - country_selected = f.object.persisted? ? f.object.country_code : 'EE' - = f.select(:country_code, SortedCountry.all_options(country_selected), + = f.select(:country_code, SApplicationController.helpers.all_country_options(country_selected), { include_blank: true }, required: true) diff --git a/app/views/registrar/contacts/form/_general.haml b/app/views/registrar/contacts/form/_general.haml index b8ff90965..d7fcea38a 100644 --- a/app/views/registrar/contacts/form/_general.haml +++ b/app/views/registrar/contacts/form/_general.haml @@ -19,7 +19,7 @@ = Country.new(f.object.ident_country_code).try(:to_s) = " [#{f.object.ident_country_code}]" - else - = f.select(:ident_country_code, SortedCountry.all_options(country_selected), {}, + = f.select(:ident_country_code, ApplicationController.helpers.all_country_options(country_selected), {}, class: 'js-ident-country-code', required: true) .form-group diff --git a/db/structure.sql b/db/structure.sql index 01565d2f9..c30e507e4 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -536,6 +536,43 @@ CREATE SEQUENCE public.certificates_id_seq ALTER SEQUENCE public.certificates_id_seq OWNED BY public.certificates.id; +-- +-- Name: contact_requests; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.contact_requests ( + id integer NOT NULL, + whois_record_id integer NOT NULL, + secret character varying NOT NULL, + email character varying NOT NULL, + name character varying NOT NULL, + valid_to timestamp without time zone NOT NULL, + status character varying DEFAULT 'new'::character varying NOT NULL, + ip_address inet, + created_at timestamp without time zone NOT NULL, + updated_at timestamp without time zone NOT NULL, + message_id character varying +); + + +-- +-- Name: contact_requests_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.contact_requests_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: contact_requests_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.contact_requests_id_seq OWNED BY public.contact_requests.id; + -- -- Name: contacts; Type: TABLE; Schema: public; Owner: - -- @@ -2735,6 +2772,13 @@ ALTER TABLE ONLY public.bounced_mail_addresses ALTER COLUMN id SET DEFAULT nextv ALTER TABLE ONLY public.certificates ALTER COLUMN id SET DEFAULT nextval('public.certificates_id_seq'::regclass); +-- +-- Name: contact_requests id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.contact_requests ALTER COLUMN id SET DEFAULT nextval('public.contact_requests_id_seq'::regclass); + + -- -- Name: contacts id; Type: DEFAULT; Schema: public; Owner: - -- @@ -3193,6 +3237,14 @@ ALTER TABLE ONLY public.certificates ADD CONSTRAINT certificates_pkey PRIMARY KEY (id); +-- +-- Name: contact_requests contact_requests_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.contact_requests + ADD CONSTRAINT contact_requests_pkey PRIMARY KEY (id); + + -- -- Name: contacts contacts_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -3780,6 +3832,34 @@ CREATE INDEX index_accounts_on_registrar_id ON public.accounts USING btree (regi CREATE INDEX index_certificates_on_api_user_id ON public.certificates USING btree (api_user_id); +-- +-- Name: index_contact_requests_on_email; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_contact_requests_on_email ON public.contact_requests USING btree (email); + + +-- +-- Name: index_contact_requests_on_ip_address; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_contact_requests_on_ip_address ON public.contact_requests USING btree (ip_address); + + +-- +-- Name: index_contact_requests_on_secret; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_contact_requests_on_secret ON public.contact_requests USING btree (secret); + + +-- +-- Name: index_contact_requests_on_whois_record_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_contact_requests_on_whois_record_id ON public.contact_requests USING btree (whois_record_id); + + -- -- Name: index_contacts_on_code; Type: INDEX; Schema: public; Owner: - -- From c613de1a1157f9d8b59b950d787b7945a24fabf7 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Mon, 3 May 2021 14:51:13 +0500 Subject: [PATCH 34/61] Refactor epp error due to Rails 6.1 changes --- app/controllers/repp/v1/base_controller.rb | 2 +- app/controllers/repp/v1/domains_controller.rb | 2 +- app/interactions/actions/domain_transfer.rb | 4 ++-- app/models/concerns/epp_errors.rb | 7 ++++--- test/integration/repp/v1/domains/transfer_test.rb | 8 ++++---- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/controllers/repp/v1/base_controller.rb b/app/controllers/repp/v1/base_controller.rb index 53519195c..a1ae1b0a3 100644 --- a/app/controllers/repp/v1/base_controller.rb +++ b/app/controllers/repp/v1/base_controller.rb @@ -67,7 +67,7 @@ module Repp @epp_errors ||= [] obj&.construct_epp_errors - @epp_errors += obj.errors[:epp_errors] if obj + @epp_errors += obj.errors.where(:epp_errors).map(&:options) if obj format_epp_errors if update @epp_errors.uniq! diff --git a/app/controllers/repp/v1/domains_controller.rb b/app/controllers/repp/v1/domains_controller.rb index b058f4505..a4f518ba2 100644 --- a/app/controllers/repp/v1/domains_controller.rb +++ b/app/controllers/repp/v1/domains_controller.rb @@ -151,7 +151,7 @@ module Repp @successful << { type: 'domain_transfer', domain_name: domain.name } else @errors << { type: 'domain_transfer', domain_name: domain.name, - errors: domain.errors[:epp_errors] } + errors: domain.errors.where(:epp_errors)[0].options } end end diff --git a/app/interactions/actions/domain_transfer.rb b/app/interactions/actions/domain_transfer.rb index 1ff9aafe9..4da078d78 100644 --- a/app/interactions/actions/domain_transfer.rb +++ b/app/interactions/actions/domain_transfer.rb @@ -13,8 +13,8 @@ module Actions end def call - return unless domain_exists? - return unless valid_transfer_code? + return false unless domain_exists? + return false unless valid_transfer_code? run_validations diff --git a/app/models/concerns/epp_errors.rb b/app/models/concerns/epp_errors.rb index d12080158..6d8ca999a 100644 --- a/app/models/concerns/epp_errors.rb +++ b/app/models/concerns/epp_errors.rb @@ -1,5 +1,8 @@ module EppErrors extend ActiveSupport::Concern + included do + attr_accessor :epp_errors + end def construct_epp_errors epp_errors = [] @@ -19,9 +22,7 @@ module EppErrors epp_errors << collect_parent_errors(attr, errors) end - - errors.add(:epp_errors, epp_errors) - errors[:epp_errors].flatten! + errors.add(:epp_errors, epp_errors) unless epp_errors.empty? end def collect_parent_errors(attr, errors) diff --git a/test/integration/repp/v1/domains/transfer_test.rb b/test/integration/repp/v1/domains/transfer_test.rb index a86395083..5854de195 100644 --- a/test/integration/repp/v1/domains/transfer_test.rb +++ b/test/integration/repp/v1/domains/transfer_test.rb @@ -78,7 +78,7 @@ class ReppV1DomainsTransferTest < ActionDispatch::IntegrationTest assert_equal 1000, json[:code] assert_equal 'Command completed successfully', json[:message] - assert_equal 'Object status prohibits operation', json[:data][:failed][0][:errors][0][:msg] + assert_equal 'Object status prohibits operation', json[:data][:failed][0][:errors][:msg] @domain.reload @@ -100,7 +100,7 @@ class ReppV1DomainsTransferTest < ActionDispatch::IntegrationTest assert_equal 1000, json[:code] assert_equal 'Command completed successfully', json[:message] - assert_equal "Invalid authorization information", json[:data][:failed][0][:errors][0][:msg] + assert_equal "Invalid authorization information", json[:data][:failed][0][:errors][:msg] end def test_does_not_transfer_domain_to_same_registrar @@ -121,7 +121,7 @@ class ReppV1DomainsTransferTest < ActionDispatch::IntegrationTest assert_equal 1000, json[:code] assert_equal 'Command completed successfully', json[:message] - assert_equal 'Domain already belongs to the querying registrar', json[:data][:failed][0][:errors][0][:msg] + assert_equal 'Domain already belongs to the querying registrar', json[:data][:failed][0][:errors][:msg] @domain.reload @@ -146,7 +146,7 @@ class ReppV1DomainsTransferTest < ActionDispatch::IntegrationTest assert_equal 1000, json[:code] assert_equal 'Command completed successfully', json[:message] - assert_equal 'Object is not eligible for transfer', json[:data][:failed][0][:errors][0][:msg] + assert_equal 'Object is not eligible for transfer', json[:data][:failed][0][:errors][:msg] @domain.reload From 1c767d0364b79f4d10311c69791e425cfda503fe Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Mon, 3 May 2021 16:53:41 +0500 Subject: [PATCH 35/61] Fix outdated pdf rendering --- app/models/invoice/pdf_generator.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/models/invoice/pdf_generator.rb b/app/models/invoice/pdf_generator.rb index 2078fad20..a1569dd3a 100644 --- a/app/models/invoice/pdf_generator.rb +++ b/app/models/invoice/pdf_generator.rb @@ -14,9 +14,7 @@ class Invoice private def invoice_html - view = ActionView::Base.new(ActionController::Base.view_paths, invoice: invoice) - view.class_eval { include ApplicationHelper } - view.render(file: 'invoice/pdf', layout: false) + ApplicationController.render(template: 'invoice/pdf', assigns: { invoice: invoice } ) end end -end \ No newline at end of file +end From d6645d47f2dcf328470c162ca3825fe0ba43f904 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Mon, 3 May 2021 16:58:03 +0500 Subject: [PATCH 36/61] Fix broken job queing test --- test/jobs/active_job_queuing_test.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/jobs/active_job_queuing_test.rb b/test/jobs/active_job_queuing_test.rb index 9f60a5b06..2aedc764b 100644 --- a/test/jobs/active_job_queuing_test.rb +++ b/test/jobs/active_job_queuing_test.rb @@ -13,8 +13,9 @@ class ActiveJobQueuingTest < ActiveJob::TestCase def test_job_retried_after_error assert_no_enqueued_jobs - assert_raises StandardError do - assert_performed_jobs 3 do + + assert_performed_jobs 3 do + assert_raises StandardError do TestRetriedJob.perform_later end end From 7be87de86551db686b4633800f841353208dac46 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Mon, 3 May 2021 17:01:56 +0500 Subject: [PATCH 37/61] Remove deprecated render file clauses --- app/controllers/registrar/bulk_change_controller.rb | 6 +++--- app/controllers/registrar/domain_transfers_controller.rb | 2 +- app/controllers/registrar/nameservers_controller.rb | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/registrar/bulk_change_controller.rb b/app/controllers/registrar/bulk_change_controller.rb index 74bbf89e8..b1609a863 100644 --- a/app/controllers/registrar/bulk_change_controller.rb +++ b/app/controllers/registrar/bulk_change_controller.rb @@ -5,7 +5,7 @@ class Registrar def new authorize! :manage, :repp @expire_date = Time.zone.now.to_date - render file: 'registrar/bulk_change/new', locals: { active_tab: default_tab } + render 'registrar/bulk_change/new', locals: { active_tab: default_tab } end def bulk_renew @@ -21,7 +21,7 @@ class Registrar flash[:notice] = nil end - render file: 'registrar/bulk_change/new', locals: { active_tab: :bulk_renew } + render 'registrar/bulk_change/new', locals: { active_tab: :bulk_renew } end private @@ -45,7 +45,7 @@ class Registrar redirect_to registrar_domains_url else @error = response.code == '404' ? 'Contact(s) not found' : parsed_response[:message] - render file: 'registrar/bulk_change/new', locals: { active_tab: active_tab } + render 'registrar/bulk_change/new', locals: { active_tab: active_tab } end end diff --git a/app/controllers/registrar/domain_transfers_controller.rb b/app/controllers/registrar/domain_transfers_controller.rb index e055c38d8..64e3910ec 100644 --- a/app/controllers/registrar/domain_transfers_controller.rb +++ b/app/controllers/registrar/domain_transfers_controller.rb @@ -36,7 +36,7 @@ class Registrar redirect_to registrar_domains_url else @api_errors = parsed_response[:message] - render file: 'registrar/bulk_change/new', locals: { active_tab: :bulk_transfer } + render 'registrar/bulk_change/new', locals: { active_tab: :bulk_transfer } end else params[:request] = true # EPP domain:transfer "op" attribute diff --git a/app/controllers/registrar/nameservers_controller.rb b/app/controllers/registrar/nameservers_controller.rb index 3eb23cd48..852a5e796 100644 --- a/app/controllers/registrar/nameservers_controller.rb +++ b/app/controllers/registrar/nameservers_controller.rb @@ -27,7 +27,7 @@ class Registrar flash: { notice: compose_notice_message(parsed_response) }) else @api_errors = parsed_response[:message] - render file: 'registrar/bulk_change/new', locals: { active_tab: :nameserver } + render 'registrar/bulk_change/new', locals: { active_tab: :nameserver } end end From 72c865e6564f4bb61edc442c0a0b87e0a74636dc Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Mon, 3 May 2021 18:55:03 +0500 Subject: [PATCH 38/61] First iteration of epp error refactoring --- app/controllers/epp/base_controller.rb | 2 +- app/models/concerns/epp_errors.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/epp/base_controller.rb b/app/controllers/epp/base_controller.rb index 820fe9098..db28d5685 100644 --- a/app/controllers/epp/base_controller.rb +++ b/app/controllers/epp/base_controller.rb @@ -102,7 +102,7 @@ module Epp if obj obj.construct_epp_errors - @errors += obj.errors[:epp_errors] + @errors += obj.errors.where[:epp_errors].flatten end if params[:parsed_frame]&.at_css('update') diff --git a/app/models/concerns/epp_errors.rb b/app/models/concerns/epp_errors.rb index 6d8ca999a..f1a3b7ede 100644 --- a/app/models/concerns/epp_errors.rb +++ b/app/models/concerns/epp_errors.rb @@ -6,8 +6,8 @@ module EppErrors def construct_epp_errors epp_errors = [] - errors.messages.each do |attr, errors| - attr = attr.to_s.split('.')[0].to_sym + errors.each do |error| + attr = error.attribute.to_s.split('.')[0].to_sym next if attr == :epp_errors if self.class.reflect_on_association(attr) @@ -20,9 +20,9 @@ module EppErrors next end - epp_errors << collect_parent_errors(attr, errors) + epp_errors << collect_parent_errors(attr, error.message) end - errors.add(:epp_errors, epp_errors) unless epp_errors.empty? + errors.add(:epp_errors, epp_errors.flatten) unless epp_errors.empty? end def collect_parent_errors(attr, errors) From d4775ba5c548bde256baf508f32af77de3ed55e2 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Tue, 4 May 2021 13:44:11 +0500 Subject: [PATCH 39/61] Use errors as first-class objects --- app/controllers/epp/base_controller.rb | 118 ++++++++------------- app/controllers/epp/contacts_controller.rb | 50 ++++----- app/controllers/epp/domains_controller.rb | 52 ++++----- app/controllers/epp/errors_controller.rb | 4 +- app/controllers/epp/polls_controller.rb | 10 +- app/controllers/epp/sessions_controller.rb | 63 +++++------ app/models/concerns/epp_errors.rb | 31 +++--- app/views/epp/error.xml.builder | 4 +- 8 files changed, 146 insertions(+), 186 deletions(-) diff --git a/app/controllers/epp/base_controller.rb b/app/controllers/epp/base_controller.rb index db28d5685..4e3ea32d1 100644 --- a/app/controllers/epp/base_controller.rb +++ b/app/controllers/epp/base_controller.rb @@ -28,27 +28,24 @@ module Epp protected def respond_with_command_failed_error(exception) - epp_errors << { - code: '2400', - msg: 'Command failed', - } + epp_errors.add(:epp_errors, + code: '2400', + message: 'Command failed') handle_errors log_exception(exception) end def respond_with_object_does_not_exist_error - epp_errors << { - code: '2303', - msg: 'Object does not exist', - } + epp_errors.add(:epp_errors, + code: '2303', + msg: 'Object does not exist') handle_errors end def respond_with_authorization_error - epp_errors << { - code: '2201', - msg: 'Authorization error', - } + epp_errors.add(:epp_errors, + code: '2201', + msg: 'Authorization error') handle_errors end @@ -63,10 +60,9 @@ module Epp def validate_against_schema return if %w[hello error].include?(params[:action]) schema.validate(params[:nokogiri_frame]).each do |error| - epp_errors << { - code: 2001, - msg: error - } + epp_errors.add(:epp_errors, + code: 2001, + msg: error) end handle_errors and return if epp_errors.any? end @@ -94,7 +90,7 @@ module Epp # ERROR + RESPONSE HANDLING def epp_errors - @errors ||= [] + @errors ||= ActiveModel::Errors.new(self) end def handle_errors(obj = nil) @@ -102,21 +98,9 @@ module Epp if obj obj.construct_epp_errors - @errors += obj.errors.where[:epp_errors].flatten + obj.errors.each { |error| @errors.import error } end - if params[:parsed_frame]&.at_css('update') - @errors.each_with_index do |errors, index| - if errors[:code] == '2304' && - errors[:value].present? && - errors[:value][:val] == DomainStatus::SERVER_DELETE_PROHIBITED && - errors[:value][:obj] == 'status' - @errors[index][:value][:val] = DomainStatus::PENDING_UPDATE - end - end - end - @errors.uniq! - render_epp_response '/epp/error' end @@ -133,10 +117,9 @@ module Epp return true end - epp_errors << { - msg: 'Parameter value policy error. Allowed only Latin characters.', - code: '2306' - } + epp_errors.add(:epp_errors, + msg: 'Parameter value policy error. Allowed only Latin characters.', + code: '2306') handle_errors and return false end @@ -180,10 +163,9 @@ module Epp else missing = el.present? ? el.text.blank? : true end - epp_errors << { - code: '2003', - msg: I18n.t('errors.messages.required_parameter_missing', key: "#{full_selector} [#{attr}]") - } if missing + epp_errors.add(:epp_errors, + code: '2003', + message: I18n.t('errors.messages.required_parameter_missing', key: "#{full_selector} [#{attr}]")) if missing end missing ? false : el # return last selector if it was present @@ -201,25 +183,22 @@ module Epp attribute = element[attribute_selector] unless attribute - epp_errors << { - code: '2003', - msg: I18n.t('errors.messages.required_parameter_missing', key: attribute_selector) - } + epp_errors.add(:epp_errors, + code: '2003', + msg: I18n.t('errors.messages.required_parameter_missing', key: attribute_selector)) return end return if options[:values].include?(attribute) if options[:policy] - epp_errors << { - code: '2306', - msg: I18n.t('attribute_is_invalid', attribute: attribute_selector) - } + epp_errors.add(:epp_errors, + code: '2306', + msg: I18n.t('attribute_is_invalid', attribute: attribute_selector)) else - epp_errors << { - code: '2004', - msg: I18n.t('parameter_value_range_error', key: attribute_selector) - } + epp_errors.add(:epp_errors, + code: '2004', + msg: I18n.t('parameter_value_range_error', key: attribute_selector)) end end @@ -231,30 +210,27 @@ module Epp attribute = element[attribute_selector] return if (attribute && options[:values].include?(attribute)) || !attribute - epp_errors << { - code: '2306', - msg: I18n.t('attribute_is_invalid', attribute: attribute_selector) - } + epp_errors.add(:epp_errors, + code: '2306', + msg: I18n.t('attribute_is_invalid', attribute: attribute_selector)) end def exactly_one_of(*selectors) full_selectors = create_full_selectors(*selectors) return if element_count(*full_selectors, use_prefix: false) == 1 - epp_errors << { - code: '2306', - msg: I18n.t(:exactly_one_parameter_required, params: full_selectors.join(' OR ')) - } + epp_errors.add(:epp_errors, + code: '2306', + msg: I18n.t(:exactly_one_parameter_required, params: full_selectors.join(' OR '))) end def mutually_exclusive(*selectors) full_selectors = create_full_selectors(*selectors) return if element_count(*full_selectors, use_prefix: false) <= 1 - epp_errors << { - code: '2306', - msg: I18n.t(:mutally_exclusive_params, params: full_selectors.join(', ')) - } + epp_errors.add(:epp_errors, + code: '2306', + msg: I18n.t(:mutally_exclusive_params, params: full_selectors.join(', '))) end def optional(selector, *validations) @@ -265,8 +241,8 @@ module Epp validations.each do |x| validator = "#{x.first[0]}_validator".camelize.constantize - err = validator.validate_epp(selector.split(' ').last, value) - epp_errors << err if err + result = validator.validate_epp(selector.split(' ').last, value) + epp_errors.add(:epp_errors, result) if result end end @@ -297,10 +273,9 @@ module Epp def xml_attrs_present?(ph, attributes) # TODO: THIS IS DEPRECATED AND WILL BE REMOVED IN FUTURE attributes.each do |x| - epp_errors << { - code: '2003', - msg: I18n.t('errors.messages.required_parameter_missing', key: x.last) - } unless has_attribute(ph, x) + epp_errors.add(:epp_errors, + code: '2003', + msg: I18n.t('errors.messages.required_parameter_missing', key: x.last)) unless has_attribute(ph, x) end epp_errors.empty? end @@ -355,10 +330,9 @@ module Epp def enforce_epp_session_timeout if epp_session.timed_out? - epp_errors << { - code: '2201', - msg: 'Authorization error: Session timeout', - } + epp_errors.add(:epp_errors, + code: '2201', + msg: 'Authorization error: Session timeout') handle_errors epp_session.destroy! else diff --git a/app/controllers/epp/contacts_controller.rb b/app/controllers/epp/contacts_controller.rb index 65354ff48..7d81c6e54 100644 --- a/app/controllers/epp/contacts_controller.rb +++ b/app/controllers/epp/contacts_controller.rb @@ -72,9 +72,10 @@ module Epp end def action_call_response(action:) - # rubocop:disable Style/AndOr - (handle_errors(@contact) and return) unless action.call - # rubocop:enable Style/AndOr + unless action.call + handle_errors(@contact) + return + end if opt_addr? @response_code = 1100 @@ -134,24 +135,16 @@ module Epp ident = params[:parsed_frame].css('ident') if ident.present? && ident.attr('type').blank? - epp_errors << { - code: '2003', - msg: I18n.t('errors.messages.required_ident_attribute_missing', key: 'type') - } + epp_errors.add(:epp_errors, + code: '2003', + msg: I18n.t('errors.messages.required_ident_attribute_missing', key: 'type')) end if ident.present? && ident.text != 'birthday' && ident.attr('cc').blank? - epp_errors << { - code: '2003', - msg: I18n.t('errors.messages.required_ident_attribute_missing', key: 'cc') - } + epp_errors.add(:epp_errors, + code: '2003', + msg: I18n.t('errors.messages.required_ident_attribute_missing', key: 'cc')) end - # if ident.present? && ident.attr('cc').blank? - # epp_errors << { - # code: '2003', - # msg: I18n.t('errors.messages.required_ident_attribute_missing', key: 'cc') - # } - # end contact_org_disabled fax_disabled status_editing_disabled @@ -178,28 +171,27 @@ module Epp return true if ENV['contact_org_enabled'] == 'true' return true if params[:parsed_frame].css('postalInfo org').text.blank? - epp_errors << { - code: '2306', - msg: "#{I18n.t(:contact_org_error)}: postalInfo > org [org]" - } + epp_errors.add(:epp_errors, + code: '2306', + msg: "#{I18n.t(:contact_org_error)}: postalInfo > org [org]" + ) end def fax_disabled return true if ENV['fax_enabled'] == 'true' return true if params[:parsed_frame].css('fax').text.blank? - epp_errors << { - code: '2306', - msg: "#{I18n.t(:contact_fax_error)}: fax [fax]" - } + epp_errors.add(:epp_errors, + code: '2306', + msg: "#{I18n.t(:contact_fax_error)}: fax [fax]") end def status_editing_disabled return true if Setting.client_status_editing_enabled return true if params[:parsed_frame].css('status').empty? - epp_errors << { - code: '2306', - msg: "#{I18n.t(:client_side_status_editing_error)}: status [status]" - } + epp_errors.add(:epp_errors, + code: '2306', + msg: "#{I18n.t(:client_side_status_editing_error)}: status [status]" + ) end def address_given? diff --git a/app/controllers/epp/domains_controller.rb b/app/controllers/epp/domains_controller.rb index 47a40857a..d2ec74fa9 100644 --- a/app/controllers/epp/domains_controller.rb +++ b/app/controllers/epp/domains_controller.rb @@ -90,10 +90,9 @@ module Epp action = params[:parsed_frame].css('transfer').first[:op] if @domain.non_transferable? - epp_errors << { - code: '2304', - msg: I18n.t(:object_status_prohibits_operation), - } + epp_errors.add(:epp_errors, + code: '2304', + msg: I18n.t(:object_status_prohibits_operation)) handle_errors return end @@ -102,10 +101,9 @@ module Epp wrong_transfer_code = provided_transfer_code != @domain.transfer_code if wrong_transfer_code - epp_errors << { - code: '2202', - msg: 'Invalid authorization information', - } + epp_errors.add(:epp_errors, + code: '2202', + msg: 'Invalid authorization information') handle_errors return end @@ -120,10 +118,9 @@ module Epp if @domain_transfer render_epp_response '/epp/domains/transfer' else - epp_errors << { - code: '2303', - msg: I18n.t('no_transfers_found') - } + epp_errors.add(:epp_errors, + code: '2303', + msg: I18n.t('no_transfers_found')) handle_errors end end @@ -184,11 +181,10 @@ module Epp def validate_transfer # period element is disabled for now if params[:parsed_frame].css('period').any? - epp_errors << { - code: '2307', - msg: I18n.t(:unimplemented_object_service), - value: { obj: 'period' } - } + epp_errors.add(:epp_errors, + code: '2307', + msg: I18n.t(:unimplemented_object_service), + value: { obj: 'period' }) end requires 'transfer > transfer' @@ -217,10 +213,10 @@ module Epp return true if Setting.client_status_editing_enabled return true if check_client_hold return true if params[:parsed_frame].css('status').empty? - epp_errors << { - code: '2306', - msg: "#{I18n.t(:client_side_status_editing_error)}: status [status]" - } + epp_errors.add(:epp_errors, + code: '2306', + msg: "#{I18n.t(:client_side_status_editing_error)}: status [status]" + ) end def check_client_hold @@ -232,17 +228,15 @@ module Epp @domain_pricelist = @domain.pricelist(operation, period.try(:to_i), unit) if @domain_pricelist.try(:price) # checking if price list is not found if current_user.registrar.balance < @domain_pricelist.price.amount - epp_errors << { - code: '2104', - msg: I18n.t('billing_failure_credit_balance_low') - } + epp_errors.add(:epp_errors, + code: '2104', + msg: I18n.t('billing_failure_credit_balance_low')) return false end else - epp_errors << { - code: '2104', - msg: I18n.t(:active_price_missing_for_this_operation) - } + epp_errors.add(:epp_errors, + code: '2104', + msg: I18n.t(:active_price_missing_for_this_operation)) return false end true diff --git a/app/controllers/epp/errors_controller.rb b/app/controllers/epp/errors_controller.rb index 6cb689166..e9f1ecea8 100644 --- a/app/controllers/epp/errors_controller.rb +++ b/app/controllers/epp/errors_controller.rb @@ -3,12 +3,12 @@ module Epp skip_authorization_check def error - epp_errors << { code: params[:code], msg: params[:msg] } + epp_errors.add(:epp_errors, code: params[:code], msg: params[:msg] ) render_epp_response '/epp/error' end def command_handler - epp_errors << { code: '2000', msg: 'Unknown command' } + epp_errors.add(:epp_errors, code: '2000', msg: 'Unknown command' ) render_epp_response '/epp/error' end end diff --git a/app/controllers/epp/polls_controller.rb b/app/controllers/epp/polls_controller.rb index a93fa300d..86218336b 100644 --- a/app/controllers/epp/polls_controller.rb +++ b/app/controllers/epp/polls_controller.rb @@ -43,11 +43,11 @@ module Epp @notification = current_user.unread_notifications.find_by(id: params[:parsed_frame].css('poll').first['msgID']) unless @notification - epp_errors << { - code: '2303', - msg: I18n.t('message_was_not_found'), - value: { obj: 'msgID', val: params[:parsed_frame].css('poll').first['msgID'] } - } + epp_errors.add(:epp_errors, + code: '2303', + msg: I18n.t('message_was_not_found'), + value: { obj: 'msgID', + val: params[:parsed_frame].css('poll').first['msgID'] }) handle_errors and return end diff --git a/app/controllers/epp/sessions_controller.rb b/app/controllers/epp/sessions_controller.rb index 04603dbe7..dea42458b 100644 --- a/app/controllers/epp/sessions_controller.rb +++ b/app/controllers/epp/sessions_controller.rb @@ -20,10 +20,9 @@ module Epp server_md5 = Certificate.parse_md_from_string(File.read(ENV['cert_path'])) if client_md5 != server_md5 - epp_errors << { - msg: 'Authentication error; server closing connection (certificate is not valid)', - code: '2501' - } + epp_errors.add(:epp_errors, + msg: 'Authentication error; server closing connection (certificate is not valid)', + code: '2501') success = false end @@ -32,56 +31,50 @@ module Epp if !Rails.env.development? && (!webclient_request && @api_user) unless @api_user.pki_ok?(request.env['HTTP_SSL_CLIENT_CERT'], request.env['HTTP_SSL_CLIENT_S_DN_CN']) - epp_errors << { - msg: 'Authentication error; server closing connection (certificate is not valid)', - code: '2501' - } + epp_errors.add(:epp_errors, + msg: 'Authentication error; server closing connection (certificate is not valid)', + code: '2501') success = false end end if success && !@api_user - epp_errors << { - msg: 'Authentication error; server closing connection (API user not found)', - code: '2501' - } + epp_errors.add(:epp_errors, + msg: 'Authentication error; server closing connection (API user not found)', + code: '2501') success = false end if success && !@api_user.try(:active) - epp_errors << { - msg: 'Authentication error; server closing connection (API user is not active)', - code: '2501' - } + epp_errors.add(:epp_errors, + msg: 'Authentication error; server closing connection (API user is not active)', + code: '2501') success = false end if success && @api_user.cannot?(:create, :epp_login) - epp_errors << { - msg: 'Authentication error; server closing connection (API user does not have epp role)', - code: '2501' - } + epp_errors.add(:epp_errors, + msg: 'Authentication error; server closing connection (API user does not have epp role)', + code: '2501') success = false end if success && !ip_white? - epp_errors << { - msg: 'Authentication error; server closing connection (IP is not whitelisted)', - code: '2501' - } + epp_errors.add(:epp_errors, + msg: 'Authentication error; server closing connection (IP is not whitelisted)', + code: '2501') success = false end if success && EppSession.limit_reached?(@api_user.registrar) - epp_errors << { - msg: 'Session limit exceeded; server closing connection (connection limit reached)', - code: '2502', - } + epp_errors.add(:epp_errors, + msg: 'Session limit exceeded; server closing connection (connection limit reached)', + code: '2502') success = false end @@ -98,10 +91,9 @@ module Epp already_authenticated = EppSession.exists?(session_id: epp_session_id) if already_authenticated - epp_errors << { - msg: 'Command use error; Already authenticated', - code: 2002, - } + epp_errors.add(:epp_errors, + msg: 'Command use error; Already authenticated', + code: 2002) handle_errors return end @@ -127,10 +119,9 @@ module Epp def logout unless signed_in? - epp_errors << { - code: 2201, - msg: 'Authorization error' - } + epp_errors.add(:epp_errors, + code: 2201, + msg: 'Authorization error') handle_errors return end diff --git a/app/models/concerns/epp_errors.rb b/app/models/concerns/epp_errors.rb index f1a3b7ede..ba2665ac9 100644 --- a/app/models/concerns/epp_errors.rb +++ b/app/models/concerns/epp_errors.rb @@ -5,35 +5,41 @@ module EppErrors end def construct_epp_errors - epp_errors = [] + epp_errors = ActiveModel::Errors.new(self) errors.each do |error| attr = error.attribute.to_s.split('.')[0].to_sym next if attr == :epp_errors if self.class.reflect_on_association(attr) - epp_errors << collect_child_errors(attr) + collect_child_errors(attr).each do |child_error| + epp_errors.import child_error + end end if self.class.reflect_on_aggregation(attr) aggregation = send(attr) - epp_errors << collect_aggregation_errors(aggregation) + collect_aggregation_errors(aggregation).each do |aggregation_error| + epp_errors.import aggregation_error + end next end - - epp_errors << collect_parent_errors(attr, error.message) + collect_parent_errors(attr, error.message).each do |parent_error| + epp_errors.import parent_error + end end - errors.add(:epp_errors, epp_errors.flatten) unless epp_errors.empty? + epp_errors.each { |epp_error| errors.import epp_error} + errors end def collect_parent_errors(attr, errors) errors = [errors] if errors.is_a?(String) - epp_errors = [] + epp_errors = ActiveModel::Errors.new(self) errors.each do |err| code, value = find_epp_code_and_value(err) next unless code msg = attr.to_sym == :base ? err : "#{err} [#{attr}]" - epp_errors << { code: code, msg: msg, value: value } + epp_errors.add(attr, code: code, msg: msg, value: value) end epp_errors end @@ -41,12 +47,13 @@ module EppErrors def collect_child_errors(attr) macro = self.class.reflect_on_association(attr).macro multi = [:has_and_belongs_to_many, :has_many] - # single = [:belongs_to, :has_one] - epp_errors = [] + epp_errors = ActiveModel::Errors.new(self) send(attr).each do |x| - x.errors.messages.each do |attribute, errors| - epp_errors << x.collect_parent_errors(attribute, errors) + x.errors.each do |error| + x.collect_parent_errors(error.attribute, error.message).each do |parent_error| + epp_errors.import parent_error + end end end if multi.include?(macro) diff --git a/app/views/epp/error.xml.builder b/app/views/epp/error.xml.builder index fceb800b7..bb3ffd117 100644 --- a/app/views/epp/error.xml.builder +++ b/app/views/epp/error.xml.builder @@ -1,6 +1,8 @@ xml.epp_head do xml.response do - @errors.each do |x| + @errors.each do |error| + x = error&.options + next if x.empty? xml.result('code' => x[:code]) do xml.msg(x[:msg], 'lang' => 'en') model_name = resource ? resource.model_name.singular.sub('epp_','') : controller.controller_name.singularize From e15fed2cd014bab2421635496b5bc2e96f967072 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Tue, 4 May 2021 15:19:50 +0500 Subject: [PATCH 40/61] Add epp errors tto the concern itself --- app/controllers/epp/base_controller.rb | 2 +- app/controllers/epp/contacts_controller.rb | 4 ++-- app/controllers/epp/domains_controller.rb | 5 ++++- app/models/concerns/epp_errors.rb | 13 +++++++++++-- app/views/epp/error.xml.builder | 2 +- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/controllers/epp/base_controller.rb b/app/controllers/epp/base_controller.rb index 4e3ea32d1..eb999d857 100644 --- a/app/controllers/epp/base_controller.rb +++ b/app/controllers/epp/base_controller.rb @@ -94,7 +94,7 @@ module Epp end def handle_errors(obj = nil) - @errors ||= [] + @errors ||= ActiveModel::Errors.new(self) if obj obj.construct_epp_errors diff --git a/app/controllers/epp/contacts_controller.rb b/app/controllers/epp/contacts_controller.rb index 7d81c6e54..4d9b6ab0e 100644 --- a/app/controllers/epp/contacts_controller.rb +++ b/app/controllers/epp/contacts_controller.rb @@ -55,13 +55,13 @@ module Epp def renew authorize! :renew, Epp::Contact - epp_errors << { code: '2101', msg: t(:'errors.messages.unimplemented_command') } + epp_errors.add(:epp_errors, code: '2101', msg: t(:'errors.messages.unimplemented_command')) handle_errors end def transfer authorize! :transfer, Epp::Contact - epp_errors << { code: '2101', msg: t(:'errors.messages.unimplemented_command') } + epp_errors.add(:epp_errors, code: '2101', msg: t(:'errors.messages.unimplemented_command')) handle_errors end diff --git a/app/controllers/epp/domains_controller.rb b/app/controllers/epp/domains_controller.rb index d2ec74fa9..f5e32f153 100644 --- a/app/controllers/epp/domains_controller.rb +++ b/app/controllers/epp/domains_controller.rb @@ -44,7 +44,10 @@ module Epp update_params = ::Deserializers::Xml::DomainUpdate.new(params[:parsed_frame], registrar_id).call action = Actions::DomainUpdate.new(@domain, update_params, false) - (handle_errors(@domain) and return) unless action.call + unless action.call + handle_errors(@domain) + return + end pending = @domain.epp_pending_update.present? render_epp_response("/epp/domains/success#{'_pending' if pending}") diff --git a/app/models/concerns/epp_errors.rb b/app/models/concerns/epp_errors.rb index ba2665ac9..22ad83556 100644 --- a/app/models/concerns/epp_errors.rb +++ b/app/models/concerns/epp_errors.rb @@ -113,11 +113,20 @@ module EppErrors end def add_epp_error(code, obj, val, msg) - errors[:epp_errors] ||= [] t = errors.generate_message(*msg) if msg.is_a?(Array) t = msg if msg.is_a?(String) err = { code: code, msg: t } + val = check_for_status(code, obj, val) err[:value] = { val: val, obj: obj } if val.present? - errors[:epp_errors] << err + self.errors.add(:epp_errors, err) + end + + def check_for_status(code, obj, val) + if code == '2304' && val.present? && val == DomainStatus::SERVER_DELETE_PROHIBITED && + obj == 'status' + DomainStatus::PENDING_UPDATE + else + val + end end end diff --git a/app/views/epp/error.xml.builder b/app/views/epp/error.xml.builder index bb3ffd117..9f0bc45e8 100644 --- a/app/views/epp/error.xml.builder +++ b/app/views/epp/error.xml.builder @@ -2,7 +2,7 @@ xml.epp_head do xml.response do @errors.each do |error| x = error&.options - next if x.empty? + next if x.empty? || x == { value: nil } xml.result('code' => x[:code]) do xml.msg(x[:msg], 'lang' => 'en') model_name = resource ? resource.model_name.singular.sub('epp_','') : controller.controller_name.singularize From 0f812d0b1530348a063d83811964315cbf4dde09 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Wed, 5 May 2021 12:40:24 +0500 Subject: [PATCH 41/61] Fixed epp error processing in repp controller --- app/controllers/repp/v1/base_controller.rb | 36 ++++++++-------------- 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/app/controllers/repp/v1/base_controller.rb b/app/controllers/repp/v1/base_controller.rb index a1ae1b0a3..e28f49a87 100644 --- a/app/controllers/repp/v1/base_controller.rb +++ b/app/controllers/repp/v1/base_controller.rb @@ -60,40 +60,28 @@ module Repp end def epp_errors - @epp_errors ||= [] + @epp_errors ||= ActiveModel::Errors.new(self) end def handle_errors(obj = nil, update: false) - @epp_errors ||= [] + @epp_errors ||= ActiveModel::Errors.new(self) - obj&.construct_epp_errors - @epp_errors += obj.errors.where(:epp_errors).map(&:options) if obj - - format_epp_errors if update - @epp_errors.uniq! + if obj + obj.construct_epp_errors + obj.errors.each { |error| @epp_errors.import error } + end render_epp_error end - def format_epp_errors - @epp_errors.each_with_index do |error, index| - blocked_by_delete_prohibited?(error, index) - end - end - - def blocked_by_delete_prohibited?(error, index) - if error[:code] == 2304 && error[:value][:val] == DomainStatus::SERVER_DELETE_PROHIBITED && - error[:value][:obj] == 'status' - - @epp_errors[index][:value][:val] = DomainStatus::PENDING_UPDATE - end - end - def render_epp_error(status = :bad_request, data = {}) - @epp_errors ||= [] - @epp_errors << { code: 2304, msg: 'Command failed' } if data != {} + @epp_errors ||= ActiveModel::Errors.new(self) + @epp_errors.add(:epp_errors, msg: 'Command failed', code: '2304') if data != {} - @response = { code: @epp_errors[0][:code].to_i, message: @epp_errors[0][:msg], data: data } + error_options = @epp_errors.errors.uniq. + select { |error| error.options[:code].present? }[0].options + + @response = { code: error_options[:code].to_i, message: error_options[:msg], data: data } render(json: @response, status: status) end From 79351d50d996071cf631fdc947aa5bc147a5a60f Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Wed, 5 May 2021 13:36:13 +0500 Subject: [PATCH 42/61] Add epp errors support to bulk renew --- .../v1/domains/admin_contacts_controller.rb | 4 +++- .../v1/domains/base_contacts_controller.rb | 8 ++++++-- .../repp/v1/domains/contacts_controller.rb | 4 +++- .../repp/v1/domains/renews_controller.rb | 20 +++++++++++-------- app/controllers/repp/v1/domains_controller.rb | 9 +++++---- app/interactions/domains/bulk_renew/start.rb | 2 +- .../domains/check_balance/mass.rb | 6 +++++- .../repp/v1/domains/bulk_renew_test.rb | 11 ++++++---- 8 files changed, 42 insertions(+), 22 deletions(-) diff --git a/app/controllers/repp/v1/domains/admin_contacts_controller.rb b/app/controllers/repp/v1/domains/admin_contacts_controller.rb index 2e9a285eb..6ec0e129b 100644 --- a/app/controllers/repp/v1/domains/admin_contacts_controller.rb +++ b/app/controllers/repp/v1/domains/admin_contacts_controller.rb @@ -6,7 +6,9 @@ module Repp super unless @new_contact.identical_to?(@current_contact) - @epp_errors << { code: 2304, msg: 'Admin contacts must be identical' } + @epp_errors.add(:epp_errors, + msg: 'Admin contacts must be identical', + code: '2304') end return handle_errors if @epp_errors.any? diff --git a/app/controllers/repp/v1/domains/base_contacts_controller.rb b/app/controllers/repp/v1/domains/base_contacts_controller.rb index b601c5313..521ca4ad4 100644 --- a/app/controllers/repp/v1/domains/base_contacts_controller.rb +++ b/app/controllers/repp/v1/domains/base_contacts_controller.rb @@ -15,8 +15,12 @@ module Repp end def update - @epp_errors ||= [] - @epp_errors << { code: 2304, msg: 'New contact must be valid' } if @new_contact.invalid? + @epp_errors ||= ActiveModel::Errors.new(self) + if @new_contact.invalid? + @epp_errors.add(:epp_errors, + msg: 'New contact must be valid', + code: '2304') + end end private diff --git a/app/controllers/repp/v1/domains/contacts_controller.rb b/app/controllers/repp/v1/domains/contacts_controller.rb index 3bde107d1..4c89243c7 100644 --- a/app/controllers/repp/v1/domains/contacts_controller.rb +++ b/app/controllers/repp/v1/domains/contacts_controller.rb @@ -50,7 +50,9 @@ module Repp super if @new_contact == @current_contact - @epp_errors << { code: 2304, msg: 'New contact must be different from current' } + @epp_errors.add(:epp_errors, + msg: 'New contact must be different from current', + code: '2304') end return handle_errors if @epp_errors.any? diff --git a/app/controllers/repp/v1/domains/renews_controller.rb b/app/controllers/repp/v1/domains/renews_controller.rb index c356d799a..f8774a325 100644 --- a/app/controllers/repp/v1/domains/renews_controller.rb +++ b/app/controllers/repp/v1/domains/renews_controller.rb @@ -29,8 +29,8 @@ module Repp renew = run_bulk_renew_task(@domains, bulk_renew_params[:renew_period]) return render_success(data: { updated_domains: @domains.map(&:name) }) if renew.valid? - @epp_errors << { code: 2002, - msg: renew.errors.keys.map { |k, _v| renew.errors[k] }.join(', ') } + msg = renew.errors.keys.map { |k, _v| renew.errors[k] }.join(', ') + @epp_errors.add(:epp_errors, msg: msg , code: '2002') handle_errors end @@ -41,20 +41,20 @@ module Repp end def validate_renew_period - @epp_errors ||= [] + @epp_errors ||= ActiveModel::Errors.new(self) periods = Depp::Domain::PERIODS.map { |p| p[1] } return if periods.include? bulk_renew_params[:renew_period] - @epp_errors << { code: 2005, msg: 'Invalid renew period' } + @epp_errors.add(:epp_errors, msg: 'Invalid renew period' , code: '2005') end def select_renewable_domains - @epp_errors ||= [] + @epp_errors ||= ActiveModel::Errors.new(self) if bulk_renew_params[:domains].instance_of?(Array) @domains = bulk_renew_domains else - @epp_errors << { code: 2005, msg: 'Domains attribute must be an array' } + @epp_errors.add(:epp_errors, msg: 'Domains attribute must be an array' , code: '2005') end return handle_errors if @epp_errors.any? @@ -73,12 +73,16 @@ module Repp end def bulk_renew_domains - @epp_errors ||= [] + @epp_errors ||= ActiveModel::Errors.new(self) domains = [] bulk_renew_params[:domains].each do |idn| domain = Epp::Domain.find_by(name: idn) domains << domain if domain - @epp_errors << { code: 2304, msg: "Object does not exist: #{idn}" } unless domain + unless domain + @epp_errors.add(:epp_errors, + msg: "Object does not exist: #{idn}", + code: '2304') + end end domains diff --git a/app/controllers/repp/v1/domains_controller.rb b/app/controllers/repp/v1/domains_controller.rb index a4f518ba2..422c2295d 100644 --- a/app/controllers/repp/v1/domains_controller.rb +++ b/app/controllers/repp/v1/domains_controller.rb @@ -108,7 +108,7 @@ module Repp api :POST, '/repp/v1/domains/transfer' desc 'Transfer multiple domains' def transfer - @errors ||= [] + @errors ||= ActiveModel::Errors.new(self) @successful = [] transfer_params[:domain_transfers].each do |transfer| @@ -150,8 +150,9 @@ module Repp if action.call @successful << { type: 'domain_transfer', domain_name: domain.name } else - @errors << { type: 'domain_transfer', domain_name: domain.name, - errors: domain.errors.where(:epp_errors)[0].options } + domain.errors.where(:epp_errors).each do |domain_error| + @errors.import domain_error + end end end @@ -187,7 +188,7 @@ module Repp end def set_authorized_domain - @epp_errors ||= [] + @epp_errors ||= ActiveModel::Errors.new(self) @domain = domain_from_url_hash end diff --git a/app/interactions/domains/bulk_renew/start.rb b/app/interactions/domains/bulk_renew/start.rb index f758b52cd..88ad6a83d 100644 --- a/app/interactions/domains/bulk_renew/start.rb +++ b/app/interactions/domains/bulk_renew/start.rb @@ -41,7 +41,7 @@ module Domains end def manage_errors(task) - task.errors.each { |k, v| errors.add(k, v) } unless task.valid? + task.errors.each { |task_error| errors.import task_error } unless task.valid? errors.add(:domain, I18n.t('not_enough_funds')) unless task.result end diff --git a/app/interactions/domains/check_balance/mass.rb b/app/interactions/domains/check_balance/mass.rb index 58af25a9f..55449c8b2 100644 --- a/app/interactions/domains/check_balance/mass.rb +++ b/app/interactions/domains/check_balance/mass.rb @@ -25,7 +25,11 @@ module Domains period: period, unit: unit) - task.valid? ? @total_price += task.result : errors.merge!(task.errors) + if task.valid? + @total_price += task.result + else + task.errors.each { |task_error| errors.import task_error } + end end end end diff --git a/test/integration/repp/v1/domains/bulk_renew_test.rb b/test/integration/repp/v1/domains/bulk_renew_test.rb index 19a3e34fc..510d09f62 100644 --- a/test/integration/repp/v1/domains/bulk_renew_test.rb +++ b/test/integration/repp/v1/domains/bulk_renew_test.rb @@ -92,7 +92,10 @@ class ReppV1DomainsBulkRenewTest < ActionDispatch::IntegrationTest end def test_throws_error_when_not_enough_balance - billing_prices(:renew_one_year).update(price_cents: 99999999) + price = Billing::Price.last + price.price_cents = 99999999 + price.save(validate: false) + payload = { "domains": [ 'invalid.test', @@ -106,7 +109,7 @@ class ReppV1DomainsBulkRenewTest < ActionDispatch::IntegrationTest assert_response :bad_request assert_equal 2002, json[:code] - assert_equal 'Domain Billing failure - credit balance low', json[:message] + assert_equal 'Billing failure - credit balance low', json[:message] end end @@ -128,7 +131,7 @@ class ReppV1DomainsBulkRenewTest < ActionDispatch::IntegrationTest private - def set_status_for_domain(domain, statuses) + def set_status_for_domain(domain, statuses) domain.update(statuses: statuses) if statuses.size > 1 @@ -148,7 +151,7 @@ class ReppV1DomainsBulkRenewTest < ActionDispatch::IntegrationTest def assert_renew_prohibited_domains(domains, payload) assert_no_changes -> { Domain.where(name: domains).pluck(:valid_to) } do json = bulk_renew(payload) - + assert_response :bad_request assert_equal 2002, json[:code] assert domains.all? do |domain| From 991d2d252cd36874464ebc7876d1a5f28f0189d9 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Wed, 5 May 2021 13:53:14 +0500 Subject: [PATCH 43/61] Fixed repp domain transfer --- app/controllers/repp/v1/domains_controller.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/controllers/repp/v1/domains_controller.rb b/app/controllers/repp/v1/domains_controller.rb index 422c2295d..4e1b6bc0d 100644 --- a/app/controllers/repp/v1/domains_controller.rb +++ b/app/controllers/repp/v1/domains_controller.rb @@ -108,13 +108,12 @@ module Repp api :POST, '/repp/v1/domains/transfer' desc 'Transfer multiple domains' def transfer - @errors ||= ActiveModel::Errors.new(self) + @errors ||= [] @successful = [] transfer_params[:domain_transfers].each do |transfer| initiate_transfer(transfer) end - render_success(data: { success: @successful, failed: @errors }) end @@ -150,9 +149,8 @@ module Repp if action.call @successful << { type: 'domain_transfer', domain_name: domain.name } else - domain.errors.where(:epp_errors).each do |domain_error| - @errors.import domain_error - end + @errors << { type: 'domain_transfer', domain_name: domain.name, + errors: domain.errors.where(:epp_errors).first.options } end end @@ -196,7 +194,7 @@ module Repp return if @domain.registrar == current_user.registrar return if @domain.transfer_code.eql?(request.headers['Auth-Code']) - @epp_errors << { code: 2202, msg: I18n.t('errors.messages.epp_authorization_error') } + @epp_errors.add(:epp_errors, code: 2202, msg: I18n.t('errors.messages.epp_authorization_error')) handle_errors end From f22fc2659fe306012b3de2d7ea2cb2b472d798c2 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Wed, 5 May 2021 13:56:49 +0500 Subject: [PATCH 44/61] Fix generation of aggregation-based errors --- app/models/concerns/epp_errors.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/epp_errors.rb b/app/models/concerns/epp_errors.rb index 22ad83556..349969507 100644 --- a/app/models/concerns/epp_errors.rb +++ b/app/models/concerns/epp_errors.rb @@ -61,7 +61,7 @@ module EppErrors end def collect_aggregation_errors(aggregation) - epp_errors = [] + epp_errors = ActiveModel::Errors.new(self) aggregation.errors.details.each do |attr, error_details| error_details.each do |error_detail| @@ -77,7 +77,7 @@ module EppErrors message = "#{aggregation.model_name.human} #{message.camelize(:lower)}" end - epp_errors << { code: epp_code, msg: message } + epp_errors.add(attr, code: epp_code, msg: message) end end end From 838522b81a2edf1420925906097b5a4d74349bd5 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Wed, 5 May 2021 15:41:30 +0500 Subject: [PATCH 45/61] Add support for PG interval field --- .../admin/billing/prices_controller.rb | 10 ++--- app/models/billing/price.rb | 37 +++++++++++-------- .../admin/billing/prices/_price.html.erb | 2 +- test/fixtures/billing/prices.yml | 4 +- test/integration/api/domain_transfers_test.rb | 2 +- test/models/billing/price_test.rb | 32 ++++++++-------- test/models/registrant_verification_test.rb | 2 +- test/system/admin_area/prices_test.rb | 1 - 8 files changed, 47 insertions(+), 43 deletions(-) diff --git a/app/controllers/admin/billing/prices_controller.rb b/app/controllers/admin/billing/prices_controller.rb index 609ebd21e..7bd0c3856 100644 --- a/app/controllers/admin/billing/prices_controller.rb +++ b/app/controllers/admin/billing/prices_controller.rb @@ -40,7 +40,6 @@ module Admin def create @price = ::Billing::Price.new(price_params) - if @price.save flash[:notice] = t('.created') redirect_to_index @@ -50,7 +49,7 @@ module Admin end def update - if @price.update_attributes(price_params) + if @price.update(price_params.compact_blank) flash[:notice] = t('.updated') redirect_to_index else @@ -81,7 +80,9 @@ module Admin valid_to ] - params.require(:price).permit(*allowed_params) + allowed = params.require(:price).permit(*allowed_params) + allowed[:duration] = ActiveSupport::Duration.build(allowed[:duration].to_i) if allowed[:duration] + allowed end def search_params @@ -104,8 +105,7 @@ module Admin end def durations - durations = ::Billing::Price::durations - durations.collect { |duration| [duration.sub('mon', 'month'), duration] } + ::Billing::Price::durations end def statuses diff --git a/app/models/billing/price.rb b/app/models/billing/price.rb index 9cd32f55c..d6705e0be 100644 --- a/app/models/billing/price.rb +++ b/app/models/billing/price.rb @@ -1,5 +1,6 @@ module Billing class Price < ApplicationRecord + attribute :duration, :interval include Billing::Price::Expirable include Versions @@ -8,33 +9,37 @@ module Billing validates :price, :valid_from, :operation_category, :duration, presence: true validates :operation_category, inclusion: { in: Proc.new { |price| price.class.operation_categories } } - validates :duration, inclusion: { in: Proc.new { |price| price.class.durations } } + validates :duration, inclusion: { in: Proc.new { |price| price.class.durations.values } }, if: :should_validate_duration? alias_attribute :effect_time, :valid_from alias_attribute :expire_time, :valid_to monetize :price_cents, allow_nil: true, numericality: { greater_than_or_equal_to: 0 } after_initialize :init_values + def should_validate_duration? + new_record? || duration_changed? + end + def self.operation_categories %w[create renew] end def self.durations - [ - '3 mons', - '6 mons', - '9 mons', - '1 year', - '2 years', - '3 years', - '4 years', - '5 years', - '6 years', - '7 years', - '8 years', - '9 years', - '10 years', - ] + { + '3 months' => 3.months, + '6 months' => 6.months, + '9 months' => 9.months, + '1 year' => 1.year, + '2 years'=> 2.years, + '3 years'=> 3.years, + '4 years'=> 4.years, + '5 years'=> 5.years, + '6 years'=> 6.years, + '7 years'=> 7.years, + '8 years'=> 8.years, + '9 years'=> 9.years, + '10 years'=> 10.years, + } end def self.statuses diff --git a/app/views/admin/billing/prices/_price.html.erb b/app/views/admin/billing/prices/_price.html.erb index 199f53e81..b9f81f8d4 100644 --- a/app/views/admin/billing/prices/_price.html.erb +++ b/app/views/admin/billing/prices/_price.html.erb @@ -1,6 +1,6 @@ <%= link_to price.zone_name, edit_admin_price_path(price), class: 'edit-price-btn' %> - <%= price.duration.sub('mons', 'months') %> + <%= price.duration %> <%= price.operation_category %> <%= number_to_currency price.price %> <%= l price.valid_from, format: :date %> diff --git a/test/fixtures/billing/prices.yml b/test/fixtures/billing/prices.yml index 24aa9f980..4be1bc9d0 100644 --- a/test/fixtures/billing/prices.yml +++ b/test/fixtures/billing/prices.yml @@ -1,5 +1,5 @@ create_one_month: - duration: 3 mons + duration: 3 months price_cents: 100 operation_category: create valid_from: 2010-07-05 @@ -7,7 +7,7 @@ create_one_month: zone: one renew_one_month: - duration: 1 mons + duration: 1 month price_cents: 100 operation_category: renew valid_from: 2010-07-05 diff --git a/test/integration/api/domain_transfers_test.rb b/test/integration/api/domain_transfers_test.rb index 3ed5b0fc6..c56417f4d 100644 --- a/test/integration/api/domain_transfers_test.rb +++ b/test/integration/api/domain_transfers_test.rb @@ -75,7 +75,7 @@ class APIDomainTransfersTest < ApplicationIntegrationTest data: { success: [], failed: [{ type: "domain_transfer", domain_name: "shop.test", - errors: [{:code=>"2304", :msg=>"Object status prohibits operation"}] }], + errors: {:code=>"2304", :msg=>"Object status prohibits operation"} }], }}), JSON.parse(response.body, symbolize_names: true) end diff --git a/test/models/billing/price_test.rb b/test/models/billing/price_test.rb index ccef56910..e87eb3765 100644 --- a/test/models/billing/price_test.rb +++ b/test/models/billing/price_test.rb @@ -65,7 +65,7 @@ class Billing::PriceTest < ActiveSupport::TestCase price.duration = 'invalid' assert price.invalid? - price.duration = Billing::Price.durations.first + price.duration = Billing::Price.durations.values.first assert price.valid? end @@ -75,21 +75,21 @@ class Billing::PriceTest < ActiveSupport::TestCase end def test_returns_durations - durations = [ - '3 mons', - '6 mons', - '9 mons', - '1 year', - '2 years', - '3 years', - '4 years', - '5 years', - '6 years', - '7 years', - '8 years', - '9 years', - '10 years', - ] + durations = { + '3 months' => 3.months, + '6 months' => 6.months, + '9 months' => 9.months, + '1 year' => 1.year, + '2 years'=> 2.years, + '3 years'=> 3.years, + '4 years'=> 4.years, + '5 years'=> 5.years, + '6 years'=> 6.years, + '7 years'=> 7.years, + '8 years'=> 8.years, + '9 years'=> 9.years, + '10 years'=> 10.years, + } assert_equal durations, Billing::Price.durations end diff --git a/test/models/registrant_verification_test.rb b/test/models/registrant_verification_test.rb index a8707fd85..f5428b2cb 100644 --- a/test/models/registrant_verification_test.rb +++ b/test/models/registrant_verification_test.rb @@ -16,7 +16,7 @@ class RegistrantVerificationTest < ActiveSupport::TestCase random_action = "random#{rand(100)}" assert_difference -> { Version::RegistrantVerificationVersion.count } do - registrant_verification.update_attributes!(action: random_action) + registrant_verification.update!(action: random_action) end end diff --git a/test/system/admin_area/prices_test.rb b/test/system/admin_area/prices_test.rb index f5a299c38..dbb91966a 100644 --- a/test/system/admin_area/prices_test.rb +++ b/test/system/admin_area/prices_test.rb @@ -20,7 +20,6 @@ class AdminAreaPricesTest < ApplicationSystemTestCase fill_in 'Valid from', with: effective_date click_on 'Create price' - assert_text 'Price has been created' assert_text I18n.localize(effective_date) end From 4554975fad43023c3fc7fe9a15080cd16255aaea Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Wed, 5 May 2021 16:11:41 +0500 Subject: [PATCH 46/61] Add support for PG interval field in DirectoInvoice sending --- app/models/concerns/registrar/book_keeping.rb | 10 +++++----- test/jobs/directo_invoice_forward_job_test.rb | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/models/concerns/registrar/book_keeping.rb b/app/models/concerns/registrar/book_keeping.rb index d8a7c2e72..710f48e3c 100644 --- a/app/models/concerns/registrar/book_keeping.rb +++ b/app/models/concerns/registrar/book_keeping.rb @@ -40,8 +40,8 @@ module Registrar::BookKeeping def fetch_invoice_lines(activity, lines) price = load_price(activity) - if price.duration.include? 'year' - price.duration.to_i.times do |duration| + if price.duration.in_years.to_i >= 1 + price.duration.in_years.to_i.times do |duration| lines << new_monthly_invoice_line(activity: activity, duration: duration + 1).as_json end else @@ -67,9 +67,9 @@ module Registrar::BookKeeping end def finalize_invoice_line(line, price:, activity:, duration:) - yearly = price.duration.include?('year') + yearly = price.duration.in_years.to_i >= 1 - line['price'] = yearly ? (price.price.amount / price.duration.to_i) : price.price.amount + line['price'] = yearly ? (price.price.amount / price.duration.in_years.to_i) : price.price.amount line['description'] = description_in_language(price: price, yearly: yearly) if duration.present? @@ -90,7 +90,7 @@ module Registrar::BookKeeping locale_string = "registrar.invoice_#{timeframe_string}_product_description" I18n.with_locale(language == 'en' ? 'en' : 'et') do - I18n.t(locale_string, tld: ".#{price.zone_name}", length: price.duration.to_i) + I18n.t(locale_string, tld: ".#{price.zone_name}", length: price.duration.in_years.to_i) end end diff --git a/test/jobs/directo_invoice_forward_job_test.rb b/test/jobs/directo_invoice_forward_job_test.rb index 4a4fcf86d..33a05f644 100644 --- a/test/jobs/directo_invoice_forward_job_test.rb +++ b/test/jobs/directo_invoice_forward_job_test.rb @@ -110,7 +110,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase def test_multi_year_purchases_have_duration_assigned activity = account_activities(:one) price = billing_prices(:create_one_year) - price.update(duration: '3 years') + price.update(duration: 3.years) activity.update(activity_type: 'create', price: price) response = <<-XML @@ -157,7 +157,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase activity = account_activities(:one) price = billing_prices(:create_one_year) - price.update(duration: '3 years') + price.update(duration: 3.years) activity.update(activity_type: 'create', price: price) # Creating account activity for second action From 156ca0b54f2f5aafe68377cce9228f6a4e495035 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Wed, 5 May 2021 16:25:08 +0500 Subject: [PATCH 47/61] Get rid of outdated rendering --- app/controllers/registrar/contacts_controller.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/registrar/contacts_controller.rb b/app/controllers/registrar/contacts_controller.rb index 18af3a29f..756495457 100644 --- a/app/controllers/registrar/contacts_controller.rb +++ b/app/controllers/registrar/contacts_controller.rb @@ -43,9 +43,11 @@ class Registrar send_data raw_csv, filename: 'contacts.csv', type: "#{Mime[:csv]}; charset=utf-8" end format.pdf do - view = ActionView::Base.new(ActionController::Base.view_paths, contacts: contacts) - view.class_eval { include ::ApplicationHelper } - raw_html = view.render(file: 'registrar/contacts/list_pdf', layout: false) + raw_html = ApplicationController.render( + template: 'registrar/contacts/list_pdf', + assigns: { contacts: contacts }, + formats: [:html] + ) raw_pdf = contacts.pdf(raw_html) send_data raw_pdf, filename: 'contacts.pdf' From 89afe0bdf2cf9ef9b79a80afb5bf4b915c54ef2d Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Wed, 5 May 2021 16:35:05 +0500 Subject: [PATCH 48/61] Fix error generation --- app/controllers/repp/v1/base_controller.rb | 4 ++-- test/integration/api/nameservers/put_test.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/repp/v1/base_controller.rb b/app/controllers/repp/v1/base_controller.rb index e28f49a87..b26de845f 100644 --- a/app/controllers/repp/v1/base_controller.rb +++ b/app/controllers/repp/v1/base_controller.rb @@ -17,10 +17,10 @@ module Repp @response = { code: 2303, message: 'Object does not exist' } render(json: @response, status: :not_found) rescue ActionController::ParameterMissing, Apipie::ParamMissing => e - @response = { code: 2003, message: e } + @response = { code: 2003, message: e.message.gsub(/\n/, '. ') } render(json: @response, status: :bad_request) rescue Apipie::ParamInvalid => e - @response = { code: 2005, message: e } + @response = { code: 2005, message: e.message.gsub(/\n/, '. ') } render(json: @response, status: :bad_request) ensure create_repp_log diff --git a/test/integration/api/nameservers/put_test.rb b/test/integration/api/nameservers/put_test.rb index a55014709..1c1c16a01 100644 --- a/test/integration/api/nameservers/put_test.rb +++ b/test/integration/api/nameservers/put_test.rb @@ -100,7 +100,7 @@ class APINameserversPutTest < ApplicationIntegrationTest assert_response 400 assert_equal ({ code: 2003, - message: 'param is missing or the value is empty: hostname' }), + message: 'param is missing or the value is empty: hostname. Did you mean? hostname' }), JSON.parse(response.body, symbolize_names: true) end From d4dc39bf22948b89e4fe514d824ab7456ab2b310 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Wed, 5 May 2021 16:49:04 +0500 Subject: [PATCH 49/61] Fix error generation in dnskeys --- app/models/dnskey.rb | 6 +++--- test/models/dnskey_test.rb | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/models/dnskey.rb b/app/models/dnskey.rb index 58d4d9e31..e9e15802f 100644 --- a/app/models/dnskey.rb +++ b/app/models/dnskey.rb @@ -60,19 +60,19 @@ class Dnskey < ApplicationRecord def validate_algorithm return if alg.blank? return if ALGORITHMS.include?(alg.to_s) - errors.add(:alg, :invalid, values: ALGORITHMS.join(', ')) + errors.add(:alg, :invalid, values: "Valid algorithms are: #{ALGORITHMS.join(', ')}") end def validate_protocol return if protocol.blank? return if PROTOCOLS.include?(protocol.to_s) - errors.add(:protocol, :invalid, values: PROTOCOLS.join(', ')) + errors.add(:protocol, :invalid, values: "Valid protocols are: #{PROTOCOLS.join(', ')}") end def validate_flags return if flags.blank? return if FLAGS.include?(flags.to_s) - errors.add(:flags, :invalid, values: FLAGS.join(', ')) + errors.add(:flags, :invalid, values: "Valid flags are: #{FLAGS.join(', ')}") end def generate_digest diff --git a/test/models/dnskey_test.rb b/test/models/dnskey_test.rb index 2f4eff3af..57869309c 100644 --- a/test/models/dnskey_test.rb +++ b/test/models/dnskey_test.rb @@ -15,29 +15,29 @@ class DnskeyTest < ActiveSupport::TestCase dns.protocol = 3 dns.alg = 8 dns.public_key = @dnskey - + assert dns.save end def test_invalid_algrorithm dns = Dnskey.new dns.alg = 666 - errors = dns.validate_algorithm - assert_equal errors, ['Valid algorithms are: 3, 5, 6, 7, 8, 10, 13, 14'] + errors = dns.validate_algorithm.options[:values] + assert_equal errors, 'Valid algorithms are: 3, 5, 6, 7, 8, 10, 13, 14' end def test_invalid_protocol dns = Dnskey.new dns.protocol = 666 - errors = dns.validate_protocol - assert_equal errors, ['Valid protocols are: 3'] + errors = dns.validate_protocol.options[:values] + assert_equal errors, 'Valid protocols are: 3' end def test_invalid_flags dns = Dnskey.new dns.flags = 666 - errors = dns.validate_flags - assert_equal errors, ['Valid flags are: 0, 256, 257'] + errors = dns.validate_flags.options[:values] + assert_equal errors, 'Valid flags are: 0, 256, 257' end def test_ds_digest_type_one @@ -49,10 +49,10 @@ class DnskeyTest < ActiveSupport::TestCase dns.protocol = 3 dns.alg = 8 dns.public_key = @dnskey - + assert dns.save assert_equal dns.ds_digest_type, 1 assert_equal dns.ds_digest, '640D173A44D9AF2856FBE282EE64CE11A76DBB84' end -end \ No newline at end of file +end From 11d97358c1ff6ceb32aa95c3af40f4431f2c777b Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Wed, 5 May 2021 17:31:13 +0500 Subject: [PATCH 50/61] Fix CC issues --- Gemfile.lock | 4 ++-- .../admin/billing/prices_controller.rb | 4 +++- app/controllers/epp/base_controller.rb | 18 +++++++++++----- app/controllers/epp/contacts_controller.rb | 6 ++---- app/controllers/epp/domains_controller.rb | 3 +-- app/controllers/epp/errors_controller.rb | 4 ++-- app/controllers/epp/sessions_controller.rb | 21 ++++++++++++------- app/controllers/repp/v1/base_controller.rb | 6 +++--- .../v1/domains/base_contacts_controller.rb | 10 ++++----- .../repp/v1/domains/renews_controller.rb | 16 +++++++------- app/controllers/repp/v1/domains_controller.rb | 4 +++- .../domains/check_balance/mass.rb | 6 ++---- app/models/billing/price.rb | 18 ++++++++-------- app/models/concerns/epp_errors.rb | 15 +++++++------ app/models/invoice/pdf_generator.rb | 2 +- app/views/epp/error.xml.builder | 1 + 16 files changed, 78 insertions(+), 60 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 166895691..8ad7e672e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -561,7 +561,7 @@ DEPENDENCIES puma que que-web - rails (~> 6.1) + rails (~> 6.0) ransack (~> 2.3) rest-client rexml @@ -580,4 +580,4 @@ DEPENDENCIES wkhtmltopdf-binary (~> 0.12.5.1) BUNDLED WITH - 2.2.15 + 2.2.16 diff --git a/app/controllers/admin/billing/prices_controller.rb b/app/controllers/admin/billing/prices_controller.rb index 7bd0c3856..4c1e2e30a 100644 --- a/app/controllers/admin/billing/prices_controller.rb +++ b/app/controllers/admin/billing/prices_controller.rb @@ -81,7 +81,9 @@ module Admin ] allowed = params.require(:price).permit(*allowed_params) - allowed[:duration] = ActiveSupport::Duration.build(allowed[:duration].to_i) if allowed[:duration] + if allowed[:duration] + allowed[:duration] = ActiveSupport::Duration.build(allowed[:duration].to_i) + end allowed end diff --git a/app/controllers/epp/base_controller.rb b/app/controllers/epp/base_controller.rb index eb999d857..3230d3e70 100644 --- a/app/controllers/epp/base_controller.rb +++ b/app/controllers/epp/base_controller.rb @@ -163,9 +163,12 @@ module Epp else missing = el.present? ? el.text.blank? : true end + next unless missing + epp_errors.add(:epp_errors, code: '2003', - message: I18n.t('errors.messages.required_parameter_missing', key: "#{full_selector} [#{attr}]")) if missing + message: I18n.t('errors.messages.required_parameter_missing', + key: "#{full_selector} [#{attr}]")) end missing ? false : el # return last selector if it was present @@ -185,7 +188,8 @@ module Epp unless attribute epp_errors.add(:epp_errors, code: '2003', - msg: I18n.t('errors.messages.required_parameter_missing', key: attribute_selector)) + msg: I18n.t('errors.messages.required_parameter_missing', + key: attribute_selector)) return end @@ -221,7 +225,8 @@ module Epp epp_errors.add(:epp_errors, code: '2306', - msg: I18n.t(:exactly_one_parameter_required, params: full_selectors.join(' OR '))) + msg: I18n.t(:exactly_one_parameter_required, + params: full_selectors.join(' OR '))) end def mutually_exclusive(*selectors) @@ -230,7 +235,8 @@ module Epp epp_errors.add(:epp_errors, code: '2306', - msg: I18n.t(:mutally_exclusive_params, params: full_selectors.join(', '))) + msg: I18n.t(:mutally_exclusive_params, + params: full_selectors.join(', '))) end def optional(selector, *validations) @@ -273,9 +279,11 @@ module Epp def xml_attrs_present?(ph, attributes) # TODO: THIS IS DEPRECATED AND WILL BE REMOVED IN FUTURE attributes.each do |x| + next if has_attribute(ph, x) + epp_errors.add(:epp_errors, code: '2003', - msg: I18n.t('errors.messages.required_parameter_missing', key: x.last)) unless has_attribute(ph, x) + msg: I18n.t('errors.messages.required_parameter_missing', key: x.last)) end epp_errors.empty? end diff --git a/app/controllers/epp/contacts_controller.rb b/app/controllers/epp/contacts_controller.rb index 4d9b6ab0e..10250563c 100644 --- a/app/controllers/epp/contacts_controller.rb +++ b/app/controllers/epp/contacts_controller.rb @@ -173,8 +173,7 @@ module Epp epp_errors.add(:epp_errors, code: '2306', - msg: "#{I18n.t(:contact_org_error)}: postalInfo > org [org]" - ) + msg: "#{I18n.t(:contact_org_error)}: postalInfo > org [org]") end def fax_disabled @@ -190,8 +189,7 @@ module Epp return true if params[:parsed_frame].css('status').empty? epp_errors.add(:epp_errors, code: '2306', - msg: "#{I18n.t(:client_side_status_editing_error)}: status [status]" - ) + msg: "#{I18n.t(:client_side_status_editing_error)}: status [status]") end def address_given? diff --git a/app/controllers/epp/domains_controller.rb b/app/controllers/epp/domains_controller.rb index f5e32f153..6f8d10ced 100644 --- a/app/controllers/epp/domains_controller.rb +++ b/app/controllers/epp/domains_controller.rb @@ -218,8 +218,7 @@ module Epp return true if params[:parsed_frame].css('status').empty? epp_errors.add(:epp_errors, code: '2306', - msg: "#{I18n.t(:client_side_status_editing_error)}: status [status]" - ) + msg: "#{I18n.t(:client_side_status_editing_error)}: status [status]") end def check_client_hold diff --git a/app/controllers/epp/errors_controller.rb b/app/controllers/epp/errors_controller.rb index e9f1ecea8..ab2e00b75 100644 --- a/app/controllers/epp/errors_controller.rb +++ b/app/controllers/epp/errors_controller.rb @@ -3,12 +3,12 @@ module Epp skip_authorization_check def error - epp_errors.add(:epp_errors, code: params[:code], msg: params[:msg] ) + epp_errors.add(:epp_errors, code: params[:code], msg: params[:msg]) render_epp_response '/epp/error' end def command_handler - epp_errors.add(:epp_errors, code: '2000', msg: 'Unknown command' ) + epp_errors.add(:epp_errors, code: '2000', msg: 'Unknown command') render_epp_response '/epp/error' end end diff --git a/app/controllers/epp/sessions_controller.rb b/app/controllers/epp/sessions_controller.rb index dea42458b..7e540bb89 100644 --- a/app/controllers/epp/sessions_controller.rb +++ b/app/controllers/epp/sessions_controller.rb @@ -20,8 +20,9 @@ module Epp server_md5 = Certificate.parse_md_from_string(File.read(ENV['cert_path'])) if client_md5 != server_md5 + msg = 'Authentication error; server closing connection (certificate is not valid)' epp_errors.add(:epp_errors, - msg: 'Authentication error; server closing connection (certificate is not valid)', + msg: msg, code: '2501') success = false @@ -31,8 +32,9 @@ module Epp if !Rails.env.development? && (!webclient_request && @api_user) unless @api_user.pki_ok?(request.env['HTTP_SSL_CLIENT_CERT'], request.env['HTTP_SSL_CLIENT_S_DN_CN']) + msg = 'Authentication error; server closing connection (certificate is not valid)' epp_errors.add(:epp_errors, - msg: 'Authentication error; server closing connection (certificate is not valid)', + msg: msg, code: '2501') success = false @@ -40,40 +42,45 @@ module Epp end if success && !@api_user + msg = 'Authentication error; server closing connection (API user not found)' epp_errors.add(:epp_errors, - msg: 'Authentication error; server closing connection (API user not found)', + msg: msg, code: '2501') success = false end if success && !@api_user.try(:active) + msg = 'Authentication error; server closing connection (API user is not active)' epp_errors.add(:epp_errors, - msg: 'Authentication error; server closing connection (API user is not active)', + msg: msg, code: '2501') success = false end if success && @api_user.cannot?(:create, :epp_login) + msg = 'Authentication error; server closing connection (API user does not have epp role)' epp_errors.add(:epp_errors, - msg: 'Authentication error; server closing connection (API user does not have epp role)', + msg: msg, code: '2501') success = false end if success && !ip_white? + msg = 'Authentication error; server closing connection (IP is not whitelisted)' epp_errors.add(:epp_errors, - msg: 'Authentication error; server closing connection (IP is not whitelisted)', + msg: msg, code: '2501') success = false end if success && EppSession.limit_reached?(@api_user.registrar) + msg = 'Session limit exceeded; server closing connection (connection limit reached)' epp_errors.add(:epp_errors, - msg: 'Session limit exceeded; server closing connection (connection limit reached)', + msg: msg, code: '2502') success = false diff --git a/app/controllers/repp/v1/base_controller.rb b/app/controllers/repp/v1/base_controller.rb index b26de845f..37d4b95be 100644 --- a/app/controllers/repp/v1/base_controller.rb +++ b/app/controllers/repp/v1/base_controller.rb @@ -63,7 +63,7 @@ module Repp @epp_errors ||= ActiveModel::Errors.new(self) end - def handle_errors(obj = nil, update: false) + def handle_errors(obj = nil) @epp_errors ||= ActiveModel::Errors.new(self) if obj @@ -78,8 +78,8 @@ module Repp @epp_errors ||= ActiveModel::Errors.new(self) @epp_errors.add(:epp_errors, msg: 'Command failed', code: '2304') if data != {} - error_options = @epp_errors.errors.uniq. - select { |error| error.options[:code].present? }[0].options + error_options = @epp_errors.errors.uniq + .select { |error| error.options[:code].present? }[0].options @response = { code: error_options[:code].to_i, message: error_options[:msg], data: data } render(json: @response, status: status) diff --git a/app/controllers/repp/v1/domains/base_contacts_controller.rb b/app/controllers/repp/v1/domains/base_contacts_controller.rb index 521ca4ad4..65dbea9ac 100644 --- a/app/controllers/repp/v1/domains/base_contacts_controller.rb +++ b/app/controllers/repp/v1/domains/base_contacts_controller.rb @@ -16,11 +16,11 @@ module Repp def update @epp_errors ||= ActiveModel::Errors.new(self) - if @new_contact.invalid? - @epp_errors.add(:epp_errors, - msg: 'New contact must be valid', - code: '2304') - end + return unless @new_contact.invalid? + + @epp_errors.add(:epp_errors, + msg: 'New contact must be valid', + code: '2304') end private diff --git a/app/controllers/repp/v1/domains/renews_controller.rb b/app/controllers/repp/v1/domains/renews_controller.rb index f8774a325..af40e17b1 100644 --- a/app/controllers/repp/v1/domains/renews_controller.rb +++ b/app/controllers/repp/v1/domains/renews_controller.rb @@ -30,7 +30,7 @@ module Repp return render_success(data: { updated_domains: @domains.map(&:name) }) if renew.valid? msg = renew.errors.keys.map { |k, _v| renew.errors[k] }.join(', ') - @epp_errors.add(:epp_errors, msg: msg , code: '2002') + @epp_errors.add(:epp_errors, msg: msg, code: '2002') handle_errors end @@ -45,7 +45,7 @@ module Repp periods = Depp::Domain::PERIODS.map { |p| p[1] } return if periods.include? bulk_renew_params[:renew_period] - @epp_errors.add(:epp_errors, msg: 'Invalid renew period' , code: '2005') + @epp_errors.add(:epp_errors, msg: 'Invalid renew period', code: '2005') end def select_renewable_domains @@ -54,7 +54,7 @@ module Repp if bulk_renew_params[:domains].instance_of?(Array) @domains = bulk_renew_domains else - @epp_errors.add(:epp_errors, msg: 'Domains attribute must be an array' , code: '2005') + @epp_errors.add(:epp_errors, msg: 'Domains attribute must be an array', code: '2005') end return handle_errors if @epp_errors.any? @@ -78,11 +78,11 @@ module Repp bulk_renew_params[:domains].each do |idn| domain = Epp::Domain.find_by(name: idn) domains << domain if domain - unless domain - @epp_errors.add(:epp_errors, - msg: "Object does not exist: #{idn}", - code: '2304') - end + next if domain + + @epp_errors.add(:epp_errors, + msg: "Object does not exist: #{idn}", + code: '2304') end domains diff --git a/app/controllers/repp/v1/domains_controller.rb b/app/controllers/repp/v1/domains_controller.rb index 4e1b6bc0d..c228bd328 100644 --- a/app/controllers/repp/v1/domains_controller.rb +++ b/app/controllers/repp/v1/domains_controller.rb @@ -194,7 +194,9 @@ module Repp return if @domain.registrar == current_user.registrar return if @domain.transfer_code.eql?(request.headers['Auth-Code']) - @epp_errors.add(:epp_errors, code: 2202, msg: I18n.t('errors.messages.epp_authorization_error')) + @epp_errors.add(:epp_errors, + code: 2202, + msg: I18n.t('errors.messages.epp_authorization_error')) handle_errors end diff --git a/app/interactions/domains/check_balance/mass.rb b/app/interactions/domains/check_balance/mass.rb index 55449c8b2..cf1867a9f 100644 --- a/app/interactions/domains/check_balance/mass.rb +++ b/app/interactions/domains/check_balance/mass.rb @@ -20,10 +20,8 @@ module Domains def calculate_total_price @total_price = 0 domains.each do |domain| - task = Domains::CheckBalance::SingleDomain.run(domain: domain, - operation: 'renew', - period: period, - unit: unit) + task = Domains::CheckBalance::SingleDomain.run(domain: domain, operation: 'renew', + period: period, unit: unit) if task.valid? @total_price += task.result diff --git a/app/models/billing/price.rb b/app/models/billing/price.rb index d6705e0be..cc42d643b 100644 --- a/app/models/billing/price.rb +++ b/app/models/billing/price.rb @@ -30,15 +30,15 @@ module Billing '6 months' => 6.months, '9 months' => 9.months, '1 year' => 1.year, - '2 years'=> 2.years, - '3 years'=> 3.years, - '4 years'=> 4.years, - '5 years'=> 5.years, - '6 years'=> 6.years, - '7 years'=> 7.years, - '8 years'=> 8.years, - '9 years'=> 9.years, - '10 years'=> 10.years, + '2 years' => 2.years, + '3 years' => 3.years, + '4 years' => 4.years, + '5 years' => 5.years, + '6 years' => 6.years, + '7 years' => 7.years, + '8 years' => 8.years, + '9 years' => 9.years, + '10 years' => 10.years, } end diff --git a/app/models/concerns/epp_errors.rb b/app/models/concerns/epp_errors.rb index 349969507..90d742609 100644 --- a/app/models/concerns/epp_errors.rb +++ b/app/models/concerns/epp_errors.rb @@ -27,7 +27,7 @@ module EppErrors epp_errors.import parent_error end end - epp_errors.each { |epp_error| errors.import epp_error} + epp_errors.each { |epp_error| errors.import epp_error } errors end @@ -49,13 +49,16 @@ module EppErrors multi = [:has_and_belongs_to_many, :has_many] epp_errors = ActiveModel::Errors.new(self) - send(attr).each do |x| - x.errors.each do |error| - x.collect_parent_errors(error.attribute, error.message).each do |parent_error| - epp_errors.import parent_error + + if multi.include?(macro) + send(attr).each do |x| + x.errors.each do |error| + x.collect_parent_errors(error.attribute, error.message).each do |parent_error| + epp_errors.import parent_error + end end end - end if multi.include?(macro) + end epp_errors end diff --git a/app/models/invoice/pdf_generator.rb b/app/models/invoice/pdf_generator.rb index a1569dd3a..14fb99814 100644 --- a/app/models/invoice/pdf_generator.rb +++ b/app/models/invoice/pdf_generator.rb @@ -14,7 +14,7 @@ class Invoice private def invoice_html - ApplicationController.render(template: 'invoice/pdf', assigns: { invoice: invoice } ) + ApplicationController.render(template: 'invoice/pdf', assigns: { invoice: invoice }) end end end diff --git a/app/views/epp/error.xml.builder b/app/views/epp/error.xml.builder index 9f0bc45e8..be6b94a6a 100644 --- a/app/views/epp/error.xml.builder +++ b/app/views/epp/error.xml.builder @@ -3,6 +3,7 @@ xml.epp_head do @errors.each do |error| x = error&.options next if x.empty? || x == { value: nil } + xml.result('code' => x[:code]) do xml.msg(x[:msg], 'lang' => 'en') model_name = resource ? resource.model_name.singular.sub('epp_','') : controller.controller_name.singularize From 0eef642dbc6ca1c51dea2df161ccc0e5e03d6332 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Thu, 6 May 2021 17:53:42 +0300 Subject: [PATCH 51/61] Update CHANGELOG.md --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dfd9b669e..13a8a1e0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +06.05.2021 +* list all unread polls for REPP [#1936](https://github.com/internetee/registry/pull/1936) +* Bump Rails to 6.1.3.1 [#1962](https://github.com/internetee/registry/pull/1962) +* Bump mimemagic to 0.4.3 [](https://github.com/internetee/registry/pull/1960) + 03.05.2021 * Imporved error handling on invalid XML over EPP [#1952](https://github.com/internetee/registry/pull/1952) * Bump bootsnap to 1.7.4 [#1963](https://github.com/internetee/registry/pull/1963) From 60e9999bd365044faa51b924c73f3b8f3a1df71f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Thu, 6 May 2021 18:26:31 +0300 Subject: [PATCH 52/61] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13a8a1e0b..a0e9563cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ 06.05.2021 -* list all unread polls for REPP [#1936](https://github.com/internetee/registry/pull/1936) +* List all unread polls option for REPP [#1936](https://github.com/internetee/registry/pull/1936) * Bump Rails to 6.1.3.1 [#1962](https://github.com/internetee/registry/pull/1962) * Bump mimemagic to 0.4.3 [](https://github.com/internetee/registry/pull/1960) From b31ea1baad16ce2c8e50ed9f5b9d501f7ab94856 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Fri, 7 May 2021 10:43:24 +0500 Subject: [PATCH 53/61] Security update --- Gemfile | 2 +- Gemfile.lock | 110 +++++++++++++++--------------- app/helpers/application_helper.rb | 2 +- 3 files changed, 57 insertions(+), 57 deletions(-) diff --git a/Gemfile b/Gemfile index 9b90c30bb..12c71f7e7 100644 --- a/Gemfile +++ b/Gemfile @@ -7,7 +7,7 @@ gem 'bootsnap', '>= 1.1.0', require: false gem 'iso8601', '0.12.1' # for dates and times gem 'mime-types-data' gem 'mimemagic', '0.4.3' -gem 'rails', '~> 6.0' +gem 'rails', '~> 6.1.3.2' gem 'rest-client' gem 'uglifier' diff --git a/Gemfile.lock b/Gemfile.lock index 8ad7e672e..344e00e55 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -76,64 +76,64 @@ GIT GEM remote: https://rubygems.org/ specs: - actioncable (6.1.3.1) - actionpack (= 6.1.3.1) - activesupport (= 6.1.3.1) + actioncable (6.1.3.2) + actionpack (= 6.1.3.2) + activesupport (= 6.1.3.2) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (6.1.3.1) - actionpack (= 6.1.3.1) - activejob (= 6.1.3.1) - activerecord (= 6.1.3.1) - activestorage (= 6.1.3.1) - activesupport (= 6.1.3.1) + actionmailbox (6.1.3.2) + actionpack (= 6.1.3.2) + activejob (= 6.1.3.2) + activerecord (= 6.1.3.2) + activestorage (= 6.1.3.2) + activesupport (= 6.1.3.2) mail (>= 2.7.1) - actionmailer (6.1.3.1) - actionpack (= 6.1.3.1) - actionview (= 6.1.3.1) - activejob (= 6.1.3.1) - activesupport (= 6.1.3.1) + actionmailer (6.1.3.2) + actionpack (= 6.1.3.2) + actionview (= 6.1.3.2) + activejob (= 6.1.3.2) + activesupport (= 6.1.3.2) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (6.1.3.1) - actionview (= 6.1.3.1) - activesupport (= 6.1.3.1) + actionpack (6.1.3.2) + actionview (= 6.1.3.2) + activesupport (= 6.1.3.2) rack (~> 2.0, >= 2.0.9) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.1.3.1) - actionpack (= 6.1.3.1) - activerecord (= 6.1.3.1) - activestorage (= 6.1.3.1) - activesupport (= 6.1.3.1) + actiontext (6.1.3.2) + actionpack (= 6.1.3.2) + activerecord (= 6.1.3.2) + activestorage (= 6.1.3.2) + activesupport (= 6.1.3.2) nokogiri (>= 1.8.5) - actionview (6.1.3.1) - activesupport (= 6.1.3.1) + actionview (6.1.3.2) + activesupport (= 6.1.3.2) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) active_interaction (4.0.0) activemodel (>= 5, < 7) - activejob (6.1.3.1) - activesupport (= 6.1.3.1) + activejob (6.1.3.2) + activesupport (= 6.1.3.2) globalid (>= 0.3.6) - activemodel (6.1.3.1) - activesupport (= 6.1.3.1) - activerecord (6.1.3.1) - activemodel (= 6.1.3.1) - activesupport (= 6.1.3.1) + activemodel (6.1.3.2) + activesupport (= 6.1.3.2) + activerecord (6.1.3.2) + activemodel (= 6.1.3.2) + activesupport (= 6.1.3.2) activerecord-import (1.0.8) activerecord (>= 3.2) - activestorage (6.1.3.1) - actionpack (= 6.1.3.1) - activejob (= 6.1.3.1) - activerecord (= 6.1.3.1) - activesupport (= 6.1.3.1) + activestorage (6.1.3.2) + actionpack (= 6.1.3.2) + activejob (= 6.1.3.2) + activerecord (= 6.1.3.2) + activesupport (= 6.1.3.2) marcel (~> 1.0.0) mini_mime (~> 1.0.2) - activesupport (6.1.3.1) + activesupport (6.1.3.2) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) @@ -362,29 +362,29 @@ GEM rack rack-test (1.1.0) rack (>= 1.0, < 3) - rails (6.1.3.1) - actioncable (= 6.1.3.1) - actionmailbox (= 6.1.3.1) - actionmailer (= 6.1.3.1) - actionpack (= 6.1.3.1) - actiontext (= 6.1.3.1) - actionview (= 6.1.3.1) - activejob (= 6.1.3.1) - activemodel (= 6.1.3.1) - activerecord (= 6.1.3.1) - activestorage (= 6.1.3.1) - activesupport (= 6.1.3.1) + rails (6.1.3.2) + actioncable (= 6.1.3.2) + actionmailbox (= 6.1.3.2) + actionmailer (= 6.1.3.2) + actionpack (= 6.1.3.2) + actiontext (= 6.1.3.2) + actionview (= 6.1.3.2) + activejob (= 6.1.3.2) + activemodel (= 6.1.3.2) + activerecord (= 6.1.3.2) + activestorage (= 6.1.3.2) + activesupport (= 6.1.3.2) bundler (>= 1.15.0) - railties (= 6.1.3.1) + railties (= 6.1.3.2) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) rails-html-sanitizer (1.3.0) loofah (~> 2.3) - railties (6.1.3.1) - actionpack (= 6.1.3.1) - activesupport (= 6.1.3.1) + railties (6.1.3.2) + actionpack (= 6.1.3.2) + activesupport (= 6.1.3.2) method_source rake (>= 0.8.7) thor (~> 1.0) @@ -561,7 +561,7 @@ DEPENDENCIES puma que que-web - rails (~> 6.0) + rails (~> 6.1.3.2) ransack (~> 2.3) rest-client rexml @@ -580,4 +580,4 @@ DEPENDENCIES wkhtmltopdf-binary (~> 0.12.5.1) BUNDLED WITH - 2.2.16 + 2.2.17 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5c742afce..7bf5cd110 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -62,7 +62,7 @@ module ApplicationHelper if model.updator.kind_of?(RegistrantUser) model.updator else - link_to(model.updator, ['admin', model.updator]) + link_to(model.updator, [:admin, model.updator]) end end From b821447cee3031d4b5f08c4f7eb751268f04b8e0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 10 May 2021 05:01:34 +0000 Subject: [PATCH 54/61] Bump bootsnap from 1.7.4 to 1.7.5 Bumps [bootsnap](https://github.com/Shopify/bootsnap) from 1.7.4 to 1.7.5. - [Release notes](https://github.com/Shopify/bootsnap/releases) - [Changelog](https://github.com/Shopify/bootsnap/blob/master/CHANGELOG.md) - [Commits](https://github.com/Shopify/bootsnap/compare/v1.7.4...v1.7.5) Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 344e00e55..c195a99ec 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -168,7 +168,7 @@ GEM aws-eventstream (~> 1, >= 1.0.2) bcrypt (3.1.16) bindata (2.4.8) - bootsnap (1.7.4) + bootsnap (1.7.5) msgpack (~> 1.0) bootstrap-sass (3.4.1) autoprefixer-rails (>= 5.2.1) From c13e8c130379b44f1a2d85f28e4285b700c19a80 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 10 May 2021 05:02:03 +0000 Subject: [PATCH 55/61] Bump truemail from 2.4.0 to 2.4.1 Bumps [truemail](https://github.com/truemail-rb/truemail) from 2.4.0 to 2.4.1. - [Release notes](https://github.com/truemail-rb/truemail/releases) - [Changelog](https://github.com/truemail-rb/truemail/blob/master/CHANGELOG.md) - [Commits](https://github.com/truemail-rb/truemail/compare/v2.4.0...v2.4.1) Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 344e00e55..492d04e11 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -464,7 +464,7 @@ GEM temple (0.8.2) thor (1.1.0) tilt (2.0.10) - truemail (2.4.0) + truemail (2.4.1) simpleidn (~> 0.2.1) tzinfo (2.0.4) concurrent-ruby (~> 1.0) From ba67461a2133f4e4c8cfe35ed35dff110c8b996c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 10 May 2021 05:04:17 +0000 Subject: [PATCH 56/61] Bump devise from 4.7.3 to 4.8.0 Bumps [devise](https://github.com/plataformatec/devise) from 4.7.3 to 4.8.0. - [Release notes](https://github.com/plataformatec/devise/releases) - [Changelog](https://github.com/heartcombo/devise/blob/master/CHANGELOG.md) - [Commits](https://github.com/plataformatec/devise/compare/v4.7.3...v4.8.0) Signed-off-by: dependabot[bot] --- Gemfile | 2 +- Gemfile.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 12c71f7e7..3231c59f1 100644 --- a/Gemfile +++ b/Gemfile @@ -37,7 +37,7 @@ gem 'kaminari' gem 'sass-rails' gem 'select2-rails', '4.0.13' # for autocomplete gem 'cancancan' -gem 'devise', '~> 4.7' +gem 'devise', '~> 4.8' # registry specfic gem 'data_migrate', '~> 7.0' diff --git a/Gemfile.lock b/Gemfile.lock index 344e00e55..aa17f4685 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -215,7 +215,7 @@ GEM activerecord (>= 5.a) database_cleaner-core (~> 2.0.0) database_cleaner-core (2.0.1) - devise (4.7.3) + devise (4.8.0) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 4.1.0) @@ -530,7 +530,7 @@ DEPENDENCIES daemons-rails (= 1.2.1) data_migrate (~> 7.0) database_cleaner - devise (~> 4.7) + devise (~> 4.8) digidoc_client! directo! dnsruby (~> 1.61) From 37b8e796bc974631dae0324c5dd0c7a04a3dfb05 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 10 May 2021 05:05:20 +0000 Subject: [PATCH 57/61] Bump iso8601 from 0.12.1 to 0.13.0 Bumps [iso8601](https://github.com/arnau/ISO8601) from 0.12.1 to 0.13.0. - [Release notes](https://github.com/arnau/ISO8601/releases) - [Changelog](https://github.com/arnau/ISO8601/blob/main/CHANGELOG.md) - [Commits](https://github.com/arnau/ISO8601/compare/v0.12.1...v0.13.0) Signed-off-by: dependabot[bot] --- Gemfile | 2 +- Gemfile.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 12c71f7e7..601d5e594 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ source 'https://rubygems.org' gem 'active_interaction', '~> 4.0' gem 'apipie-rails', '~> 0.5.18' gem 'bootsnap', '>= 1.1.0', require: false -gem 'iso8601', '0.12.1' # for dates and times +gem 'iso8601', '0.13.0' # for dates and times gem 'mime-types-data' gem 'mimemagic', '0.4.3' gem 'rails', '~> 6.1.3.2' diff --git a/Gemfile.lock b/Gemfile.lock index 344e00e55..61c9535b1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -253,7 +253,7 @@ GEM concurrent-ruby (~> 1.0) i18n_data (0.11.0) isikukood (0.1.2) - iso8601 (0.12.1) + iso8601 (0.13.0) jmespath (1.4.0) jquery-rails (4.4.0) rails-dom-testing (>= 1, < 3) @@ -541,7 +541,7 @@ DEPENDENCIES figaro (~> 1.2) haml (~> 5.0) isikukood - iso8601 (= 0.12.1) + iso8601 (= 0.13.0) jquery-rails jquery-ui-rails (= 6.0.1) kaminari From 706dc838c9123edfb76f6c38c9c5874292a03c40 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 10 May 2021 05:06:04 +0000 Subject: [PATCH 58/61] Bump puma from 5.2.2 to 5.3.0 Bumps [puma](https://github.com/puma/puma) from 5.2.2 to 5.3.0. - [Release notes](https://github.com/puma/puma/releases) - [Changelog](https://github.com/puma/puma/blob/master/History.md) - [Commits](https://github.com/puma/puma/compare/v5.2.2...v5.3.0) Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 344e00e55..a1effa4d1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -343,7 +343,7 @@ GEM coderay (~> 1.1) method_source (~> 1.0) public_suffix (4.0.6) - puma (5.2.2) + puma (5.3.0) nio4r (~> 2.0) que (0.14.3) que-web (0.7.2) From 9df52af96b42c279b3d1e5359f88ea9abe7f9065 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Mon, 10 May 2021 11:44:22 +0500 Subject: [PATCH 59/61] Fix domain update confirm if pendong_json current_user_id got non-string values --- .../process_update_confirmed.rb | 8 ++++++- test/jobs/domain_update_confirm_job_test.rb | 23 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/app/interactions/domains/update_confirm/process_update_confirmed.rb b/app/interactions/domains/update_confirm/process_update_confirmed.rb index 316c1db86..734dbf5d8 100644 --- a/app/interactions/domains/update_confirm/process_update_confirmed.rb +++ b/app/interactions/domains/update_confirm/process_update_confirmed.rb @@ -29,11 +29,17 @@ module Domains end def assign_domain_update_meta - user = ApiUser.find_by(id: domain.pending_json['current_user_id']) + user = ApiUser.find_by(id: user_id) if user_id.present? && user_id.is_a?(String) domain.upid = user.registrar.id if user.present? && user.registrar domain.up_date = Time.zone.now end + + private + + def user_id + @user_id ||= domain.pending_json.dig('current_user_id') + end end end end diff --git a/test/jobs/domain_update_confirm_job_test.rb b/test/jobs/domain_update_confirm_job_test.rb index aa686a9f8..183fd5cf1 100644 --- a/test/jobs/domain_update_confirm_job_test.rb +++ b/test/jobs/domain_update_confirm_job_test.rb @@ -127,6 +127,29 @@ class DomainUpdateConfirmJobTest < ActiveSupport::TestCase assert @domain.statuses.include? DomainStatus::DISPUTED end + def test_works_id_current_user_id_broken + epp_xml = "\n\n \n \n \n #{@domain.name}\n" \ + " \n #{@new_registrant.code}\n \n \n \n \n \n" \ + " \n #{@legal_doc_path}\n \n" \ + " \n 20alla-1594199756\n \n\n" + parsed_frame = Deserializers::Xml::DomainUpdate.new(Nokogiri::XML(epp_xml), @domain.registrar.id).call + + @domain.pending_json['frame'] = parsed_frame + @domain.pending_json['current_user_id'] = { key: 'some_value'} + @domain.update(pending_json: @domain.pending_json) + @domain.update(statuses: [DomainStatus::DELETE_CANDIDATE, DomainStatus::DISPUTED]) + + assert_nothing_raised do + DomainUpdateConfirmJob.perform_now(@domain.id, RegistrantVerification::CONFIRMED) + end + @domain.reload + + assert_not @domain.statuses.include? DomainStatus::PENDING_DELETE_CONFIRMATION + assert_not @domain.statuses.include? DomainStatus::PENDING_DELETE + assert @domain.statuses.include? DomainStatus::DELETE_CANDIDATE + assert @domain.statuses.include? DomainStatus::DISPUTED + end + def test_clears_pending_update_and_inactive_after_denial epp_xml = "\n\n \n \n \n #{@domain.name}\n" \ " \n #{@new_registrant.code}\n \n \n \n \n \n" \ From 043bf63b397954f8a1b9c82de8dd2cfc971af46b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Mon, 10 May 2021 15:53:41 +0300 Subject: [PATCH 60/61] Update CHANGELOG.md --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0e9563cc..9be8824da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +10.05.2021 +* Domain update confirmation fix [#1975](https://github.com/internetee/registry/pull/1975) +* Bump bootsnap to 1.7.5 [#1970](https://github.com/internetee/registry/pull/1970) +* Bump truemail to 2.4.1 [#1971](https://github.com/internetee/registry/pull/1971) +* Bump devise to 4.8.0 [#1972](https://github.com/internetee/registry/pull/1972) +* Bump iso8601 to 0.13.0 [#1973](https://github.com/internetee/registry/pull/1973) +* Bump puma to 5.3.0 [#1974](https://github.com/internetee/registry/pull/1974) + 06.05.2021 * List all unread polls option for REPP [#1936](https://github.com/internetee/registry/pull/1936) * Bump Rails to 6.1.3.1 [#1962](https://github.com/internetee/registry/pull/1962) From 7bec1b5880486c2d279278a272cac401405e2442 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Wed, 12 May 2021 17:00:16 +0500 Subject: [PATCH 61/61] Fix CI description in readme --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ed68e62af..d0766bd15 100644 --- a/README.md +++ b/README.md @@ -396,10 +396,9 @@ sudo apt-get install libxext-dev libxrender1 fontconfig * [Testing](/doc/testing.md) -### Travis CI +### Github Actions CI -* Travis is configured to build against master and staging branches by default. -* Notification emails are sent to committer by default. +* Github Actions CI is configured to build all the PRs. ### EPP web client