Skip to content

Commit

Permalink
add routing_tag_ids chosen select to batch form (#950)
Browse files Browse the repository at this point in the history
* add routing_tag_ids chosen select to batch form

* add option to remove all tags

* fix vulnerability rexml CVE-2021-28965


Co-authored-by: Denis Talakevich <[email protected]>
  • Loading branch information
BigG1947 and senid231 authored Apr 30, 2021
1 parent a7ad52a commit 4fd7fd3
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/assets/javascripts/active_admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
//= require import_apply_unique_fields
//= require ajax-chosen
//= require credential_generator
//= require vendor/jquery.serialize-object.min.js
//= require build_tags


$(document).ready(function () {
Expand Down
38 changes: 38 additions & 0 deletions app/assets/javascripts/build_tags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Build chosen field for routing tag ids select on update batch action form

$(document).on('mass_update_modal_dialog:after_open', function (event, form) {
var tagsChosen = $(form).find("select[name='routing_tag_ids']").prop({
'name': 'routing_tag_ids[]',
'class': 'chosen',
'id': 'batch_update_routing_tag_ids',
'value': '', // reset default value
'multiple': true
});
var tagsCheckbox = $('#mass_update_dialog_routing_tag_ids');

if (tagsChosen.length === 0) {
return;
}

var hidden = $('<input>', {
'type': 'hidden',
'id': 'hidden_routing_tag_ids',
'name': 'routing_tag_ids',
'value': '',
'disabled': true
}).appendTo(form);

tagsChosen.chosen({no_results_text: "No results matched", width: '240px', search_contains: true, allow_single_deselect: true});

tagsChosen.change(function() {
tagsChosen.val().length === 0 ? hidden.prop('disabled', false) : hidden.prop('disabled', true);
});

tagsCheckbox.change(function () {
if (tagsCheckbox.is(':checked') && tagsChosen.val().length === 0) {
hidden.prop('disabled', false);
} else {
hidden.prop('disabled', true);
}
});
});
9 changes: 9 additions & 0 deletions app/assets/javascripts/vendor/jquery.serialize-object.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/forms/batch_update_form/destination.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class BatchUpdateForm::Destination < BatchUpdateForm::Base
attribute :asr_limit
attribute :acd_limit
attribute :short_calls_limit
attribute :routing_tag_ids, type: :foreign_key, class_name: 'Routing::RoutingTag'

# presence validations
validates :dst_number_min_length, presence: true, if: :dst_number_min_length_changed?
Expand Down
1 change: 1 addition & 0 deletions app/forms/batch_update_form/dialpeer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class BatchUpdateForm::Dialpeer < BatchUpdateForm::Base
attribute :src_rewrite_result
attribute :dst_rewrite_rule
attribute :dst_rewrite_result
attribute :routing_tag_ids, type: :foreign_key, class_name: 'Routing::RoutingTag'

# presence
validates :dst_number_min_length, presence: true, if: :dst_number_min_length_changed?
Expand Down
25 changes: 24 additions & 1 deletion spec/features/routing/destinations/batch_update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
let!(:routing_tag_mode) { Routing::RoutingTagMode.take! }
let!(:rate_policy) { Routing::DestinationRatePolicy.take! }
let!(:profit_control_mode) { Routing::RateProfitControlMode.take! || FactoryBot.create(:rate_profit_control_mode) }
let!(:routing_tags) { create_list(:routing_tag, 5) }

before do
visit destinations_path
Expand Down Expand Up @@ -44,7 +45,8 @@
dp_margin_percent: '2',
asr_limit: '0.9',
acd_limit: '1',
short_calls_limit: '4'
short_calls_limit: '4',
routing_tag_ids: routing_tags.map { |tag| tag.id.to_s }
}
end

Expand Down Expand Up @@ -163,6 +165,16 @@
check :Short_calls_limit
fill_in :short_calls_limit, with: assign_params[:short_calls_limit]
end

if assign_params.key? :routing_tag_ids
check :Routing_tag_ids
page.scroll_to find_button('OK')
if assign_params[:routing_tag_ids].present?
assign_params[:routing_tag_ids].each do |tag_id|
fill_in_chosen 'routing_tag_ids[]', with: Routing::RoutingTag.find(tag_id).name, multiple: true
end
end
end
end

context 'should check validates' do
Expand All @@ -183,5 +195,16 @@
end.to have_enqueued_job(AsyncBatchUpdateJob).on_queue('batch_actions').with 'Routing::Destination', be_present, assign_params, be_present
end
end

context 'when routing tag ids field is empty' do
let(:assign_params) { { routing_tag_ids: '' } }

it 'should have success message' do
expect do
subject
expect(page).to have_selector '.flash', text: success_message
end.to have_enqueued_job(AsyncBatchUpdateJob).on_queue('batch_actions').with 'Routing::Destination', be_present, assign_params, be_present
end
end
end
end
21 changes: 20 additions & 1 deletion spec/features/routing/dialpeers/batch_update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
let!(:routing_tag_mode) { Routing::RoutingTagMode.last! }
let!(:routeset_discriminator) { Routing::RoutesetDiscriminator.last! }
let(:pg_max_smallint) { Yeti::ActiveRecord::PG_MAX_SMALLINT }
let!(:routing_tags) { create_list(:routing_tag, 5) }

before do
visit dialpeers_path
Expand Down Expand Up @@ -58,7 +59,8 @@
src_rewrite_rule: '12',
src_rewrite_result: '12',
dst_rewrite_rule: '12',
dst_rewrite_result: '12'
dst_rewrite_result: '12',
routing_tag_ids: routing_tags.map { |tag| tag.id.to_s }
}
end
let(:fill_batch_form) do
Expand Down Expand Up @@ -221,6 +223,12 @@
check :Dst_rewrite_result
fill_in :dst_rewrite_result, with: assign_params[:dst_rewrite_result]
end

if assign_params.key? :routing_tag_ids
check :Routing_tag_ids
routing_tags.select { |tag| assign_params[:routing_tag_ids].include? tag.id.to_s }
.each { |tag| fill_in_chosen 'routing_tag_ids[]', with: tag.name, multiple: true, visible: false }
end
end

subject do
Expand All @@ -246,5 +254,16 @@
end.to have_enqueued_job(AsyncBatchUpdateJob).on_queue('batch_actions').with 'Dialpeer', be_present, assign_params, be_present
end
end

context 'when routing tag ids field is empty' do
let(:assign_params) { { routing_tag_ids: '' } }

it 'should have success message' do
expect do
subject
expect(page).to have_selector '.flash', text: success_message
end.to have_enqueued_job(AsyncBatchUpdateJob).on_queue('batch_actions').with 'Dialpeer', be_present, assign_params, be_present
end
end
end
end
32 changes: 32 additions & 0 deletions spec/jobs/async_batch_update_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,38 @@
end
end
end

context 'with routing tags changes' do
let!(:routing_tag_ids) { create_list(:routing_tag, 3).map { |tag| tag.id.to_s } }
let(:changes) { { routing_tag_ids: routing_tag_ids } }

context 'no filter/selection' do
let(:sql_query) { Routing::Destination.all.to_sql }

it { expect { subject }.to change(Routing::Destination.where(routing_tag_ids: routing_tag_ids), :count).by(3) }
end

context 'records selected' do
let(:sql_query) { Routing::Destination.where(id: [1, 3]).to_sql }

it { expect { subject }.to change(Routing::Destination.where(routing_tag_ids: routing_tag_ids), :count).by(2) }
it { expect { subject }.to change(Routing::Destination.where(id: 2, routing_tag_ids: []), :count).by(0) }
end

context 'records filtered' do
let(:sql_query) { Routing::Destination.where('initial_rate < ?', 0.5).to_sql }

it { expect { subject }.to change(Routing::Destination.where(routing_tag_ids: routing_tag_ids), :count).by(1) }
it { expect { subject }.to change(Routing::Destination.where(id: 1, routing_tag_ids: routing_tag_ids), :count).by(1) }
end

context 'records filtered and ordering' do
let(:sql_query) { Routing::Destination.where('initial_rate < ?', 0.5).order(:id).to_sql }

it { expect { subject }.to change(Routing::Destination.where(routing_tag_ids: routing_tag_ids), :count).by(1) }
it { expect { subject }.to change(Routing::Destination.where(id: 1, routing_tag_ids: routing_tag_ids), :count).by(1) }
end
end
end
end
end

0 comments on commit 4fd7fd3

Please sign in to comment.