From 5c70e9f38b677362950e8751b9b4cd924b0d00f9 Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Mon, 11 Jul 2022 11:20:05 -0300 Subject: [PATCH] Add registrant phone to whois record json --- .../api/v1/contact_requests_controller.rb | 3 +- app/models/concerns/zone/whois_queryable.rb | 2 +- app/models/contact_request.rb | 30 ++++++++++--------- app/models/whois_record.rb | 1 + doc/registrant-api/v1/contact.md | 2 +- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/app/controllers/api/v1/contact_requests_controller.rb b/app/controllers/api/v1/contact_requests_controller.rb index 1ef73e9ef..51c967bd5 100644 --- a/app/controllers/api/v1/contact_requests_controller.rb +++ b/app/controllers/api/v1/contact_requests_controller.rb @@ -3,7 +3,6 @@ module Api class ContactRequestsController < BaseController before_action :authenticate_shared_key - # POST api/v1/contact_requests/ def create return head(:bad_request) if contact_request_params[:email].blank? @@ -19,6 +18,8 @@ module Api process_id(params[:id]) end + private + def process_id(id) record = ContactRequest.find_by(id: id) return :not_found unless record diff --git a/app/models/concerns/zone/whois_queryable.rb b/app/models/concerns/zone/whois_queryable.rb index 7c6ff511d..1a08b7ab1 100644 --- a/app/models/concerns/zone/whois_queryable.rb +++ b/app/models/concerns/zone/whois_queryable.rb @@ -47,7 +47,7 @@ module Zone::WhoisQueryable def registrant_vars { registrant: Setting.registry_juridical_name, registrant_reg_no: Setting.registry_reg_no, registrant_ident_country_code: Setting.registry_country_code, registrant_kind: 'org', - registrant_disclosed_attributes: %w[name email] } + registrant_disclosed_attributes: %w[name email phone] } end def contact_vars diff --git a/app/models/contact_request.rb b/app/models/contact_request.rb index f4c6db716..9dc028885 100644 --- a/app/models/contact_request.rb +++ b/app/models/contact_request.rb @@ -15,15 +15,6 @@ class ContactRequest < ApplicationRecord attr_readonly :secret, :valid_to - def self.save_record(params) - contact_request = new(params) - contact_request.secret = create_random_secret - contact_request.valid_to = set_valid_to_24_hours_from_now - contact_request.status = STATUS_NEW - contact_request.save! - contact_request - end - def update_record(params) self.status = params['status'] if params['status'] self.ip_address = params['ip'] if params['ip'] @@ -31,11 +22,22 @@ class ContactRequest < ApplicationRecord save! end - def self.create_random_secret - SecureRandom.hex(64) - end + class << self + def save_record(params) + contact_request = new(params) + contact_request.secret = create_random_secret + contact_request.valid_to = set_valid_to_24_hours_from_now + contact_request.status = STATUS_NEW + contact_request.save! + contact_request + end - def self.set_valid_to_24_hours_from_now - (Time.zone.now + 24.hours) + def create_random_secret + SecureRandom.hex(64) + end + + def set_valid_to_24_hours_from_now + (Time.zone.now + 24.hours) + end end end diff --git a/app/models/whois_record.rb b/app/models/whois_record.rb index 8d30110b4..9ee864c92 100644 --- a/app/models/whois_record.rb +++ b/app/models/whois_record.rb @@ -51,6 +51,7 @@ class WhoisRecord < ApplicationRecord end h[:email] = registrant.email + h[:phone] = registrant.phone h[:registrant_changed] = registrant.updated_at.try(:to_s, :iso8601) h[:registrant_disclosed_attributes] = registrant.disclosed_attributes diff --git a/doc/registrant-api/v1/contact.md b/doc/registrant-api/v1/contact.md index 87519c0aa..37a60e1a2 100644 --- a/doc/registrant-api/v1/contact.md +++ b/doc/registrant-api/v1/contact.md @@ -113,7 +113,7 @@ Update contact. | address[city] | false | String | | New city name | | address[state] | false | String | | New state name | | address[country_code] | false | String | | New country code in 2 letter format (ISO 3166-1 alpha-2) | -| disclosed_attributes | false | Array | | Possible values: "name", "email" +| disclosed_attributes | false | Array | | Possible values: "name", "email", "phone" #### Request