From 694ea4601196fa79c55a18647fde0a7de9a23731 Mon Sep 17 00:00:00 2001 From: Jerome Pratt Date: Tue, 21 Nov 2023 20:15:54 +0000 Subject: [PATCH] [RUBY-2709] Add call recording control and integrate defra_ruby_storm service --- Gemfile.lock | 25 +++++++++++ .../copy_cards_payment_forms_controller.rb | 2 + .../edit_payment_summary_forms_controller.rb | 2 + .../payment_summary_forms_controller.rb | 3 +- .../can_control_call_recording.rb | 31 ++++++++++++++ .../call_recording_service.rb | 41 +++++++++++++++++++ .../copy_cards_payment_forms/new.html.erb | 1 + .../edit_payment_summary_forms/new.html.erb | 1 + .../payment_summary_forms/new.html.erb | 1 + .../shared/_call_recording_banner.html.erb | 24 +++++++++++ config/initializers/defra_ruby_storm.rb | 7 ++++ waste_carriers_engine.gemspec | 2 + 12 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 app/services/concerns/waste_carriers_engine/can_control_call_recording.rb create mode 100644 app/services/waste_carriers_engine/call_recording_service.rb create mode 100644 app/views/waste_carriers_engine/shared/_call_recording_banner.html.erb create mode 100644 config/initializers/defra_ruby_storm.rb diff --git a/Gemfile.lock b/Gemfile.lock index 260fcb635..3be6fc91e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,6 +9,7 @@ PATH defra_ruby_area (~> 2.0.3) defra_ruby_email (~> 1.3.0) defra_ruby_govpay + defra_ruby_storm defra_ruby_validators (~> 2.5.1) high_voltage (~> 3.1.2) jbuilder (~> 2.11.5) @@ -99,6 +100,9 @@ GEM airbrake-ruby (~> 6.0) airbrake-ruby (6.2.2) rbtree3 (~> 0.6) + akami (1.3.1) + gyoku (>= 0.4.0) + nokogiri ast (2.4.2) async (2.6.2) console (~> 1.10) @@ -154,6 +158,8 @@ GEM sprockets-rails defra_ruby_govpay (0.2.3) rest-client (~> 2.1) + defra_ruby_storm (0.1.0) + savon (~> 2.13.0) defra_ruby_style (0.3.0) rubocop (>= 1.0, < 2.0) defra_ruby_template (3.13.0) @@ -212,6 +218,9 @@ GEM activemodel (>= 6.1) activesupport (>= 6.1) html-attributes-utils (~> 1) + gyoku (1.4.0) + builder (>= 2.1.2) + rexml (~> 3.0) hashdiff (1.0.1) high_voltage (3.1.2) html-attributes-utils (1.0.2) @@ -219,6 +228,8 @@ GEM http-accept (1.7.0) http-cookie (1.0.5) domain_name (~> 0.5) + httpi (3.0.1) + rack i18n (1.14.1) concurrent-ruby (~> 1.0) io-event (1.2.2) @@ -271,6 +282,7 @@ GEM nokogiri (1.15.4) mini_portile2 (~> 2.8.2) racc (~> 1.4) + nori (2.6.0) notifications-ruby-client (5.4.0) jwt (>= 1.5, < 3) octokit (4.25.1) @@ -403,6 +415,15 @@ GEM sprockets (> 3.0) sprockets-rails tilt + savon (2.13.1) + akami (~> 1.2) + builder (>= 2.1.2) + gyoku (~> 1.2) + httpi (>= 2.4.5) + mail (~> 2.5) + nokogiri (>= 1.8.1) + nori (~> 2.4) + wasabi (~> 3.4) sawyer (0.9.2) addressable (>= 2.3.5) faraday (>= 0.17.3, < 3) @@ -448,6 +469,10 @@ GEM vcr (6.2.0) warden (1.2.9) rack (>= 2.0.9) + wasabi (3.8.0) + addressable + httpi (~> 3.0) + nokogiri (>= 1.4.2) web-console (4.2.1) actionview (>= 6.0.0) activemodel (>= 6.0.0) diff --git a/app/controllers/waste_carriers_engine/copy_cards_payment_forms_controller.rb b/app/controllers/waste_carriers_engine/copy_cards_payment_forms_controller.rb index e1831911e..51f0b20f3 100644 --- a/app/controllers/waste_carriers_engine/copy_cards_payment_forms_controller.rb +++ b/app/controllers/waste_carriers_engine/copy_cards_payment_forms_controller.rb @@ -2,6 +2,8 @@ module WasteCarriersEngine class CopyCardsPaymentFormsController < ::WasteCarriersEngine::FormsController + include CanControlCallRecording + def new super(CopyCardsPaymentForm, "copy_cards_payment_form") end diff --git a/app/controllers/waste_carriers_engine/edit_payment_summary_forms_controller.rb b/app/controllers/waste_carriers_engine/edit_payment_summary_forms_controller.rb index cd4ed03c1..2ba3b5072 100644 --- a/app/controllers/waste_carriers_engine/edit_payment_summary_forms_controller.rb +++ b/app/controllers/waste_carriers_engine/edit_payment_summary_forms_controller.rb @@ -2,6 +2,8 @@ module WasteCarriersEngine class EditPaymentSummaryFormsController < ::WasteCarriersEngine::FormsController + include CanControlCallRecording + def new return unless super(EditPaymentSummaryForm, "edit_payment_summary_form") diff --git a/app/controllers/waste_carriers_engine/payment_summary_forms_controller.rb b/app/controllers/waste_carriers_engine/payment_summary_forms_controller.rb index b5463116c..bf07d5c4f 100644 --- a/app/controllers/waste_carriers_engine/payment_summary_forms_controller.rb +++ b/app/controllers/waste_carriers_engine/payment_summary_forms_controller.rb @@ -2,9 +2,10 @@ module WasteCarriersEngine class PaymentSummaryFormsController < ::WasteCarriersEngine::FormsController + include CanControlCallRecording + def new return unless super(PaymentSummaryForm, "payment_summary_form") - @presenter = ResourceTypeFormPresenter.new(@transient_registration) end diff --git a/app/services/concerns/waste_carriers_engine/can_control_call_recording.rb b/app/services/concerns/waste_carriers_engine/can_control_call_recording.rb new file mode 100644 index 000000000..a5e180cf3 --- /dev/null +++ b/app/services/concerns/waste_carriers_engine/can_control_call_recording.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +module WasteCarriersEngine + module CanControlCallRecording + extend ActiveSupport::Concern + + included do + before_action :check_and_pause_call_recording, only: %i[new] + end + + def check_and_pause_call_recording + if FeatureToggle.active?(:control_call_recording) + if call_recording_service.pause + flash[:call_recording] = { success: "Call recording is paused" } + else + flash[:call_recording] = { error: "There is an issue with pausing the call recording, please check that call recording is paused before taking a card payment" } + end + end + end + + private + + def pause_call_recording + call_recording_service.pause + end + + def call_recording_service + @call_recording_service ||= WasteCarriersEngine::CallRecordingService.new(user: current_user) + end + end +end diff --git a/app/services/waste_carriers_engine/call_recording_service.rb b/app/services/waste_carriers_engine/call_recording_service.rb new file mode 100644 index 000000000..6703ff2b9 --- /dev/null +++ b/app/services/waste_carriers_engine/call_recording_service.rb @@ -0,0 +1,41 @@ +module WasteCarriersEngine + class CallRecordingService + SUCCESS_RESULT = "0" + attr_reader :user + + def initialize(user:) + @user = user + end + + def pause + response = DefraRuby::Storm::PauseCallRecordingService.run(agent_user_id: get_agent_user_id(user)) + + if response.result == SUCCESS_RESULT + return true + else + return false + end + rescue DefraRuby::Storm::ApiError => e + Rails.logger.error "Error pausing call recording: #{e.message}" + return false + end + + private + + def get_agent_user_id(user) + return user.storm_user_id unless user.storm_user_id.nil? + return get_agent_user_id_from_email(user) unless user.email.nil? + + nil + end + + def get_agent_user_id_from_email(user) + agency_user_id = DefraRuby::Storm::UserDetailsService.run(username: user.email)&.user_id + user.update(storm_user_id: agency_user_id) unless agency_user_id.nil? + return agency_user_id + rescue DefraRuby::Storm::ApiError => e + Rails.logger.error "Error getting agent user id from email: #{e.class} #{e.message}" + raise e + end + end +end diff --git a/app/views/waste_carriers_engine/copy_cards_payment_forms/new.html.erb b/app/views/waste_carriers_engine/copy_cards_payment_forms/new.html.erb index cfdb5a9a2..63a00d6da 100644 --- a/app/views/waste_carriers_engine/copy_cards_payment_forms/new.html.erb +++ b/app/views/waste_carriers_engine/copy_cards_payment_forms/new.html.erb @@ -2,6 +2,7 @@
+ <%= render("waste_carriers_engine/shared/call_recording_banner") %> <%= form_for(@copy_cards_payment_form) do |f| %> <% if flash[:error].present? %>