Skip to content

Commit

Permalink
Merge pull request #349 from dmitry-sinina/fixes1.7
Browse files Browse the repository at this point in the history
Fixes1.7
  • Loading branch information
dmitry-sinina authored Aug 26, 2018
2 parents eff8205 + 1df9418 commit 6b2fc6c
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 25 deletions.
10 changes: 2 additions & 8 deletions app/admin/system/network_prefix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,8 @@ def scoped_collection
# }
filter :id
filter :prefix
filter :country, input_html: {
class: 'chosen',
onchange: remote_chosen_request(:get, 'system_countries/get_networks', {country_id: "$(this).val()"}, :q_network_id)
}

filter :network, input_html: {class: 'chosen'}, collection: -> {
System::Country.find(assigns["search"].country_id_eq).networks rescue []
}
filter :country, input_html: {class: 'chosen'}
filter :network, input_html: {class: 'chosen'}
filter :number_contains

index do
Expand Down
2 changes: 1 addition & 1 deletion app/models/cdr/auth_log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# origination_proto_id :integer
# username :string
# realm :string
# method :string
# request_method :string
# ruri :string
# from_uri :string
# to_uri :string
Expand Down
2 changes: 1 addition & 1 deletion app/models/system/api_access.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def accounts
# Auth

def authenticate_ip(remote_ip)
allowed_ips.any? { |ip| ip.include?(remote_ip) }
allowed_ips.any? { |ip| IPAddr.new(ip).include?(remote_ip) }
end

def self.from_token_request(request)
Expand Down
12 changes: 12 additions & 0 deletions app/resources/api/rest/admin/account_resource.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Api::Rest::Admin::AccountResource < ::BaseResource
attributes :name, :min_balance, :max_balance, :external_id,
:balance_low_threshold, :balance_high_threshold, :send_balance_notifications_to,
:origination_capacity, :termination_capacity, :send_invoices_to

has_one :contractor
Expand All @@ -12,11 +13,22 @@ class Api::Rest::Admin::AccountResource < ::BaseResource

filter :name

def send_invoices_to=(value)
_model.send_invoices_to = Array.wrap(value)
end

def send_balance_notifications_to=(value)
_model.send_balance_notifications_to = Array.wrap(value)
end

def self.updatable_fields(_context)
[
:name,
:min_balance,
:max_balance,
:balance_low_threshold,
:balance_high_threshold,
:send_balance_notifications_to,
:vat,
:origination_capacity,
:termination_capacity,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ImportingRemoveNotNullConstraint < ActiveRecord::Migration
class ImportingRemoveNotNullConstraint < ActiveRecord::Migration[5.0]
def up
execute %q{
ALTER TABLE data_import.import_customers_auth
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20180405132225_add_rows_count_to_cdr_exports.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddRowsCountToCdrExports < ActiveRecord::Migration
class AddRowsCountToCdrExports < ActiveRecord::Migration[5.0]
def change
add_column :cdr_exports, :rows_count, :integer
end
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20180416121932_reject_calls_at_customer_auth.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class RejectCallsAtCustomerAuth < ActiveRecord::Migration
class RejectCallsAtCustomerAuth < ActiveRecord::Migration[5.0]

def up
execute %q{
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20180418101559_add_src_dst_prefix_to_rtdr.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddSrcDstPrefixToRtdr < ActiveRecord::Migration
class AddSrcDstPrefixToRtdr < ActiveRecord::Migration[5.0]
def change
add_column 'class4.routing_tag_detection_rules', :src_prefix, :string, null: false, default: ''
add_column 'class4.routing_tag_detection_rules', :dst_prefix, :string, null: false, default: ''
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20180425203717_routing_tag_and_operation.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class RoutingTagAndOperation < ActiveRecord::Migration
class RoutingTagAndOperation < ActiveRecord::Migration[5.0]
def up
execute %q{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateImportNumberlistItems < ActiveRecord::Migration
class CreateImportNumberlistItems < ActiveRecord::Migration[5.0]
def change
create_table 'data_import.import_numberlists' do |t|
t.integer :o_id, limit: 2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CdrAmountRounding < ActiveRecord::Migration
class CdrAmountRounding < ActiveRecord::Migration[5.0]
def up
execute %q{
create table sys.amount_round_modes(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CustomerPriceNoVatFixNull < ActiveRecord::Migration
class CustomerPriceNoVatFixNull < ActiveRecord::Migration[5.0]
def up
execute %q{
CREATE or replace FUNCTION billing.bill_cdr(i_cdr cdr.cdr) RETURNS cdr.cdr
Expand Down
6 changes: 5 additions & 1 deletion spec/acceptance/rest/admin/api/accounts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
let(:type) { 'accounts' }

required_params = %i(name min-balance max-balance)
optional_params = %i(origination-capacity termination-capacity send-invoices-to, external-id)
optional_params = %i(origination-capacity termination-capacity send-invoices-to external-id balance-low-threshold balance-high-threshold send-balance-notifications-to)

required_relationships = %i(contractor timezone)
optional_relationships = %i(
Expand Down Expand Up @@ -43,6 +43,10 @@
let(:name) { 'name' }
let(:'min-balance') { 1 }
let(:'max-balance') { 10 }
let(:'balance-low-threshold') { 90 }
let(:'balance-high-threshold') { 95 }
let(:'send-balance-notifications-to') { Billing::Contact.collection.map(&:id) }

let(:timezone) { wrap_relationship(:'timezones', 1) }
let(:contractor) { wrap_relationship(:contractors, create(:contractor, vendor: true).id) }

Expand Down
25 changes: 22 additions & 3 deletions spec/controllers/api/rest/admin/accounts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@

it { expect(response.status).to eq(200) }
it { expect(response_data['id']).to eq(account.id.to_s) }
it 'has balance threshold attributes' do
expect(response_data['attributes']).to include(
'balance-low-threshold',
'balance-high-threshold',
'send-balance-notifications-to')
end
end

context 'when account does not exist' do
Expand All @@ -56,10 +62,15 @@

context 'when attributes are valid' do
let(:attributes) do
{ name: 'name',
{
name: 'name',
'min-balance': 1,
'external-id': 100,
'max-balance': 10 }
'max-balance': 10,
'balance-low-threshold': 90,
'balance-high-threshold': 95,
'send-balance-notifications-to': Array.wrap(Billing::Contact.collection.first.id)
}
end

let(:relationships) do
Expand Down Expand Up @@ -92,7 +103,15 @@
end

context 'when attributes are valid' do
let(:attributes) { { name: 'name' } }
let(:attributes) do
{
name: 'name',
'balance-low-threshold': 90,
'balance-high-threshold': 95,
'send-balance-notifications-to': Billing::Contact.collection.first.id,
'send-invoices-to': Billing::Contact.collection.first.id
}
end

it { expect(response.status).to eq(200) }
it { expect(account.reload.name).to eq('name') }
Expand Down
19 changes: 16 additions & 3 deletions spec/controllers/api/rest/customer/v1/auth_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
before { request.remote_addr = remote_ip }

describe 'POST create' do
let(:attributes) { { login: user.login, password: user.password } }

before { post :create, params: { auth: attributes } }

context 'when attributes are valid' do
let(:attributes) { { login: user.login, password: user.password } }

it { expect(response.status).to eq(201) }
it { expect(response_body).to include(:jwt) }
end
Expand All @@ -37,11 +37,24 @@
end

context 'when IP is not allowed' do
let(:attributes) { { login: user.login, password: user.password } }
let(:remote_ip) { '127.0.0.2' }

it { expect(response).to return_404_with_empty_body }
end

context 'Issue#338: 0.0.0.0/0 allows requests from any IP' do
let!(:user) { create :api_access, allowed_ips: ['0.0.0.0/0'] }
let(:remote_ip) { '104.81.225.117' }

it { expect(response.status).to eq(201) }
end

context 'Issue#338: request from IP not matches the mask' do
let!(:user) { create :api_access, allowed_ips: ['192.168.0.0/24'] }
let(:remote_ip) { '192.169.1.1' }

it { expect(response).to return_404_with_empty_body }
end
end

end

0 comments on commit 6b2fc6c

Please sign in to comment.