mirror of
https://github.com/internetee/registry.git
synced 2025-07-25 12:08:27 +02:00
Merge pull request #1968 from internetee/61-registrant-contact-update-fix
Fix contact update via registrant center
This commit is contained in:
commit
21009142d6
2 changed files with 30 additions and 4 deletions
|
@ -35,6 +35,8 @@ module Api
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
logger.debug 'Received update request'
|
||||||
|
logger.debug params
|
||||||
contact = current_user_contacts.find_by!(uuid: params[:uuid])
|
contact = current_user_contacts.find_by!(uuid: params[:uuid])
|
||||||
contact.name = params[:name] if params[:name].present?
|
contact.name = params[:name] if params[:name].present?
|
||||||
contact.email = params[:email] if params[:email].present?
|
contact.email = params[:email] if params[:email].present?
|
||||||
|
@ -44,10 +46,12 @@ module Api
|
||||||
# https://github.com/rails/rails/pull/13157
|
# https://github.com/rails/rails/pull/13157
|
||||||
reparsed_request_json = ActiveSupport::JSON.decode(request.body.string)
|
reparsed_request_json = ActiveSupport::JSON.decode(request.body.string)
|
||||||
.with_indifferent_access
|
.with_indifferent_access
|
||||||
|
logger.debug 'Reparsed request is following'
|
||||||
|
logger.debug reparsed_request_json.to_s
|
||||||
disclosed_attributes = reparsed_request_json[:disclosed_attributes]
|
disclosed_attributes = reparsed_request_json[:disclosed_attributes]
|
||||||
|
|
||||||
if 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." \
|
error_msg = "Legal person's data is visible by default and cannot be concealed." \
|
||||||
' Please remove this parameter.'
|
' Please remove this parameter.'
|
||||||
render json: { errors: [{ disclosed_attributes: [error_msg] }] }, status: :bad_request
|
render json: { errors: [{ disclosed_attributes: [error_msg] }] }, status: :bad_request
|
||||||
|
@ -57,6 +61,8 @@ module Api
|
||||||
contact.disclosed_attributes = disclosed_attributes
|
contact.disclosed_attributes = disclosed_attributes
|
||||||
end
|
end
|
||||||
|
|
||||||
|
logger.debug "Setting.address_processing is set to #{Setting.address_processing}"
|
||||||
|
|
||||||
if Setting.address_processing && params[:address]
|
if Setting.address_processing && params[:address]
|
||||||
address = Contact::Address.new(params[:address][:street],
|
address = Contact::Address.new(params[:address][:street],
|
||||||
params[:address][:zip],
|
params[:address][:zip],
|
||||||
|
@ -75,6 +81,7 @@ module Api
|
||||||
contact.fax = params[:fax] if params[:fax].present?
|
contact.fax = params[:fax] if params[:fax].present?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
logger.debug "ENV['fax_enabled'] is set to #{ENV['fax_enabled']}"
|
||||||
if ENV['fax_enabled'] != 'true' && params[:fax]
|
if ENV['fax_enabled'] != 'true' && params[:fax]
|
||||||
error_msg = 'Fax processing is disabled and therefore cannot be updated'
|
error_msg = 'Fax processing is disabled and therefore cannot be updated'
|
||||||
render json: { errors: [{ address: [error_msg] }] }, status: :bad_request and return
|
render json: { errors: [{ address: [error_msg] }] }, status: :bad_request and return
|
||||||
|
@ -116,6 +123,10 @@ module Api
|
||||||
def serialize_contact(contact, links)
|
def serialize_contact(contact, links)
|
||||||
Serializers::RegistrantApi::Contact.new(contact, links).to_json
|
Serializers::RegistrantApi::Contact.new(contact, links).to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def logger
|
||||||
|
Rails.logger
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,7 +9,7 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
|
||||||
@original_address_processing = Setting.address_processing
|
@original_address_processing = Setting.address_processing
|
||||||
@original_fax_enabled_setting = ENV['fax_enabled']
|
@original_fax_enabled_setting = ENV['fax_enabled']
|
||||||
@user = users(:registrant)
|
@user = users(:registrant)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
teardown do
|
teardown do
|
||||||
|
@ -160,6 +160,21 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
|
||||||
assert_equal %w[name], @contact.disclosed_attributes
|
assert_equal %w[name], @contact.disclosed_attributes
|
||||||
end
|
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
|
def test_conceal_private_persons_data
|
||||||
@contact.update!(ident_type: Contact::PRIV, disclosed_attributes: %w[name])
|
@contact.update!(ident_type: Contact::PRIV, disclosed_attributes: %w[name])
|
||||||
|
|
||||||
|
@ -244,9 +259,9 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
|
||||||
headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
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_json = JSON.parse(response.body, symbolize_names: true)
|
||||||
response_msg = response_json[:errors][0][:disclosed_attributes][0]
|
response_msg = response_json[:errors][0][:disclosed_attributes][0]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue