Skip to content

Commit

Permalink
admin api: fix cdr resource filters (#1618)
Browse files Browse the repository at this point in the history
* admin api: fix cdr resource filters
* admin api: more always_include_linkage_data: true
  • Loading branch information
dmitry-sinina authored Nov 14, 2024
1 parent 849df7e commit 4ad44ee
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 94 deletions.
6 changes: 3 additions & 3 deletions app/resources/api/rest/admin/account_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class Api::Rest::Admin::AccountResource < BaseResource
:origination_capacity, :termination_capacity, :total_capacity,
:send_invoices_to, :invoice_period

has_one :contractor
has_one :timezone, class_name: 'System::Timezone'
has_one :invoice_template, class_name: 'Billing::InvoiceTemplate'
has_one :contractor, always_include_linkage_data: true
has_one :timezone, class_name: 'System::Timezone', always_include_linkage_data: true
has_one :invoice_template, class_name: 'Billing::InvoiceTemplate', always_include_linkage_data: true

filter :name

Expand Down
9 changes: 3 additions & 6 deletions app/resources/api/rest/admin/cdr/auth_log_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ def self.default_sort
:origination_ip, :origination_port, :origination_proto_id, :transport_proto_id,
:transport_remote_ip, :transport_remote_port,
:transport_local_ip, :transport_local_port,
:pop_id,
:node_id,
:gateway_id,
:username, :realm,
:request_method,
:ruri,
Expand All @@ -38,9 +35,9 @@ def self.default_sort
:x_yeti_auth,
:diversion, :pai, :ppi, :privacy, :rpid, :rpid_privacy

has_one :gateway, class_name: 'Gateway', force_routed: true
has_one :pop, class_name: 'Pop', force_routed: true
has_one :node, class_name: 'Node', force_routed: true
has_one :gateway, class_name: 'Gateway', force_routed: true, always_include_linkage_data: true
has_one :pop, class_name: 'Pop', force_routed: true, always_include_linkage_data: true
has_one :node, class_name: 'Node', force_routed: true, always_include_linkage_data: true
has_one :origination_protocol, class_name: 'TransportProtocol', foreign_key: :origination_proto_id, force_routed: true
has_one :transport_protocol, class_name: 'TransportProtocol', foreign_key: :transport_proto_id, force_routed: true

Expand Down
44 changes: 18 additions & 26 deletions app/resources/api/rest/admin/cdr/cdr_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def self.updatable_fields(_context)
:is_last_cdr,
:lega_disconnect_code,
:lega_disconnect_reason,
:node_id,
:src_name_in,
:src_name_out,
:diversion_in,
Expand All @@ -74,10 +73,6 @@ def self.updatable_fields(_context)
:auth_orig_ip,
:auth_orig_port,
:global_tag,
:src_network_id,
:src_country_id,
:dst_country_id,
:dst_network_id,
:src_prefix_routing,
:dst_prefix_routing,
:routing_delay,
Expand Down Expand Up @@ -136,6 +131,7 @@ def self.updatable_fields(_context)
has_one :rateplan, class_name: 'Rateplan', force_routed: true, always_include_linkage_data: true
has_one :dialpeer, force_routed: true, always_include_linkage_data: true
has_one :pop, force_routed: true, always_include_linkage_data: true
has_one :node, force_routed: true, always_include_linkage_data: true
has_one :routing_group, class_name: 'RoutingGroup', force_routed: true, always_include_linkage_data: true
has_one :routing_plan, class_name: 'RoutingPlan', force_routed: true, always_include_linkage_data: true
has_one :destination, class_name: 'Destination', force_routed: true, always_include_linkage_data: true
Expand Down Expand Up @@ -235,22 +231,23 @@ def self.updatable_fields(_context)
}

ransack_filter :rateplan_id, type: :foreign_key
ransack_filter :dialpeer, type: :foreign_key
ransack_filter :pop, type: :foreign_key
ransack_filter :routing_group, type: :foreign_key
ransack_filter :routing_plan, type: :foreign_key
ransack_filter :destination, type: :foreign_key
ransack_filter :customer_auth, type: :foreign_key
ransack_filter :vendor, type: :foreign_key
ransack_filter :customer, type: :foreign_key
ransack_filter :customer_acc, type: :foreign_key
ransack_filter :vendor_acc, type: :foreign_key
ransack_filter :orig_gw, type: :foreign_key
ransack_filter :term_gw, type: :foreign_key
ransack_filter :dst_country, type: :foreign_key
ransack_filter :dst_network, type: :foreign_key
ransack_filter :src_country, type: :foreign_key
ransack_filter :src_network, type: :foreign_key
ransack_filter :dialpeer_id, type: :foreign_key
ransack_filter :pop_id, type: :foreign_key
ransack_filter :node_id, type: :foreign_key
ransack_filter :routing_group_id, type: :foreign_key
ransack_filter :routing_plan_id, type: :foreign_key
ransack_filter :destination_id, type: :foreign_key
ransack_filter :customer_auth_id, type: :foreign_key
ransack_filter :vendor_id, type: :foreign_key
ransack_filter :customer_id, type: :foreign_key
ransack_filter :customer_acc_id, type: :foreign_key
ransack_filter :vendor_acc_id, type: :foreign_key
ransack_filter :orig_gw_id, type: :foreign_key
ransack_filter :term_gw_id, type: :foreign_key
ransack_filter :dst_country_id, type: :foreign_key
ransack_filter :dst_network_id, type: :foreign_key
ransack_filter :src_country_id, type: :foreign_key
ransack_filter :src_network_id, type: :foreign_key

ransack_filter :id, type: :number
ransack_filter :time_start, type: :datetime
Expand Down Expand Up @@ -295,7 +292,6 @@ def self.updatable_fields(_context)
ransack_filter :is_last_cdr, type: :boolean
ransack_filter :lega_disconnect_code, type: :number
ransack_filter :lega_disconnect_reason, type: :string
ransack_filter :node_id, type: :number
ransack_filter :src_name_in, type: :string
ransack_filter :src_name_out, type: :string
ransack_filter :diversion_in, type: :string
Expand All @@ -306,10 +302,6 @@ def self.updatable_fields(_context)
ransack_filter :auth_orig_ip, type: :inet
ransack_filter :auth_orig_port, type: :number
ransack_filter :global_tag, type: :string
ransack_filter :src_country_id, type: :number
ransack_filter :src_network_id, type: :number
ransack_filter :dst_country_id, type: :number
ransack_filter :dst_network_id, type: :number
ransack_filter :src_prefix_routing, type: :string
ransack_filter :dst_prefix_routing, type: :string
ransack_filter :routing_delay, type: :number
Expand Down
2 changes: 1 addition & 1 deletion app/resources/api/rest/admin/contact_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Api::Rest::Admin::ContactResource < ::BaseResource

paginator :paged

has_one :contractor
has_one :contractor, always_include_linkage_data: true

ransack_filter :email, type: :string
ransack_filter :notes, type: :string
Expand Down
2 changes: 1 addition & 1 deletion app/resources/api/rest/admin/contractor_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Api::Rest::Admin::ContractorResource < BaseResource

paginator :paged

has_one :smtp_connection, class_name: 'System::SmtpConnection'
has_one :smtp_connection, class_name: 'System::SmtpConnection', always_include_linkage_data: true

filter :name

Expand Down
26 changes: 13 additions & 13 deletions app/resources/api/rest/admin/customers_auth_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ class Api::Rest::Admin::CustomersAuthResource < BaseResource

paginator :paged

has_one :customer
has_one :rateplan, class_name: 'Routing::Rateplan'
has_one :routing_plan, class_name: 'RoutingPlan'
has_one :gateway
has_one :account
has_one :diversion_policy
has_one :pop
has_one :dst_numberlist, class_name: 'Routing::Numberlist'
has_one :src_numberlist, class_name: 'Routing::Numberlist'
has_one :tag_action, class_name: 'Routing::TagAction'
has_one :radius_auth_profile, class_name: 'Equipment::Radius::AuthProfile'
has_one :radius_accounting_profile, class_name: 'Equipment::Radius::AccountingProfile'
has_one :transport_protocol, class_name: 'Equipment::TransportProtocol'
has_one :customer, always_include_linkage_data: true
has_one :rateplan, class_name: 'Routing::Rateplan', always_include_linkage_data: true
has_one :routing_plan, class_name: 'RoutingPlan', always_include_linkage_data: true
has_one :gateway, always_include_linkage_data: true
has_one :account, always_include_linkage_data: true
has_one :diversion_policy, always_include_linkage_data: true
has_one :pop, always_include_linkage_data: true
has_one :dst_numberlist, class_name: 'Routing::Numberlist', always_include_linkage_data: true
has_one :src_numberlist, class_name: 'Routing::Numberlist', always_include_linkage_data: true
has_one :tag_action, class_name: 'Routing::TagAction', always_include_linkage_data: true
has_one :radius_auth_profile, class_name: 'Equipment::Radius::AuthProfile', always_include_linkage_data: true
has_one :radius_accounting_profile, class_name: 'Equipment::Radius::AccountingProfile', always_include_linkage_data: true
has_one :transport_protocol, class_name: 'Equipment::TransportProtocol', always_include_linkage_data: true

filter :name

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Api::Rest::Admin::DialpeerNextRateResource < BaseResource

paginator :paged

has_one :dialpeer
has_one :dialpeer, always_include_linkage_data: true

filter :external_id

Expand Down
14 changes: 7 additions & 7 deletions app/resources/api/rest/admin/dialpeer_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class Api::Rest::Admin::DialpeerResource < BaseResource

paginator :paged

has_one :gateway
has_one :gateway_group
has_one :routing_group, class_name: 'Routing::RoutingGroup'
has_one :vendor, class_name: 'Contractor'
has_one :account
has_one :routing_tag_mode, class_name: 'Routing::RoutingTagMode'
has_one :routeset_discriminator, class_name: 'Routing::RoutesetDiscriminator'
has_one :gateway, always_include_linkage_data: true
has_one :gateway_group, always_include_linkage_data: true
has_one :routing_group, class_name: 'Routing::RoutingGroup', always_include_linkage_data: true
has_one :vendor, class_name: 'Contractor', always_include_linkage_data: true
has_one :account, always_include_linkage_data: true
has_one :routing_tag_mode, class_name: 'Routing::RoutingTagMode', always_include_linkage_data: true
has_one :routeset_discriminator, class_name: 'Routing::RoutesetDiscriminator', always_include_linkage_data: true

has_many :dialpeer_next_rates

Expand Down
2 changes: 1 addition & 1 deletion app/resources/api/rest/admin/gateway_group_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Api::Rest::Admin::GatewayGroupResource < BaseResource

paginator :paged

has_one :vendor, class_name: 'Contractor'
has_one :vendor, class_name: 'Contractor', always_include_linkage_data: true

filter :name

Expand Down
44 changes: 22 additions & 22 deletions app/resources/api/rest/admin/gateway_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,28 @@ class Api::Rest::Admin::GatewayResource < ::BaseResource

paginator :paged

has_one :contractor
has_one :session_refresh_method
has_one :sdp_alines_filter_type, class_name: 'FilterType'
has_one :term_disconnect_policy, class_name: 'DisconnectPolicy'
has_one :orig_disconnect_policy, class_name: 'DisconnectPolicy'
has_one :gateway_group
has_one :diversion_send_mode, class_name: 'Equipment::GatewayDiversionSendMode'
has_one :pop
has_one :codec_group
has_one :sdp_c_location, class_name: 'SdpCLocation'
has_one :sensor, class_name: 'System::Sensor'
has_one :sensor_level, class_name: 'System::SensorLevel'
has_one :dtmf_receive_mode, class_name: 'System::DtmfReceiveMode'
has_one :dtmf_send_mode, class_name: 'System::DtmfSendMode'
has_one :transport_protocol, class_name: 'Equipment::TransportProtocol'
has_one :term_proxy_transport_protocol, class_name: 'Equipment::TransportProtocol'
has_one :orig_proxy_transport_protocol, class_name: 'Equipment::TransportProtocol'
has_one :rel100_mode, class_name: 'Equipment::GatewayRel100Mode'
has_one :rx_inband_dtmf_filtering_mode, class_name: 'Equipment::GatewayInbandDtmfFilteringMode'
has_one :tx_inband_dtmf_filtering_mode, class_name: 'Equipment::GatewayInbandDtmfFilteringMode'
has_one :network_protocol_priority, class_name: 'Equipment::GatewayNetworkProtocolPriority'
has_one :media_encryption_mode, class_name: 'Equipment::GatewayMediaEncryptionMode'
has_one :contractor, always_include_linkage_data: true
has_one :session_refresh_method, always_include_linkage_data: true
has_one :sdp_alines_filter_type, class_name: 'FilterType', always_include_linkage_data: true
has_one :term_disconnect_policy, class_name: 'DisconnectPolicy', always_include_linkage_data: true
has_one :orig_disconnect_policy, class_name: 'DisconnectPolicy', always_include_linkage_data: true
has_one :gateway_group, always_include_linkage_data: true
has_one :diversion_send_mode, class_name: 'Equipment::GatewayDiversionSendMode', always_include_linkage_data: true
has_one :pop, always_include_linkage_data: true
has_one :codec_group, always_include_linkage_data: true
has_one :sdp_c_location, class_name: 'SdpCLocation', always_include_linkage_data: true
has_one :sensor, class_name: 'System::Sensor', always_include_linkage_data: true
has_one :sensor_level, class_name: 'System::SensorLevel', always_include_linkage_data: true
has_one :dtmf_receive_mode, class_name: 'System::DtmfReceiveMode', always_include_linkage_data: true
has_one :dtmf_send_mode, class_name: 'System::DtmfSendMode', always_include_linkage_data: true
has_one :transport_protocol, class_name: 'Equipment::TransportProtocol', always_include_linkage_data: true
has_one :term_proxy_transport_protocol, class_name: 'Equipment::TransportProtocol', always_include_linkage_data: true
has_one :orig_proxy_transport_protocol, class_name: 'Equipment::TransportProtocol', always_include_linkage_data: true
has_one :rel100_mode, class_name: 'Equipment::GatewayRel100Mode', always_include_linkage_data: true
has_one :rx_inband_dtmf_filtering_mode, class_name: 'Equipment::GatewayInbandDtmfFilteringMode', always_include_linkage_data: true
has_one :tx_inband_dtmf_filtering_mode, class_name: 'Equipment::GatewayInbandDtmfFilteringMode', always_include_linkage_data: true
has_one :network_protocol_priority, class_name: 'Equipment::GatewayNetworkProtocolPriority', always_include_linkage_data: true
has_one :media_encryption_mode, class_name: 'Equipment::GatewayMediaEncryptionMode', always_include_linkage_data: true

filter :name # DEPRECATED

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,6 @@
'transport-local-ip' => auth_log.transport_local_ip,
'transport-local-port' => auth_log.transport_local_port,

'pop-id' => auth_log.pop_id,
'node-id' => auth_log.node_id,
'gateway-id' => auth_log.gateway_id,
'username' => auth_log.username,
'realm' => auth_log.realm,
'request-method' => auth_log.request_method,
Expand Down
15 changes: 5 additions & 10 deletions spec/controllers/api/rest/admin/cdr/cdrs_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,8 @@
let(:trait) { :with_id_and_uuid }
let(:json_api_request_query) { nil }

# TODO add tests for filters by foreign keys

it_behaves_like :jsonapi_filters_by_datetime_field, :time_start
it_behaves_like :jsonapi_filters_by_number_field, :destination_next_rate
it_behaves_like :jsonapi_filters_by_number_field, :destination_fee
Expand Down Expand Up @@ -487,7 +489,6 @@
it_behaves_like :jsonapi_filters_by_boolean_field, :is_last_cdr
it_behaves_like :jsonapi_filters_by_number_field, :lega_disconnect_code
it_behaves_like :jsonapi_filters_by_string_field, :lega_disconnect_reason
it_behaves_like :jsonapi_filters_by_number_field, :node_id
it_behaves_like :jsonapi_filters_by_string_field, :src_name_in
it_behaves_like :jsonapi_filters_by_string_field, :src_name_out
it_behaves_like :jsonapi_filters_by_string_field, :diversion_in
Expand All @@ -498,10 +499,6 @@
it_behaves_like :jsonapi_filters_by_inet_field, :auth_orig_ip
it_behaves_like :jsonapi_filters_by_number_field, :auth_orig_port
it_behaves_like :jsonapi_filters_by_string_field, :global_tag
it_behaves_like :jsonapi_filters_by_number_field, :src_country_id
it_behaves_like :jsonapi_filters_by_number_field, :src_network_id
it_behaves_like :jsonapi_filters_by_number_field, :dst_country_id
it_behaves_like :jsonapi_filters_by_number_field, :dst_network_id
it_behaves_like :jsonapi_filters_by_string_field, :src_prefix_routing
it_behaves_like :jsonapi_filters_by_string_field, :dst_prefix_routing
it_behaves_like :jsonapi_filters_by_number_field, :routing_delay
Expand Down Expand Up @@ -623,7 +620,6 @@
'is-last-cdr' => cdr.is_last_cdr,
'lega-disconnect-code' => cdr.lega_disconnect_code,
'lega-disconnect-reason' => cdr.lega_disconnect_reason,
'node-id' => cdr.node_id,
'src-name-in' => cdr.src_name_in,
'src-name-out' => cdr.src_name_out,
'diversion-in' => cdr.diversion_in,
Expand All @@ -634,10 +630,6 @@
'auth-orig-ip' => cdr.auth_orig_ip,
'auth-orig-port' => cdr.auth_orig_port,
'global-tag' => cdr.global_tag,
'src-country-id' => cdr.src_country_id,
'src-network-id' => cdr.src_network_id,
'dst-country-id' => cdr.dst_country_id,
'dst-network-id' => cdr.dst_network_id,
'src-prefix-routing' => cdr.src_prefix_routing,
'dst-prefix-routing' => cdr.dst_prefix_routing,
'routing-delay' => cdr.routing_delay,
Expand Down Expand Up @@ -703,6 +695,9 @@
'pop' => hash_including(
'data' => nil
),
'node' => hash_including(
'data' => nil
),
'routing-group' => hash_including(
'data' => nil
),
Expand Down

0 comments on commit 4ad44ee

Please sign in to comment.