Fix condition on disclosed attrs presence

This commit is contained in:
Alex Sherman 2021-05-12 14:10:10 +05:00
parent b5d175798e
commit 40579a8488
2 changed files with 20 additions and 5 deletions

View file

@ -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

View file

@ -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])