Restructure white ip interfaces #2713

This commit is contained in:
Martin Lensment 2015-09-15 14:00:19 +03:00
parent cc32312328
commit c6073c7e87
9 changed files with 32 additions and 23 deletions

View file

@ -51,6 +51,6 @@ class Admin::WhiteIpsController < AdminController
end
def white_ip_params
params.require(:white_ip).permit(:ipv4, :ipv6, :interface, :registrar_id)
params.require(:white_ip).permit(:ipv4, :ipv6, :registrar_id, { interfaces: [] })
end
end

View file

@ -17,19 +17,17 @@ class WhiteIp < ActiveRecord::Base
REGISTRAR = 'registrar'
INTERFACES = [API, REGISTRAR]
scope :api, -> { where(interface: API) }
scope :registrar, -> { where(interface: REGISTRAR) }
scope :api, -> { where("interfaces @> ?::varchar[]", "{#{API}}") }
scope :registrar, -> { where("interfaces @> ?::varchar[]", "{#{REGISTRAR}}") }
def interfaces=(interfaces)
super(interfaces.reject(&:blank?))
end
class << self
def registrar_ip_white?(ip)
return true unless Setting.registrar_ip_whitelist_enabled
at = WhiteIp.arel_table
WhiteIp.where(
at[:interface].eq(REGISTRAR).and(
at[:ipv4].eq(ip)
)
).any?
WhiteIp.where(ipv4: ip).registrar.any?
end
end
end

View file

@ -92,10 +92,10 @@
%tr
%th{class: 'col-xs-4'}= t(:ipv4)
%th{class: 'col-xs-6'}= t(:ipv6)
%th{class: 'col-xs-2'}= t(:interface)
%th{class: 'col-xs-2'}= t(:interfaces)
%tbody
- @registrar.white_ips.order(:interface).each do |x|
- @registrar.white_ips.each do |x|
%tr
%td= link_to(x.ipv4, [:admin, @registrar, x])
%td= link_to(x.ipv6, [:admin, @registrar, x])
%td= x.interface.upcase
%td= x.interfaces.join(', ').upcase

View file

@ -19,11 +19,13 @@
= f.label :ipv6
.col-md-7
= f.text_field(:ipv6, class: 'form-control', ipv6: true, autocomplete: 'off')
.form-group
.col-md-4.control-label
= f.label :interface
.col-md-7
= f.select :interface, WhiteIp::INTERFACES.map {|x| [x.upcase, x]}, {}, class: 'form-control selectize'
- WhiteIp::INTERFACES.each do |x|
.form-group
.col-md-4.control-label
= f.label x
.col-md-7
= f.check_box :interfaces, { multiple: true }, x, nil
= hidden_field_tag "white_ip[interfaces][]", nil
%hr
.row
.col-md-8.text-right

View file

@ -20,5 +20,5 @@
%dt= t(:ipv6)
%dd= @white_ip.ipv6
%dt= t(:interface)
%dd= @white_ip.interface.upcase
%dt= t(:interfaces)
%dd= @white_ip.interfaces.join(', ').upcase

View file

@ -921,3 +921,4 @@ en:
contact_is_not_valid: 'Contact %{value} is not valid, please fix the invalid contact'
force_delete_subject: 'Kustutusmenetluse teade'
welcome_to_eis_registrar_portal: 'Welcome to EIS Registrar portal'
interfaces: 'Interfaces'

View file

@ -0,0 +1,6 @@
class AddMultipleInterfacesForWhiteIp < ActiveRecord::Migration
def change
change_column :white_ips, :interface, "varchar[] USING (string_to_array(interface, ','))"
rename_column :white_ips, :interface, :interfaces
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150910113839) do
ActiveRecord::Schema.define(version: 20150915094707) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -1064,7 +1064,7 @@ ActiveRecord::Schema.define(version: 20150910113839) do
t.integer "registrar_id"
t.string "ipv4"
t.string "ipv6"
t.string "interface"
t.string "interfaces", array: true
t.datetime "created_at"
t.datetime "updated_at"
t.string "creator_str"

View file

@ -2717,7 +2717,7 @@ CREATE TABLE white_ips (
registrar_id integer,
ipv4 character varying,
ipv6 character varying,
interface character varying,
interfaces character varying[],
created_at timestamp without time zone,
updated_at timestamp without time zone,
creator_str character varying,
@ -4934,3 +4934,5 @@ INSERT INTO schema_migrations (version) VALUES ('20150827151906');
INSERT INTO schema_migrations (version) VALUES ('20150910113839');
INSERT INTO schema_migrations (version) VALUES ('20150915094707');