-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RUBY-2709] Add call recording control and integrate defra_ruby_storm…
… service
- Loading branch information
Showing
12 changed files
with
139 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
app/services/concerns/waste_carriers_engine/can_control_call_recording.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
41
app/services/waste_carriers_engine/call_recording_service.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
app/views/waste_carriers_engine/shared/_call_recording_banner.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters