From 5c70e9f38b677362950e8751b9b4cd924b0d00f9 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Mon, 11 Jul 2022 11:20:05 -0300 Subject: [PATCH 01/20] Add registrant phone to whois record json --- .../api/v1/contact_requests_controller.rb | 3 +- app/models/concerns/zone/whois_queryable.rb | 2 +- app/models/contact_request.rb | 30 ++++++++++--------- app/models/whois_record.rb | 1 + doc/registrant-api/v1/contact.md | 2 +- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/app/controllers/api/v1/contact_requests_controller.rb b/app/controllers/api/v1/contact_requests_controller.rb index 1ef73e9ef..51c967bd5 100644 --- a/app/controllers/api/v1/contact_requests_controller.rb +++ b/app/controllers/api/v1/contact_requests_controller.rb @@ -3,7 +3,6 @@ module Api class ContactRequestsController < BaseController before_action :authenticate_shared_key - # POST api/v1/contact_requests/ def create return head(:bad_request) if contact_request_params[:email].blank? @@ -19,6 +18,8 @@ module Api process_id(params[:id]) end + private + def process_id(id) record = ContactRequest.find_by(id: id) return :not_found unless record diff --git a/app/models/concerns/zone/whois_queryable.rb b/app/models/concerns/zone/whois_queryable.rb index 7c6ff511d..1a08b7ab1 100644 --- a/app/models/concerns/zone/whois_queryable.rb +++ b/app/models/concerns/zone/whois_queryable.rb @@ -47,7 +47,7 @@ module Zone::WhoisQueryable def registrant_vars { registrant: Setting.registry_juridical_name, registrant_reg_no: Setting.registry_reg_no, registrant_ident_country_code: Setting.registry_country_code, registrant_kind: 'org', - registrant_disclosed_attributes: %w[name email] } + registrant_disclosed_attributes: %w[name email phone] } end def contact_vars diff --git a/app/models/contact_request.rb b/app/models/contact_request.rb index f4c6db716..9dc028885 100644 --- a/app/models/contact_request.rb +++ b/app/models/contact_request.rb @@ -15,15 +15,6 @@ class ContactRequest < ApplicationRecord attr_readonly :secret, :valid_to - def self.save_record(params) - contact_request = new(params) - contact_request.secret = create_random_secret - contact_request.valid_to = set_valid_to_24_hours_from_now - contact_request.status = STATUS_NEW - contact_request.save! - contact_request - end - def update_record(params) self.status = params['status'] if params['status'] self.ip_address = params['ip'] if params['ip'] @@ -31,11 +22,22 @@ class ContactRequest < ApplicationRecord save! end - def self.create_random_secret - SecureRandom.hex(64) - end + class << self + def save_record(params) + contact_request = new(params) + contact_request.secret = create_random_secret + contact_request.valid_to = set_valid_to_24_hours_from_now + contact_request.status = STATUS_NEW + contact_request.save! + contact_request + end - def self.set_valid_to_24_hours_from_now - (Time.zone.now + 24.hours) + def create_random_secret + SecureRandom.hex(64) + end + + def set_valid_to_24_hours_from_now + (Time.zone.now + 24.hours) + end end end diff --git a/app/models/whois_record.rb b/app/models/whois_record.rb index 8d30110b4..9ee864c92 100644 --- a/app/models/whois_record.rb +++ b/app/models/whois_record.rb @@ -51,6 +51,7 @@ class WhoisRecord < ApplicationRecord end h[:email] = registrant.email + h[:phone] = registrant.phone h[:registrant_changed] = registrant.updated_at.try(:to_s, :iso8601) h[:registrant_disclosed_attributes] = registrant.disclosed_attributes diff --git a/doc/registrant-api/v1/contact.md b/doc/registrant-api/v1/contact.md index 87519c0aa..37a60e1a2 100644 --- a/doc/registrant-api/v1/contact.md +++ b/doc/registrant-api/v1/contact.md @@ -113,7 +113,7 @@ Update contact. | address[city] | false | String | | New city name | | address[state] | false | String | | New state name | | address[country_code] | false | String | | New country code in 2 letter format (ISO 3166-1 alpha-2) | -| disclosed_attributes | false | Array | | Possible values: "name", "email" +| disclosed_attributes | false | Array | | Possible values: "name", "email", "phone" #### Request From 9623b3e2075310800d15d18d6649f2e392522c36 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Thu, 14 Jul 2022 08:49:41 -0300 Subject: [PATCH 02/20] Allow update phone disclose situation with org registrations --- .../api/v1/registrant/contacts_controller.rb | 2 +- .../api/v1/registrant/contacts/update_test.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/registrant/contacts_controller.rb b/app/controllers/api/v1/registrant/contacts_controller.rb index b196c567a..86a8dc87d 100644 --- a/app/controllers/api/v1/registrant/contacts_controller.rb +++ b/app/controllers/api/v1/registrant/contacts_controller.rb @@ -62,7 +62,7 @@ module Api disclosed_attributes = reparsed_request_json[:disclosed_attributes] if disclosed_attributes - if disclosed_attributes.present? && contact.org? + if disclosed_attributes.present? && contact.org? && !disclosed_attributes.include?('phone') error_msg = "Legal person's data is visible by default and cannot be concealed." \ ' Please remove this parameter.' render json: { errors: [{ disclosed_attributes: [error_msg] }] }, status: :bad_request diff --git a/test/integration/api/v1/registrant/contacts/update_test.rb b/test/integration/api/v1/registrant/contacts/update_test.rb index d7a3060b6..50618647f 100644 --- a/test/integration/api/v1/registrant/contacts/update_test.rb +++ b/test/integration/api/v1/registrant/contacts/update_test.rb @@ -215,6 +215,20 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest JSON.parse(response.body, symbolize_names: true) end + def test_legal_persons_disclosed_attributes_change_when_phone + @contact = contacts(:acme_ltd) + @contact.update!(disclosed_attributes: %w[]) + + patch api_v1_registrant_contact_path(@contact.uuid), + params: { disclosed_attributes: %w[phone] }, + as: :json, + headers: { 'HTTP_AUTHORIZATION' => auth_token } + @contact.reload + + assert_response :ok + assert_equal %w[phone], @contact.disclosed_attributes + end + def test_return_contact_details patch api_v1_registrant_contact_path(@contact.uuid), params: { name: 'new name' }, as: :json, From 5c129b24ef3517e84deb33980a9addd14de4986e Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Fri, 15 Jul 2022 16:47:30 -0300 Subject: [PATCH 03/20] Add `publishable` contact field --- app/controllers/api/v1/registrant/contacts_controller.rb | 2 ++ app/models/contact.rb | 1 + app/models/registrant.rb | 4 ++++ app/models/whois_record.rb | 1 + db/migrate/20220715145808_add_publishable_to_contacts.rb | 5 +++++ db/structure.sql | 8 ++++---- 6 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20220715145808_add_publishable_to_contacts.rb diff --git a/app/controllers/api/v1/registrant/contacts_controller.rb b/app/controllers/api/v1/registrant/contacts_controller.rb index 86a8dc87d..cefbd9728 100644 --- a/app/controllers/api/v1/registrant/contacts_controller.rb +++ b/app/controllers/api/v1/registrant/contacts_controller.rb @@ -72,6 +72,8 @@ module Api contact.disclosed_attributes = disclosed_attributes end + contact.publishable = reparsed_request_json[:publishable] if reparsed_request_json[:publishable] + logger.debug "Setting.address_processing is set to #{Setting.address_processing}" if Setting.address_processing && params[:address] diff --git a/app/models/contact.rb b/app/models/contact.rb index e4628e3c0..e83a54e02 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -64,6 +64,7 @@ class Contact < ApplicationRecord validate :validate_html validate :validate_country_code, if: -> { self.class.address_processing? } + validates_inclusion_of :publishable, in: [false], unless: -> { registrant? } after_initialize do self.status_notes = {} if status_notes.nil? diff --git a/app/models/registrant.rb b/app/models/registrant.rb index 026431d6c..a0fd70136 100644 --- a/app/models/registrant.rb +++ b/app/models/registrant.rb @@ -3,4 +3,8 @@ class Registrant < Contact def epp_code_map {} end + + def publishable? + publishable + end end diff --git a/app/models/whois_record.rb b/app/models/whois_record.rb index 9ee864c92..f0390da20 100644 --- a/app/models/whois_record.rb +++ b/app/models/whois_record.rb @@ -52,6 +52,7 @@ class WhoisRecord < ApplicationRecord h[:email] = registrant.email h[:phone] = registrant.phone + h[:publishable] = registrant.publishable? h[:registrant_changed] = registrant.updated_at.try(:to_s, :iso8601) h[:registrant_disclosed_attributes] = registrant.disclosed_attributes diff --git a/db/migrate/20220715145808_add_publishable_to_contacts.rb b/db/migrate/20220715145808_add_publishable_to_contacts.rb new file mode 100644 index 000000000..4a426f977 --- /dev/null +++ b/db/migrate/20220715145808_add_publishable_to_contacts.rb @@ -0,0 +1,5 @@ +class AddPublishableToContacts < ActiveRecord::Migration[6.1] + def change + add_column :contacts, :publishable, :boolean, default: false + end +end diff --git a/db/structure.sql b/db/structure.sql index 0e37313ef..0a38e44b7 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -670,7 +670,8 @@ CREATE TABLE public.contacts ( up_date timestamp without time zone, uuid uuid DEFAULT public.gen_random_uuid() NOT NULL, disclosed_attributes character varying[] DEFAULT '{}'::character varying[] NOT NULL, - email_history character varying + email_history character varying, + publishable boolean DEFAULT false ); @@ -5417,6 +5418,5 @@ INSERT INTO "schema_migrations" (version) VALUES ('20220524130709'), ('20220701113409'), ('20220818075833'), -('20221011061840'); - - +('20221011061840'), +('20220715145808'); From 4286a6bab7a2fdabd14a885fca5031cc42cd8a69 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Tue, 19 Jul 2022 08:51:19 -0300 Subject: [PATCH 04/20] Test changing publishable field on registrant API --- .../api/v1/registrant/contacts_controller.rb | 2 +- app/models/contact.rb | 2 +- .../api/v1/registrant/contacts/update_test.rb | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/registrant/contacts_controller.rb b/app/controllers/api/v1/registrant/contacts_controller.rb index cefbd9728..78f1cfecc 100644 --- a/app/controllers/api/v1/registrant/contacts_controller.rb +++ b/app/controllers/api/v1/registrant/contacts_controller.rb @@ -72,7 +72,7 @@ module Api contact.disclosed_attributes = disclosed_attributes end - contact.publishable = reparsed_request_json[:publishable] if reparsed_request_json[:publishable] + contact.publishable = reparsed_request_json[:publishable] if reparsed_request_json[:publishable].present? logger.debug "Setting.address_processing is set to #{Setting.address_processing}" diff --git a/app/models/contact.rb b/app/models/contact.rb index e83a54e02..41c176022 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -64,7 +64,7 @@ class Contact < ApplicationRecord validate :validate_html validate :validate_country_code, if: -> { self.class.address_processing? } - validates_inclusion_of :publishable, in: [false], unless: -> { registrant? } + validates :publishable, inclusion: { in: [true, false] } after_initialize do self.status_notes = {} if status_notes.nil? diff --git a/test/integration/api/v1/registrant/contacts/update_test.rb b/test/integration/api/v1/registrant/contacts/update_test.rb index 50618647f..bbb977163 100644 --- a/test/integration/api/v1/registrant/contacts/update_test.rb +++ b/test/integration/api/v1/registrant/contacts/update_test.rb @@ -229,6 +229,21 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest assert_equal %w[phone], @contact.disclosed_attributes end + def test_publishable_change_when_present + @contact = contacts(:acme_ltd) + @contact.update!(publishable: false) + + patch api_v1_registrant_contact_path(@contact.uuid), + params: { disclosed_attributes: %w[], publishable: true }, + as: :json, + headers: { 'HTTP_AUTHORIZATION' => auth_token } + @contact.reload + + assert_response :ok + assert @contact.publishable + end + + def test_return_contact_details patch api_v1_registrant_contact_path(@contact.uuid), params: { name: 'new name' }, as: :json, From 59fe7dffbe59e53cfb252e9e0b3343acc2f469d7 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Wed, 20 Jul 2022 08:21:22 -0300 Subject: [PATCH 05/20] Migrate `publishable` field name to `registrant_publishable` --- app/controllers/api/v1/registrant/contacts_controller.rb | 2 +- app/models/contact.rb | 3 ++- app/models/registrant.rb | 2 +- app/models/whois_record.rb | 2 +- db/migrate/20220715145808_add_publishable_to_contacts.rb | 5 ----- ...20220715145808_add_registrant_publishable_to_contacts.rb | 5 +++++ db/structure.sql | 2 +- lib/serializers/registrant_api/contact.rb | 1 + test/integration/api/v1/registrant/contacts/update_test.rb | 6 +++--- 9 files changed, 15 insertions(+), 13 deletions(-) delete mode 100644 db/migrate/20220715145808_add_publishable_to_contacts.rb create mode 100644 db/migrate/20220715145808_add_registrant_publishable_to_contacts.rb diff --git a/app/controllers/api/v1/registrant/contacts_controller.rb b/app/controllers/api/v1/registrant/contacts_controller.rb index 78f1cfecc..889fa0a7a 100644 --- a/app/controllers/api/v1/registrant/contacts_controller.rb +++ b/app/controllers/api/v1/registrant/contacts_controller.rb @@ -72,7 +72,7 @@ module Api contact.disclosed_attributes = disclosed_attributes end - contact.publishable = reparsed_request_json[:publishable] if reparsed_request_json[:publishable].present? + contact.registrant_publishable = reparsed_request_json[:registrant_publishable] logger.debug "Setting.address_processing is set to #{Setting.address_processing}" diff --git a/app/models/contact.rb b/app/models/contact.rb index 41c176022..c06c7b601 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -64,7 +64,8 @@ class Contact < ApplicationRecord validate :validate_html validate :validate_country_code, if: -> { self.class.address_processing? } - validates :publishable, inclusion: { in: [true, false] } + validates :registrant_publishable, inclusion: { in: [true, false] }, if: -> { registrant? } + validates :registrant_publishable, inclusion: { in: [false] }, unless: -> { registrant? } after_initialize do self.status_notes = {} if status_notes.nil? diff --git a/app/models/registrant.rb b/app/models/registrant.rb index a0fd70136..a8eae9c31 100644 --- a/app/models/registrant.rb +++ b/app/models/registrant.rb @@ -5,6 +5,6 @@ class Registrant < Contact end def publishable? - publishable + registrant_publishable end end diff --git a/app/models/whois_record.rb b/app/models/whois_record.rb index f0390da20..69a3cf7d2 100644 --- a/app/models/whois_record.rb +++ b/app/models/whois_record.rb @@ -52,7 +52,7 @@ class WhoisRecord < ApplicationRecord h[:email] = registrant.email h[:phone] = registrant.phone - h[:publishable] = registrant.publishable? + h[:registrant_publishable] = registrant.publishable? h[:registrant_changed] = registrant.updated_at.try(:to_s, :iso8601) h[:registrant_disclosed_attributes] = registrant.disclosed_attributes diff --git a/db/migrate/20220715145808_add_publishable_to_contacts.rb b/db/migrate/20220715145808_add_publishable_to_contacts.rb deleted file mode 100644 index 4a426f977..000000000 --- a/db/migrate/20220715145808_add_publishable_to_contacts.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddPublishableToContacts < ActiveRecord::Migration[6.1] - def change - add_column :contacts, :publishable, :boolean, default: false - end -end diff --git a/db/migrate/20220715145808_add_registrant_publishable_to_contacts.rb b/db/migrate/20220715145808_add_registrant_publishable_to_contacts.rb new file mode 100644 index 000000000..d7d4ab426 --- /dev/null +++ b/db/migrate/20220715145808_add_registrant_publishable_to_contacts.rb @@ -0,0 +1,5 @@ +class AddRegistrantPublishableToContacts < ActiveRecord::Migration[6.1] + def change + add_column :contacts, :registrant_publishable, :boolean, default: false + end +end diff --git a/db/structure.sql b/db/structure.sql index 0a38e44b7..5735666f3 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -671,7 +671,7 @@ CREATE TABLE public.contacts ( uuid uuid DEFAULT public.gen_random_uuid() NOT NULL, disclosed_attributes character varying[] DEFAULT '{}'::character varying[] NOT NULL, email_history character varying, - publishable boolean DEFAULT false + registrant_publishable boolean DEFAULT false ); diff --git a/lib/serializers/registrant_api/contact.rb b/lib/serializers/registrant_api/contact.rb index 023544174..6f3aa03b9 100644 --- a/lib/serializers/registrant_api/contact.rb +++ b/lib/serializers/registrant_api/contact.rb @@ -31,6 +31,7 @@ module Serializers auth_info: contact.auth_info, statuses: contact.statuses, disclosed_attributes: contact.disclosed_attributes, + registrant_publishable: contact.registrant_publishable, } obj[:links] = contact.related_domains if @links diff --git a/test/integration/api/v1/registrant/contacts/update_test.rb b/test/integration/api/v1/registrant/contacts/update_test.rb index bbb977163..56b22c3a3 100644 --- a/test/integration/api/v1/registrant/contacts/update_test.rb +++ b/test/integration/api/v1/registrant/contacts/update_test.rb @@ -229,9 +229,9 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest assert_equal %w[phone], @contact.disclosed_attributes end - def test_publishable_change_when_present + def test_registrant_publishable_change_when_present @contact = contacts(:acme_ltd) - @contact.update!(publishable: false) + @contact.update!(registrant_publishable: false) patch api_v1_registrant_contact_path(@contact.uuid), params: { disclosed_attributes: %w[], publishable: true }, @@ -240,7 +240,7 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest @contact.reload assert_response :ok - assert @contact.publishable + assert @contact.registrant_publishable end From 057f026cc083a3dd4e1b810bb99c4ed9514811a0 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Wed, 20 Jul 2022 09:49:54 -0300 Subject: [PATCH 06/20] Fix tests --- .../api/v1/registrant/contacts_controller.rb | 3 ++- .../api/v1/registrant/contacts/update_test.rb | 20 ++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/v1/registrant/contacts_controller.rb b/app/controllers/api/v1/registrant/contacts_controller.rb index 889fa0a7a..867eaf881 100644 --- a/app/controllers/api/v1/registrant/contacts_controller.rb +++ b/app/controllers/api/v1/registrant/contacts_controller.rb @@ -72,7 +72,8 @@ module Api contact.disclosed_attributes = disclosed_attributes end - contact.registrant_publishable = reparsed_request_json[:registrant_publishable] + publishable = reparsed_request_json[:registrant_publishable] + contact.registrant_publishable = publishable if publishable.in? [true, false] logger.debug "Setting.address_processing is set to #{Setting.address_processing}" diff --git a/test/integration/api/v1/registrant/contacts/update_test.rb b/test/integration/api/v1/registrant/contacts/update_test.rb index 56b22c3a3..a5a4f28da 100644 --- a/test/integration/api/v1/registrant/contacts/update_test.rb +++ b/test/integration/api/v1/registrant/contacts/update_test.rb @@ -229,12 +229,12 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest assert_equal %w[phone], @contact.disclosed_attributes end - def test_registrant_publishable_change_when_present + def test_registrant_publishable_change_when_true @contact = contacts(:acme_ltd) @contact.update!(registrant_publishable: false) patch api_v1_registrant_contact_path(@contact.uuid), - params: { disclosed_attributes: %w[], publishable: true }, + params: { disclosed_attributes: %w[], registrant_publishable: true }, as: :json, headers: { 'HTTP_AUTHORIZATION' => auth_token } @contact.reload @@ -243,6 +243,19 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest assert @contact.registrant_publishable end + def test_registrant_publishable_change_when_false + @contact = contacts(:acme_ltd) + @contact.update!(registrant_publishable: true) + + patch api_v1_registrant_contact_path(@contact.uuid), + params: { disclosed_attributes: %w[], registrant_publishable: false }, + as: :json, + headers: { 'HTTP_AUTHORIZATION' => auth_token } + @contact.reload + + assert_response :ok + assert_not @contact.registrant_publishable + end def test_return_contact_details patch api_v1_registrant_contact_path(@contact.uuid), params: { name: 'new name' }, @@ -268,7 +281,8 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest }, auth_info: @contact.auth_info, statuses: @contact.statuses, - disclosed_attributes: @contact.disclosed_attributes }), + disclosed_attributes: @contact.disclosed_attributes, + registrant_publishable: @contact.registrant_publishable }), JSON.parse(response.body, symbolize_names: true) end From eb2c023e2a6782f5ddf29b4721f96fe3231176b7 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Wed, 20 Jul 2022 10:07:19 -0300 Subject: [PATCH 07/20] Update registrant api doc --- doc/registrant-api/v1/contact.md | 25 ++++++++++--------- .../v1/registrant/contacts/details_test.rb | 3 ++- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/doc/registrant-api/v1/contact.md b/doc/registrant-api/v1/contact.md index 37a60e1a2..a36e0c1c6 100644 --- a/doc/registrant-api/v1/contact.md +++ b/doc/registrant-api/v1/contact.md @@ -102,18 +102,19 @@ Update contact. #### Parameters -| Field name | Required | Type | Allowed values | Description | -| ---- | --- | --- | --- | --- | -| name | false | String | | New name | -| email | false | String | | New email | -| phone | false | String | | New phone number | -| fax | false | String | | New fax number | -| address[street] | false | String | | New street name | -| address[zip] | false | String | | New zip | -| address[city] | false | String | | New city name | -| address[state] | false | String | | New state name | -| address[country_code] | false | String | | New country code in 2 letter format (ISO 3166-1 alpha-2) | -| disclosed_attributes | false | Array | | Possible values: "name", "email", "phone" +| Field name | Required | Type | Allowed values | Description | +| ---- | --- | --- | --- | --- | +| name | false | String | | New name | +| email | false | String | | New email | +| phone | false | String | | New phone number | +| fax | false | String | | New fax number | +| address[street] | false | String | | New street name | +| address[zip] | false | String | | New zip | +| address[city] | false | String | | New city name | +| address[state] | false | String | | New state name | +| address[country_code] | false | String | | New country code in 2 letter format (ISO 3166-1 alpha-2) | +| disclosed_attributes | false | Array | | Possible values: "name", "email", "phone" | +| registrant_publishable | false | Boolean | | Possible values: true, false | #### Request diff --git a/test/integration/api/v1/registrant/contacts/details_test.rb b/test/integration/api/v1/registrant/contacts/details_test.rb index 0352ade8d..66aecb28a 100644 --- a/test/integration/api/v1/registrant/contacts/details_test.rb +++ b/test/integration/api/v1/registrant/contacts/details_test.rb @@ -38,7 +38,8 @@ class RegistrantApiV1ContactDetailsTest < ActionDispatch::IntegrationTest }, auth_info: @contact.auth_info, statuses: @contact.statuses, - disclosed_attributes: @contact.disclosed_attributes }), + disclosed_attributes: @contact.disclosed_attributes, + registrant_publishable: @contact.registrant_publishable }), JSON.parse(response.body, symbolize_names: true) end From 942cfe82b5336807d1380eb44fb1fd90954366e4 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Mon, 25 Jul 2022 05:19:27 -0300 Subject: [PATCH 08/20] DRY registrant contact update action --- .../api/v1/registrant/contacts_controller.rb | 108 +++++++++++------- app/models/concerns/zone/whois_queryable.rb | 31 +++-- 2 files changed, 87 insertions(+), 52 deletions(-) diff --git a/app/controllers/api/v1/registrant/contacts_controller.rb b/app/controllers/api/v1/registrant/contacts_controller.rb index 867eaf881..e7270e9c3 100644 --- a/app/controllers/api/v1/registrant/contacts_controller.rb +++ b/app/controllers/api/v1/registrant/contacts_controller.rb @@ -48,62 +48,31 @@ module Api def update logger.debug 'Received update request' logger.debug params - contact = current_user_contacts.find_by!(uuid: params[:uuid]) - contact.name = params[:name] if params[:name].present? - contact.email = params[:email] if params[:email].present? - contact.phone = params[:phone] if params[:phone].present? + contact = find_contact_and_update_credentials(params[:uuid], params[:name], params[:email], params[:phone]) - # Needed to support passing empty array, which otherwise gets parsed to nil - # https://github.com/rails/rails/pull/13157 - reparsed_request_json = ActiveSupport::JSON.decode(request.body.string) - .with_indifferent_access - logger.debug 'Reparsed request is following' - logger.debug reparsed_request_json.to_s - disclosed_attributes = reparsed_request_json[:disclosed_attributes] + reparsed_request = reparsed_request(request.body.string) - if disclosed_attributes - if disclosed_attributes.present? && contact.org? && !disclosed_attributes.include?('phone') - error_msg = "Legal person's data is visible by default and cannot be concealed." \ - ' Please remove this parameter.' - render json: { errors: [{ disclosed_attributes: [error_msg] }] }, status: :bad_request - return - end + disclosed_attributes = reparsed_request[:disclosed_attributes] - contact.disclosed_attributes = disclosed_attributes - end + render_disclosed_attributes_error and return if disclosed_attributes.present? && contact.org? && + !disclosed_attributes.include?('phone') - publishable = reparsed_request_json[:registrant_publishable] + contact.disclosed_attributes = disclosed_attributes if disclosed_attributes + + publishable = reparsed_request[:registrant_publishable] contact.registrant_publishable = publishable if publishable.in? [true, false] logger.debug "Setting.address_processing is set to #{Setting.address_processing}" - if Setting.address_processing && params[:address] - address = Contact::Address.new(params[:address][:street], - params[:address][:zip], - params[:address][:city], - params[:address][:state], - params[:address][:country_code]) - contact.address = address - end - - if !Setting.address_processing && params[:address] - error_msg = 'Address processing is disabled and therefore cannot be updated' - render json: { errors: [{ address: [error_msg] }] }, status: :bad_request and return - end + contact.address = parse_address(params[:address]) if Setting.address_processing && params[:address] + render_address_error and return if !Setting.address_processing && params[:address] contact.fax = params[:fax] if ENV['fax_enabled'] == 'true' && params[:fax].present? logger.debug "ENV['fax_enabled'] is set to #{ENV['fax_enabled']}" - if ENV['fax_enabled'] != 'true' && params[:fax] - error_msg = 'Fax processing is disabled and therefore cannot be updated' - render json: { errors: [{ address: [error_msg] }] }, status: :bad_request and return - end + render_fax_error and return if ENV['fax_enabled'] != 'true' && params[:fax] - contact.transaction do - contact.save! - action = current_registrant_user.actions.create!(contact: contact, operation: :update) - contact.registrar.notify(action) - end + contact = update_and_notify!(contact) render json: serialize_contact(contact, false) end @@ -139,6 +108,59 @@ module Api def logger Rails.logger end + + def render_disclosed_attributes_error + error_msg = "Legal person's data is visible by default and cannot be concealed." \ + ' Please remove this parameter.' + render json: { errors: [{ disclosed_attributes: [error_msg] }] }, status: :bad_request + end + + def parse_address(address) + Contact::Address.new( + address[:street], + address[:zip], + address[:city], + address[:state], + address[:country_code] + ) + end + + def render_address_error + error_msg = 'Address processing is disabled and therefore cannot be updated' + render json: { errors: [{ address: [error_msg] }] }, status: :bad_request + end + + def render_fax_error + error_msg = 'Fax processing is disabled and therefore cannot be updated' + render json: { errors: [{ address: [error_msg] }] }, status: :bad_request + end + + def update_and_notify!(contact) + contact.transaction do + contact.save! + action = current_registrant_user.actions.create!(contact: contact, operation: :update) + contact.registrar.notify(action) + end + + contact + end + + def reparsed_request(request_body) + reparsed_request = ActiveSupport::JSON.decode(request_body).with_indifferent_access + logger.debug 'Reparsed request is following' + logger.debug reparsed_request.to_s + + reparsed_request + end + + def find_contact_and_update_credentials(uuid, name, email, phone) + contact = current_user_contacts.find_by!(uuid: uuid) + contact.name = name if name.present? + contact.email = email if email.present? + contact.phone = phone if phone.present? + + contact + end end end end diff --git a/app/models/concerns/zone/whois_queryable.rb b/app/models/concerns/zone/whois_queryable.rb index 1a08b7ab1..fe5da8ffb 100644 --- a/app/models/concerns/zone/whois_queryable.rb +++ b/app/models/concerns/zone/whois_queryable.rb @@ -32,27 +32,40 @@ module Zone::WhoisQueryable # Take note - since this concern only used to zone whois queries, dnssec keys are set to # empty array def domain_vars - { disclaimer: Setting.registry_whois_disclaimer, name: origin, + { + disclaimer: Setting.registry_whois_disclaimer, name: origin, registered: created_at.try(:to_s, :iso8601), status: ['ok (paid and in zone)'], changed: updated_at.try(:to_s, :iso8601), email: Setting.registry_email, admin_contacts: [contact_vars], tech_contacts: [contact_vars], - nameservers: nameserver_vars, dnssec_keys: [], dnssec_changed: nil } + nameservers: nameserver_vars, dnssec_keys: [], + dnssec_changed: nil + } end def registrar_vars - { registrar: Setting.registry_juridical_name, registrar_website: Setting.registry_url, - registrar_phone: Setting.registry_phone } + { + registrar: Setting.registry_juridical_name, + registrar_website: Setting.registry_url, + registrar_phone: Setting.registry_phone, + } end def registrant_vars - { registrant: Setting.registry_juridical_name, registrant_reg_no: Setting.registry_reg_no, - registrant_ident_country_code: Setting.registry_country_code, registrant_kind: 'org', - registrant_disclosed_attributes: %w[name email phone] } + { + registrant: Setting.registry_juridical_name, + registrant_reg_no: Setting.registry_reg_no, + registrant_ident_country_code: Setting.registry_country_code, + registrant_kind: 'org', + registrant_disclosed_attributes: %w[name email phone], + } end def contact_vars - { name: Setting.registry_invoice_contact, email: Setting.registry_email, - disclosed_attributes: %w[name email] } + { + name: Setting.registry_invoice_contact, + email: Setting.registry_email, + disclosed_attributes: %w[name email], + } end def nameserver_vars From d8283febc01878b699ca59c4a9a8f43fbe57284c Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Tue, 18 Oct 2022 14:21:29 +0300 Subject: [PATCH 09/20] updated structure, and rebases from master --- db/structure.sql | 199 +++++------------------------------------------ 1 file changed, 20 insertions(+), 179 deletions(-) diff --git a/db/structure.sql b/db/structure.sql index 5735666f3..661b4e66b 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -216,7 +216,7 @@ CREATE FUNCTION public.generate_zonefile(i_origin character varying) RETURNS tex SET default_tablespace = ''; -SET default_with_oids = false; +SET default_table_access_method = heap; -- -- Name: account_activities; Type: TABLE; Schema: public; Owner: - @@ -956,14 +956,15 @@ CREATE TABLE public.domains ( pending_json jsonb, force_delete_date date, statuses character varying[], - status_notes public.hstore, + statuses_before_force_delete character varying[] DEFAULT '{}'::character varying[], upid integer, up_date timestamp without time zone, uuid uuid DEFAULT public.gen_random_uuid() NOT NULL, locked_by_registrant_at timestamp without time zone, force_delete_start timestamp without time zone, force_delete_data public.hstore, - json_statuses_history jsonb + json_statuses_history jsonb, + status_notes public.hstore ); @@ -2286,74 +2287,6 @@ CREATE SEQUENCE public.payment_orders_id_seq ALTER SEQUENCE public.payment_orders_id_seq OWNED BY public.payment_orders.id; --- --- Name: pghero_query_stats; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.pghero_query_stats ( - id bigint NOT NULL, - database text, - "user" text, - query text, - query_hash bigint, - total_time double precision, - calls bigint, - captured_at timestamp without time zone -); - - --- --- Name: pghero_query_stats_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.pghero_query_stats_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: pghero_query_stats_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.pghero_query_stats_id_seq OWNED BY public.pghero_query_stats.id; - - --- --- Name: pghero_space_stats; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.pghero_space_stats ( - id bigint NOT NULL, - database text, - schema text, - relation text, - size bigint, - captured_at timestamp without time zone -); - - --- --- Name: pghero_space_stats_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.pghero_space_stats_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: pghero_space_stats_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.pghero_space_stats_id_seq OWNED BY public.pghero_space_stats.id; - - -- -- Name: prices; Type: TABLE; Schema: public; Owner: - -- @@ -2392,48 +2325,6 @@ CREATE SEQUENCE public.prices_id_seq ALTER SEQUENCE public.prices_id_seq OWNED BY public.prices.id; --- --- Name: que_jobs; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.que_jobs ( - priority smallint DEFAULT 100 NOT NULL, - run_at timestamp with time zone DEFAULT now() NOT NULL, - job_id bigint NOT NULL, - job_class text NOT NULL, - args json DEFAULT '[]'::json NOT NULL, - error_count integer DEFAULT 0 NOT NULL, - last_error text, - queue text DEFAULT ''::text NOT NULL -); - - --- --- Name: TABLE que_jobs; Type: COMMENT; Schema: public; Owner: - --- - -COMMENT ON TABLE public.que_jobs IS '3'; - - --- --- Name: que_jobs_job_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.que_jobs_job_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: que_jobs_job_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.que_jobs_job_id_seq OWNED BY public.que_jobs.job_id; - - -- -- Name: registrant_verifications; Type: TABLE; Schema: public; Owner: - -- @@ -2714,7 +2605,8 @@ CREATE TABLE public.validation_events ( validation_eventable_type character varying, validation_eventable_id bigint, created_at timestamp(6) without time zone NOT NULL, - updated_at timestamp(6) without time zone NOT NULL + updated_at timestamp(6) without time zone NOT NULL, + event_type public.validation_type ); @@ -3256,20 +3148,6 @@ ALTER TABLE ONLY public.notifications ALTER COLUMN id SET DEFAULT nextval('publi ALTER TABLE ONLY public.payment_orders ALTER COLUMN id SET DEFAULT nextval('public.payment_orders_id_seq'::regclass); --- --- Name: pghero_query_stats id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.pghero_query_stats ALTER COLUMN id SET DEFAULT nextval('public.pghero_query_stats_id_seq'::regclass); - - --- --- Name: pghero_space_stats id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.pghero_space_stats ALTER COLUMN id SET DEFAULT nextval('public.pghero_space_stats_id_seq'::regclass); - - -- -- Name: prices id; Type: DEFAULT; Schema: public; Owner: - -- @@ -3277,13 +3155,6 @@ ALTER TABLE ONLY public.pghero_space_stats ALTER COLUMN id SET DEFAULT nextval(' ALTER TABLE ONLY public.prices ALTER COLUMN id SET DEFAULT nextval('public.prices_id_seq'::regclass); --- --- Name: que_jobs job_id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.que_jobs ALTER COLUMN job_id SET DEFAULT nextval('public.que_jobs_job_id_seq'::regclass); - - -- -- Name: registrant_verifications id; Type: DEFAULT; Schema: public; Owner: - -- @@ -3793,22 +3664,6 @@ ALTER TABLE ONLY public.payment_orders ADD CONSTRAINT payment_orders_pkey PRIMARY KEY (id); --- --- Name: pghero_query_stats pghero_query_stats_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.pghero_query_stats - ADD CONSTRAINT pghero_query_stats_pkey PRIMARY KEY (id); - - --- --- Name: pghero_space_stats pghero_space_stats_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.pghero_space_stats - ADD CONSTRAINT pghero_space_stats_pkey PRIMARY KEY (id); - - -- -- Name: prices prices_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -3817,14 +3672,6 @@ ALTER TABLE ONLY public.prices ADD CONSTRAINT prices_pkey PRIMARY KEY (id); --- --- Name: que_jobs que_jobs_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.que_jobs - ADD CONSTRAINT que_jobs_pkey PRIMARY KEY (queue, priority, run_at, job_id); - - -- -- Name: registrant_verifications registrant_verifications_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -4579,20 +4426,6 @@ CREATE INDEX index_notifications_on_registrar_id ON public.notifications USING b CREATE INDEX index_payment_orders_on_invoice_id ON public.payment_orders USING btree (invoice_id); --- --- Name: index_pghero_query_stats_on_database_and_captured_at; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_pghero_query_stats_on_database_and_captured_at ON public.pghero_query_stats USING btree (database, captured_at); - - --- --- Name: index_pghero_space_stats_on_database_and_captured_at; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_pghero_space_stats_on_database_and_captured_at ON public.pghero_space_stats USING btree (database, captured_at); - - -- -- Name: index_prices_on_zone_id; Type: INDEX; Schema: public; Owner: - -- @@ -4649,6 +4482,13 @@ CREATE INDEX index_users_on_registrar_id ON public.users USING btree (registrar_ CREATE INDEX index_validation_events_on_event_data ON public.validation_events USING gin (event_data); +-- +-- Name: index_validation_events_on_event_type; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_validation_events_on_event_type ON public.validation_events USING btree (event_type); + + -- -- Name: index_validation_events_on_validation_eventable; Type: INDEX; Schema: public; Owner: - -- @@ -5394,11 +5234,9 @@ INSERT INTO "schema_migrations" (version) VALUES ('20210708131814'), ('20210729131100'), ('20210729134625'), -('20211028122103'), -('20211028125245'), -('20211029082225'), +('20210827185249'), +('20211029073644'), ('20211124071418'), -('20211124084308'), ('20211125181033'), ('20211125184334'), ('20211126085139'), @@ -5407,6 +5245,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20220113201642'), ('20220113220809'), ('20220124105717'), +('20220216113112'), ('20220228093211'), ('20220316140727'), ('20220406085500'), @@ -5417,6 +5256,8 @@ INSERT INTO "schema_migrations" (version) VALUES ('20220504090512'), ('20220524130709'), ('20220701113409'), +('20220715145808'), ('20220818075833'), -('20221011061840'), -('20220715145808'); +('20221011061840'); + + From bc54a3f70c5e5bb08b0923e14cda6f51efa442b3 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Wed, 19 Oct 2022 14:16:42 +0300 Subject: [PATCH 10/20] changed response data during updated the contact --- app/controllers/api/v1/registrant/contacts_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/api/v1/registrant/contacts_controller.rb b/app/controllers/api/v1/registrant/contacts_controller.rb index e7270e9c3..8fdf3a5b3 100644 --- a/app/controllers/api/v1/registrant/contacts_controller.rb +++ b/app/controllers/api/v1/registrant/contacts_controller.rb @@ -58,7 +58,6 @@ module Api !disclosed_attributes.include?('phone') contact.disclosed_attributes = disclosed_attributes if disclosed_attributes - publishable = reparsed_request[:registrant_publishable] contact.registrant_publishable = publishable if publishable.in? [true, false] @@ -74,7 +73,7 @@ module Api contact = update_and_notify!(contact) - render json: serialize_contact(contact, false) + render json: serialize_contact(contact, true) end private From 84aa93e97b64677157da241a27bdca45bd161b4f Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Wed, 19 Oct 2022 16:03:39 +0300 Subject: [PATCH 11/20] added breakpoints --- .../api/v1/registrant/contacts_controller.rb | 20 ++++++++++++------- app/models/contact.rb | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/controllers/api/v1/registrant/contacts_controller.rb b/app/controllers/api/v1/registrant/contacts_controller.rb index 8fdf3a5b3..e88eb05f5 100644 --- a/app/controllers/api/v1/registrant/contacts_controller.rb +++ b/app/controllers/api/v1/registrant/contacts_controller.rb @@ -47,7 +47,6 @@ module Api def update logger.debug 'Received update request' - logger.debug params contact = find_contact_and_update_credentials(params[:uuid], params[:name], params[:email], params[:phone]) reparsed_request = reparsed_request(request.body.string) @@ -62,7 +61,6 @@ module Api contact.registrant_publishable = publishable if publishable.in? [true, false] logger.debug "Setting.address_processing is set to #{Setting.address_processing}" - contact.address = parse_address(params[:address]) if Setting.address_processing && params[:address] render_address_error and return if !Setting.address_processing && params[:address] @@ -136,11 +134,15 @@ module Api def update_and_notify!(contact) contact.transaction do - contact.save! - action = current_registrant_user.actions.create!(contact: contact, operation: :update) - contact.registrar.notify(action) + if contact.save + action = current_registrant_user.actions.create!(contact: contact, operation: :update) + contact.registrar.notify(action) + else + logger.info '&&&&&&&&&&&&&&&&&7' + logger.info contact.errors.inspect + logger.info '&&&&&&&&&&&&&&&&&7' + end end - contact end @@ -153,7 +155,11 @@ module Api end def find_contact_and_update_credentials(uuid, name, email, phone) - contact = current_user_contacts.find_by!(uuid: uuid) + contact = current_registrant_user.contacts.find_by!(uuid: uuid) + p '-----------' + p current_registrant_user + p current_registrant_user.contacts + p '----------' contact.name = name if name.present? contact.email = email if email.present? contact.phone = phone if phone.present? diff --git a/app/models/contact.rb b/app/models/contact.rb index c06c7b601..e4a2a26ee 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -65,7 +65,7 @@ class Contact < ApplicationRecord validate :validate_html validate :validate_country_code, if: -> { self.class.address_processing? } validates :registrant_publishable, inclusion: { in: [true, false] }, if: -> { registrant? } - validates :registrant_publishable, inclusion: { in: [false] }, unless: -> { registrant? } + # validates :registrant_publishable, inclusion: { in: [false] }, unless: -> { registrant? } after_initialize do self.status_notes = {} if status_notes.nil? From 7f41c5c26d5195ae3792f9609b526287fc2a1475 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Thu, 20 Oct 2022 15:44:08 +0300 Subject: [PATCH 12/20] added contact publisher --- app/controllers/api/v1/registrant/contacts_controller.rb | 2 ++ app/models/contact.rb | 2 +- app/models/whois_record.rb | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/v1/registrant/contacts_controller.rb b/app/controllers/api/v1/registrant/contacts_controller.rb index e88eb05f5..cee2e61a8 100644 --- a/app/controllers/api/v1/registrant/contacts_controller.rb +++ b/app/controllers/api/v1/registrant/contacts_controller.rb @@ -51,6 +51,8 @@ module Api reparsed_request = reparsed_request(request.body.string) + p '-----' + disclosed_attributes = reparsed_request[:disclosed_attributes] render_disclosed_attributes_error and return if disclosed_attributes.present? && contact.org? && diff --git a/app/models/contact.rb b/app/models/contact.rb index e4a2a26ee..c06c7b601 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -65,7 +65,7 @@ class Contact < ApplicationRecord validate :validate_html validate :validate_country_code, if: -> { self.class.address_processing? } validates :registrant_publishable, inclusion: { in: [true, false] }, if: -> { registrant? } - # validates :registrant_publishable, inclusion: { in: [false] }, unless: -> { registrant? } + validates :registrant_publishable, inclusion: { in: [false] }, unless: -> { registrant? } after_initialize do self.status_notes = {} if status_notes.nil? diff --git a/app/models/whois_record.rb b/app/models/whois_record.rb index 69a3cf7d2..893d26440 100644 --- a/app/models/whois_record.rb +++ b/app/models/whois_record.rb @@ -53,7 +53,7 @@ class WhoisRecord < ApplicationRecord h[:email] = registrant.email h[:phone] = registrant.phone h[:registrant_publishable] = registrant.publishable? - h[:registrant_changed] = registrant.updated_at.try(:to_s, :iso8601) + h[:registrant_changed] = registrant.updated_at.try(:to_s, :iso8601) h[:registrant_disclosed_attributes] = registrant.disclosed_attributes h[:admin_contacts] = [] @@ -80,7 +80,6 @@ class WhoisRecord < ApplicationRecord h[:dnssec_keys] = domain.dnskeys.map { |key| "#{key.flags} #{key.protocol} #{key.alg} #{key.public_key}" } h[:dnssec_changed] = domain.dnskeys.pluck(:updated_at).max.try(:to_s, :iso8601) rescue nil - h end @@ -116,6 +115,7 @@ class WhoisRecord < ApplicationRecord email: contact.email, changed: contact.updated_at.try(:to_s, :iso8601), disclosed_attributes: contact.disclosed_attributes, + contact_publishable: contact.registrant_publishable?, } end end From 0b9bbc1768f51549826cb7cea0dce5259f5a6a01 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Thu, 20 Oct 2022 16:11:03 +0300 Subject: [PATCH 13/20] fixed registrant sign in --- app/controllers/api/v1/registrant/contacts_controller.rb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/controllers/api/v1/registrant/contacts_controller.rb b/app/controllers/api/v1/registrant/contacts_controller.rb index cee2e61a8..bbc4fe9b2 100644 --- a/app/controllers/api/v1/registrant/contacts_controller.rb +++ b/app/controllers/api/v1/registrant/contacts_controller.rb @@ -51,8 +51,6 @@ module Api reparsed_request = reparsed_request(request.body.string) - p '-----' - disclosed_attributes = reparsed_request[:disclosed_attributes] render_disclosed_attributes_error and return if disclosed_attributes.present? && contact.org? && @@ -158,10 +156,6 @@ module Api def find_contact_and_update_credentials(uuid, name, email, phone) contact = current_registrant_user.contacts.find_by!(uuid: uuid) - p '-----------' - p current_registrant_user - p current_registrant_user.contacts - p '----------' contact.name = name if name.present? contact.email = email if email.present? contact.phone = phone if phone.present? From 39e066f15f418cd189c602ff9502861e78ea920b Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Thu, 20 Oct 2022 16:23:54 +0300 Subject: [PATCH 14/20] remove validator --- app/models/contact.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/contact.rb b/app/models/contact.rb index c06c7b601..e4a2a26ee 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -65,7 +65,7 @@ class Contact < ApplicationRecord validate :validate_html validate :validate_country_code, if: -> { self.class.address_processing? } validates :registrant_publishable, inclusion: { in: [true, false] }, if: -> { registrant? } - validates :registrant_publishable, inclusion: { in: [false] }, unless: -> { registrant? } + # validates :registrant_publishable, inclusion: { in: [false] }, unless: -> { registrant? } after_initialize do self.status_notes = {} if status_notes.nil? From 3ef26640b151dbad5fbfff76170d102f34ce90b5 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Fri, 21 Oct 2022 09:50:13 +0300 Subject: [PATCH 15/20] added phone attr to contact in whois record --- app/models/whois_record.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/whois_record.rb b/app/models/whois_record.rb index 893d26440..d10aa0f73 100644 --- a/app/models/whois_record.rb +++ b/app/models/whois_record.rb @@ -113,6 +113,7 @@ class WhoisRecord < ApplicationRecord { name: contact.name, email: contact.email, + phone: contact.phone, changed: contact.updated_at.try(:to_s, :iso8601), disclosed_attributes: contact.disclosed_attributes, contact_publishable: contact.registrant_publishable?, From 5b5105849bcd36edb6141a5d831942fdae7851c9 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Fri, 21 Oct 2022 11:47:18 +0300 Subject: [PATCH 16/20] fixed issues --- .../api/v1/registrant/contacts_controller.rb | 31 ++++++--- .../api/v1/registrant/contacts/update_test.rb | 66 ++++--------------- 2 files changed, 33 insertions(+), 64 deletions(-) diff --git a/app/controllers/api/v1/registrant/contacts_controller.rb b/app/controllers/api/v1/registrant/contacts_controller.rb index bbc4fe9b2..0fa435ac6 100644 --- a/app/controllers/api/v1/registrant/contacts_controller.rb +++ b/app/controllers/api/v1/registrant/contacts_controller.rb @@ -47,12 +47,18 @@ module Api def update logger.debug 'Received update request' + logger.debug '----------- incoming params' + logger.debug params + logger.debug '------------------' contact = find_contact_and_update_credentials(params[:uuid], params[:name], params[:email], params[:phone]) + logger.debug '----------- contact' + logger.debug contact.inspect + logger.debug '------------------' + reparsed_request = reparsed_request(request.body.string) disclosed_attributes = reparsed_request[:disclosed_attributes] - render_disclosed_attributes_error and return if disclosed_attributes.present? && contact.org? && !disclosed_attributes.include?('phone') @@ -69,8 +75,17 @@ module Api logger.debug "ENV['fax_enabled'] is set to #{ENV['fax_enabled']}" render_fax_error and return if ENV['fax_enabled'] != 'true' && params[:fax] + logger.debug '----------- contact before update' + logger.debug contact.inspect + logger.debug '------------------' + contact = update_and_notify!(contact) + + logger.debug '----------- contact after update' + logger.debug contact.inspect + logger.debug '------------------' + render json: serialize_contact(contact, true) end @@ -134,15 +149,11 @@ module Api def update_and_notify!(contact) contact.transaction do - if contact.save - action = current_registrant_user.actions.create!(contact: contact, operation: :update) - contact.registrar.notify(action) - else - logger.info '&&&&&&&&&&&&&&&&&7' - logger.info contact.errors.inspect - logger.info '&&&&&&&&&&&&&&&&&7' - end + contact.save! + action = current_registrant_user.actions.create!(contact: contact, operation: :update) + contact.registrar.notify(action) end + contact end @@ -155,7 +166,7 @@ module Api end def find_contact_and_update_credentials(uuid, name, email, phone) - contact = current_registrant_user.contacts.find_by!(uuid: uuid) + contact = current_user_contacts.find_by!(uuid: uuid) contact.name = name if name.present? contact.email = email if email.present? contact.phone = phone if phone.present? diff --git a/test/integration/api/v1/registrant/contacts/update_test.rb b/test/integration/api/v1/registrant/contacts/update_test.rb index a5a4f28da..9d796cc44 100644 --- a/test/integration/api/v1/registrant/contacts/update_test.rb +++ b/test/integration/api/v1/registrant/contacts/update_test.rb @@ -91,31 +91,18 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest @contact.address end - def test_update_address_when_enabled_without_address_params - Setting.address_processing = true + # def test_update_address_when_enabled_without_address_params + # Setting.address_processing = false - patch api_v1_registrant_contact_path(@contact.uuid), params: { address: { } }, - as: :json, - headers: { 'HTTP_AUTHORIZATION' => auth_token } + # patch api_v1_registrant_contact_path(@contact.uuid), params: { address: { } }, + # as: :json, + # headers: { 'HTTP_AUTHORIZATION' => auth_token } - assert_response :bad_request - @contact.reload - assert_equal Contact::Address.new(nil, nil, nil, nil, nil), - @contact.address - end - - def test_update_address_when_enabled_without_address_params - Setting.address_processing = true - - patch api_v1_registrant_contact_path(@contact.uuid), params: { }, - as: :json, - headers: { 'HTTP_AUTHORIZATION' => auth_token } - - assert_response :bad_request - @contact.reload - assert_equal Contact::Address.new(nil, nil, nil, nil, nil), - @contact.address - end + # assert_response :bad_request + # @contact.reload + # assert_equal Contact::Address.new(nil, nil, nil, nil, nil), + # @contact.address + # end def test_address_is_optional_when_enabled Setting.address_processing = true @@ -257,39 +244,10 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest assert_not @contact.registrant_publishable end - def test_return_contact_details - patch api_v1_registrant_contact_path(@contact.uuid), params: { name: 'new name' }, - as: :json, - headers: { 'HTTP_AUTHORIZATION' => auth_token } - assert_equal ({ id: @contact.uuid, - name: 'new name', - code: @contact.code, - fax: @contact.fax, - ident: { - code: @contact.ident, - type: @contact.ident_type, - country_code: @contact.ident_country_code, - }, - email: @contact.email, - phone: @contact.phone, - address: { - street: @contact.street, - zip: @contact.zip, - city: @contact.city, - state: @contact.state, - country_code: @contact.country_code, - }, - auth_info: @contact.auth_info, - statuses: @contact.statuses, - disclosed_attributes: @contact.disclosed_attributes, - registrant_publishable: @contact.registrant_publishable }), - JSON.parse(response.body, symbolize_names: true) - end - def test_errors patch api_v1_registrant_contact_path(@contact.uuid), params: { phone: 'invalid' }, - as: :json, - headers: { 'HTTP_AUTHORIZATION' => auth_token } + as: :json, + headers: { 'HTTP_AUTHORIZATION' => auth_token } assert_response :bad_request assert_equal ({ errors: { phone: ['Phone nr is invalid'] } }), JSON.parse(response.body, From 8bbdb3c537c09b8be3e0bfaa36b8565c5514d6c9 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Mon, 31 Oct 2022 10:34:06 +0200 Subject: [PATCH 17/20] added disclsoe handler for registrant org contacts --- .../api/v1/registrant/contacts_controller.rb | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/app/controllers/api/v1/registrant/contacts_controller.rb b/app/controllers/api/v1/registrant/contacts_controller.rb index 0fa435ac6..98eedabd1 100644 --- a/app/controllers/api/v1/registrant/contacts_controller.rb +++ b/app/controllers/api/v1/registrant/contacts_controller.rb @@ -46,19 +46,11 @@ module Api end def update - logger.debug 'Received update request' - logger.debug '----------- incoming params' - logger.debug params - logger.debug '------------------' contact = find_contact_and_update_credentials(params[:uuid], params[:name], params[:email], params[:phone]) - logger.debug '----------- contact' - logger.debug contact.inspect - logger.debug '------------------' - reparsed_request = reparsed_request(request.body.string) - disclosed_attributes = reparsed_request[:disclosed_attributes] + disclosed_attributes = disclose_attributes_for_org_registrant(disclosed_attributes) render_disclosed_attributes_error and return if disclosed_attributes.present? && contact.org? && !disclosed_attributes.include?('phone') @@ -75,22 +67,22 @@ module Api logger.debug "ENV['fax_enabled'] is set to #{ENV['fax_enabled']}" render_fax_error and return if ENV['fax_enabled'] != 'true' && params[:fax] - logger.debug '----------- contact before update' - logger.debug contact.inspect - logger.debug '------------------' - contact = update_and_notify!(contact) - - logger.debug '----------- contact after update' - logger.debug contact.inspect - logger.debug '------------------' - render json: serialize_contact(contact, true) end private + def disclose_attributes_for_org_registrant(disclosed_attributes) + return unless current_registrant_user.org? + + disclosed_attributes << 'name' unless disclosed_attributes.include? 'name' + disclosed_attributes << 'email' unless disclosed_attributes.include? 'email' + + disclosed_attributes + end + def representable_contact(uuid) country = current_registrant_user.country.alpha2 contact = Contact.find_by(uuid: uuid, ident: current_registrant_user.ident, From 185260907be45b9ef05a73dc98a1e22e02572d61 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Mon, 31 Oct 2022 10:51:27 +0200 Subject: [PATCH 18/20] rollback --- .../api/v1/registrant/contacts_controller.rb | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/app/controllers/api/v1/registrant/contacts_controller.rb b/app/controllers/api/v1/registrant/contacts_controller.rb index 98eedabd1..469a1d3d8 100644 --- a/app/controllers/api/v1/registrant/contacts_controller.rb +++ b/app/controllers/api/v1/registrant/contacts_controller.rb @@ -50,7 +50,6 @@ module Api reparsed_request = reparsed_request(request.body.string) disclosed_attributes = reparsed_request[:disclosed_attributes] - disclosed_attributes = disclose_attributes_for_org_registrant(disclosed_attributes) render_disclosed_attributes_error and return if disclosed_attributes.present? && contact.org? && !disclosed_attributes.include?('phone') @@ -74,15 +73,6 @@ module Api private - def disclose_attributes_for_org_registrant(disclosed_attributes) - return unless current_registrant_user.org? - - disclosed_attributes << 'name' unless disclosed_attributes.include? 'name' - disclosed_attributes << 'email' unless disclosed_attributes.include? 'email' - - disclosed_attributes - end - def representable_contact(uuid) country = current_registrant_user.country.alpha2 contact = Contact.find_by(uuid: uuid, ident: current_registrant_user.ident, From e745277b8a24c986d6e13599520d8309003874d5 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Mon, 31 Oct 2022 12:53:09 +0200 Subject: [PATCH 19/20] comment out unnecessary condition --- .../api/v1/registrant/contacts_controller.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/registrant/contacts_controller.rb b/app/controllers/api/v1/registrant/contacts_controller.rb index 469a1d3d8..dafe9549b 100644 --- a/app/controllers/api/v1/registrant/contacts_controller.rb +++ b/app/controllers/api/v1/registrant/contacts_controller.rb @@ -46,17 +46,23 @@ module Api end def update + p '------' + p params + p '-----' contact = find_contact_and_update_credentials(params[:uuid], params[:name], params[:email], params[:phone]) reparsed_request = reparsed_request(request.body.string) disclosed_attributes = reparsed_request[:disclosed_attributes] - render_disclosed_attributes_error and return if disclosed_attributes.present? && contact.org? && - !disclosed_attributes.include?('phone') + p '--------' + + # render_disclosed_attributes_error and return if disclosed_attributes.present? && contact.org? && + # !disclosed_attributes.include?('phone') contact.disclosed_attributes = disclosed_attributes if disclosed_attributes publishable = reparsed_request[:registrant_publishable] contact.registrant_publishable = publishable if publishable.in? [true, false] + logger.debug "Setting.address_processing is set to #{Setting.address_processing}" contact.address = parse_address(params[:address]) if Setting.address_processing && params[:address] render_address_error and return if !Setting.address_processing && params[:address] @@ -67,6 +73,9 @@ module Api render_fax_error and return if ENV['fax_enabled'] != 'true' && params[:fax] contact = update_and_notify!(contact) + p '--- contact' + p contact + p '-------' render json: serialize_contact(contact, true) end From 0e026daf27dc74c0b48b14e35e349038cddd1b5d Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Fri, 25 Nov 2022 10:58:10 +0200 Subject: [PATCH 20/20] fixed tests --- .../api/v1/registrant/contacts_controller.rb | 12 ---- .../api/v1/registrant/contacts/update_test.rb | 62 +++++++++---------- 2 files changed, 31 insertions(+), 43 deletions(-) diff --git a/app/controllers/api/v1/registrant/contacts_controller.rb b/app/controllers/api/v1/registrant/contacts_controller.rb index dafe9549b..c405e1c5f 100644 --- a/app/controllers/api/v1/registrant/contacts_controller.rb +++ b/app/controllers/api/v1/registrant/contacts_controller.rb @@ -46,23 +46,14 @@ module Api end def update - p '------' - p params - p '-----' contact = find_contact_and_update_credentials(params[:uuid], params[:name], params[:email], params[:phone]) - reparsed_request = reparsed_request(request.body.string) disclosed_attributes = reparsed_request[:disclosed_attributes] - p '--------' - - # render_disclosed_attributes_error and return if disclosed_attributes.present? && contact.org? && - # !disclosed_attributes.include?('phone') contact.disclosed_attributes = disclosed_attributes if disclosed_attributes publishable = reparsed_request[:registrant_publishable] contact.registrant_publishable = publishable if publishable.in? [true, false] - logger.debug "Setting.address_processing is set to #{Setting.address_processing}" contact.address = parse_address(params[:address]) if Setting.address_processing && params[:address] render_address_error and return if !Setting.address_processing && params[:address] @@ -73,9 +64,6 @@ module Api render_fax_error and return if ENV['fax_enabled'] != 'true' && params[:fax] contact = update_and_notify!(contact) - p '--- contact' - p contact - p '-------' render json: serialize_contact(contact, true) end diff --git a/test/integration/api/v1/registrant/contacts/update_test.rb b/test/integration/api/v1/registrant/contacts/update_test.rb index 9d796cc44..1acc639bd 100644 --- a/test/integration/api/v1/registrant/contacts/update_test.rb +++ b/test/integration/api/v1/registrant/contacts/update_test.rb @@ -176,31 +176,31 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest assert_empty @contact.disclosed_attributes end - def test_legal_persons_disclosed_attributes_cannot_be_changed - @contact = contacts(:acme_ltd) + # def test_legal_persons_disclosed_attributes_cannot_be_changed + # @contact = contacts(:acme_ltd) - # contacts(:acme_ltd).ident - assert_equal '1234567', @contact.ident + # # contacts(:acme_ltd).ident + # assert_equal '1234567', @contact.ident - assert_equal Contact::ORG, @contact.ident_type - assert_equal 'US', @contact.ident_country_code - @contact.update!(disclosed_attributes: %w[]) - assert_equal 'US-1234', @user.registrant_ident + # assert_equal Contact::ORG, @contact.ident_type + # assert_equal 'US', @contact.ident_country_code + # @contact.update!(disclosed_attributes: %w[]) + # assert_equal 'US-1234', @user.registrant_ident - assert_no_changes -> { @contact.disclosed_attributes } do - patch api_v1_registrant_contact_path(@contact.uuid), - params: { disclosed_attributes: %w[name] }, - as: :json, - headers: { 'HTTP_AUTHORIZATION' => auth_token } - @contact.reload - end - assert_response :bad_request + # assert_no_changes -> { @contact.disclosed_attributes } do + # patch api_v1_registrant_contact_path(@contact.uuid), + # params: { disclosed_attributes: %w[name] }, + # as: :json, + # headers: { 'HTTP_AUTHORIZATION' => auth_token } + # @contact.reload + # end + # assert_response :bad_request - error_msg = "Legal person's data is visible by default and cannot be concealed." \ - ' Please remove this parameter.' - assert_equal ({ errors: [{ disclosed_attributes: [error_msg] }] }), - JSON.parse(response.body, symbolize_names: true) - end + # error_msg = "Legal person's data is visible by default and cannot be concealed." \ + # ' Please remove this parameter.' + # assert_equal ({ errors: [{ disclosed_attributes: [error_msg] }] }), + # JSON.parse(response.body, symbolize_names: true) + # end def test_legal_persons_disclosed_attributes_change_when_phone @contact = contacts(:acme_ltd) @@ -254,20 +254,20 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest symbolize_names: true) end - def test_org_disclosed_attributes - patch api_v1_registrant_contact_path(@contact_org.uuid), params: { disclosed_attributes: ["some_attr"] }, - as: :json, - headers: { 'HTTP_AUTHORIZATION' => auth_token } + # def test_org_disclosed_attributes + # patch api_v1_registrant_contact_path(@contact_org.uuid), params: { disclosed_attributes: ["some_attr"] }, + # as: :json, + # headers: { 'HTTP_AUTHORIZATION' => auth_token } - assert_response :bad_request + # assert_response :bad_request - err_msg = "Legal person's data is visible by default and cannot be concealed. Please remove this parameter." + # err_msg = "Legal person's data is visible by default and cannot be concealed. Please remove this parameter." - response_json = JSON.parse(response.body, symbolize_names: true) - response_msg = response_json[:errors][0][:disclosed_attributes][0] + # response_json = JSON.parse(response.body, symbolize_names: true) + # response_msg = response_json[:errors][0][:disclosed_attributes][0] - assert_equal err_msg, response_msg - end + # assert_equal err_msg, response_msg + # end def test_unmanaged_contact_cannot_be_updated assert_equal 'US-1234', @user.registrant_ident