mirror of
https://github.com/internetee/registry.git
synced 2025-06-12 07:34:45 +02:00
REPP Domains: Allow create/read/update for domain-scoped contacts
This commit is contained in:
parent
9dcd40ee3b
commit
fda58e9a41
3 changed files with 62 additions and 1 deletions
|
@ -4,6 +4,53 @@ module Repp
|
||||||
class ContactsController < BaseController
|
class ContactsController < BaseController
|
||||||
before_action :set_current_contact, only: [:update]
|
before_action :set_current_contact, only: [:update]
|
||||||
before_action :set_new_contact, only: [:update]
|
before_action :set_new_contact, only: [:update]
|
||||||
|
before_action :set_domain, only: %i[index create destroy]
|
||||||
|
|
||||||
|
api :GET, '/repp/v1/domains/:domain_name/contacts'
|
||||||
|
desc "View domain's admin and tech contacts"
|
||||||
|
def index
|
||||||
|
admin_contacts = @domain.admin_domain_contacts.pluck(:contact_code_cache)
|
||||||
|
tech_contacts = @domain.tech_domain_contacts.pluck(:contact_code_cache)
|
||||||
|
|
||||||
|
data = { admin_contacts: admin_contacts, tech_contacts: tech_contacts }
|
||||||
|
render_success(data: data)
|
||||||
|
end
|
||||||
|
|
||||||
|
api :POST, '/repp/v1/domains/:domain_name/contacts'
|
||||||
|
desc "Link new contact(s) to domain"
|
||||||
|
param :contacts, Array, required: true, desc: 'Array of new linked contacts' do
|
||||||
|
param :code, String, required: true, desc: 'Contact code'
|
||||||
|
param :type, String, required: true, desc: 'Role of contact (admin/tech)'
|
||||||
|
end
|
||||||
|
def create
|
||||||
|
contact_create_params[:contacts].each { |c| c[:action] = 'add' }
|
||||||
|
action = Actions::DomainUpdate.new(@domain, contact_create_params, current_user)
|
||||||
|
|
||||||
|
unless action.call
|
||||||
|
handle_errors(@domain)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
render_success(data: { domain: { name: @domain.name } })
|
||||||
|
end
|
||||||
|
|
||||||
|
api :DELETE, '/repp/v1/domains/:domain_name/contacts'
|
||||||
|
desc "Remove contact(s) from domain"
|
||||||
|
param :contacts, Array, required: true, desc: 'Array of new linked contacts' do
|
||||||
|
param :code, String, required: true, desc: 'Contact code'
|
||||||
|
param :type, String, required: true, desc: 'Role of contact (admin/tech)'
|
||||||
|
end
|
||||||
|
def destroy
|
||||||
|
contact_create_params[:contacts].each { |c| c[:action] = 'rem' }
|
||||||
|
action = Actions::DomainUpdate.new(@domain, contact_create_params, current_user)
|
||||||
|
|
||||||
|
unless action.call
|
||||||
|
handle_errors(@domain)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
render_success(data: { domain: { name: @domain.name } })
|
||||||
|
end
|
||||||
|
|
||||||
def set_current_contact
|
def set_current_contact
|
||||||
@current_contact = current_user.registrar.contacts.find_by!(
|
@current_contact = current_user.registrar.contacts.find_by!(
|
||||||
|
@ -32,6 +79,18 @@ module Repp
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def set_domain
|
||||||
|
registrar = current_user.registrar
|
||||||
|
@domain = Epp::Domain.find_by(registrar: registrar, name: params[:domain_id])
|
||||||
|
@domain ||= Epp::Domain.find_by!(registrar: registrar, name_puny: params[:domain_id])
|
||||||
|
|
||||||
|
@domain
|
||||||
|
end
|
||||||
|
|
||||||
|
def contact_create_params
|
||||||
|
params.permit!
|
||||||
|
end
|
||||||
|
|
||||||
def contact_params
|
def contact_params
|
||||||
params.require(%i[current_contact_id new_contact_id])
|
params.require(%i[current_contact_id new_contact_id])
|
||||||
params.permit(:current_contact_id, :new_contact_id)
|
params.permit(:current_contact_id, :new_contact_id)
|
||||||
|
|
|
@ -154,7 +154,7 @@ module Actions
|
||||||
def assign_contact(obj, add: false, admin: true, code:)
|
def assign_contact(obj, add: false, admin: true, code:)
|
||||||
if obj.blank?
|
if obj.blank?
|
||||||
domain.add_epp_error('2303', 'contact', code, %i[domain_contacts not_found])
|
domain.add_epp_error('2303', 'contact', code, %i[domain_contacts not_found])
|
||||||
elsif obj.org? && admin
|
elsif obj.try(:org?) && admin && add
|
||||||
domain.add_epp_error('2306', 'contact', code,
|
domain.add_epp_error('2306', 'contact', code,
|
||||||
%i[domain_contacts admin_contact_can_be_only_private_person])
|
%i[domain_contacts admin_contact_can_be_only_private_person])
|
||||||
else
|
else
|
||||||
|
|
|
@ -62,7 +62,9 @@ Rails.application.routes.draw do
|
||||||
resources :domains, constraints: { id: /.*/ } do
|
resources :domains, constraints: { id: /.*/ } do
|
||||||
resources :nameservers, only: %i[create destroy], constraints: { id: /.*/ }, controller: 'domains/nameservers'
|
resources :nameservers, only: %i[create destroy], constraints: { id: /.*/ }, controller: 'domains/nameservers'
|
||||||
resources :dnssec, only: %i[index create], constraints: { id: /.*/ }, controller: 'domains/dnssec'
|
resources :dnssec, only: %i[index create], constraints: { id: /.*/ }, controller: 'domains/dnssec'
|
||||||
|
resources :contacts, only: %i[index create], constraints: { id: /.*/ }, controller: 'domains/contacts'
|
||||||
match "dnssec", to: "domains/dnssec#destroy", via: "delete", defaults: { id: nil }
|
match "dnssec", to: "domains/dnssec#destroy", via: "delete", defaults: { id: nil }
|
||||||
|
match "contacts", to: "domains/contacts#destroy", via: "delete", defaults: { id: nil }
|
||||||
collection do
|
collection do
|
||||||
get ':id/transfer_info', to: 'domains#transfer_info', constraints: { id: /.*/ }
|
get ':id/transfer_info', to: 'domains#transfer_info', constraints: { id: /.*/ }
|
||||||
post 'transfer', to: 'domains#transfer'
|
post 'transfer', to: 'domains#transfer'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue