Skip to content

Commit

Permalink
Merge branch 'main' into feature/def-analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
raul-gracia authored Sep 25, 2023
2 parents 540bdc5 + 7a3e5f2 commit f81cc54
Show file tree
Hide file tree
Showing 56 changed files with 636 additions and 394 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ AllCops:
- 'bin/*'
- 'db/schema.rb'
- 'node_modules/**/*'
- 'spec/models/reports/applications_spec.rb'

Style/MethodCallWithArgsParentheses:
AllowParenthesesInMultilineCall: true
Expand Down Expand Up @@ -75,6 +76,7 @@ RSpec/ExampleLength:
Max: 10
Exclude:
- 'spec/features/*'
- 'spec/models/reports/home_office_spec.rb'

RSpec/NoExpectationExample:
Exclude:
Expand Down
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ gem "foreman"
gem "jbuilder"
gem "okcomputer"
gem "pg", "~> 1.5"
gem "puma", "~> 6.3"
gem "puma", "~> 6.4"
gem "rails", "~> 7.0.8"
gem "sprockets-rails"
gem "tzinfo-data", platforms: %i[mingw mswin x64_mingw jruby]
Expand All @@ -36,6 +36,9 @@ gem "audited", "~> 5.3", ">= 5.3.3"
gem "config", "~> 4.2"
gem "devise", "~> 4.9"
gem "dfe-analytics", github: "DFE-Digital/dfe-analytics", tag: "v1.10.1"
gem "flipper"
gem "flipper-active_record"
gem "flipper-ui"
gem "httparty", "~> 0.21"
gem "invisible_captcha"
gem "omniauth-azure-activedirectory-v2"
Expand Down
23 changes: 21 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ GEM
bootsnap (1.16.0)
msgpack (~> 1.2)
brakeman (6.0.1)
brow (0.4.1)
builder (3.2.4)
bundler-audit (0.9.1)
bundler (>= 1.2.0, < 3)
Expand Down Expand Up @@ -179,6 +180,18 @@ GEM
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-net_http (3.0.2)
flipper (1.0.0)
brow (~> 0.4.1)
concurrent-ruby (< 2)
flipper-active_record (1.0.0)
activerecord (>= 4.2, < 8)
flipper (~> 1.0.0)
flipper-ui (1.0.0)
erubi (>= 1.0.0, < 2.0.0)
flipper (~> 1.0.0)
rack (>= 1.4, < 4)
rack-protection (>= 1.5.3, <= 4.0.0)
sanitize (< 7)
foreman (0.87.2)
fugit (1.8.1)
et-orbi (~> 1, >= 1.2.7)
Expand Down Expand Up @@ -317,7 +330,7 @@ GEM
byebug (~> 11.0)
pry (>= 0.13, < 0.15)
public_suffix (5.0.1)
puma (6.3.1)
puma (6.4.0)
nio4r (~> 2.0)
raabro (1.4.0)
racc (1.7.1)
Expand Down Expand Up @@ -430,6 +443,9 @@ GEM
rubocop-factory_bot (~> 2.22)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
sanitize (6.1.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
scenic (1.7.0)
activerecord (>= 4.0.0)
railties (>= 4.0.0)
Expand Down Expand Up @@ -521,6 +537,9 @@ DEPENDENCIES
dotenv-rails
factory_bot_rails
faker
flipper
flipper-active_record
flipper-ui
foreman
govuk-components (= 4.1.1)
govuk_design_system_formbuilder
Expand All @@ -536,7 +555,7 @@ DEPENDENCIES
pg (~> 1.5)
phonelib
pry-byebug
puma (~> 6.3)
puma (~> 6.4)
rails (~> 7.0.8)
rspec-rails
rubocop-govuk
Expand Down
31 changes: 0 additions & 31 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,6 @@ class ApplicationController < ActionController::Base

before_action :check_service_open!

delegate :application_route, to: :current_application
helper_method :application_route

def check_application!
return if session["application_id"]

redirect_to(root_path)
end

def current_application
Application.in_progress.find(session["application_id"])
end
helper_method :current_application

def current_applicant
current_application.applicant
end
helper_method :current_applicant

def check_teacher!
return unless application_route != "teacher"

redirect_to(new_applicants_application_route_path)
end

def check_trainee!
return unless application_route != "salaried_trainee"

redirect_to(new_applicants_application_route_path)
end

def check_service_open!
return if request.path == destroy_user_session_path # skip this for log out page
return if Gatekeeper.application_open?
Expand Down
17 changes: 2 additions & 15 deletions app/controllers/system_admin/applicants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ApplicantsController < AdminController
include Pagy::Backend

def index
results = Application.submitted
results = Application.all
.search(params[:search])
.filter_by_status(params[:status])
.order(created_at: :desc)
Expand All @@ -18,20 +18,7 @@ def index

@pagy, @applications = pagy_array(results)
session[:filter_status] = params[:status]
session[:application_ids] = @applications.map(&:id)
end

def download_qa_csv
status = session[:filter_status]
application_ids = session[:application_ids]

applications = Application.where(id: application_ids).reject(&:qa?)

applications.each(&:mark_as_qa!)

report = Reports::QaReport.new(applications, status)
create_audit(action: "Downloaded QA CSV report (#{status.humanize})")
send_data(report.csv, filename: report.name)
session[:application_ids] = results.map(&:id)
end

def duplicates
Expand Down
14 changes: 5 additions & 9 deletions app/controllers/system_admin/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@ class ReportsController < AdminController
def index; end

def show
report = find_report(params[:id])
create_audit(action: "Downloaded #{report.class.to_s.capitalize} report")
service = Report.call(params[:id], **report_params)
create_audit(action: "Downloaded #{service.report_name} report")

send_data(report.csv, filename: report.name)
send_data(service.data, filename: service.filename)
end

private

def find_report(report_id)
{
home_office: Reports::HomeOffice.new,
standing_data: Reports::StandingData.new,
payroll: Reports::Payroll.new,
}.with_indifferent_access.fetch(report_id)
def report_params
params.permit(:id, :status)
end
end
end
14 changes: 14 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,18 @@ def mailto_irp_express_interest
def banner_feedback_form
govuk_link_to("feedback", "https://forms.office.com/e/p45Wm1Vmxg", target: "_blank")
end

def application_statuses
ApplicationProgress
.statuses
.keys
.map { |status| [status.humanize, status] }
end

def application_statuses_options(selected: nil, all_statuses: false)
statuses = application_statuses
statuses = application_statuses.unshift(["All statuses", ""]) if all_statuses

options_for_select(statuses, selected:)
end
end
5 changes: 5 additions & 0 deletions app/javascript/packs/stylesheets/custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
padding: 5px;
font-size: 20px;
}

a {
color: #fff;
text-decoration: none;
}
}
}

Expand Down
29 changes: 7 additions & 22 deletions app/models/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ class Application < ApplicationRecord
delegate :sla_breached?, to: :application_progress
delegate :status, to: :application_progress, allow_nil: false

default_scope { submitted }
scope :submitted, -> { where.not(urn: nil) }
scope :in_progress, -> { unscoped.where(urn: nil) }

scope :search, lambda { |term|
return if term.blank?

Expand Down Expand Up @@ -64,22 +60,11 @@ def mark_as_qa!
unique_by: %i[application_id status])
end

with_options if: :submitted? do
validates(:application_date, presence: true)
validates(:application_route, presence: true)
validates(:date_of_entry, presence: true)
validates(:start_date, presence: true)
validates(:subject, presence: true)
validates(:visa_type, presence: true)
validates(:urn, presence: true)
validates(:applicant, presence: true)
end

def assign_urn!
update!(urn: Urn.generate(application_route))
end

def submitted?
urn.present?
end
validates(:application_date, presence: true)
validates(:application_route, presence: true)
validates(:date_of_entry, presence: true)
validates(:start_date, presence: true)
validates(:subject, presence: true)
validates(:visa_type, presence: true)
validates(:applicant, presence: true)
end
6 changes: 5 additions & 1 deletion app/models/kpis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def initialize
end

def total_applications
Application.submitted.count
Application.count
end

def total_rejections
Expand Down Expand Up @@ -62,4 +62,8 @@ def time_to_banking_approval
def time_to_payment_confirmation
TimeToPaymentConfirmationQuery.new.call
end

def status_breakdown
StatusBreakdownQuery.call
end
end
29 changes: 0 additions & 29 deletions app/models/policies/contract_start_date.rb

This file was deleted.

21 changes: 0 additions & 21 deletions app/models/policies/entry_date.rb

This file was deleted.

Loading

0 comments on commit f81cc54

Please sign in to comment.