Merge remote-tracking branch 'origin/master' into 1580-registrar-api-contacts-endpoint

This commit is contained in:
Karl Erik Õunapuu 2020-11-17 09:55:32 +02:00
commit db50a89d85
No known key found for this signature in database
GPG key ID: C9DD647298A34764
51 changed files with 801 additions and 285 deletions

View file

@ -5,10 +5,13 @@ module Repp
before_action :verify_nameserver_existance, only: %i[update]
def update
domains = current_user.registrar
.replace_nameservers(hostname, hostname_params[:data][:attributes])
domains = params[:data][:domains] || []
affected = current_user.registrar
.replace_nameservers(hostname,
hostname_params[:data][:attributes],
domains: domains)
render_success(data: data_format_for_success(domains))
render_success(data: data_format_for_success(affected))
rescue ActiveRecord::RecordInvalid => e
handle_errors(e.record)
end
@ -16,15 +19,23 @@ module Repp
private
def data_format_for_success(affected_domains)
{ type: 'nameserver', id: params[:data][:attributes][:hostname],
attributes: params[:data][:attributes], affected_domains: affected_domains }
{
type: 'nameserver',
id: params[:data][:attributes][:hostname],
attributes: params[:data][:attributes],
affected_domains: affected_domains,
}
end
def hostname_params
params.require(:data).require(%i[type id])
params.require(:data).require(:attributes).require([:hostname])
params.permit(data: [:type, :id, attributes: [:hostname, ipv4: [], ipv6: []]])
params.permit(data: [
:type, :id,
{ domains: [],
attributes: [:hostname, { ipv4: [], ipv6: [] }] },
])
end
def hostname