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,