Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/assets/javascripts/kaui/multi_functions_bar_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ $(document).ready(function() {
container.hide();

populateSavedSearchesDropdown();
$('#advanceSearchModal').modal('hide');
$('#applyAdvanceSearch').trigger('click');
});

$(document).on('hidden.bs.modal', '#advanceSearchModal', function () {
Expand Down
24 changes: 24 additions & 0 deletions app/controllers/kaui/admin_tenants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,19 @@ def new_overdue_config
options = tenant_options_for_client
options[:api_key] = @tenant.api_key
options[:api_secret] = @tenant.api_secret
@overdue_config_exists = false
begin
@overdue = Kaui::Overdue.get_overdue_json(options)
@overdue_corrupted = false
@overdue_config_exists = @overdue.overdue_states.present? && !@overdue.has_states
Comment thread
tungleduyxyz marked this conversation as resolved.
rescue KillBillClient::API::NotFound
@overdue = KillBillClient::Model::Overdue.new.tap { |o| o.overdue_states = [] }
@overdue_corrupted = false
rescue StandardError => e
Rails.logger.warn("Failed to load overdue configuration for tenant #{@tenant.id}: #{e.class}: #{e.message}")
@overdue = KillBillClient::Model::Overdue.new.tap { |o| o.overdue_states = [] }
@overdue_corrupted = true
@overdue_config_exists = true
flash.now[:warning] = 'The existing overdue configuration is corrupted and cannot be loaded. Use the XML upload below to replace it with a valid configuration.'
end
end
Expand Down Expand Up @@ -342,6 +348,24 @@ def upload_overdue_config
redirect_to admin_tenant_path(current_tenant.id, active_tab: 'OverdueShow'), notice: I18n.t('flashes.notices.overdue_uploaded_successfully')
end

def delete_overdue_config
current_tenant = safely_find_tenant_by_id(params[:id])

options = tenant_options_for_client
options[:api_key] = current_tenant.api_key
options[:api_secret] = current_tenant.api_secret

begin
Kaui::AdminTenant.delete_tenant_user_key_value('OVERDUE_CONFIG', options[:username], nil, comment, options)
rescue StandardError => e
flash[:error] = "Failed to delete overdue config: #{as_string(e)}"
redirect_to admin_tenant_new_overdue_config_path(id: current_tenant.id) and return
end

flash[:overdue_deleted] = true
redirect_to admin_tenant_path(current_tenant.id, active_tab: 'OverdueShow'), notice: I18n.t('flashes.notices.overdue_deleted_successfully')
end

def upload_invoice_template
current_tenant = safely_find_tenant_by_id(params[:id])

Expand Down
3 changes: 2 additions & 1 deletion app/controllers/kaui/engine_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def check_for_redirect_to_tenant_screen
end

def populate_account_details
@account ||= params[:account_id].present? ? Kaui::Account.find_by_id(params[:account_id], false, false, options_for_klient) : Kaui::Account.new
account_id = scalar_account_id_param
@account ||= account_id.present? ? Kaui::Account.find_by_id(account_id, false, false, options_for_klient) : Kaui::Account.new
end

def retrieve_tenants_for_current_user
Expand Down
28 changes: 26 additions & 2 deletions app/controllers/kaui/engine_controller_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def remapping_addvanced_search_fields(search_string, advanced_search_name_change
end

def paginate(searcher, data_extractor, formatter, table_default_columns = [])
search_key = (params[:search] || {})[:value].presence
advance_search_query = params[:advance_search_query].presence
search_key = normalize_search_key((params[:search] || {})[:value]).presence
advance_search_query = normalize_search_key(params[:advance_search_query]).presence

search_key = advance_search_query if advance_search_query
search_key = handle_balance_search(search_key) if search_key.present?
Expand Down Expand Up @@ -84,6 +84,30 @@ def paginate(searcher, data_extractor, formatter, table_default_columns = [])
end
end

def advanced_search_query?(search_key)
search_key.to_s.include?('_q')
end

def scalar_account_id_param
path_account_id = request.path_parameters[:account_id].presence
return path_account_id if path_account_id.present?

account_id = params[:account_id]
account_id if account_id.is_a?(String) || account_id.is_a?(Numeric)
end

def normalize_search_key(search_key)
return if search_key.blank?

if search_key.respond_to?(:to_unsafe_h)
search_key.to_unsafe_h.to_query
elsif search_key.is_a?(Hash)
search_key.to_query
else
search_key
end
end

def promise(&)
# Evaluation starts immediately
::Concurrent::Promises.future do
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/kaui/invoices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
module Kaui
class InvoicesController < Kaui::EngineController
def index
@search_query = params[:account_id]
@search_query = scalar_account_id_param
@advance_search_query = params[:q] || request.query_string
@ordering = params[:ordering] || 'desc'
@offset = params[:offset] || 0
Expand All @@ -15,7 +15,7 @@ def index
end

def download
account_id = params[:account_id]
account_id = scalar_account_id_param
start_date = params[:startDate]
end_date = params[:endDate]
all_fields_checked = params[:allFieldsChecked] == 'true'
Expand Down Expand Up @@ -60,7 +60,7 @@ def pagination

searcher = lambda do |search_key, offset, limit|
account = begin
Kaui::Account.find_by_id_or_key(search_key, false, false, cached_options_for_klient)
Kaui::Account.find_by_id_or_key(search_key, false, false, cached_options_for_klient) unless advanced_search_query?(search_key)
rescue StandardError
nil
end
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/kaui/payments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module Kaui
class PaymentsController < Kaui::EngineController
def index
@search_query = params[:q] || params[:account_id]
@search_query = params[:q] || scalar_account_id_param
@advance_search_query = params[:q] || request.query_string
@ordering = params[:ordering] || (@search_query.blank? ? 'desc' : 'asc')
@offset = params[:offset] || 0
Expand All @@ -16,7 +16,7 @@ def index
end

def download
account_id = params[:account_id]
account_id = scalar_account_id_param
start_date = params[:startDate]
end_date = params[:endDate]
all_fields_checked = params[:allFieldsChecked] == 'true'
Expand Down Expand Up @@ -104,7 +104,7 @@ def pagination
payments = Kaui::Payment.list_or_search(payment_state, offset, limit, options_for_klient)
else
account = begin
Kaui::Account.find_by_id_or_key(search_key, false, false, options_for_klient)
Kaui::Account.find_by_id_or_key(search_key, false, false, options_for_klient) unless advanced_search_query?(search_key)
rescue StandardError
nil
end
Expand Down
13 changes: 13 additions & 0 deletions app/views/kaui/admin_tenants/new_overdue_config.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@
</span>
Overdue Configuration
</h5>
<% if @overdue_config_exists && can?(:config_upload, Kaui::AdminTenant) %>
<% overdue_delete_confirmation = t('admin_tenants.delete_overdue_config_confirmation') %>
<div class="form-group d-flex justify-content-end pb-3">
<%= form_tag(kaui_engine.admin_tenant_delete_overdue_config_path(id: @tenant.id), method: :delete, class: 'd-inline', onsubmit: "return confirm('#{j(overdue_delete_confirmation)}');") do %>
Comment thread
tungleduyxyz marked this conversation as resolved.
<%= render "kaui/components/button/button", {
label: 'Delete',
variant: "d-inline-flex align-items-center gap-1",
type: "submit",
html_class: "kaui-button delete-button custom-hover"
} %>
<% end %>
</div>
<% end %>
<div class="form-group d-flex pb-3">
<label class="col-sm-1 control-label">Type</label>
<div class="toggle-segment col-sm-9">
Expand Down
6 changes: 3 additions & 3 deletions app/views/kaui/invoices/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ $(document).ready(function() {
}
});

var stateKey = 'DataTables_invoices-table_' + window.location.pathname.replace(/\//g, '_');
var stateKey = 'DataTables_invoices-table';
var state = JSON.parse(localStorage.getItem(stateKey));
if (state) {
state.start = <%= @offset %>;
Expand All @@ -64,10 +64,10 @@ $(document).ready(function() {
},
"stateSave": true,
"stateSaveCallback": function(settings, data) {
localStorage.setItem('DataTables_invoices-table', JSON.stringify(data));
localStorage.setItem(stateKey, JSON.stringify(data));
},
"stateLoadCallback": function(settings) {
return JSON.parse(localStorage.getItem('DataTables_invoices-table'));
return JSON.parse(localStorage.getItem(stateKey));
Comment thread
tungleduyxyz marked this conversation as resolved.
},
"scrollX": true,
"dom": "<'row'r>t<'row'<'col-md-6'i><'col-md-6'p>>",
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ en:
overdue_uploaded_successfully: 'Overdue config was successfully uploaded'
overdue_added_successfully: 'Overdue config was successfully added'
overdue_updated_successfully: 'Overdue config was successfully updated'
overdue_deleted_successfully: 'Overdue config was successfully deleted'
invoice_template_uploaded_successfully: 'Invoice template was successfully uploaded'
invoice_translation_uploaded_successfully: 'Invoice translation was successfully uploaded'
catalog_translation_uploaded_successfully: 'Catalog translation was successfully uploaded'
Expand Down Expand Up @@ -85,3 +86,4 @@ en:

admin_tenants:
clock_warning: "This action will affect all tenants across the system. Proceed with caution."
delete_overdue_config_confirmation: "This action is irreversible and will permanently delete the overdue configuration for this tenant. Are you sure you want to continue?"
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def nested_param
delete '/:id/delete_catalog' => 'admin_tenants#delete_catalog', :as => 'admin_tenant_delete_catalog'
get '/:id/new_plan_currency' => 'admin_tenants#new_plan_currency', :as => 'admin_tenant_new_plan_currency'
get '/:id/new_overdue_config' => 'admin_tenants#new_overdue_config', :as => 'admin_tenant_new_overdue_config'
delete '/:id' => 'admin_tenants#delete_overdue_config', :as => 'admin_tenant_delete_overdue_config'
post '/upload_catalog' => 'admin_tenants#upload_catalog', :as => 'admin_tenant_upload_catalog'
post '/display_catalog_xml' => 'admin_tenants#display_catalog_xml', :as => 'admin_tenant_display_catalog_xml'
post '/display_overdue_xml' => 'admin_tenants#display_overdue_xml', :as => 'admin_tenant_display_overdue_xml'
Expand Down
3 changes: 2 additions & 1 deletion lib/kaui/error_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ module ErrorHandler
end

def perform_redirect_after_error(error:, error_message:, redirect: true)
account_id = nested_hash_value(params.permit!.to_h, :account_id)
account_id = request.path_parameters[:account_id].presence || nested_hash_value(params.permit!.to_h, :account_id)
account_id = nil unless account_id.is_a?(String) || account_id.is_a?(Numeric)
home_path = kaui_engine.home_path
redirect_path = if redirect && account_id.present?
kaui_engine.account_path(account_id)
Expand Down
43 changes: 43 additions & 0 deletions test/functional/kaui/admin_tenants_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,49 @@ class AdminTenantsControllerTest < Kaui::FunctionalTestHelper
assert_response :success
end

test 'should upload and delete overdue config' do
tenant = create_kaui_tenant

post :upload_overdue_config, params: { id: tenant.id, overdue: fixture_file_upload("#{FIXTURES_PATH}/overdue-v1.xml") }
assert_redirected_to admin_tenant_path(tenant.id, active_tab: 'OverdueShow')
assert_equal I18n.t('flashes.notices.overdue_uploaded_successfully'), flash[:notice]

delete :delete_overdue_config, params: { id: tenant.id }
assert_redirected_to admin_tenant_path(tenant.id, active_tab: 'OverdueShow')
assert_equal I18n.t('flashes.notices.overdue_deleted_successfully'), flash[:notice]
end

test 'should delete overdue config created via modify' do
tenant = create_kaui_tenant

parameters = {
id: tenant.id,
kill_bill_client_model_overdue: {
states: { '0' => {
name: 'Overdue_test',
external_message: 'Overdue_Test_Ya',
is_block_changes: true,
subscription_cancellation_policy: 'NONE',
condition: {
time_since_earliest_unpaid_invoice_equals_or_exceeds: 1,
control_tag_inclusion: 'NONE',
control_tag_exclusion: 'NONE',
number_of_unpaid_invoices_equals_or_exceeds: 0,
total_unpaid_invoice_balance_equals_or_exceeds: 0
}
} }
}
}

post :modify_overdue_config, params: parameters
assert_redirected_to admin_tenant_path(tenant.id, active_tab: 'OverdueShow')
assert_equal I18n.t('flashes.notices.overdue_added_successfully'), flash[:notice].to_s.strip

delete :delete_overdue_config, params: { id: tenant.id }
assert_redirected_to admin_tenant_path(tenant.id, active_tab: 'OverdueShow')
assert_equal I18n.t('flashes.notices.overdue_deleted_successfully'), flash[:notice]
end

test 'should modify overdue config' do
tenant = create_kaui_tenant

Expand Down
Loading