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

@ -22,7 +22,7 @@ module Admin
send_email
domain.update(contact_notification_sent_date: Time.zone.today)
else
domain.update(template_name: params[:template_name])
domain.update(template_name: domain.notification_template)
end
end
@ -46,7 +46,7 @@ module Admin
DomainDeleteMailer.forced(domain: domain,
registrar: domain.registrar,
registrant: domain.registrant,
template_name: params[:template_name]).deliver_now
template_name: domain.notification_template).deliver_now
end
def force_delete_type

View file

@ -2,7 +2,6 @@ module Admin
class DomainsController < BaseController
before_action :set_domain, only: %i[show edit update keep]
authorize_resource
helper_method :force_delete_templates
def index
params[:q] ||= {}
@ -105,9 +104,5 @@ module Admin
params[:q][:valid_to_lteq] = ca_cache
end
def force_delete_templates
DomainDeleteMailer.force_delete_templates
end
end
end

View file

@ -79,19 +79,32 @@ module Epp
if success && EppSession.limit_reached?(@api_user.registrar)
epp_errors << {
msg: 'Authentication error; server closing connection (connection limit reached)',
code: '2501'
msg: 'Session limit exceeded; server closing connection (connection limit reached)',
code: '2502',
}
success = false
end
if success
if params[:parsed_frame].css('newPW').first
unless @api_user.update(plain_text_password: params[:parsed_frame].css('newPW').first.text)
handle_errors(@api_user) and return
new_password = params[:parsed_frame].at_css('newPW')&.text
password_change = new_password.present?
if password_change
@api_user.plain_text_password = new_password
@api_user.save!
end
already_authenticated = EppSession.exists?(session_id: epp_session_id)
if already_authenticated
epp_errors << {
msg: 'Command use error; Already authenticated',
code: 2002,
}
handle_errors
return
end
end
epp_session = EppSession.new
epp_session.session_id = epp_session_id
@ -100,8 +113,8 @@ module Epp
render_epp_response('login_success')
else
handle_errors
end
end
end
def ip_white?
webclient_request = ENV['webclient_ips'].split(',').map(&:strip).include?(request.ip)
@ -125,7 +138,7 @@ module Epp
@api_user = current_user # cache current_user for logging
epp_session.destroy
render_epp_response('logout')
end
end
### HELPER METHODS ###

View file

@ -11,26 +11,27 @@ class Registrar
search_params[:name_matches].present?
domain = Domain.find_by(name: search_params[:name_matches])
if domain
redirect_to info_registrar_domains_url(domain_name: domain.name) and return
end
redirect_to info_registrar_domains_url(domain_name: domain.name) and return if domain
end
if params[:statuses_contains]
domains = current_registrar_user.registrar.domains.includes(:registrar, :registrant).where(
"statuses @> ?::varchar[]", "{#{params[:statuses_contains].join(',')}}"
)
else
domains = current_registrar_user.registrar.domains.includes(:registrar, :registrant)
domains = if params[:statuses_contains]
current_domain_scope.where('domains.statuses @> ?::varchar[]',
"{#{params[:statuses_contains].join(',')}}")
else
current_domain_scope
end
if params[:contacts_ident_eq]
domains = domains.where(contacts: { ident: params[:contacts_ident_eq] })
end
normalize_search_parameters do
@q = domains.search(search_params)
@q = domains.search(search_params.except(:contacts_ident_eq))
@domains = @q.result.page(params[:page])
# if we do not get any results, add wildcards to the name field and search again
if @domains.count == 0 && search_params[:name_matches] !~ /^%.+%$/
new_search_params = search_params.to_h
new_search_params = search_params.to_h.except(:contacts_ident_eq)
new_search_params[:name_matches] = "%#{new_search_params[:name_matches]}%"
@q = domains.search(new_search_params)
@domains = @q.result.page(params[:page])
@ -56,6 +57,10 @@ class Registrar
end
end
def current_domain_scope
current_registrar_user.registrar.domains.includes(:registrar, :registrant)
end
def info
authorize! :info, Depp::Domain
@data = @domain.info(params[:domain_name]) if params[:domain_name]

View file

@ -6,9 +6,12 @@ class Registrar
ipv4 = params[:ipv4].split("\r\n")
ipv6 = params[:ipv6].split("\r\n")
domains = domain_list_from_csv
uri = URI.parse("#{ENV['repp_url']}registrar/nameservers")
request = Net::HTTP::Put.new(uri, 'Content-Type' => 'application/json')
request.body = { data: { type: 'nameserver', id: params[:old_hostname],
domains: domains,
attributes: { hostname: params[:new_hostname],
ipv4: ipv4,
ipv6: ipv6 } } }.to_json
@ -55,5 +58,13 @@ class Registrar
render file: 'registrar/bulk_change/new', locals: { active_tab: :nameserver }
end
end
def domain_list_from_csv
return [] if params[:puny_file].blank?
domains = []
CSV.read(params[:puny_file].path, headers: true).each { |b| domains << b['domain_name'] }
domains
end
end
end

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