Skip to content

Commit

Permalink
use status tags in customer auth index table (#1669)
Browse files Browse the repository at this point in the history
* use status tags in customer auth index table
  • Loading branch information
dmitry-sinina authored Jan 2, 2025
1 parent 8373801 commit b12932c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
18 changes: 4 additions & 14 deletions app/admin/routing/customers_auths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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|
Expand All @@ -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|
Expand Down Expand Up @@ -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' }

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
20 changes: 16 additions & 4 deletions app/decorators/customers_auth_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(', ')
Expand Down
4 changes: 4 additions & 0 deletions app/models/customers_auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit b12932c

Please sign in to comment.