Skip to content

Commit

Permalink
[RUBY-2709] Add call recording control and integrate defra_ruby_storm…
Browse files Browse the repository at this point in the history
… service
  • Loading branch information
jjromeo committed Nov 21, 2023
1 parent 53cc876 commit 694ea46
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 1 deletion.
25 changes: 25 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -212,13 +218,18 @@ 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)
activesupport (>= 6.1.4.4)
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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module WasteCarriersEngine
class CopyCardsPaymentFormsController < ::WasteCarriersEngine::FormsController
include CanControlCallRecording

def new
super(CopyCardsPaymentForm, "copy_cards_payment_form")
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module WasteCarriersEngine
class EditPaymentSummaryFormsController < ::WasteCarriersEngine::FormsController
include CanControlCallRecording

def new
return unless super(EditPaymentSummaryForm, "edit_payment_summary_form")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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
41 changes: 41 additions & 0 deletions app/services/waste_carriers_engine/call_recording_service.rb
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= render("waste_carriers_engine/shared/call_recording_banner") %>
<%= form_for(@copy_cards_payment_form) do |f| %>
<% if flash[:error].present? %>
<div class="govuk-error-summary" role="alert">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= render("waste_carriers_engine/shared/call_recording_banner") %>
<%= form_for(@edit_payment_summary_form) do |f| %>
<%= render("waste_carriers_engine/shared/payment_errors") %>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">

<%= render("waste_carriers_engine/shared/call_recording_banner") %>
<%= form_for(@payment_summary_form) do |f| %>
<%= render("waste_carriers_engine/shared/payment_errors") %>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<% if call_recording_flash = flash[:call_recording] %>
<% if success_message = call_recording_flash[:success] %>
<div class="govuk-notification-banner govuk-notification-banner--success" role="region" aria-labelledby="govuk-notification-banner-title" data-module="govuk-notification-banner">
<div class="govuk-notification-banner__content">
<p class="govuk-notification-banner__heading">
<%= success_message %>
</p>
</div>
</div>
<% end %>

<% if error_message = call_recording_flash[:error] %>
<div class="govuk-error-summary" aria-labelledby="error-summary-title" role="alert" tabindex="-1" data-module="govuk-error-summary">
<h2 class="govuk-error-summary__title" id="error-summary-title">
Warning
</h2>
<div class="govuk-error-summary__body">
<p>
<%= error_message %>
</p>
</div>
</div>
<% end %>
<% end %>
7 changes: 7 additions & 0 deletions config/initializers/defra_ruby_storm.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# config/initializers/defra_ruby_storm.rb
require "defra_ruby/storm"

DefraRuby::Storm.configure do |config|
config.storm_api_username = ENV["STORM_API_USERNAME"]
config.storm_api_password = ENV["STORM_API_PASSWORD"]
end
2 changes: 2 additions & 0 deletions waste_carriers_engine.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@ Gem::Specification.new do |s|

s.add_dependency "defra_ruby_area", "~> 2.0.3"

s.add_dependency "defra_ruby_storm"

end

0 comments on commit 694ea46

Please sign in to comment.