mirror of
https://github.com/internetee/registry.git
synced 2025-07-27 21:16:12 +02:00
Modified white ip form and created mailer
This commit is contained in:
parent
311834c085
commit
e00e44c9b8
10 changed files with 83 additions and 21 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue