diff --git a/Gemfile b/Gemfile index 7b809cb7f..3d40444da 100644 --- a/Gemfile +++ b/Gemfile @@ -42,10 +42,10 @@ group :development do end group :development, :test do - gem 'rubocop', require: false + gem 'rubocop', '~> 1.89.0', require: false gem 'rubocop-performance', require: false - gem 'rubocop-rails', require: false - gem 'rubocop-rspec', require: false + gem 'rubocop-rails', '~> 2.36.0', require: false + gem 'rubocop-rspec', '~> 3.10.2', require: false gem 'rubocop-thread_safety', require: false end diff --git a/app/assets/images/kaui/blocking-states/shield-white.svg b/app/assets/images/kaui/blocking-states/shield-white.svg new file mode 100644 index 000000000..4babaa3ca --- /dev/null +++ b/app/assets/images/kaui/blocking-states/shield-white.svg @@ -0,0 +1,3 @@ + + + diff --git a/app/assets/images/kaui/timeline/block.svg b/app/assets/images/kaui/timeline/block.svg new file mode 100644 index 000000000..b3f883476 --- /dev/null +++ b/app/assets/images/kaui/timeline/block.svg @@ -0,0 +1,4 @@ + + + + diff --git a/app/assets/stylesheets/kaui/subscription.css b/app/assets/stylesheets/kaui/subscription.css index 988da87c6..e687883b9 100644 --- a/app/assets/stylesheets/kaui/subscription.css +++ b/app/assets/stylesheets/kaui/subscription.css @@ -437,6 +437,44 @@ table tr.expired td { right: 0.5rem; } +/* app/views/kaui/components/blocking_state_form/_about_panel.html.erb */ + +.blocking-state-about-panel { + flex: 0 0 20rem; + max-width: 20rem; + height: fit-content; + padding: 1.25rem; + background-color: #EFF6FF; + border: 0.0625rem solid #DBEAFE; + border-radius: 0.5rem; +} + +.blocking-state-about-panel .icon-container { + display: inline-flex; + justify-content: center; + align-items: center; + width: 2.5rem; + height: 2.5rem; + border-radius: 50%; + background-color: #2563EB; + flex-shrink: 0; +} + +.blocking-state-about-panel h6 { + font-weight: 600; + font-size: 1rem; + line-height: 1.5rem; + color: #1B1C1E; +} + +.blocking-state-about-panel p { + font-size: 0.875rem; + font-weight: 400; + line-height: 1.25rem; + color: #414651; + margin-bottom: 0; +} + .kaui-subscription-new .form-group.d-flex.pb-3 .form-control { height: 2.5rem; border-radius: 0.375rem; diff --git a/app/controllers/kaui/account_timelines_controller.rb b/app/controllers/kaui/account_timelines_controller.rb index d86c00ff7..1b11f8128 100644 --- a/app/controllers/kaui/account_timelines_controller.rb +++ b/app/controllers/kaui/account_timelines_controller.rb @@ -11,6 +11,7 @@ def show @invoices = timeline.invoices @payments = timeline.payments extract_invoices_by_id(@invoices) + @account_blocking_states = fetch_account_blocking_states(@account) # Lookup all bundle names @bundle_names = {} @@ -51,6 +52,7 @@ def download @invoices = timeline.invoices @payments = timeline.payments extract_invoices_by_id(@invoices) + @account_blocking_states = fetch_account_blocking_states(@account) # Lookup all bundle names @bundle_names = {} @@ -117,20 +119,30 @@ def download @bundles.each do |bundle| bundle.subscriptions.each do |sub| sub.events.each do |event| - # Skip SERVICE_STATE_CHANGE events - next if event.event_type == 'SERVICE_STATE_CHANGE' - effective_date = event.effective_date.present? ? Date.parse(event.effective_date).to_s : '[unknown]' bundle_keys = @bundle_names[bundle.external_key] - event_type = event.event_type - phase = event.phase audit_logs = event.audit_logs.present? ? event.audit_logs.map { |entry| Kaui::AuditLog.description(entry) }.join(', ') : '' + details = if event.event_type == 'SERVICE_STATE_CHANGE' || event.is_blocked_billing || event.is_blocked_entitlement + "#{event.service_name}/#{event.service_state_name} (billing=#{event.is_blocked_billing}, entitlement=#{event.is_blocked_entitlement})" + else + event.phase + end - csv << [effective_date, bundle_keys, event_type, phase, audit_logs] if filter_date?(effective_date, start_date, end_date) + csv << [effective_date, bundle_keys, event.event_type, details, audit_logs] if filter_date?(effective_date, start_date, end_date) end end end end + + if %w[ENTITLEMENT ALL].include?(event_type) + @account_blocking_states.each do |blocking_state| + effective_date = blocking_state.effective_date.present? ? Date.parse(blocking_state.effective_date).to_s : '[unknown]' + audit_logs = blocking_state.audit_logs.present? ? blocking_state.audit_logs.map { |entry| Kaui::AuditLog.description(entry) }.join(', ') : '' + details = "#{blocking_state.service}/#{blocking_state.state_name} (billing=#{blocking_state.is_block_billing}, entitlement=#{blocking_state.is_block_entitlement}, change=#{blocking_state.is_block_change})" + + csv << [effective_date, '', 'SERVICE_STATE_CHANGE', details, audit_logs] if filter_date?(effective_date, start_date, end_date) + end + end end send_data csv_string, filename: "account-timelines-#{Time.zone.today}.csv", type: 'text/csv' @@ -161,5 +173,11 @@ def extract_invoices_by_id(all_invoices) [invoice.invoice_id, Kaui::Invoice.build_from_raw_invoice(invoice)] end end + + def fetch_account_blocking_states(account) + account.blocking_states(nil, nil, 'NONE', options_for_klient) + rescue StandardError + [] + end end end diff --git a/app/controllers/kaui/accounts_controller.rb b/app/controllers/kaui/accounts_controller.rb index 0ee2c0bc4..d2830016f 100644 --- a/app/controllers/kaui/accounts_controller.rb +++ b/app/controllers/kaui/accounts_controller.rb @@ -391,5 +391,20 @@ def export_account data = KillBillClient::Model::Export.find_by_account_id(params[:account_id], current_user.kb_username, options_for_klient) send_data data, filename: "account#{params[:account_id]}.txt", type: :txt end + + def block + @account = Kaui::Account.find_by_id(params.require(:account_id), false, false, options_for_klient) + end + + def do_block + account_id = params.require(:account_id) + account = Kaui::Account.new(account_id:) + account.set_blocking_state(params.require(:state_name), params.require(:service), + params[:is_block_change] == '1', params[:is_block_entitlement] == '1', + params[:is_block_billing] == '1', params[:requested_date].presence, + current_user.kb_username, params[:reason], params[:comment], options_for_klient) + + redirect_to account_path(account_id), notice: 'Blocking state was successfully created' + end end end diff --git a/app/controllers/kaui/bundles_controller.rb b/app/controllers/kaui/bundles_controller.rb index 585daafbd..016995feb 100644 --- a/app/controllers/kaui/bundles_controller.rb +++ b/app/controllers/kaui/bundles_controller.rb @@ -128,6 +128,20 @@ def do_pause_resume redirect_to kaui_engine.account_bundles_path(@account.account_id), notice: msg end + def block + @bundle = Kaui::Bundle.find_by_id_or_key(params.require(:id), options_for_klient) + end + + def do_block + bundle = Kaui::Bundle.new(bundle_id: params.require(:id)) + bundle.set_blocking_state(params.require(:state_name), params.require(:service), + params[:is_block_change] == '1', params[:is_block_entitlement] == '1', + params[:is_block_billing] == '1', params[:requested_date].presence, + current_user.kb_username, params[:reason], params[:comment], options_for_klient) + + redirect_to kaui_engine.account_bundles_path(params.require(:account_id)), notice: 'Blocking state was successfully created' + end + private def search_bundles(query, search_by, options) diff --git a/app/controllers/kaui/subscriptions_controller.rb b/app/controllers/kaui/subscriptions_controller.rb index 77bc2d625..8037b0c48 100644 --- a/app/controllers/kaui/subscriptions_controller.rb +++ b/app/controllers/kaui/subscriptions_controller.rb @@ -150,6 +150,20 @@ def update_bcd redirect_to kaui_engine.account_bundles_path(input_subscription['account_id']), notice: 'Subscription BCD was successfully changed' end + def block + @subscription = Kaui::Subscription.find_by_id(params.require(:id), 'NONE', options_for_klient) + end + + def do_block + subscription = Kaui::Subscription.new(subscription_id: params.require(:id)) + subscription.set_blocking_state(params.require(:state_name), params.require(:service), + params[:is_block_change] == '1', params[:is_block_entitlement] == '1', + params[:is_block_billing] == '1', params[:requested_date].presence, + current_user.kb_username, params[:reason], params[:comment], options_for_klient) + + redirect_to kaui_engine.account_bundles_path(params.require(:account_id)), notice: 'Blocking state was successfully created' + end + def edit_quantity @subscription = Kaui::Subscription.find_by_id(params.require(:id), 'NONE', options_for_klient) end diff --git a/app/views/kaui/account_timelines/show.html.erb b/app/views/kaui/account_timelines/show.html.erb index 73032eefc..1a8f2c2b4 100644 --- a/app/views/kaui/account_timelines/show.html.erb +++ b/app/views/kaui/account_timelines/show.html.erb @@ -29,19 +29,25 @@
- <%= select_tag 'payment_filter', options_for_select(''.html_safe), :class => 'form-control' %> + <%= select_tag 'payment_filter', options_for_select(''.html_safe), :class => 'form-control' %>
- <%= select_tag 'subscription_filter', options_for_select(''.html_safe), :class => 'form-control' %> + <%= select_tag 'subscription_filter', options_for_select(''.html_safe), :class => 'form-control' %>
- <%= select_tag 'billing_filter', options_for_select(''.html_safe), :class => 'form-control' %> + <%= select_tag 'billing_filter', options_for_select(''.html_safe), :class => 'form-control' %> +
+
+
+ +
+ <%= select_tag 'blocking_state_filter', options_for_select(''.html_safe), :class => 'form-control' %>
@@ -49,13 +55,6 @@
-
-
- - <%= select_tag 'group-by', options_for_select([['Object Type', 'type'], ['Date', 'date']], 'type'), :class => 'form-control' %> -
-
-
<% if @account.present? %> <% @invoices.each do |invoice_stub| %> @@ -67,7 +66,7 @@ <% else %> <% invoice = invoice_stub %> <% end %> -
+
<% if invoice.target_date.present? %> <%= invoice.target_date %> @@ -155,7 +154,7 @@ <% invoice = nil %> <% end %> <% payment.transactions.each do |transaction| %> -
+
<% if transaction.effective_date.present? %> <%= format_date(transaction.effective_date, @account.time_zone).html_safe %> @@ -235,61 +234,179 @@ <% @bundles.each do |bundle| %> <% bundle.subscriptions.each do |sub| %> <% sub.events.each do |event| %> - <% next if event.event_type == 'SERVICE_STATE_CHANGE' %> -
-
- <% if event.effective_date.present? %> - <%= format_date(event.effective_date, @account.time_zone).html_safe %> - <% else %> - [unknown] - <% end %> -
-