Modified white ip form and created mailer

This commit is contained in:
Sergei Tsoganov 2023-07-05 15:28:43 +03:00
parent 311834c085
commit e00e44c9b8
10 changed files with 83 additions and 21 deletions

View file

@ -130,6 +130,11 @@ module Repp
render(json: @response, status: :unauthorized)
end
def render_unauthorized_response
@response = { code: 2202, message: I18n.t('registrar.authorization.ip_not_allowed', ip: request.ip) }
render json: @response, status: :unauthorized
end
def webclient_request?
return false if Rails.env.test? || Rails.env.development?
@ -144,8 +149,7 @@ module Repp
webclient_cn = ENV['webclient_cert_common_name'] || 'webclient'
return if request_name == webclient_cn
@response = { code: 2202,
message: I18n.t('registrar.authorization.ip_not_allowed', ip: request.ip) }
@response = { code: 2202, message: 'Invalid webclient certificate' }
render(json: @response, status: :unauthorized)
end

View file

@ -31,28 +31,34 @@ module Repp
return
end
notify_admins if @white_ip.interfaces.include? WhiteIp::API
render_success(data: { ip: { id: @white_ip.id } })
end
api :PUT, '/repp/v1/white_ips/:id'
desc 'Update whitelisted IP address'
def update
api = @white_ip.interfaces.include? WhiteIp::API
unless @white_ip.update(white_ip_params)
handle_non_epp_errors(@white_ip)
return
end
notify_admins if @white_ip.interfaces.include? WhiteIp::API
notify_admins if api && !@white_ip.interfaces.include?(WhiteIp::API)
render_success(data: { ip: { id: @white_ip.id } })
end
api :DELETE, '/repp/v1/white_ips/:id'
desc 'Delete a specific whitelisted IP address'
def destroy
ip = @white_ip
unless @white_ip.destroy
handle_non_epp_errors(@white_ip)
return
end
notify_admins(ip: ip, action: 'deleted') if ip.interfaces.include?(WhiteIp::API)
render_success
end
@ -65,6 +71,19 @@ module Repp
def white_ip_params
params.require(:white_ip).permit(:address, interfaces: [])
end
def notify_admins(ip: @white_ip, action: 'updated')
admin_users_emails = User.admin.pluck(:email).reject(&:blank?)
return if admin_users_emails.empty?
admin_users_emails.each do |email|
WhiteIpMailer.with(email: email, api_user: current_user,
white_ip: ip)
.send("api_ip_address_#{action}")
.deliver_now
end
end
end
end
end