From 698b580db467011b7b7ae44517eafb97cc1dd43a Mon Sep 17 00:00:00 2001 From: Adam Cooke Date: Fri, 28 Apr 2017 16:40:53 +0100 Subject: [PATCH] remove types from ip pools closes #24 --- app/controllers/ip_pools_controller.rb | 2 +- .../organization_ip_pools_controller.rb | 2 +- app/models/ip_pool.rb | 16 ---------------- app/models/organization.rb | 4 ++-- app/views/ip_pool_rules/_form.html.haml | 2 +- app/views/ip_pool_rules/index.html.haml | 4 ++-- app/views/ip_pools/_form.html.haml | 3 --- app/views/organization_ip_pools/_nav.html.haml | 2 +- .../20170428153353_remove_type_from_ip_pools.rb | 5 +++++ db/schema.rb | 3 +-- 10 files changed, 14 insertions(+), 29 deletions(-) create mode 100644 db/migrate/20170428153353_remove_type_from_ip_pools.rb diff --git a/app/controllers/ip_pools_controller.rb b/app/controllers/ip_pools_controller.rb index d38a1a7..c57f91b 100644 --- a/app/controllers/ip_pools_controller.rb +++ b/app/controllers/ip_pools_controller.rb @@ -38,7 +38,7 @@ class IPPoolsController < ApplicationController private def safe_params - params.require(:ip_pool).permit(:name, :type, :default) + params.require(:ip_pool).permit(:name, :default) end end diff --git a/app/controllers/organization_ip_pools_controller.rb b/app/controllers/organization_ip_pools_controller.rb index ebbc686..0437dde 100644 --- a/app/controllers/organization_ip_pools_controller.rb +++ b/app/controllers/organization_ip_pools_controller.rb @@ -4,7 +4,7 @@ class OrganizationIPPoolsController < ApplicationController before_action :admin_required, :only => [:assignments] def index - @ip_pools = organization.ip_pools.dedicated.order(:name) + @ip_pools = organization.ip_pools.order(:name) end def assignments diff --git a/app/models/ip_pool.rb b/app/models/ip_pool.rb index 22e2df6..df1a301 100644 --- a/app/models/ip_pool.rb +++ b/app/models/ip_pool.rb @@ -8,7 +8,6 @@ # created_at :datetime # updated_at :datetime # default :boolean default(FALSE) -# type :string(255) # # Indexes # @@ -17,8 +16,6 @@ class IPPool < ApplicationRecord - TYPES = ['Transactional', 'Bulk', 'Forwarding', 'Dedicated'] - include HasUUID validates :name, :presence => true @@ -28,21 +25,8 @@ class IPPool < ApplicationRecord has_many :organization_ip_pools, :dependent => :destroy has_many :organizations, :through => :organization_ip_pools - scope :transactional, -> { where(:type => 'Transactional') } - scope :bulk, -> { where(:type => 'Bulk') } - scope :forwarding, -> { where(:type => 'Forwarding') } - scope :dedicated, -> { where(:type => 'Dedicated') } - def self.default where(:default => true).order(:id).first end - def description - desc = "#{name}" - if self.type == 'Dedicated' - desc += " (#{ip_addresses.map(&:ipv4).to_sentence})" - end - desc - end - end diff --git a/app/models/organization.rb b/app/models/organization.rb index 54dbab9..bfdfd40 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -48,8 +48,8 @@ class Organization < ApplicationRecord has_many :ip_pool_rules, :dependent => :destroy, :as => :owner after_create do - if pool = IPPool.transactional.default - self.ip_pools << IPPool.transactional.default + if pool = IPPool.default + self.ip_pools << IPPool.default end end diff --git a/app/views/ip_pool_rules/_form.html.haml b/app/views/ip_pool_rules/_form.html.haml index eaff492..e8155df 100644 --- a/app/views/ip_pool_rules/_form.html.haml +++ b/app/views/ip_pool_rules/_form.html.haml @@ -24,7 +24,7 @@ .fieldSet__field = f.label :ip_pool_id, "IP Pool", :class => 'fieldSet__label' .fieldSet__input - = f.collection_select :ip_pool_id, organization.ip_pools.includes(:ip_addresses).order("`default` desc, name asc"), :id, :description, {}, :class => 'input input--select' + = f.collection_select :ip_pool_id, organization.ip_pools.includes(:ip_addresses).order("`default` desc, name asc"), :id, :name, {}, :class => 'input input--select' %p.fieldSet__text This is the IP pool that this message should be delivered from. diff --git a/app/views/ip_pool_rules/index.html.haml b/app/views/ip_pool_rules/index.html.haml index 577cf0a..7c6772e 100644 --- a/app/views/ip_pool_rules/index.html.haml +++ b/app/views/ip_pool_rules/index.html.haml @@ -59,7 +59,7 @@ %dl.ipPoolRuleList__condition %dt Will be sent using: - %dd= ip_pool_rule.ip_pool.description + %dd= ip_pool_rule.ip_pool.name - if @server - %p.ipPoolRuleListDefault.u-margin All mail that doesn't match a rule above will be sent using #{@server.ip_pool.description}. + %p.ipPoolRuleListDefault.u-margin All mail that doesn't match a rule above will be sent using #{@server.ip_pool.name}. %p.u-center= link_to "Add another rule", [:new, organization, @server, :ip_pool_rule], :class => "button button--positive" diff --git a/app/views/ip_pools/_form.html.haml b/app/views/ip_pools/_form.html.haml index 0742894..293d1c2 100644 --- a/app/views/ip_pools/_form.html.haml +++ b/app/views/ip_pools/_form.html.haml @@ -4,9 +4,6 @@ .fieldSet__field = f.label :name, :class => 'fieldSet__label' .fieldSet__input= f.text_field :name, :autofocus => true, :class => 'input input--text' - .fieldSet__field - = f.label :type, :class => 'fieldSet__label' - .fieldSet__input= f.select :type, IPPool::TYPES, {}, :class => 'input input--select' - if @ip_pool.persisted? %table.dataTable.u-margin-half diff --git a/app/views/organization_ip_pools/_nav.html.haml b/app/views/organization_ip_pools/_nav.html.haml index cab2752..5f86487 100644 --- a/app/views/organization_ip_pools/_nav.html.haml +++ b/app/views/organization_ip_pools/_nav.html.haml @@ -1,4 +1,4 @@ .navBar.navBar--secondary %ul - %li.navBar__item= link_to "Dedicated IPs", organization_ip_pools_path(organization), :class => ['navBar__link', active_nav == :ips ? 'is-active' : ''] + %li.navBar__item= link_to "IP Pools", organization_ip_pools_path(organization), :class => ['navBar__link', active_nav == :ips ? 'is-active' : ''] %li.navBar__item= link_to "Rules", organization_ip_pool_rules_path(organization), :class => ['navBar__link', active_nav == :rules ? 'is-active' : ''] diff --git a/db/migrate/20170428153353_remove_type_from_ip_pools.rb b/db/migrate/20170428153353_remove_type_from_ip_pools.rb new file mode 100644 index 0000000..b3e0d0b --- /dev/null +++ b/db/migrate/20170428153353_remove_type_from_ip_pools.rb @@ -0,0 +1,5 @@ +class RemoveTypeFromIPPools < ActiveRecord::Migration[5.0] + def change + remove_column :ip_pools, :type, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 93c5f81..f99a704 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170421195415) do +ActiveRecord::Schema.define(version: 20170428153353) do create_table "additional_route_endpoints", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4" do |t| t.integer "route_id" @@ -141,7 +141,6 @@ ActiveRecord::Schema.define(version: 20170421195415) do t.datetime "created_at", precision: 6 t.datetime "updated_at", precision: 6 t.boolean "default", default: false - t.string "type" t.index ["uuid"], name: "index_ip_pools_on_uuid", length: { uuid: 8 }, using: :btree end