From b12932c0bf772f07a4905909dc29fc555c39c53f Mon Sep 17 00:00:00 2001 From: Dmitry Sinina Date: Thu, 2 Jan 2025 13:54:21 +0200 Subject: [PATCH] use status tags in customer auth index table (#1669) * use status tags in customer auth index table --- app/admin/routing/customers_auths.rb | 18 ++++-------------- app/decorators/customers_auth_decorator.rb | 20 ++++++++++++++++---- app/models/customers_auth.rb | 4 ++++ config/locales/en.yml | 1 + 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/app/admin/routing/customers_auths.rb b/app/admin/routing/customers_auths.rb index 1a26bbc01..e65661742 100644 --- a/app/admin/routing/customers_auths.rb +++ b/app/admin/routing/customers_auths.rb @@ -128,11 +128,8 @@ def update id_column actions column :name - column :enabled - column :reject_calls - column :ip do |c| - c.transport_protocol_id.nil? ? c.ip : "#{c.transport_protocol_name} #{c.ip}" - end + column :enabled, &:decorated_enabled + column :ip, &:decorated_ip column :pop column :src_prefix column :src_number_length do |c| @@ -145,7 +142,6 @@ def update column :uri_domain column :from_domain column :to_domain - column :x_yeti_auth column :interface column :customer, sortable: 'contractors.name' do |row| @@ -159,7 +155,6 @@ def update column :gateway, sortable: 'gateways.name' do |row| auto_link(row.gateway, row.gateway.decorated_origination_display_name) end - column :require_incoming_auth column :rateplan, sortable: 'rateplans.name' column :routing_plan, sortable: 'routing_plans.name' do |row| @@ -300,8 +295,6 @@ def update 'data-required-param': 'q[origination_contractor_id_eq]' } - f.input :require_incoming_auth - f.input :rateplan, input_html: { class: 'chosen' } f.input :routing_plan, input_html: { class: 'chosen' } @@ -330,6 +323,7 @@ def update input_html: { class: :chosen } f.input :ip, as: :array_of_strings + f.input :require_incoming_auth f.input :pop, as: :select, include_blank: 'Any', input_html: { class: 'chosen' } f.input :src_prefix, as: :array_of_strings f.input :src_number_min_length @@ -450,11 +444,6 @@ def update row :account row :check_account_balance row :gateway - row :require_incoming_auth - - # row :enable_redirect - # row :redirect_method - # row :redirect_to row :rateplan row :routing_plan do @@ -475,6 +464,7 @@ def update attributes_table_for s do row :transport_protocol, &:transport_protocol_name row :ip + row :require_incoming_auth row :pop row :src_prefix row :src_number_min_length diff --git a/app/decorators/customers_auth_decorator.rb b/app/decorators/customers_auth_decorator.rb index c75ef9c11..19eb9a865 100644 --- a/app/decorators/customers_auth_decorator.rb +++ b/app/decorators/customers_auth_decorator.rb @@ -9,10 +9,6 @@ class CustomersAuthDecorator < BillingDecorator decorates_association :account, with: AccountDecorator decorates_association :routing_plan, with: RoutingPlanDecorator - def privacy_mode_name - CustomersAuth::PRIVACY_MODES[privacy_mode_id] - end - def display_tag_action_value h.tag_action_values_badges(model.tag_action_value) end @@ -25,6 +21,22 @@ def decorated_display_name end end + def decorated_ip + h.safe_join([ + *(h.tag.span(transport_protocol_name, class: 'status_tag ok') unless transport_protocol_id.nil?), + ip, + *(h.tag.span('Require Auth', class: 'status_tag warn') if require_incoming_auth?), + *(h.tag.span('X-Yeti-Auth', class: 'status_tag blue') unless x_yeti_auth.empty?) + ], ' ') + end + + def decorated_enabled + h.safe_join([ + h.tag.span(enabled? ? 'Yes' : 'No', class: enabled? ? 'status_tag ok' : 'status_tag'), + *(h.tag.span('Reject calls', class: 'status_tag red') if reject_calls?) + ], ' ') + end + CustomersAuth::CONST::MATCH_CONDITION_ATTRIBUTES.each do |attribute_name| define_method attribute_name do model.public_send(attribute_name).map(&:strip).join(', ') diff --git a/app/models/customers_auth.rb b/app/models/customers_auth.rb index 85edf31ca..0c02780d3 100644 --- a/app/models/customers_auth.rb +++ b/app/models/customers_auth.rb @@ -394,6 +394,10 @@ def src_name_field_name SRC_NAME_FIELDS[src_name_field_id] end + def privacy_mode_name + PRIVACY_MODES[privacy_mode_id] + end + # TODO: move to decorator when ActiveAdmin fix problem # Problem is: # on "update" AA uses decorated object diff --git a/config/locales/en.yml b/config/locales/en.yml index 79ebb2488..0e2251bbe 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -98,6 +98,7 @@ en: customers_auth: check_account_balance: "Reject calls if originator hasn't enough funds" ip: 'Comma-separated list of IPs with masks' + require_incoming_auth: 'When enabled SIP digest auth procedure will be initiated' src_prefix: 'Comma-separated list of SRC number prefixes accepted by this auth record' dst_prefix: 'Comma-separated list of DST number prefixes accepted by this auth record' uri_domain: 'Comma-separated list of SIP R-URI domains accepted by this auth record'