mirror of
https://github.com/internetee/registry.git
synced 2025-07-28 05:26:17 +02:00
Added committed param to white ip
This commit is contained in:
parent
e00e44c9b8
commit
1c8a46bd89
12 changed files with 130 additions and 15 deletions
|
@ -41,7 +41,7 @@ module Admin
|
|||
def sign
|
||||
if @certificate.sign!(password: certificate_params[:password])
|
||||
flash[:notice] = I18n.t('record_updated')
|
||||
notify_api_user
|
||||
notify_registrar
|
||||
redirect_to [:admin, @api_user, @certificate]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_update_record')
|
||||
|
@ -88,10 +88,10 @@ module Admin
|
|||
end
|
||||
end
|
||||
|
||||
def notify_api_user
|
||||
api_user_email = @api_user.registrar.email
|
||||
def notify_registrar
|
||||
email = @api_user.registrar.email
|
||||
|
||||
CertificateMailer.signed(email: api_user_email, api_user: @api_user,
|
||||
CertificateMailer.signed(email: email, api_user: @api_user,
|
||||
crt: OpenSSL::X509::Certificate.new(@certificate.crt))
|
||||
.deliver_now
|
||||
end
|
||||
|
|
|
@ -36,7 +36,11 @@ module Admin
|
|||
end
|
||||
|
||||
def update
|
||||
previously_committed = @white_ip.committed
|
||||
|
||||
if @white_ip.update(white_ip_params)
|
||||
notify_registrar if !previously_committed && @white_ip.committed
|
||||
|
||||
flash[:notice] = I18n.t('record_updated')
|
||||
redirect_to [:admin, @registrar, @white_ip]
|
||||
else
|
||||
|
@ -52,7 +56,14 @@ module Admin
|
|||
end
|
||||
|
||||
def white_ip_params
|
||||
params.require(:white_ip).permit(:ipv4, :ipv6, :registrar_id, { interfaces: [] })
|
||||
params.require(:white_ip).permit(:ipv4, :ipv6, :registrar_id, :committed, { interfaces: [] })
|
||||
end
|
||||
|
||||
def notify_registrar
|
||||
email = @white_ip.registrar.email
|
||||
|
||||
WhiteIpMailer.committed(email: email, ip: @white_ip)
|
||||
.deliver_now
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -174,7 +174,7 @@ module Repp
|
|||
end
|
||||
|
||||
def serialized_ips(ips)
|
||||
ips.as_json(only: %i[id ipv4 ipv6 interfaces])
|
||||
ips.as_json(only: %i[id ipv4 ipv6 interfaces committed])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -31,21 +31,21 @@ module Repp
|
|||
return
|
||||
end
|
||||
|
||||
notify_admins if @white_ip.interfaces.include? WhiteIp::API
|
||||
uncommit_and_notify_admins if api_interface?(@white_ip)
|
||||
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
|
||||
previously_api = api_interface?(@white_ip)
|
||||
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)
|
||||
uncommit_and_notify_admins if api_interface?(@white_ip)
|
||||
uncommit_and_notify_admins if previously_api && !api_interface?(@white_ip)
|
||||
render_success(data: { ip: { id: @white_ip.id } })
|
||||
end
|
||||
|
||||
|
@ -58,12 +58,16 @@ module Repp
|
|||
return
|
||||
end
|
||||
|
||||
notify_admins(ip: ip, action: 'deleted') if ip.interfaces.include?(WhiteIp::API)
|
||||
uncommit_and_notify_admins(ip: ip, action: 'deleted') if ip.interfaces.include?(WhiteIp::API)
|
||||
render_success
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def api_interface?(ip)
|
||||
ip.interfaces.include? WhiteIp::API
|
||||
end
|
||||
|
||||
def find_white_ip
|
||||
@white_ip = current_user.registrar.white_ips.find(params[:id])
|
||||
end
|
||||
|
@ -72,7 +76,8 @@ module Repp
|
|||
params.require(:white_ip).permit(:address, interfaces: [])
|
||||
end
|
||||
|
||||
def notify_admins(ip: @white_ip, action: 'updated')
|
||||
def uncommit_and_notify_admins(ip: @white_ip, action: 'updated')
|
||||
@white_ip.update(committed: false) if action == 'updated'
|
||||
admin_users_emails = User.admin.pluck(:email).reject(&:blank?)
|
||||
|
||||
return if admin_users_emails.empty?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue