From 5c129b24ef3517e84deb33980a9addd14de4986e Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Fri, 15 Jul 2022 16:47:30 -0300 Subject: [PATCH] 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');