Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: shared gateway groups. refs #1077 #1084

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion app/admin/equipment/gateway_groups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@

acts_as_export :id,
:name,
:is_shared,
[:vendor_name, proc { |row| row.vendor.try(:name) }],
[:balancing_mode_name, proc { |row| row.balancing_mode.try(:name) }]

acts_as_import resource_class: Importing::GatewayGroup

decorate_with GatewayGroupDecorator

permit_params :vendor_id, :name, :balancing_mode_id
permit_params :vendor_id, :name, :balancing_mode_id, :is_shared

controller do
def scoped_collection
Expand All @@ -33,11 +34,17 @@ def scoped_collection
render plain: view_context.options_from_collection_for_select(@gr, :id, :display_name)
end

collection_action :for_termination do
@gr = GatewayGroup.for_termination(params[:contractor_id].to_i)
render plain: view_context.options_from_collection_for_select(@gr, :id, :display_name)
end

index do
selectable_column
id_column
actions
column :name
column :is_shared
column :vendor do |c|
auto_link(c.vendor, c.vendor.decorated_display_name)
end
Expand All @@ -46,6 +53,7 @@ def scoped_collection

filter :id
filter :name
filter :is_shared
filter :vendor,
input_html: { class: 'chosen-ajax', 'data-path': '/contractors/search?q[vendor_eq]=true' },
collection: proc {
Expand All @@ -59,6 +67,7 @@ def scoped_collection
attributes_table do
row :id
row :name
row :is_shared
row :vendor do
auto_link(s.vendor, s.vendor.decorated_display_name)
end
Expand All @@ -68,8 +77,11 @@ def scoped_collection
table_for resource.gateways do |_g|
column :id
column :name
column :priority
column :weight
column :host
column :port
column :allow_termination
end
end
end
Expand All @@ -78,6 +90,7 @@ def scoped_collection
f.semantic_errors *f.object.errors.attribute_names
f.inputs form_title do
f.input :name
f.input :is_shared
f.input :vendor, input_html: { class: 'chosen' }, collection: Contractor.vendors
f.input :balancing_mode, as: :select, include_blank: false
end
Expand Down
4 changes: 2 additions & 2 deletions app/admin/routing/dialpeers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def update
class: 'chosen',
onchange: remote_chosen_request(:get, with_contractor_accounts_path, { contractor_id: '$(this).val()' }, :dialpeer_account_id) +
remote_chosen_request(:get, for_termination_gateways_path, { contractor_id: '$(this).val()' }, :dialpeer_gateway_id) +
remote_chosen_request(:get, with_contractor_gateway_groups_path, { contractor_id: '$(this).val()' }, :dialpeer_gateway_group_id)
remote_chosen_request(:get, for_termination_gateway_groups_path, { contractor_id: '$(this).val()' }, :dialpeer_gateway_group_id)
}
f.input :account, collection: (f.object.vendor.nil? ? [] : f.object.vendor.accounts),
include_blank: false,
Expand All @@ -253,7 +253,7 @@ def update
include_blank: 'None',
input_html: { class: 'chosen' }

f.input :gateway_group, collection: (f.object.vendor.nil? ? [] : f.object.vendor.gateway_groups),
f.input :gateway_group, collection: (f.object.vendor.nil? ? [] : f.object.vendor.for_termination_gateway_groups),
include_blank: 'None',
input_html: { class: 'chosen' }

Expand Down
4 changes: 4 additions & 0 deletions app/models/contractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ def for_termination_gateways
Gateway.for_termination(id)
end

def for_termination_gateway_groups
GatewayGroup.for_termination(id)
end

private

def vendor_or_customer?
Expand Down
6 changes: 5 additions & 1 deletion app/models/dialpeer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,11 @@ def vendor_owners_the_gateway
end

def vendor_owners_the_gateway_group
errors.add(:gateway_group, 'must be owned by selected vendor') unless gateway_group_id.nil? || (vendor_id && gateway_group_id && vendor_id == gateway_group.vendor_id)
return true if gateway_group_id.nil? || gateway_group.is_shared?

unless vendor_id && vendor_id == gateway_group.vendor_id
errors.add(:gateway_group, 'must be owned by selected vendor or be shared')
end
end

scope :routing_tag_ids_array_contains, ->(*tag_id) { where.contains routing_tag_ids: Array(tag_id) }
Expand Down
4 changes: 2 additions & 2 deletions app/models/gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,10 @@ def is_shared_can_be_changed
return true unless is_shared_changed?(from: true, to: false)

if dialpeers.any?
errors.add(:is_shared, I18n.t('activerecord.errors.models.gateway.attributes.contractor.cant_be_changed_when_linked_to_dialpeer'))
errors.add(:is_shared, I18n.t('activerecord.errors.models.gateway.attributes.is_shared.cant_be_disabled_when_linked_to_dialpeer'))
end
if customers_auths.any?
errors.add(:is_shared, I18n.t('activerecord.errors.models.gateway.attributes.contractor.cant_be_changed_when_linked_to_customers_auth'))
errors.add(:is_shared, I18n.t('activerecord.errors.models.gateway.attributes.is_shared.cant_be_disabled_when_linked_to_customers_auth'))
end
end

Expand Down
16 changes: 16 additions & 0 deletions app/models/gateway_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Table name: gateway_groups
#
# id :integer(4) not null, primary key
# is_shared :boolean default(FALSE), not null
# name :string not null
# prefer_same_pop :boolean default(TRUE), not null
# balancing_mode_id :integer(2) default(1), not null
Expand Down Expand Up @@ -35,6 +36,13 @@ class GatewayGroup < ApplicationRecord

validate :contractor_is_vendor
validate :vendor_can_be_changed
validate :is_shared_can_be_changed

scope :for_termination, lambda { |contractor_id|
where("#{table_name}.vendor_id=? OR #{table_name}.is_shared", contractor_id)
.joins(:vendor)
.order(:name)
}

def display_name
"#{name} | #{id}"
Expand All @@ -56,4 +64,12 @@ def vendor_can_be_changed
errors.add(:vendor, "can't be changed because Gateway Group belongs to dialpeers") if dialpeers.any?
end
end

def is_shared_can_be_changed
return true unless is_shared_changed?(from: true, to: false)

if dialpeers.any?
errors.add(:is_shared, I18n.t('activerecord.errors.models.gateway_group.attributes.is_shared.cant_be_disabled_when_linked_to_dialpeer'))
end
end
end
2 changes: 1 addition & 1 deletion app/models/lnp/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# id :integer(4) not null, primary key
# data :string
# dst :string not null
# expires_at :datetime
# expires_at :datetime not null
# lrn :string not null
# tag :string
# created_at :datetime
Expand Down
11 changes: 5 additions & 6 deletions app/models/lnp/database_alcazar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
#
# Table name: class4.lnp_databases_alcazar
#
# id :integer(2) not null, primary key
# host :string not null
# key :string not null
# port :integer(4)
# timeout :integer(2) default(300), not null
# database_id :integer(4)
# id :integer(2) not null, primary key
# host :string not null
# key :string not null
# port :integer(4)
# timeout :integer(2) default(300), not null
#

class Lnp::DatabaseAlcazar < ApplicationRecord
Expand Down
1 change: 0 additions & 1 deletion app/models/lnp/database_coure_anq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# password :string not null
# timeout :integer(2) default(300), not null
# username :string not null
# database_id :integer(4)
#

class Lnp::DatabaseCoureAnq < ApplicationRecord
Expand Down
9 changes: 7 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,17 @@ en:
contractor:
vendor_cant_be_changed: "can't be changed because Gateway belongs to dialpeers"
is_shared:
cant_be_changed_when_linked_to_dialpeer: "cant'be changed because Gateway belongs to Dialpeers"
cant_be_changed_when_linked_to_customers_auth: "cant'be changed because Gateway belongs to CustomersAuth"
cant_be_disabled_when_linked_to_dialpeer: "can't be disabled because Gateway belongs to Dialpeers"
cant_be_disabled_when_linked_to_customers_auth: "can't be disabled because Gateway belongs to CustomersAuth"
incoming_auth_username:
cant_be_cleared: "Can't be cleared when gateway used at Customer auth with require_incoming_auth"
incoming_auth_password:
cant_be_cleared: "Can't be cleared when gateway used at Customer auth with require_incoming_auth"
gateway_group:
attributes:
is_shared:
cant_be_disabled_when_linked_to_dialpeer: "can't be disabled because GatewayGroup belongs to Dialpeers"

customers_auth:
attributes:
gateway:
Expand Down
Loading