From 40579a8488d46e96b6fb99659333e7820522137d Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Wed, 12 May 2021 14:10:10 +0500 Subject: [PATCH] Fix condition on disclosed attrs presence --- .../api/v1/registrant/contacts_controller.rb | 4 ++-- .../api/v1/registrant/contacts/update_test.rb | 21 ++++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/v1/registrant/contacts_controller.rb b/app/controllers/api/v1/registrant/contacts_controller.rb index ce65766e2..73bd98cba 100644 --- a/app/controllers/api/v1/registrant/contacts_controller.rb +++ b/app/controllers/api/v1/registrant/contacts_controller.rb @@ -47,11 +47,11 @@ module Api reparsed_request_json = ActiveSupport::JSON.decode(request.body.string) .with_indifferent_access logger.debug 'Reparsed request is following' - logger.debug "#{reparsed_request_json}" + logger.debug reparsed_request_json.to_s disclosed_attributes = reparsed_request_json[:disclosed_attributes] if disclosed_attributes - if contact.org? + if disclosed_attributes.present? && contact.org? 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 c1eaa005c..d7a3060b6 100644 --- a/test/integration/api/v1/registrant/contacts/update_test.rb +++ b/test/integration/api/v1/registrant/contacts/update_test.rb @@ -9,7 +9,7 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest @original_address_processing = Setting.address_processing @original_fax_enabled_setting = ENV['fax_enabled'] @user = users(:registrant) - + end teardown do @@ -160,6 +160,21 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest assert_equal %w[name], @contact.disclosed_attributes end + def test_updates_org_person_data + name = 'SomeWeirdName' + @contact.update!(ident_type: Contact::ORG, + disclosed_attributes: %w[]) + + patch api_v1_registrant_contact_path(@contact.uuid), + params: { disclosed_attributes: %w[], name: name }, + as: :json, + headers: { 'HTTP_AUTHORIZATION' => auth_token } + @contact.reload + + assert_response :ok + assert_equal name, @contact.name + end + def test_conceal_private_persons_data @contact.update!(ident_type: Contact::PRIV, disclosed_attributes: %w[name]) @@ -244,9 +259,9 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest headers: { 'HTTP_AUTHORIZATION' => auth_token } assert_response :bad_request - + 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]