Skip to content

Commit

Permalink
remove sip schemas table (#1419)
Browse files Browse the repository at this point in the history
* remove sip schemas table
* user=phone in uri support
  • Loading branch information
dmitry-sinina authored Feb 5, 2024
1 parent 2e2cc0e commit f9f9b63
Show file tree
Hide file tree
Showing 37 changed files with 1,805 additions and 300 deletions.
9 changes: 5 additions & 4 deletions app/admin/equipment/gateways.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
:force_cancel_routeset,
[:orig_disconnect_policy_name, proc { |row| row.orig_disconnect_policy.try(:name) }],
[:transport_protocol_name, proc { |row| row.transport_protocol.try(:name) }],
[:sip_schema_name, proc { |row| row.sip_schema.try(:name) }],
:sip_schema_name,
:host,
:port,
:registered_aor_mode_name,
Expand Down Expand Up @@ -111,7 +111,7 @@
:radius_accounting_profile,
:transport_protocol, :term_proxy_transport_protocol, :orig_proxy_transport_protocol,
:rel100_mode, :rx_inband_dtmf_filtering_mode, :tx_inband_dtmf_filtering_mode,
:network_protocol_priority, :media_encryption_mode, :sip_schema,
:network_protocol_priority, :media_encryption_mode,
:termination_src_numberlist, :termination_dst_numberlist, :lua_script, :stir_shaken_crt

controller do
Expand Down Expand Up @@ -314,6 +314,7 @@ def resource_params
filter :incoming_auth_password
filter :codec_group, input_html: { class: 'chosen' }, collection: proc { CodecGroup.pluck(:name, :id) }
filter :diversion_send_mode
filter :sip_schema_id, as: :select, collection: proc { Gateway::SIP_SCHEMAS.invert }

form do |f|
f.semantic_errors *f.object.errors.attribute_names
Expand Down Expand Up @@ -398,7 +399,7 @@ def resource_params
column do
f.inputs 'Termination' do
f.input :transport_protocol, as: :select, include_blank: false
f.input :sip_schema, as: :select, include_blank: false
f.input :sip_schema_id, as: :select, include_blank: false, collection: Gateway::SIP_SCHEMAS.invert
f.input :host
f.input :port
f.input :registered_aor_mode_id, as: :select, include_blank: false,
Expand Down Expand Up @@ -586,7 +587,7 @@ def resource_params
panel 'Termination' do
attributes_table_for s do
row :transport_protocol
row :sip_schema
row :sip_schema_id, &:sip_schema_name
row :host
row :port

Expand Down
12 changes: 6 additions & 6 deletions app/admin/equipment/registrations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
menu parent: 'Equipment', priority: 81, label: 'Registrations'
config.batch_actions = true

includes :pop, :node, :transport_protocol, :proxy_transport_protocol, :sip_schema
includes :pop, :node, :transport_protocol, :proxy_transport_protocol

acts_as_export :id, :name, :enabled,
[:pop_name, proc { |row| row.pop.try(:name) }],
[:node_name, proc { |row| row.node.try(:name) }],
[:transport_protocol_name, proc { |row| row.transport_protocol.try(:name) }],
[:sip_schema_name, proc { |row| row.sip_schema.try(:name) }],
:sip_schema_name,
:sip_interface_name,
:domain,
:username,
Expand Down Expand Up @@ -45,7 +45,7 @@
column :enabled
column :pop
column :node
column :sip_schema
column :sip_schema_id, &:sip_schema_name
column 'SIP Interface Name', :sip_interface_name, sortable: :sip_interface_name
column :transport_protocol
column :domain
Expand All @@ -67,7 +67,7 @@
filter :enabled, as: :select, collection: [['Yes', true], ['No', false]]
filter :pop, input_html: { class: 'chosen' }
filter :node, input_html: { class: 'chosen' }
filter :sip_schema
filter :sip_schema_id, as: :select, collection: proc { Equipment::Registration::SIP_SCHEMAS.invert }
filter :sip_interface_name, label: 'SIP Interface Name'
filter :transport_protocol, input_html: { class: 'chosen' }, collection: proc { Equipment::TransportProtocol.pluck(:name, :id) }
filter :domain
Expand All @@ -87,7 +87,7 @@
f.input :node, as: :select,
include_blank: 'Any',
input_html: { class: 'chosen' }
f.input :sip_schema, as: :select, include_blank: false
f.input :sip_schema_id, as: :select, include_blank: false, collection: Equipment::Registration::SIP_SCHEMAS.invert
f.input :sip_interface_name, label: 'SIP Interface Name'
f.input :transport_protocol, as: :select, include_blank: false
f.input :domain
Expand All @@ -113,7 +113,7 @@
row :enabled
row :pop
row :node
row :sip_schema
row :sip_schema_id, &:sip_schema_name
row :sip_interface_name
row :transport_protocol
row :domain
Expand Down
12 changes: 6 additions & 6 deletions app/admin/equipment/sip_options_probers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
menu parent: 'Equipment', priority: 82, label: 'SIP Options probers'
config.batch_actions = true

includes :pop, :node, :transport_protocol, :proxy_transport_protocol, :sip_schema
includes :pop, :node, :transport_protocol, :proxy_transport_protocol

acts_as_export :id, :name, :enabled,
[:pop_name, proc { |row| row.pop.try(:name) }],
[:node_name, proc { |row| row.node.try(:name) }],
[:transport_protocol_name, proc { |row| row.transport_protocol.try(:name) }],
[:sip_schema_name, proc { |row| row.sip_schema.try(:name) }],
:sip_schema_name,
:ruri_domain,
:ruri_username,
:from_uri,
Expand Down Expand Up @@ -43,7 +43,7 @@
column :enabled
column :pop
column :node
column :sip_schema
column :sip_schema_id, &:sip_schema_name
column :transport_protocol
column :ruri_domain
column :ruri_username
Expand All @@ -64,7 +64,7 @@
filter :enabled, as: :select, collection: [['Yes', true], ['No', false]]
filter :pop, input_html: { class: 'chosen' }
filter :node, input_html: { class: 'chosen' }
filter :sip_schema
filter :sip_schema_id, as: :select, collection: proc { Equipment::SipOptionsProber::SIP_SCHEMAS.invert }
filter :external_id

form do |f|
Expand All @@ -78,7 +78,7 @@
f.input :node, as: :select,
include_blank: 'Any',
input_html: { class: 'chosen' }
f.input :sip_schema, as: :select, include_blank: false
f.input :sip_schema_id, as: :select, include_blank: false, collection: Equipment::SipOptionsProber::SIP_SCHEMAS.invert
f.input :transport_protocol, as: :select, include_blank: false
f.input :ruri_domain
f.input :ruri_username
Expand All @@ -102,7 +102,7 @@
row :enabled
row :pop
row :node
row :sip_schema
row :sip_schema_id, &:sip_schema_name
row :transport_protocol
row :ruri_domain
row :ruri_username
Expand Down
1 change: 1 addition & 0 deletions app/admin/import/import_gateways.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def resource_params

column :pop, sortable: :pop_name
column :transport_protocol_name
column :sip_schema, &:sip_schema_display_name
column :host
column :port
column :registered_aor_mode, &:registered_aor_mode_display_name
Expand Down

This file was deleted.

16 changes: 13 additions & 3 deletions app/models/equipment/registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,44 @@
# registrations_node_id_fkey (node_id => nodes.id)
# registrations_pop_id_fkey (pop_id => pops.id)
# registrations_proxy_transport_protocol_id_fkey (proxy_transport_protocol_id => transport_protocols.id)
# registrations_sip_schema_id_fkey (sip_schema_id => sip_schemas.id)
# registrations_transport_protocol_id_fkey (transport_protocol_id => transport_protocols.id)
#

class Equipment::Registration < ApplicationRecord
self.table_name = 'class4.registrations'

SIP_SCHEMA_SIP = 1
SIP_SCHEMA_SIPS = 2
SIP_SCHEMAS = {
SIP_SCHEMA_SIP => 'sip',
SIP_SCHEMA_SIPS => 'sips'
}.freeze

belongs_to :transport_protocol, class_name: 'Equipment::TransportProtocol', foreign_key: :transport_protocol_id
belongs_to :proxy_transport_protocol, class_name: 'Equipment::TransportProtocol', foreign_key: :proxy_transport_protocol_id
belongs_to :pop, optional: true
belongs_to :node, optional: true
belongs_to :sip_schema, class_name: 'System::SipSchema', foreign_key: :sip_schema_id

validates :name, uniqueness: { allow_blank: false }
validates :name, :domain, :username, :retry_delay, :transport_protocol, :proxy_transport_protocol, :sip_schema, presence: true
validates :name, :domain, :username, :retry_delay, :transport_protocol, :proxy_transport_protocol, :sip_schema_id, presence: true

# validates_format_of :contact, :with => /\Asip:(.*)\z/
validates :contact, format: URI::DEFAULT_PARSER.make_regexp(%w[sip])

validates :retry_delay, numericality: { greater_than: 0, less_than_or_equal_to: PG_MAX_SMALLINT, allow_nil: false, only_integer: true }
validates :max_attempts, numericality: { greater_than: 0, less_than_or_equal_to: PG_MAX_SMALLINT, allow_nil: true, only_integer: true }
validates :sip_schema_id, inclusion: { in: SIP_SCHEMAS.keys }, allow_nil: false

include WithPaperTrail

def display_name
"#{name} | #{id}"
end

def sip_schema_name
SIP_SCHEMAS[sip_schema_id]
end

include Yeti::ResourceStatus
include Yeti::RegistrationReloader
include Yeti::StateUpdater
Expand Down
16 changes: 13 additions & 3 deletions app/models/equipment/sip_options_prober.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,27 @@
# sip_options_probers_node_id_fkey (node_id => nodes.id)
# sip_options_probers_pop_id_fkey (pop_id => pops.id)
# sip_options_probers_proxy_transport_protocol_id_fkey (proxy_transport_protocol_id => transport_protocols.id)
# sip_options_probers_sip_schema_id_fkey (sip_schema_id => sip_schemas.id)
# sip_options_probers_transport_protocol_id_fkey (transport_protocol_id => transport_protocols.id)
#
class Equipment::SipOptionsProber < ApplicationRecord
self.table_name = 'class4.sip_options_probers'

SIP_SCHEMA_SIP = 1
SIP_SCHEMA_SIPS = 2
SIP_SCHEMAS = {
SIP_SCHEMA_SIP => 'sip',
SIP_SCHEMA_SIPS => 'sips'
}.freeze

belongs_to :transport_protocol, class_name: 'Equipment::TransportProtocol', foreign_key: :transport_protocol_id
belongs_to :proxy_transport_protocol, class_name: 'Equipment::TransportProtocol', foreign_key: :proxy_transport_protocol_id
belongs_to :pop, optional: true
belongs_to :node, optional: true
belongs_to :sip_schema, class_name: 'System::SipSchema', foreign_key: :sip_schema_id

validates :name, uniqueness: { allow_blank: false }
validates :external_id, uniqueness: { allow_blank: true }
validates :name, :ruri_domain, :ruri_username, :transport_protocol, :proxy_transport_protocol, :sip_schema, presence: true
validates :name, :ruri_domain, :ruri_username, :transport_protocol, :proxy_transport_protocol, :sip_schema_id, presence: true
validates :sip_schema_id, inclusion: { in: SIP_SCHEMAS.keys }, allow_nil: false

# validates_format_of :contact, :with => /\Asip:(.*)\z/
# validates :contact_uri, format: URI::DEFAULT_PARSER.make_regexp(%w[sip])
Expand All @@ -64,6 +70,10 @@ def display_name
"#{name} | #{id}"
end

def sip_schema_name
SIP_SCHEMAS[sip_schema_id]
end

include Yeti::ResourceStatus
include Yeti::SipOptionsProberReloader
include Yeti::StateUpdater
Expand Down
23 changes: 19 additions & 4 deletions app/models/gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
# orig_proxy_transport_protocol_id :integer(2) default(1), not null
# pai_send_mode_id :integer(2) default(0), not null
# pop_id :integer(4)
# privacy_mode_id :integer(2) default(0), not null
# radius_accounting_profile_id :integer(2)
# registered_aor_mode_id :integer(2) default(0), not null
# rel100_mode_id :integer(2) default(4), not null
Expand Down Expand Up @@ -157,7 +158,6 @@
# gateways_sensor_id_fkey (sensor_id => sensors.id)
# gateways_sensor_level_id_fkey (sensor_level_id => sensor_levels.id)
# gateways_session_refresh_method_id_fkey (session_refresh_method_id => session_refresh_methods.id)
# gateways_sip_schema_id_fkey (sip_schema_id => sip_schemas.id)
# gateways_stir_shaken_crt_id_fkey (stir_shaken_crt_id => stir_shaken_signing_certificates.id)
# gateways_term_disconnect_policy_id_fkey (term_disconnect_policy_id => disconnect_policy.id)
# gateways_term_proxy_transport_protocol_id_fkey (term_proxy_transport_protocol_id => transport_protocols.id)
Expand All @@ -176,10 +176,12 @@ class Gateway < ApplicationRecord
PAI_SEND_MODE_NO_SEND = 0
PAI_SEND_MODE_BUILD_TEL = 1
PAI_SEND_MODE_BUILD_SIP = 2
PAI_SEND_MODE_BUILD_SIP_WITH_USER_PHONE = 3
PAI_SEND_MODES = {
PAI_SEND_MODE_NO_SEND => 'Do not send',
PAI_SEND_MODE_BUILD_TEL => 'Build TEL URI from Source Number',
PAI_SEND_MODE_BUILD_SIP => 'Build SIP URI from Source Number'
PAI_SEND_MODE_BUILD_SIP => 'Build SIP URI from Source Number',
PAI_SEND_MODE_BUILD_SIP_WITH_USER_PHONE => 'Build SIP URI from Source Number with user=phone'
}.freeze

REGISTERED_AOR_MODE_NO_USE = 0
Expand All @@ -198,6 +200,15 @@ class Gateway < ApplicationRecord
STIR_SHAKEN_MODE_INSERT => 'Insert identity'
}.freeze

SIP_SCHEMA_SIP = 1
SIP_SCHEMA_SIPS = 2
SIP_SCHEMA_SIP_WITH_USER_PHONE = 3
SIP_SCHEMAS = {
SIP_SCHEMA_SIP => 'sip',
SIP_SCHEMA_SIPS => 'sips',
SIP_SCHEMA_SIP_WITH_USER_PHONE => 'sip with user=phone'
}.freeze

class << self
# Returns a reference if host is IPv6, otherwise returns host
# @param value [String]
Expand Down Expand Up @@ -233,7 +244,6 @@ def normalize_host(value)
belongs_to :tx_inband_dtmf_filtering_mode, class_name: 'Equipment::GatewayInbandDtmfFilteringMode', foreign_key: :tx_inband_dtmf_filtering_mode_id
belongs_to :network_protocol_priority, class_name: 'Equipment::GatewayNetworkProtocolPriority', foreign_key: :network_protocol_priority_id
belongs_to :media_encryption_mode, class_name: 'Equipment::GatewayMediaEncryptionMode', foreign_key: :media_encryption_mode_id
belongs_to :sip_schema, class_name: 'System::SipSchema', foreign_key: :sip_schema_id
belongs_to :termination_dst_numberlist, class_name: 'Routing::Numberlist', foreign_key: :termination_dst_numberlist_id, optional: true
belongs_to :termination_src_numberlist, class_name: 'Routing::Numberlist', foreign_key: :termination_src_numberlist_id, optional: true
belongs_to :lua_script, class_name: 'System::LuaScript', foreign_key: :lua_script_id, optional: true
Expand Down Expand Up @@ -277,7 +287,7 @@ def normalize_host(value)

validates :fake_180_timer, numericality: { greater_than: 0, less_than_or_equal_to: PG_MAX_SMALLINT, allow_nil: true, only_integer: true }
validates :transport_protocol, :term_proxy_transport_protocol, :orig_proxy_transport_protocol,
:network_protocol_priority, :media_encryption_mode, :sdp_c_location, :sip_schema, presence: true
:network_protocol_priority, :media_encryption_mode, :sdp_c_location, :sip_schema_id, presence: true

validates :registered_aor_mode_id, inclusion: { in: REGISTERED_AOR_MODES.keys }, allow_nil: true

Expand All @@ -294,6 +304,7 @@ def normalize_host(value)

validates :stir_shaken_mode_id, inclusion: { in: STIR_SHAKEN_MODES.keys }, allow_nil: false
validates :stir_shaken_crt_id, presence: true, if: -> { stir_shaken_mode_id == STIR_SHAKEN_MODE_INSERT }
validates :sip_schema_id, inclusion: { in: SIP_SCHEMAS.keys }, allow_nil: false

validate :vendor_owners_the_gateway_group
validate :vendor_can_be_changed
Expand Down Expand Up @@ -398,6 +409,10 @@ def stir_shaken_mode_name
STIR_SHAKEN_MODES[stir_shaken_mode_id]
end

def sip_schema_name
SIP_SCHEMAS[sip_schema_id]
end

def use_registered_aor?
registered_aor_mode_id > 0
end
Expand Down
6 changes: 6 additions & 0 deletions app/models/importing/gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ class Importing::Gateway < Importing::Base
priority
weight
pop_id
sip_schema_id
host port
origination_capacity
termination_capacity
Expand Down Expand Up @@ -243,8 +244,13 @@ def registered_aor_mode_display_name
registered_aor_mode_id.nil? ? 'unknown' : Gateway::REGISTERED_AOR_MODES[registered_aor_mode_id]
end

def sip_schema_display_name
sip_schema_id.nil? ? 'unknown' : Gateway::SIP_SCHEMAS[sip_schema_id]
end

def self.after_import_hook
resolve_integer_constant('registered_aor_mode_id', 'registered_aor_mode_name', Gateway::REGISTERED_AOR_MODES)
resolve_integer_constant('sip_schema_id', 'sip_schema_name', Gateway::SIP_SCHEMAS)
super
end
end
19 changes: 0 additions & 19 deletions app/models/system/sip_schema.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class Api::Rest::Admin::Equipment::RegistrationResource < ::BaseResource
:proxy,
:retry_delay,
:sip_interface_name,
:username
:username,
:sip_schema_id

has_one :transport_protocol, class_name: 'TransportProtocol'
has_one :sip_schema, class_name: 'SipSchema'
has_one :proxy_transport_protocol, class_name: 'TransportProtocol'
has_one :pop, class_name: 'Pop'
has_one :node, class_name: 'Node'
Expand Down
Loading

0 comments on commit f9f9b63

Please sign in to comment.