From c7d3788a36354d9e47997f92792d7ee2583c0742 Mon Sep 17 00:00:00 2001 From: tsoganov Date: Fri, 16 Aug 2024 13:35:14 +0300 Subject: [PATCH] Updated contact name data type in schemas --- app/controllers/epp/base_controller.rb | 2 + app/models/concerns/epp_errors.rb | 1 + app/models/contact.rb | 1 + app/models/epp/contact.rb | 2 + config/locales/contacts.en.yml | 1 + db/api_log_schema.rb | 53 +++++++++---------- ...180306183549_remove_log_domain_statuses.rb | 2 +- ..._change_request_object_type_in_epp_logs.rb | 29 ++++++++++ ...0816092636_change_data_type_in_contacts.rb | 29 ++++++++++ db/structure.sql | 22 ++++---- db/whois_schema.rb | 10 ++-- test/test_helper.rb | 2 +- 12 files changed, 109 insertions(+), 45 deletions(-) create mode 100644 db/migrate/20240816091049_change_request_object_type_in_epp_logs.rb create mode 100644 db/migrate/20240816092636_change_data_type_in_contacts.rb diff --git a/app/controllers/epp/base_controller.rb b/app/controllers/epp/base_controller.rb index 1f1de8458..3272630bf 100644 --- a/app/controllers/epp/base_controller.rb +++ b/app/controllers/epp/base_controller.rb @@ -74,6 +74,7 @@ module Epp def validate_against_schema return if %w[hello error].include?(params[:action]) + schema.validate(params[:nokogiri_frame]).each do |error| epp_errors.add(:epp_errors, code: 2001, @@ -100,6 +101,7 @@ module Epp def current_user return unless signed_in? + epp_session.user end diff --git a/app/models/concerns/epp_errors.rb b/app/models/concerns/epp_errors.rb index cdb3c5d80..3dbeb8740 100644 --- a/app/models/concerns/epp_errors.rb +++ b/app/models/concerns/epp_errors.rb @@ -38,6 +38,7 @@ module EppErrors 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.add(attr, code: code, msg: msg, value: value) end diff --git a/app/models/contact.rb b/app/models/contact.rb index 3da4c20d8..0e076155b 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -46,6 +46,7 @@ class Contact < ApplicationRecord [\u005B-\u005F\u007B-\u007E\u2040-\u206F\u20A0-\u20BF\u2100-\u218F])/x validates :name, :email, presence: true + validates :name, length: { maximum: 255, message: :too_long_contact_name } validates :name, format: { without: NAME_REGEXP, message: :invalid }, if: -> { priv? } validates :street, :city, :zip, :country_code, presence: true, if: lambda { diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index 5f694b085..dcde57db5 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -12,6 +12,7 @@ class Epp::Contact < Contact def manage_permissions return unless update_prohibited? || delete_prohibited? + add_epp_error('2304', nil, nil, I18n.t(:object_status_prohibits_operation)) throw(:abort) end @@ -76,6 +77,7 @@ class Epp::Contact < Contact ], '2005' => [ # Value syntax error [:name, :invalid], + [:name, :too_long_contact_name], [:phone, :invalid], [:email, :invalid], [:country_code, :invalid], diff --git a/config/locales/contacts.en.yml b/config/locales/contacts.en.yml index c3fe0d47c..361e63530 100644 --- a/config/locales/contacts.en.yml +++ b/config/locales/contacts.en.yml @@ -15,6 +15,7 @@ en: name: blank: "Required parameter missing - name" invalid: "Name is invalid" + too_long_contact_name: "Contact name is too long, max 255 characters" phone: blank: "Required parameter missing - phone" invalid: "Phone nr is invalid" diff --git a/db/api_log_schema.rb b/db/api_log_schema.rb index f2b0324bd..d219f7b46 100644 --- a/db/api_log_schema.rb +++ b/db/api_log_schema.rb @@ -1,13 +1,12 @@ -# encoding: UTF-8 # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # -# Note that this schema.rb definition is the authoritative source for your -# database schema. If you need to create the application database on another -# system, you should be using db:schema:load, not running all the migrations -# from scratch. The latter is a flawed and unsustainable approach (the more migrations -# you'll amass, the slower it'll run and the greater likelihood for issues). +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. # # It's strongly recommended that you check this file into your version control system. @@ -17,35 +16,33 @@ ActiveRecord::Schema.define(version: 0) do enable_extension "plpgsql" create_table "epp_logs", force: :cascade do |t| - t.text "request" - t.text "response" - t.string "request_command", limit: 255 - t.string "request_object", limit: 255 - t.boolean "request_successful" - t.string "api_user_name", limit: 255 - t.string "api_user_registrar", limit: 255 - t.string "ip", limit: 255 + t.text "request" + t.text "response" + t.string "request_command", limit: 255 + t.string "request_object" + t.boolean "request_successful" + t.string "api_user_name", limit: 255 + t.string "api_user_registrar", limit: 255 + t.string "ip", limit: 255 t.datetime "created_at" t.datetime "updated_at" - t.string "uuid" + t.string "uuid" + t.index ["uuid"], name: "epp_logs_uuid" end - add_index "epp_logs", ["uuid"], name: "epp_logs_uuid", using: :btree - create_table "repp_logs", force: :cascade do |t| - t.string "request_path", limit: 255 - t.string "request_method", limit: 255 - t.text "request_params" - t.text "response" - t.string "response_code", limit: 255 - t.string "api_user_name", limit: 255 - t.string "api_user_registrar", limit: 255 - t.string "ip", limit: 255 + t.string "request_path", limit: 255 + t.string "request_method", limit: 255 + t.text "request_params" + t.text "response" + t.string "response_code", limit: 255 + t.string "api_user_name", limit: 255 + t.string "api_user_registrar", limit: 255 + t.string "ip", limit: 255 t.datetime "created_at" t.datetime "updated_at" - t.string "uuid" + t.string "uuid" + t.index ["uuid"], name: "repp_logs_uuid" end - add_index "repp_logs", ["uuid"], name: "repp_logs_uuid", using: :btree - end diff --git a/db/migrate/20180306183549_remove_log_domain_statuses.rb b/db/migrate/20180306183549_remove_log_domain_statuses.rb index 04a1eae3c..11e191ddc 100644 --- a/db/migrate/20180306183549_remove_log_domain_statuses.rb +++ b/db/migrate/20180306183549_remove_log_domain_statuses.rb @@ -1,5 +1,5 @@ class RemoveLogDomainStatuses < ActiveRecord::Migration[6.0] def change - drop_table :log_domain_statuses + drop_table :log_domain_statuses if table_exists?(:log_domain_statuses) end end diff --git a/db/migrate/20240816091049_change_request_object_type_in_epp_logs.rb b/db/migrate/20240816091049_change_request_object_type_in_epp_logs.rb new file mode 100644 index 000000000..b4dba098f --- /dev/null +++ b/db/migrate/20240816091049_change_request_object_type_in_epp_logs.rb @@ -0,0 +1,29 @@ +class ChangeRequestObjectTypeInEppLogs < ActiveRecord::Migration[6.1] + def up + with_api_log_connection do |connection| + connection.change_column :epp_logs, :request_object, :string, limit: nil + end + end + + def down + with_api_log_connection do |connection| + connection.change_column :epp_logs, :request_object, :string, limit: 255 + end + end + + private + + def with_api_log_connection + api_log_connection = ActiveRecord::Base.establish_connection("api_log_#{Rails.env}".to_sym).connection + + yield(api_log_connection) + + ensure + # Re-establish the original connection + ActiveRecord::Base.establish_connection(original_connection_config) + end + + def original_connection_config + Rails.configuration.database_configuration[Rails.env] + end +end diff --git a/db/migrate/20240816092636_change_data_type_in_contacts.rb b/db/migrate/20240816092636_change_data_type_in_contacts.rb new file mode 100644 index 000000000..83b15467a --- /dev/null +++ b/db/migrate/20240816092636_change_data_type_in_contacts.rb @@ -0,0 +1,29 @@ +class ChangeDataTypeInContacts < ActiveRecord::Migration[6.1] + def up + safety_assured do + change_column :contacts, :code, :string, limit: 255 + change_column :contacts, :phone, :string, limit: 255 + change_column :contacts, :email, :string, limit: 255 + change_column :contacts, :fax, :string, limit: 255 + change_column :contacts, :ident, :string, limit: 255 + change_column :contacts, :ident_type, :string, limit: 255 + change_column :contacts, :auth_info, :string, limit: 255 + change_column :contacts, :name, :string, limit: 255 + change_column :contacts, :org_name, :string, limit: 255 + end + end + + def down + safety_assured do + change_column :contacts, :code, :string, limit: nil + change_column :contacts, :phone, :string, limit: nil + change_column :contacts, :email, :string, limit: nil + change_column :contacts, :fax, :string, limit: nil + change_column :contacts, :ident, :string, limit: nil + change_column :contacts, :ident_type, :string, limit: nil + change_column :contacts, :auth_info, :string, limit: nil + change_column :contacts, :name, :string, limit: nil + change_column :contacts, :org_name, :string, limit: nil + end + end +end diff --git a/db/structure.sql b/db/structure.sql index 117880656..fc2c2df12 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -661,17 +661,17 @@ ALTER SEQUENCE public.contact_requests_id_seq OWNED BY public.contact_requests.i CREATE TABLE public.contacts ( id integer NOT NULL, - code character varying NOT NULL, - phone character varying, - email character varying NOT NULL, - fax character varying, + code character varying(255) NOT NULL, + phone character varying(255), + email character varying(255) NOT NULL, + fax character varying(255), created_at timestamp without time zone, updated_at timestamp without time zone, - ident character varying, - ident_type character varying, - auth_info character varying NOT NULL, - name character varying NOT NULL, - org_name character varying, + ident character varying(255), + ident_type character varying(255), + auth_info character varying(255) NOT NULL, + name character varying(255) NOT NULL, + org_name character varying(255), registrar_id integer NOT NULL, creator_str character varying, updator_str character varying, @@ -5470,6 +5470,8 @@ INSERT INTO "schema_migrations" (version) VALUES ('20221214073933'), ('20221214074252'), ('20230531111154'), -('20230707084741'); +('20230707084741'), +('20240816091049'), +('20240816092636'); diff --git a/db/whois_schema.rb b/db/whois_schema.rb index 9353bd80c..5081c4623 100644 --- a/db/whois_schema.rb +++ b/db/whois_schema.rb @@ -2,11 +2,11 @@ # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # -# Note that this schema.rb definition is the authoritative source for your -# database schema. If you need to create the application database on another -# system, you should be using db:schema:load, not running all the migrations -# from scratch. The latter is a flawed and unsustainable approach (the more migrations -# you'll amass, the slower it'll run and the greater likelihood for issues). +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. # # It's strongly recommended that you check this file into your version control system. diff --git a/test/test_helper.rb b/test/test_helper.rb index ca63e2f35..3f1989c02 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -9,7 +9,7 @@ if ENV['COVERAGE'] end end -ENV['RAILS_ENV'] ||= 'test' +ENV['RAILS_ENV'] = 'test' require_relative '../config/environment' require 'rails/test_help' require 'minitest/mock'