Skip to content

Commit

Permalink
Merge pull request #1468 from senid231/customer-v1-hide-cdr-attrs
Browse files Browse the repository at this point in the history
Customer API cdrs - hide configured attributes/relationships
  • Loading branch information
dmitry-sinina committed Apr 30, 2024
2 parents 80b5e28 + 052533c commit 1d11ff0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/resources/api/rest/customer/v1/cdr_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ def rec
_model.has_recording?
end

def fetchable_fields
fields = super
hidden_fields = YetiConfig.customer_api_cdr_hide_fields || []
fields - hidden_fields.map(&:to_sym)
end

def self.apply_allowed_accounts(records, options)
context = options[:context]
scope = records.where_customer(context[:customer_id])
Expand Down
2 changes: 2 additions & 0 deletions config/initializers/_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def self.setting_files(config_root, _env)
optional(:url_callback).maybe(:string)
optional(:url_return).maybe(:string)
end

optional(:customer_api_cdr_hide_fields).array(:string)
end
end

Expand Down
16 changes: 16 additions & 0 deletions spec/requests/api/rest/customer/v1/cdrs_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,22 @@
)
end

context 'when customer_api_cdr_hide_fields configured' do
before do
allow(YetiConfig).to receive(:customer_api_cdr_hide_fields).and_return(
%w[auth_orig_ip lega_user_agent]
)
end

it 'returns record with expected attributes' do
subject
attribute_keys = response_json[:data][:attributes].keys
expect(attribute_keys).to include(:'auth-orig-port')
expect(attribute_keys).not_to include(:'auth-orig-ip')
expect(attribute_keys).not_to include(:'lega-user-agent')
end
end

context 'with include auth-orig-transport-protocol' do
let(:json_api_request_query) { { include: 'auth-orig-transport-protocol' } }

Expand Down

0 comments on commit 1d11ff0

Please sign in to comment.