mirror of
https://github.com/internetee/registry.git
synced 2025-06-11 23:24:48 +02:00
REPP: Hide contact internal ID
This commit is contained in:
parent
fc816ad67b
commit
3d0150076c
3 changed files with 53 additions and 7 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
require 'serializers/repp/contact'
|
||||||
module Repp
|
module Repp
|
||||||
module V1
|
module V1
|
||||||
class ContactsController < BaseController
|
class ContactsController < BaseController
|
||||||
|
@ -14,7 +15,8 @@ module Repp
|
||||||
|
|
||||||
## GET /repp/v1/contacts/1
|
## GET /repp/v1/contacts/1
|
||||||
def show
|
def show
|
||||||
render_success(data: @contact.as_json)
|
serializer = ::Serializers::Repp::Contact.new(@contact, show_address: Contact.address_processing?)
|
||||||
|
render_success(data: serializer.to_json)
|
||||||
end
|
end
|
||||||
|
|
||||||
## GET /repp/v1/contacts/check/1
|
## GET /repp/v1/contacts/check/1
|
||||||
|
@ -76,11 +78,13 @@ module Repp
|
||||||
|
|
||||||
def showable_contacts(details, limit, offset)
|
def showable_contacts(details, limit, offset)
|
||||||
contacts = current_user.registrar.contacts.limit(limit).offset(offset)
|
contacts = current_user.registrar.contacts.limit(limit).offset(offset)
|
||||||
unless Contact.address_processing? && params[:details] == 'true'
|
|
||||||
contacts = contacts.select(Contact.attribute_names - Contact.address_attribute_names)
|
|
||||||
end
|
|
||||||
|
|
||||||
contacts = contacts.pluck(:code) unless details
|
return contacts.pluck(:code) unless details
|
||||||
|
|
||||||
|
contacts = contacts.map do |contact|
|
||||||
|
serializer = ::Serializers::Repp::Contact.new(contact, show_address: Contact.address_processing?)
|
||||||
|
serializer.to_json
|
||||||
|
end
|
||||||
|
|
||||||
contacts
|
contacts
|
||||||
end
|
end
|
||||||
|
@ -104,7 +108,7 @@ module Repp
|
||||||
|
|
||||||
def contact_create_params(required: true)
|
def contact_create_params(required: true)
|
||||||
params.require(:contact).require(%i[name email phone]) if required
|
params.require(:contact).require(%i[name email phone]) if required
|
||||||
params.require(:contact).permit(:name, :email, :phone, :code)
|
params.require(:contact).permit(:name, :email, :phone, :id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def contact_ident_params(required: true)
|
def contact_ident_params(required: true)
|
||||||
|
|
|
@ -36,7 +36,7 @@ class Epp::Contact < Contact
|
||||||
attrs = epp ? attrs_from(frame, new_record: true) : frame
|
attrs = epp ? attrs_from(frame, new_record: true) : frame
|
||||||
super(
|
super(
|
||||||
attrs.merge(
|
attrs.merge(
|
||||||
code: epp ? frame.css('id').text : frame[:code],
|
code: epp ? frame.css('id').text : frame[:id],
|
||||||
registrar: registrar
|
registrar: registrar
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
42
lib/serializers/repp/contact.rb
Normal file
42
lib/serializers/repp/contact.rb
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
module Serializers
|
||||||
|
module Repp
|
||||||
|
class Contact
|
||||||
|
attr_reader :contact
|
||||||
|
|
||||||
|
def initialize(contact, show_address:)
|
||||||
|
@contact = contact
|
||||||
|
@show_address = show_address
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_json
|
||||||
|
json = {
|
||||||
|
id: contact.code,
|
||||||
|
name: contact.name,
|
||||||
|
ident: {
|
||||||
|
code: contact.ident,
|
||||||
|
type: contact.ident_type,
|
||||||
|
country_code: contact.ident_country_code,
|
||||||
|
},
|
||||||
|
email: contact.email,
|
||||||
|
phone: contact.phone,
|
||||||
|
fax: contact.fax,
|
||||||
|
auth_info: contact.auth_info,
|
||||||
|
statuses: contact.statuses,
|
||||||
|
disclosed_attributes: contact.disclosed_attributes,
|
||||||
|
}
|
||||||
|
|
||||||
|
return json unless @show_address
|
||||||
|
|
||||||
|
json[:address] = {
|
||||||
|
street: contact.street,
|
||||||
|
zip: contact.zip,
|
||||||
|
city: contact.city,
|
||||||
|
state: contact.state,
|
||||||
|
country_code: contact.country_code,
|
||||||
|
}
|
||||||
|
|
||||||
|
json
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue