mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 06:34:46 +02:00
Merge remote-tracking branch 'origin/master' into repp-domains
This commit is contained in:
commit
43e5b74668
29 changed files with 357 additions and 49 deletions
|
@ -1,7 +1,7 @@
|
|||
module Repp
|
||||
module V1
|
||||
class BaseController < ActionController::API # rubocop:disable Metrics/ClassLength
|
||||
rescue_from ActiveRecord::RecordNotFound, with: :not_found_error
|
||||
around_action :log_request
|
||||
before_action :authenticate_user
|
||||
before_action :validate_webclient_ca
|
||||
before_action :check_ip_restriction
|
||||
|
@ -9,22 +9,31 @@ module Repp
|
|||
|
||||
before_action :set_paper_trail_whodunnit
|
||||
|
||||
rescue_from ActionController::ParameterMissing, Apipie::ParamInvalid,
|
||||
Apipie::ParamMissing do |exception|
|
||||
render json: { code: 2003, message: exception }, status: :bad_request
|
||||
private
|
||||
|
||||
def log_request
|
||||
yield
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
@response = { code: 2303, message: 'Object does not exist' }
|
||||
render(json: @response, status: :not_found)
|
||||
rescue ActionController::ParameterMissing, Apipie::ParamInvalid, Apipie::ParamMissing => e
|
||||
@response = { code: 2003, message: e }
|
||||
render(json: @response, status: :bad_request)
|
||||
ensure
|
||||
create_repp_log
|
||||
end
|
||||
|
||||
after_action do
|
||||
# rubocop:disable Metrics/AbcSize
|
||||
def create_repp_log
|
||||
ApiLog::ReppLog.create(
|
||||
request_path: request.path, request_method: request.request_method,
|
||||
request_params: request.params.except('route_info').to_json, uuid: request.try(:uuid),
|
||||
response: @response.to_json, response_code: status, ip: request.ip,
|
||||
response: @response.to_json, response_code: response.status, ip: request.ip,
|
||||
api_user_name: current_user.try(:username),
|
||||
api_user_registrar: current_user.try(:registrar).try(:to_s)
|
||||
)
|
||||
end
|
||||
|
||||
private
|
||||
# rubocop:enable Metrics/AbcSize
|
||||
|
||||
def set_domain
|
||||
registrar = current_user.registrar
|
||||
|
@ -131,11 +140,6 @@ module Repp
|
|||
|
||||
render(json: @response, status: :unauthorized)
|
||||
end
|
||||
|
||||
def not_found_error
|
||||
@response = { code: 2303, message: 'Object does not exist' }
|
||||
render(json: @response, status: :not_found)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,6 +3,7 @@ module Repp
|
|||
module V1
|
||||
class DomainsController < BaseController # rubocop:disable Metrics/ClassLength
|
||||
before_action :set_authorized_domain, only: %i[transfer_info destroy]
|
||||
before_action :validate_registrar_authorization, only: %i[transfer_info destroy]
|
||||
before_action :forward_registrar_id, only: %i[create destroy]
|
||||
before_action :set_domain, only: %i[show update]
|
||||
|
||||
|
@ -182,11 +183,7 @@ module Repp
|
|||
|
||||
def set_authorized_domain
|
||||
@epp_errors ||= []
|
||||
h = {}
|
||||
h[transfer_info_params[:id].match?(/\A[0-9]+\z/) ? :id : :name] = transfer_info_params[:id]
|
||||
@domain = Epp::Domain.find_by!(h)
|
||||
|
||||
validate_registrar_authorization
|
||||
@domain = domain_from_url_hash
|
||||
end
|
||||
|
||||
def validate_registrar_authorization
|
||||
|
@ -197,6 +194,13 @@ module Repp
|
|||
handle_errors
|
||||
end
|
||||
|
||||
def domain_from_url_hash
|
||||
entry = transfer_info_params[:id]
|
||||
return Domain.find(entry) if entry.match?(/\A[0-9]+\z/)
|
||||
|
||||
Domain.find_by!('name = ? OR name_puny = ?', entry, entry)
|
||||
end
|
||||
|
||||
def limit
|
||||
index_params[:limit] || 200
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue