mirror of
https://github.com/internetee/registry.git
synced 2025-07-19 17:25:57 +02:00
Create white ips
This commit is contained in:
parent
254849494f
commit
8e37355e13
15 changed files with 246 additions and 3 deletions
56
app/controllers/admin/white_ips_controller.rb
Normal file
56
app/controllers/admin/white_ips_controller.rb
Normal file
|
@ -0,0 +1,56 @@
|
|||
class Admin::WhiteIpsController < AdminController
|
||||
load_and_authorize_resource
|
||||
|
||||
before_action :set_registrar, only: [:new, :show, :edit, :destroy, :update]
|
||||
|
||||
def new
|
||||
@white_ip = WhiteIp.new(registrar: @registrar)
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
||||
def edit; end
|
||||
|
||||
def destroy
|
||||
if @white_ip.destroy
|
||||
flash[:notice] = I18n.t('record_deleted')
|
||||
redirect_to admin_registrar_path(@registrar)
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_delete_record')
|
||||
render 'show'
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@white_ip = WhiteIp.new(white_ip_params)
|
||||
@registrar = @white_ip.registrar
|
||||
|
||||
if @white_ip.save
|
||||
flash[:notice] = I18n.t('record_created')
|
||||
redirect_to [:admin, @registrar, @white_ip]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_create_record')
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if @white_ip.update(white_ip_params)
|
||||
flash[:notice] = I18n.t('record_updated')
|
||||
redirect_to [:admin, @registrar, @white_ip]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_update_record')
|
||||
render 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_registrar
|
||||
@registrar = Registrar.find_by(id: params[:registrar_id])
|
||||
end
|
||||
|
||||
def white_ip_params
|
||||
params.require(:white_ip).permit(:ipv4, :ipv6, :interface, :registrar_id)
|
||||
end
|
||||
end
|
|
@ -97,6 +97,7 @@ class Ability
|
|||
can :manage, BankStatement
|
||||
can :manage, BankTransaction
|
||||
can :manage, Invoice
|
||||
can :manage, WhiteIp
|
||||
can :read, ApiLog::EppLog
|
||||
can :read, ApiLog::ReppLog
|
||||
# can :index, :delayed_job
|
||||
|
|
|
@ -10,6 +10,7 @@ class Registrar < ActiveRecord::Base
|
|||
has_many :nameservers, through: :domains
|
||||
has_many :whois_records
|
||||
has_many :priv_contacts, -> { privs }, class_name: 'Contact'
|
||||
has_many :white_ips, dependent: :destroy
|
||||
|
||||
validates :name, :reg_no, :country_code, :email, :code, presence: true
|
||||
validates :name, :reg_no, :reference_no, :code, uniqueness: true
|
||||
|
@ -48,7 +49,7 @@ class Registrar < ActiveRecord::Base
|
|||
|
||||
after_save :update_whois_records
|
||||
def update_whois_records
|
||||
return true unless changed? && (changes.keys & WHOIS_TRIGGERS).present?
|
||||
return true unless changed? && (changes.keys & WHOIS_TRIGGERS).present?
|
||||
whois_records.map(&:save) # slow currently
|
||||
end
|
||||
|
||||
|
|
16
app/models/white_ip.rb
Normal file
16
app/models/white_ip.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
class WhiteIp < ActiveRecord::Base
|
||||
belongs_to :registrar
|
||||
|
||||
# rubocop: disable Metrics/LineLength
|
||||
validates :ipv4, format: { with: /\A(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\z/, allow_blank: true }
|
||||
validates :ipv6, format: { with: /(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/, allow_blank: true }
|
||||
# rubocop: enable Metrics/LineLength
|
||||
|
||||
validate :validate_ipv4_and_ipv6
|
||||
def validate_ipv4_and_ipv6
|
||||
return if ipv4.present? || ipv6.present?
|
||||
errors.add(:base, I18n.t(:ipv4_or_ipv6_must_be_present))
|
||||
end
|
||||
|
||||
INTERFACES = ['epp', 'repp', 'registrar']
|
||||
end
|
|
@ -63,7 +63,7 @@
|
|||
.pull-left
|
||||
= t(:api_users)
|
||||
.pull-right
|
||||
= link_to(t(:create_new_api_user), new_admin_registrar_api_user_path(@registrar), class: 'btn btn-primary btn-xs')
|
||||
= link_to(t(:create_new_api_user), new_admin_registrar_api_user_path(@registrar), class: 'btn btn-default btn-xs')
|
||||
|
||||
.table-responsive
|
||||
%table.table.table-hover.table-bordered.table-condensed
|
||||
|
@ -76,3 +76,26 @@
|
|||
%tr
|
||||
%td= link_to(x, [:admin, x])
|
||||
%td= x.active
|
||||
|
||||
.row
|
||||
.col-md-12
|
||||
#epp-users.panel.panel-default
|
||||
.panel-heading.clearfix
|
||||
.pull-left
|
||||
= t(:white_ips)
|
||||
.pull-right
|
||||
= link_to(t(:create_new_white_ip), new_admin_registrar_white_ip_path(@registrar), class: 'btn btn-default btn-xs')
|
||||
|
||||
.table-responsive
|
||||
%table.table.table-hover.table-bordered.table-condensed
|
||||
%thead
|
||||
%tr
|
||||
%th{class: 'col-xs-4'}= t(:ipv4)
|
||||
%th{class: 'col-xs-6'}= t(:ipv6)
|
||||
%th{class: 'col-xs-2'}= t(:interface)
|
||||
%tbody
|
||||
- @registrar.white_ips.order(:interface).each do |x|
|
||||
%tr
|
||||
%td= link_to(x.ipv4, [:admin, @registrar, x])
|
||||
%td= link_to(x.ipv6, [:admin, @registrar, x])
|
||||
%td= x.interface.upcase
|
||||
|
|
30
app/views/admin/white_ips/_form.haml
Normal file
30
app/views/admin/white_ips/_form.haml
Normal file
|
@ -0,0 +1,30 @@
|
|||
= form_for([:admin, @registrar, @white_ip], html: {class: 'form-horizontal'}) do |f|
|
||||
= render 'shared/full_errors', object: @white_ip
|
||||
|
||||
.row
|
||||
.col-md-8
|
||||
.form-group
|
||||
.col-md-4.control-label
|
||||
= f.label :registrar
|
||||
.col-md-7
|
||||
= f.text_field(:registrar, class: 'form-control', disabled: :disabled)
|
||||
= f.hidden_field(:registrar_id, class: 'js-registrar-id')
|
||||
.form-group
|
||||
.col-md-4.control-label
|
||||
= f.label :ipv4
|
||||
.col-md-7
|
||||
= f.text_field(:ipv4, class: 'form-control')
|
||||
.form-group
|
||||
.col-md-4.control-label
|
||||
= f.label :ipv6
|
||||
.col-md-7
|
||||
= f.text_field(:ipv6, class: 'form-control')
|
||||
.form-group
|
||||
.col-md-4.control-label
|
||||
= f.label :interface
|
||||
.col-md-7
|
||||
= f.select :interface, [[t(:choose), '']] + WhiteIp::INTERFACES.map {|x| [x.upcase, x]}, {}, class: 'form-control selectize', placeholder: t(:choose)
|
||||
%hr
|
||||
.row
|
||||
.col-md-8.text-right
|
||||
= button_tag(t(:save), class: 'btn btn-primary')
|
5
app/views/admin/white_ips/edit.haml
Normal file
5
app/views/admin/white_ips/edit.haml
Normal file
|
@ -0,0 +1,5 @@
|
|||
- content_for :actions do
|
||||
= link_to(t(:back_to_registrar), admin_registrar_path(@registrar), class: 'btn btn-default')
|
||||
|
||||
= render 'shared/title', name: t(:edit_white_ip)
|
||||
= render 'form'
|
5
app/views/admin/white_ips/new.haml
Normal file
5
app/views/admin/white_ips/new.haml
Normal file
|
@ -0,0 +1,5 @@
|
|||
- content_for :actions do
|
||||
= link_to(t(:back_to_registrar), admin_registrar_path(@registrar), class: 'btn btn-default')
|
||||
|
||||
= render 'shared/title', name: t(:create_new_white_ip)
|
||||
= render 'form'
|
24
app/views/admin/white_ips/show.haml
Normal file
24
app/views/admin/white_ips/show.haml
Normal file
|
@ -0,0 +1,24 @@
|
|||
- content_for :actions do
|
||||
= link_to(t(:edit), edit_admin_registrar_white_ip_path(@registrar, @white_ip), class: 'btn btn-primary')
|
||||
= link_to(t(:delete), admin_registrar_white_ip_path(@registrar, @white_ip),
|
||||
method: :delete, data: { confirm: t(:are_you_sure) }, class: 'btn btn-danger')
|
||||
= render 'shared/title', name: t('white_ip')
|
||||
|
||||
.row
|
||||
.col-md-12
|
||||
.panel.panel-default
|
||||
.panel-heading
|
||||
%h3.panel-title= t(:general)
|
||||
.panel-body
|
||||
%dl.dl-horizontal
|
||||
%dt= t(:registrar)
|
||||
%dd= link_to(@registrar, [:admin, @registrar])
|
||||
|
||||
%dt= t(:ipv4)
|
||||
%dd= @white_ip.ipv4
|
||||
|
||||
%dt= t(:ipv6)
|
||||
%dd= @white_ip.ipv6
|
||||
|
||||
%dt= t(:interface)
|
||||
%dd= @white_ip.interface.upcase
|
Loading…
Add table
Add a link
Reference in a new issue