Skip to content

Commit

Permalink
remove customer_auth_number_fields tables (#1655)
Browse files Browse the repository at this point in the history
* remove customer_auth_number_fields tables
* remove transport protocol FK in customer auth
  • Loading branch information
dmitry-sinina authored Dec 16, 2024
1 parent 8ac0ef6 commit a24781f
Show file tree
Hide file tree
Showing 23 changed files with 200 additions and 318 deletions.
1 change: 1 addition & 0 deletions app/admin/cdr/cdrs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def scoped_collection
scope :short_calls, show_count: false
scope :rerouted_calls, show_count: false
scope :with_trace, show_count: false
scope :with_recording, show_count: false
scope :not_authorized, show_count: false
scope :bad_routing, show_count: false
scope :package_billing, show_count: false
Expand Down
2 changes: 1 addition & 1 deletion app/admin/import/import_customers_auths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def resource_params
column :name
column :enabled
column :reject_calls
column :transport_protocol, sortable: :transport_protocol_name
column :transport_protocol, &:transport_protocol_display_name
column :ip
column :pop, sortable: :pop_name
column :src_prefix
Expand Down
59 changes: 37 additions & 22 deletions app/admin/routing/customers_auths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
decorate_with CustomersAuthDecorator

acts_as_export :id, :enabled, :reject_calls, :name,
[:transport_protocol_name, proc { |row| row.transport_protocol.try(:name) || '' }],
:transport_protocol_name,
:ip,
[:pop_name, proc { |row| row.pop.try(:name) || '' }],
:src_prefix,
Expand Down Expand Up @@ -46,9 +46,9 @@
:diversion_policy_name,
:diversion_rewrite_rule, :diversion_rewrite_result,
:pai_policy_name, :pai_rewrite_rule, :pai_rewrite_result,
[:src_number_field_name, proc { |row| row.src_number_field.try(:name) }],
[:src_name_field_name, proc { |row| row.src_name_field.try(:name) }],
[:dst_number_field_name, proc { |row| row.dst_number_field.try(:name) }],
:src_number_field_name,
:src_name_field_name,
:dst_number_field_name,
:src_name_rewrite_rule, :src_name_rewrite_result,
:src_rewrite_rule, :src_rewrite_result,
:dst_rewrite_rule, :dst_rewrite_result,
Expand Down Expand Up @@ -100,8 +100,8 @@
# , :enable_redirect, :redirect_method, :redirect_to

includes :tag_action, :rateplan, :routing_plan, :gateway, :src_numberlist, :dst_numberlist,
:pop, :radius_auth_profile, :radius_accounting_profile, :customer, :transport_protocol,
:lua_script, :src_name_field, :src_number_field, :dst_number_field, :cnam_database,
:pop, :radius_auth_profile, :radius_accounting_profile, :customer,
:lua_script, :cnam_database,
account: :contractor

controller do
Expand Down Expand Up @@ -130,7 +130,7 @@ def update
column :name
column :enabled
column :reject_calls
column :transport_protocol
column :transport_protocol, &:transport_protocol_name
column :ip
column :pop
column :src_prefix
Expand Down Expand Up @@ -177,20 +177,17 @@ def update
column :send_billing_information

column :diversion_policy, &:diversion_policy_name
column :diversion_rewrite_rule
column :diversion_rewrite_result

column :pai_policy, &:pai_policy_name

column :src_name_field
column :src_name_field, &:src_name_field_name
column :src_name_rewrite_rule
column :src_name_rewrite_result

column :src_number_field
column :src_number_field, &:src_number_field_name
column :src_rewrite_rule
column :src_rewrite_result

column :dst_number_field
column :dst_number_field, &:dst_number_field_name
column :dst_rewrite_rule
column :dst_rewrite_result

Expand Down Expand Up @@ -235,7 +232,7 @@ def update
filter :pai_policy_id_eq, label: 'PAI policy', as: :select, collection: CustomersAuth::PAI_POLICIES.invert
filter :privacy_mode_id_eq, label: 'Privacy mode', as: :select, collection: CustomersAuth::PRIVACY_MODES.invert, input_html: { class: 'chosen' }
filter :enable_audio_recording, as: :select, collection: [['Yes', true], ['No', false]]
filter :transport_protocol
filter :transport_protocol_id_eq, label: 'Transport protocol', as: :select, collection: CustomersAuth::TRANSPORT_PROTOCOLS.invert
filter :ip_covers,
as: :string,
input_html: { class: 'search_filter_string' },
Expand Down Expand Up @@ -325,7 +322,12 @@ def update
end

f.inputs 'Match conditions' do
f.input :transport_protocol, as: :select, include_blank: 'Any'
f.input :transport_protocol_id,
as: :select,
include_blank: 'Any',
collection: CustomersAuth::TRANSPORT_PROTOCOLS.invert,
input_html: { class: :chosen }

f.input :ip, as: :array_of_strings
f.input :pop, as: :select, include_blank: 'Any', input_html: { class: 'chosen' }
f.input :src_prefix, as: :array_of_strings
Expand Down Expand Up @@ -367,17 +369,30 @@ def update
f.input :pai_rewrite_rule
f.input :pai_rewrite_result

f.input :src_name_field, as: :select, include_blank: false, input_html: { class: :chosen }
f.input :src_name_field_id,
as: :select,
include_blank: false,
collection: CustomersAuth::SRC_NAME_FIELDS.invert,
input_html: { class: :chosen }
f.input :src_name_rewrite_rule
f.input :src_name_rewrite_result

f.input :src_number_field, as: :select, include_blank: false, input_html: { class: :chosen }
f.input :src_number_field_id,
as: :select,
include_blank: false,
collection: CustomersAuth::SRC_NUMBER_FIELDS.invert,
input_html: { class: :chosen }
f.input :src_rewrite_rule
f.input :src_rewrite_result

f.input :dst_number_field, as: :select, include_blank: false, input_html: { class: :chosen }
f.input :dst_number_field_id,
as: :select,
include_blank: false,
collection: CustomersAuth::DST_NUMBER_FIELDS.invert,
input_html: { class: :chosen }
f.input :dst_rewrite_rule
f.input :dst_rewrite_result

f.input :lua_script, input_html: { class: 'chosen' }, include_blank: 'None'
f.input :cnam_database, input_html: { class: 'chosen' }, include_blank: 'None'
end
Expand Down Expand Up @@ -457,7 +472,7 @@ def update
end
panel 'Match conditions' do
attributes_table_for s do
row :transport_protocol
row :transport_protocol, &:transport_protocol_name
row :ip
row :pop
row :src_prefix
Expand Down Expand Up @@ -486,15 +501,15 @@ def update
row :pai_rewrite_rule
row :pai_rewrite_result

row :src_name_field
row :src_name_field, &:src_name_field_name
row :src_name_rewrite_rule
row :src_name_rewrite_result

row :src_number_field
row :src_number_field, &:src_number_field_name
row :src_rewrite_rule
row :src_rewrite_result

row :dst_number_field
row :dst_number_field, &:dst_number_field_name
row :dst_rewrite_rule
row :dst_rewrite_result

Expand Down
1 change: 1 addition & 0 deletions app/models/cdr/cdr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ class Cdr::Cdr < Cdr::Base
scope :not_authorized, -> { where('customer_auth_id is null') }
scope :bad_routing, -> { where('customer_auth_id is not null AND disconnect_initiator_id=0') }
scope :with_trace, -> { where('dump_level_id > 0') }
scope :with_recording, -> { where('audio_recorded and duration > 0 and local_tag is not null') }
scope :package_billing, -> { where('package_counter_id is not null') }

scope :account_id_eq, ->(account_id) { where('vendor_acc_id =? OR customer_acc_id =?', account_id, account_id) }
Expand Down
67 changes: 56 additions & 11 deletions app/models/customers_auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
# customers_auth_cnam_database_id_fkey (cnam_database_id => cnam_databases.id)
# customers_auth_customer_id_fkey (customer_id => contractors.id)
# customers_auth_dst_blacklist_id_fkey (dst_numberlist_id => numberlists.id)
# customers_auth_dst_number_field_id_fkey (dst_number_field_id => customers_auth_dst_number_fields.id)
# customers_auth_gateway_id_fkey (gateway_id => gateways.id)
# customers_auth_lua_script_id_fkey (lua_script_id => lua_scripts.id)
# customers_auth_pop_id_fkey (pop_id => pops.id)
Expand All @@ -100,15 +99,21 @@
# customers_auth_rateplan_id_fkey (rateplan_id => rateplans.id)
# customers_auth_routing_plan_id_fkey (routing_plan_id => routing_plans.id)
# customers_auth_src_blacklist_id_fkey (src_numberlist_id => numberlists.id)
# customers_auth_src_name_field_id_fkey (src_name_field_id => customers_auth_src_name_fields.id)
# customers_auth_src_number_field_id_fkey (src_number_field_id => customers_auth_src_number_fields.id)
# customers_auth_tag_action_id_fkey (tag_action_id => tag_actions.id)
# customers_auth_transport_protocol_id_fkey (transport_protocol_id => transport_protocols.id)
#

class CustomersAuth < ApplicationRecord
self.table_name = 'class4.customers_auth'

TRANSPORT_PROTOCOL_UDP = 1
TRANSPORT_PROTOCOL_TCP = 2
TRANSPORT_PROTOCOL_TLS = 3
TRANSPORT_PROTOCOLS = {
TRANSPORT_PROTOCOL_UDP => 'UDP',
TRANSPORT_PROTOCOL_TCP => 'TCP',
TRANSPORT_PROTOCOL_TLS => 'TLS'
}.freeze

DUMP_LEVEL_DISABLED = 0
DUMP_LEVEL_CAPTURE_SIP = 1
DUMP_LEVEL_CAPTURE_RTP = 2
Expand Down Expand Up @@ -183,6 +188,29 @@ class CustomersAuth < ApplicationRecord
PAI_POLICY_REQUIRE => 'Require'
}.freeze

DST_NUMBER_FIELD_RURI_USERPART = 1
DST_NUMBER_FIELD_TO_USERPART = 2
DST_NUMBER_FIELD_DIVERSION_USERPART = 3
DST_NUMBER_FIELDS = {
DST_NUMBER_FIELD_RURI_USERPART => 'R-URI userpart',
DST_NUMBER_FIELD_TO_USERPART => 'To URI userpart',
DST_NUMBER_FIELD_DIVERSION_USERPART => 'Top Diversion header userpart'
}.freeze

SRC_NUMBER_FIELD_FROM_USERPART = 1
SRC_NUMBER_FIELD_FROM_DSP = 2
SRC_NUMBER_FIELDS = {
SRC_NUMBER_FIELD_FROM_USERPART => 'From URI userpart',
SRC_NUMBER_FIELD_FROM_DSP => 'From URI display name'
}.freeze

SRC_NAME_FIELD_FROM_DSP = 1
SRC_NAME_FIELD_FROM_USERPART = 2
SRC_NAME_FIELDS = {
SRC_NAME_FIELD_FROM_DSP => 'From URI display name',
SRC_NAME_FIELD_FROM_USERPART => 'From URI userpart'
}.freeze

module CONST
MATCH_CONDITION_ATTRIBUTES = %i[ip
src_prefix
Expand Down Expand Up @@ -211,15 +239,10 @@ module CONST
belongs_to :src_numberlist, class_name: 'Routing::Numberlist', foreign_key: :src_numberlist_id, optional: true
belongs_to :radius_auth_profile, class_name: 'Equipment::Radius::AuthProfile', foreign_key: :radius_auth_profile_id, optional: true
belongs_to :radius_accounting_profile, class_name: 'Equipment::Radius::AccountingProfile', foreign_key: :radius_accounting_profile_id, optional: true
belongs_to :transport_protocol, class_name: 'Equipment::TransportProtocol', foreign_key: :transport_protocol_id, optional: true

belongs_to :tag_action, class_name: 'Routing::TagAction', optional: true
belongs_to :lua_script, class_name: 'System::LuaScript', foreign_key: :lua_script_id, optional: true

belongs_to :dst_number_field, class_name: 'Routing::CustomerAuthDstNumberField', foreign_key: :dst_number_field_id
belongs_to :src_number_field, class_name: 'Routing::CustomerAuthSrcNumberField', foreign_key: :src_number_field_id
belongs_to :src_name_field, class_name: 'Routing::CustomerAuthSrcNameField', foreign_key: :src_name_field_id

belongs_to :cnam_database, class_name: 'Cnam::Database', foreign_key: :cnam_database_id, optional: true

array_belongs_to :tag_action_values, class_name: 'Routing::RoutingTag', foreign_key: :tag_action_value
Expand Down Expand Up @@ -257,8 +280,6 @@ module CONST
validate :validate_account
validate :validate_gateway

validates :src_name_field, :src_number_field, :dst_number_field, presence: true

validates :dst_number_min_length, :dst_number_max_length, :src_number_min_length, :src_number_max_length, presence: true
validates :src_number_min_length, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 100, allow_nil: false, only_integer: true }
validates :src_number_max_length, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 100, allow_nil: false, only_integer: true }
Expand All @@ -280,6 +301,14 @@ module CONST
validate :validate_rewrite_ss_status
validates :privacy_mode_id, inclusion: { in: PRIVACY_MODES.keys }, allow_nil: false

validates :src_name_field_id, :src_number_field_id, :dst_number_field_id, presence: true

validates :src_name_field_id, inclusion: { in: CustomersAuth::SRC_NAME_FIELDS.keys }, allow_nil: false
validates :src_number_field_id, inclusion: { in: CustomersAuth::SRC_NUMBER_FIELDS.keys }, allow_nil: false
validates :dst_number_field_id, inclusion: { in: CustomersAuth::DST_NUMBER_FIELDS.keys }, allow_nil: false

validates :transport_protocol_id, inclusion: { in: CustomersAuth::TRANSPORT_PROTOCOLS.keys }, allow_nil: true

validates_with TagActionValueValidator

include Yeti::StateUpdater
Expand Down Expand Up @@ -321,6 +350,10 @@ def display_name
"#{name} | #{id}"
end

def transport_protocol_name
transport_protocol_id.nil? ? 'Any' : TRANSPORT_PROTOCOLS[transport_protocol_id]
end

def dump_level_name
dump_level_id.nil? ? DUMP_LEVELS[0] : DUMP_LEVELS[dump_level_id]
end
Expand Down Expand Up @@ -349,6 +382,18 @@ def diversion_policy_name
DIVERSION_POLICIES[diversion_policy_id]
end

def dst_number_field_name
DST_NUMBER_FIELDS[dst_number_field_id]
end

def src_number_field_name
SRC_NUMBER_FIELDS[src_number_field_id]
end

def src_name_field_name
SRC_NAME_FIELDS[src_name_field_id]
end

# TODO: move to decorator when ActiveAdmin fix problem
# Problem is:
# on "update" AA uses decorated object
Expand Down
13 changes: 10 additions & 3 deletions app/models/importing/customers_auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# diversion_policy_name :string
# diversion_rewrite_result :string
# diversion_rewrite_rule :string
# dst_number_field_name :integer(2)
# dst_number_field_name :string
# dst_number_max_length :integer(4)
# dst_number_min_length :integer(4)
# dst_number_radius_rewrite_result :string
Expand Down Expand Up @@ -48,7 +48,7 @@
# routing_group_name :string
# routing_plan_name :string
# send_billing_information :boolean default(FALSE), not null
# src_name_field_name :integer(2)
# src_name_field_name :string
# src_name_rewrite_result :string
# src_name_rewrite_rule :string
# src_number_field_name :string
Expand Down Expand Up @@ -106,7 +106,6 @@ class Importing::CustomersAuth < Importing::Base
belongs_to :src_numberlist, class_name: '::Routing::Numberlist', foreign_key: :src_numberlist_id, optional: true
belongs_to :radius_auth_profile, class_name: '::Equipment::Radius::AuthProfile', foreign_key: :radius_auth_profile_id, optional: true
belongs_to :radius_accounting_profile, class_name: '::Equipment::Radius::AccountingProfile', foreign_key: :radius_accounting_profile_id, optional: true
belongs_to :transport_protocol, class_name: 'Equipment::TransportProtocol', foreign_key: :transport_protocol_id, optional: true
belongs_to :tag_action, class_name: 'Routing::TagAction', optional: true
belongs_to :lua_script, class_name: 'System::LuaScript', foreign_key: :lua_script_id, optional: true

Expand Down Expand Up @@ -163,6 +162,10 @@ class Importing::CustomersAuth < Importing::Base

import_for ::CustomersAuth

def transport_protocol_display_name
transport_protocol_id.nil? ? 'Any' : CustomersAuth::TRANSPORT_PROTOCOLS[transport_protocol_id]
end

def dump_level_display_name
dump_level_id.nil? ? 'unknown' : CustomersAuth::DUMP_LEVELS[dump_level_id]
end
Expand All @@ -179,10 +182,14 @@ def self.after_import_hook
where(src_prefix: nil).update_all(src_prefix: '')
where(dst_prefix: nil).update_all(dst_prefix: '')
resolve_array_of_tags('tag_action_value', 'tag_action_value_names')
resolve_integer_constant('transport_protocol_id', 'transport_protocol_name', CustomersAuth::TRANSPORT_PROTOCOLS)
resolve_integer_constant('dump_level_id', 'dump_level_name', CustomersAuth::DUMP_LEVELS)
resolve_integer_constant('privacy_mode_id', 'privacy_mode_name', CustomersAuth::PRIVACY_MODES)
resolve_integer_constant('diversion_policy_id', 'diversion_policy_name', CustomersAuth::DIVERSION_POLICIES)
resolve_integer_constant('pai_policy_id', 'pai_policy_name', CustomersAuth::PAI_POLICIES)
resolve_integer_constant('src_name_field_id', 'src_name_field_name', CustomersAuth::SRC_NAME_FIELDS)
resolve_integer_constant('src_number_field_id', 'src_number_field_name', CustomersAuth::SRC_NUMBER_FIELDS)
resolve_integer_constant('dst_number_field_id', 'dst_number_field_name', CustomersAuth::DST_NUMBER_FIELDS)
super
CustomersAuth.increment_state_value
end
Expand Down
22 changes: 0 additions & 22 deletions app/models/routing/customer_auth_dst_number_field.rb

This file was deleted.

Loading

0 comments on commit a24781f

Please sign in to comment.