Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maat integration #6438

Closed
wants to merge 9 commits into from
Closed
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
28 changes: 15 additions & 13 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ gem 'devise', '~> 4.9.3'
gem 'dotenv-rails'
gem 'factory_bot_rails', '~> 6.4.3'
gem 'faker', '~> 3.2.3'
gem 'govuk-components', '~> 4.1'
gem 'govuk_design_system_formbuilder', '~> 5.2'
gem 'govuk_notify_rails', '~> 2.2.0'
gem 'grape', '~> 2.0.0'
Expand Down Expand Up @@ -50,58 +51,59 @@ gem 'sprockets-rails', '~> 3.4.2'
gem 'state_machines-activerecord'
gem 'state_machines-audit_trail'
gem 'tzinfo-data'
gem 'zendesk_api' , '~> 3.0'
gem 'zendesk_api' , '1.37.0'
gem 'sidekiq', '~> 7.2'
gem 'sidekiq-failures', '~> 1.0', '>= 1.0.4'
gem 'sidekiq-scheduler', '~> 5.0.3'
gem 'utf8-cleaner', '~> 1.0'
gem 'colorize'
gem 'shell-spinner', '~> 1.0', '>= 1.0.4'
gem 'ruby-progressbar'
gem 'laa-fee-calculator-client', '~> 2.0'
gem 'laa-fee-calculator-client', '~> 1.4'
gem 'active_storage_validations'
gem 'faraday', '~> 2.0'
gem 'faraday-follow_redirects', '~> 0.3'
gem 'faraday', '~> 1.10'
gem 'faraday_middleware', '~> 1.2'
gem 'puma'

group :development, :test do
gem 'annotate'
gem 'brakeman', :require => false
gem 'better_errors'
gem 'binding_of_caller'
gem 'byebug'
gem 'listen', '~> 3.9.0'
gem 'listen', '~> 3.8.0'
gem 'meta_request'
gem 'parallel_tests'
gem 'pry-byebug'
gem 'pry-rails'
gem 'rack-livereload', '~> 0.5.2'
gem 'rspec-rails', '~> 6.1.1'
gem 'rack-livereload', '~> 0.5.1'
gem 'rspec-rails', '~> 6.1.0'
gem 'rspec-collection_matchers'
gem 'rspec_junit_formatter'
gem 'net-ssh', '~> 7.2'
gem 'net-scp', '~> 4.0'
gem 'rubocop', '~> 1.62'
gem 'rubocop', '~> 1.59'
gem 'rubocop-capybara', '~> 2.20'
gem 'rubocop-factory_bot', '~> 2.25'
gem 'rubocop-rspec', '~> 2.27'
gem 'rubocop-rails', '~> 2.24'
gem 'rubocop-rspec', '~> 2.26'
gem 'rubocop-rails', '~> 2.23'
gem 'rubocop-performance', '~> 1.20'
gem 'site_prism', '~> 5.0'
end

group :test do
gem 'axe-core-cucumber', '~> 4.8'
gem 'capybara-selenium'
gem 'capybara', '~> 3.40'
gem 'capybara', '~> 3.39'
gem 'cucumber-rails', '~> 3.0.0', require: false
gem 'database_cleaner'
gem 'i18n-tasks'
gem 'json_spec'
gem 'launchy', '~> 3.0.0'
gem 'launchy', '~> 2.5.2'
gem 'rails-controller-testing'
gem 'rspec-html-matchers', '~> 0.10.0'
gem 'rspec-mocks'
gem 'shoulda-matchers', '~> 6.1'
gem 'shoulda-matchers', '~> 6.0'
gem 'simplecov', require: false
gem 'timecop'
gem 'vcr'
Expand Down
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ GEM
raabro (~> 1.4)
globalid (1.2.1)
activesupport (>= 6.1)
govuk-components (4.1.2)
html-attributes-utils (~> 1.0.0, >= 1.0.0)
pagy (~> 6.0)
view_component (>= 3.3, < 3.7)
govuk_design_system_formbuilder (5.2.0)
actionview (>= 6.1)
activemodel (>= 6.1)
Expand Down Expand Up @@ -414,6 +418,7 @@ GEM
notifications-ruby-client (5.4.0)
jwt (>= 1.5, < 3)
orm_adapter (0.5.0)
pagy (6.5.0)
paper_trail (15.1.0)
activerecord (>= 6.1)
request_store (~> 1.4)
Expand Down Expand Up @@ -700,6 +705,7 @@ DEPENDENCIES
faker (~> 3.2.3)
faraday (~> 2.0)
faraday-follow_redirects (~> 0.3)
govuk-components
govuk_design_system_formbuilder (~> 5.2)
govuk_notify_rails (~> 2.2.0)
grape (~> 2.0.0)
Expand Down
7 changes: 6 additions & 1 deletion app/controllers/case_workers/claims_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class ClaimsController < CaseWorkers::ApplicationController
respond_to :html

# callback order is important (must set claims before filtering and sorting)
before_action :set_claims, only: %i[index archived]
before_action :set_claims, only: %i[index archived]
before_action :set_presenters
before_action :filter_current_claims, only: [:index]
before_action :filter_archived_claims, only: [:archived]
before_action :sort_claims, only: %i[index archived]
Expand Down Expand Up @@ -87,6 +88,10 @@ def set_claims
@claims = Claims::CaseWorkerClaims.new(current_user:, action: tab, criteria: criteria_params).claims
end

def set_presenters
@defendant_presenter = CaseWorkers::DefendantPresenter
end

# Only these 2 actions are handle in this controller. Rest of actions in the admin-namespaced controller.
def tab
%w[current archived].include?(params[:tab]) ? params[:tab] : 'current'
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/external_users/claims_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ResourceClassNotDefined < StandardError; end

prepend_before_action :clean_multiparameter_dates, only: %i[create update]
before_action :set_user_and_provider
before_action :set_presenters
before_action :set_claims_context, only: %i[index archived outstanding authorised]
before_action :set_financial_summary, only: %i[index outstanding authorised]

Expand Down Expand Up @@ -212,6 +213,10 @@ def set_user_and_provider
@provider = @external_user.provider
end

def set_presenters
@defendant_presenter = ExternalUsers::DefendantPresenter
end

def set_claims_context
context = Claims::ContextMapper.new(@external_user, scheme:)
@claims_context = context.available_claims
Expand Down
9 changes: 9 additions & 0 deletions app/presenters/case_workers/defendant_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module CaseWorkers
class DefendantPresenter < BasePresenter
presents :defendant

def representation_orders
defendant.representation_orders.map { |rep_order| RepresentationOrder.new(rep_order, @view) }
end
end
end
6 changes: 6 additions & 0 deletions app/presenters/case_workers/representation_order.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module CaseWorkers
class RepresentationOrder < BasePresenter
presents :representation_order
def maat_details = @maat_details ||= MaatService.call(maat_reference:)
end
end
9 changes: 9 additions & 0 deletions app/presenters/external_users/defendant_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module ExternalUsers
class DefendantPresenter < BasePresenter
presents :defendant

def representation_orders
defendant.representation_orders.map { |rep_order| RepresentationOrder.new(rep_order, @view) }
end
end
end
9 changes: 9 additions & 0 deletions app/presenters/external_users/representation_order.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module ExternalUsers
class RepresentationOrder < BasePresenter
presents :representation_order

def maat_details
{ case_number: '???' }
end
end
end
17 changes: 17 additions & 0 deletions app/services/maat_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class MaatService
def self.call(...) = new(...).call

def initialize(**kwargs)
@connection = MaatService::Connection.instance
@maat_reference = kwargs[:maat_reference]
end

def call
data = @connection.fetch(@maat_reference)

{
case_number: data['caseId'] || '???',
representation_order_date: data['crownRepOrderDate'] || '???'
}
end
end
35 changes: 35 additions & 0 deletions app/services/maat_service/connection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class MaatService
class Connection
include Singleton

def fetch(maat_reference)
JSON.parse(client.get("assessment/rep-orders/#{maat_reference}").body)
rescue Faraday::ConnectionFailed
{}
end

private

def client
@client ||= Faraday.new(ENV.fetch('MAAT_API_DEV_URL'), request: { timeout: 2 }) do |conn|
conn.authorization :Bearer, oauth_token
end
end

def oauth_token
response = Faraday.post(maat_credentials)
JSON.parse(response.body)['access_token']
end

def maat_credentials
ENV.fetch('OAUTH_URL')
{
client_id: ENV.fetch('OAUTH_CLIENT_ID'),
client_secret: ENV.fetch('OAUTH_CLIENT_SECRET'),
scope: ENV.fetch('OAUTH_SCOPE'),
grant_type: 'client_credentials'
}
{ content_type: 'application/x-www-form-urlencoded' }
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# NOTE: Once all models are using this module then the method(s)
# can be promoted to the superclass and this module removed
#
module GOVUKDesignSystemFormBuilderErrorable
module GovukDesignSystemFormBuilderErrorable
extend ActiveSupport::Concern

included do
Expand Down
2 changes: 1 addition & 1 deletion app/validators/supplier_number_sub_model_validator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class SupplierNumberSubModelValidator < BaseSubModelValidator
include GOVUKDesignSystemFormBuilderErrorable
include GovukDesignSystemFormBuilderErrorable

def has_many_association_names
[:lgfs_supplier_numbers]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
%h2.govuk-heading-m
= t('.allocation_queue')

= govuk_table(class: 'app-jq-datatable', style: 'width: 100%') do
= cccd_govuk_table(class: 'app-jq-datatable', style: 'width: 100%') do
= govuk_table_caption(class: 'govuk-visually-hidden') do
= t('.table_summary')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
= f.govuk_submit t('.re_allocate'), name: 'tab', value: 'allocated'

- if @claims.any?
= govuk_table(class: 'js-checkbox-table') do
= cccd_govuk_table(class: 'js-checkbox-table') do
= govuk_table_caption(id: 'allocation-claim-ids-field-error') do
.govuk-grid-row
.govuk-grid-column-one-half
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
.govuk-grid-row{class: 'govuk-!-margin-top-9'}
.govuk-grid-column-full

= govuk_table do
= cccd_govuk_table do
= govuk_table_caption(class: 'govuk-visually-hidden') do
= t('.caption')

Expand Down
2 changes: 1 addition & 1 deletion app/views/case_workers/claims/_claims_list.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
= t('.number_of_claims', claim_count: claims.total_count)

.govuk-grid-column-full
= govuk_table do
= cccd_govuk_table do
= govuk_table_caption(class: 'govuk-visually-hidden') do
= params[:action] == 'archived' ? t('case_workers.table_headings.archived_claims') : t('case_workers.table_headings.your_claims')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
= render partial: 'shared/search_form', locals: { search_path: external_users_admin_external_users_path(anchor: 'search-button'), hint_text: t('hint.search_users'), button_text: t('search.users') }


= govuk_table do
= cccd_govuk_table do
= govuk_table_caption(class: 'govuk-visually-hidden') do
= t('.table_caption', provider_name: "#{current_user.provider.name}")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
= govuk_table do
= cccd_govuk_table do
= govuk_table_caption(class: 'govuk-visually-hidden') do
= 'Cost summary'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
= govuk_table do
= cccd_govuk_table do
= govuk_table_caption do
.govuk-grid-row
.govuk-grid-column-one-half
Expand Down
4 changes: 2 additions & 2 deletions app/views/external_users/claims/_summary_fees.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

- if local_assigns.has_key?(:fee)
- if fee
= govuk_table do
= cccd_govuk_table do
= govuk_table_caption(class: 'govuk-visually-hidden') do
= t('.caption')
= govuk_table_tbody do
Expand All @@ -43,7 +43,7 @@
%h3.govuk-heading-m
= t('shared.summary.basic_fees')

= govuk_table do
= cccd_govuk_table do
= govuk_table_caption(class: 'govuk-visually-hidden') do
= t('.caption')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
%p
= t('shared.summary.no_values.disbursements')
- else
= govuk_table do
= cccd_govuk_table do
= govuk_table_caption(class: 'govuk-visually-hidden') do
= t('.caption')

Expand Down
4 changes: 2 additions & 2 deletions app/views/external_users/claims/expenses/_summary.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
%h2.govuk-heading-m
= t('shared.summary.cost_summary')

= govuk_table do
= cccd_govuk_table do
= govuk_table_caption(class: 'govuk-visually-hidden') do
= t('.caption')

Expand Down Expand Up @@ -63,7 +63,7 @@
%h3.govuk-heading-m
= t('shared.summary.expenses.travel_details')

= govuk_table do
= cccd_govuk_table do
= govuk_table_caption(class: 'govuk-visually-hidden') do
= t('.additional_information')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- if @claim.documents.any?(&:persisted?)
= govuk_table(class: 'files') do
= cccd_govuk_table(class: 'files') do
= govuk_table_caption do
= t('.previously_uploaded_docs')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
label: { text: t('.upload_file') },
multiple: true

= govuk_table(id: 'dropzone-files', class: 'files hidden') do
= cccd_govuk_table(id: 'dropzone-files', class: 'files hidden') do
= govuk_table_caption do
= t('.uploading_docs')

Expand Down
Loading