Skip to content

Commit

Permalink
remove types from ip pools
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcooke committed Apr 28, 2017
1 parent 88974ce commit 698b580
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 29 deletions.
2 changes: 1 addition & 1 deletion app/controllers/ip_pools_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def destroy
private

def safe_params
params.require(:ip_pool).permit(:name, :type, :default)
params.require(:ip_pool).permit(:name, :default)
end

end
2 changes: 1 addition & 1 deletion app/controllers/organization_ip_pools_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 0 additions & 16 deletions app/models/ip_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
# created_at :datetime
# updated_at :datetime
# default :boolean default(FALSE)
# type :string(255)
#
# Indexes
#
Expand All @@ -17,8 +16,6 @@

class IPPool < ApplicationRecord

TYPES = ['Transactional', 'Bulk', 'Forwarding', 'Dedicated']

include HasUUID

validates :name, :presence => true
Expand All @@ -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
4 changes: 2 additions & 2 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion app/views/ip_pool_rules/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions app/views/ip_pool_rules/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 0 additions & 3 deletions app/views/ip_pools/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/organization_ip_pools/_nav.html.haml
Original file line number Diff line number Diff line change
@@ -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' : '']
5 changes: 5 additions & 0 deletions db/migrate/20170428153353_remove_type_from_ip_pools.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemoveTypeFromIPPools < ActiveRecord::Migration[5.0]
def change
remove_column :ip_pools, :type, :string
end
end
3 changes: 1 addition & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -141,7 +141,6 @@
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

Expand Down

0 comments on commit 698b580

Please sign in to comment.