Skip to content

Commit

Permalink
Merge branch 'main' into withdrawals-flow-v3
Browse files Browse the repository at this point in the history
  • Loading branch information
kennyevil committed Dec 9, 2024
2 parents e08e035 + 1cab287 commit 000cce2
Show file tree
Hide file tree
Showing 54 changed files with 1,275 additions and 600 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ gem "mechanize" # interact with HESA
gem "dfe-reference-data", require: "dfe/reference_data", github: "DFE-Digital/dfe-reference-data", tag: "v3.6.7"

# for sending analytics data to the analytics platform
gem "dfe-analytics", github: "DFE-Digital/dfe-analytics", tag: "v1.15.1"
gem "dfe-analytics", github: "DFE-Digital/dfe-analytics", tag: "v1.15.2"

gem "ruby-progressbar" # useful for tracking long running rake tasks

Expand Down
26 changes: 13 additions & 13 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
GIT
remote: https://github.com/DFE-Digital/dfe-analytics.git
revision: 7618b23697e91ab1ababee5234faaa260f6c873e
tag: v1.15.1
revision: 82c94b22afd8e799d445394ffc387e41f8fd9366
tag: v1.15.2
specs:
dfe-analytics (1.15.1)
dfe-analytics (1.15.2)
google-cloud-bigquery (~> 1.38)
httparty (~> 0.21)
multi_xml (~> 0.6.0)
Expand Down Expand Up @@ -268,7 +268,7 @@ GEM
raabro (~> 1.4)
globalid (1.2.1)
activesupport (>= 6.1)
google-apis-bigquery_v2 (0.80.0)
google-apis-bigquery_v2 (0.81.0)
google-apis-core (>= 0.15.0, < 2.a)
google-apis-core (0.15.1)
addressable (~> 2.5, >= 2.5.1)
Expand All @@ -278,7 +278,7 @@ GEM
mutex_m
representable (~> 3.0)
retriable (>= 2.0, < 4.a)
google-cloud-bigquery (1.50.0)
google-cloud-bigquery (1.51.0)
bigdecimal (~> 3.0)
concurrent-ruby (~> 1.0)
google-apis-bigquery_v2 (~> 0.71)
Expand Down Expand Up @@ -334,7 +334,7 @@ GEM
reline (>= 0.4.2)
jsbundling-rails (1.3.1)
railties (>= 6.0.0)
json (2.8.2)
json (2.9.0)
json-jwt (1.16.6)
activesupport (>= 4.2)
aes_key_wrap
Expand Down Expand Up @@ -363,7 +363,7 @@ GEM
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
logger (1.6.1)
logger (1.6.2)
loofah (2.23.1)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
Expand Down Expand Up @@ -399,7 +399,7 @@ GEM
multi_json (1.15.0)
multi_xml (0.6.0)
mutex_m (0.3.0)
net-http (0.5.0)
net-http (0.6.0)
uri
net-http-digest_auth (1.4.1)
net-http-persistent (4.0.4)
Expand Down Expand Up @@ -636,14 +636,14 @@ GEM
websocket (~> 1.0)
semantic_logger (4.16.1)
concurrent-ruby (~> 1.0)
sentry-rails (5.21.0)
sentry-rails (5.22.0)
railties (>= 5.0)
sentry-ruby (~> 5.21.0)
sentry-ruby (5.21.0)
sentry-ruby (~> 5.22.0)
sentry-ruby (5.22.0)
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
sentry-sidekiq (5.21.0)
sentry-ruby (~> 5.21.0)
sentry-sidekiq (5.22.0)
sentry-ruby (~> 5.22.0)
sidekiq (>= 3.0)
shoulda-matchers (6.4.0)
activesupport (>= 5.2.0)
Expand Down
11 changes: 11 additions & 0 deletions app/components/bulk_update/trainee_uploads/row/view.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<tr class="govuk-table__row">
<td class="govuk-table__cell">
<%= submitted_at %>
</td>
<td class="govuk-table__cell">
<%= filename %>
</td>
<td class="govuk-table__cell">
<%= status %>
</td>
</tr>
36 changes: 36 additions & 0 deletions app/components/bulk_update/trainee_uploads/row/view.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

module BulkUpdate
module TraineeUploads
module Row
class View < ViewComponent::Base
COLOURS = {
"pending" => "govuk-tag--light-blue",
"validated" => "govuk-tag--turquoise",
"in_progress" => "govuk-tag--blue",
"succeeded" => "govuk-tag--green",
"failed" => "govuk-tag--red",
"cancelled" => "govuk-tag--yellow",
}.freeze

attr_reader :upload

delegate :filename, to: :upload

def initialize(upload:)
@upload = upload
end

def status
content_tag(:span, class: "govuk-tag #{COLOURS[upload.status]}") do
upload.status.humanize
end
end

def submitted_at
upload.submitted_at&.to_fs(:govuk_date_and_time)
end
end
end
end
end
2 changes: 1 addition & 1 deletion app/components/performance_profile_banner/view.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%= govuk_notification_banner(title_text: "Important") do |banner| %>
<% banner.with_heading(text: banner_heading_text) %>

<%= govuk_link_to("Sign off your performance profile", "#")%> by the <%= deadline_date %> deadline.
<%= govuk_link_to("Sign off your performance profile", performance_profiles_reports_path)%> by the <%= deadline_date %> deadline.
<% end %>
8 changes: 7 additions & 1 deletion app/controllers/bulk_update/trainees/uploads_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ module Trainees
class UploadsController < ApplicationController
before_action { require_feature_flag(:bulk_add_trainees) }

def index
@bulk_update_trainee_uploads = policy_scope(
BulkUpdate::TraineeUpload,
).current_academic_cycle.includes(:file_attachment)
end

def show
authorize(bulk_update_trainee_upload)
end
Expand Down Expand Up @@ -36,7 +42,7 @@ def create
end

def destroy
authorize(bulk_update_trainee_upload).cancelled!
authorize(bulk_update_trainee_upload).cancel!

redirect_to(bulk_update_path, flash: { success: t(".success") })
end
Expand Down
9 changes: 7 additions & 2 deletions app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ class ReportsController < BaseTraineeController

def index
authorize(current_user, :reports?)

@partial_page = DetermineSignOffPeriod.call

if @partial_page == :performance_period && current_user.organisation.performance_profile_signed_off?
@partial_page = :outside_period
end
end

def itt_new_starter_data_sign_off
Expand Down Expand Up @@ -41,8 +47,7 @@ def performance_profiles

respond_to do |format|
format.html do
@sign_off_date = Date.new(@current_academic_cycle.end_year, 1, 31).strftime("%d %B %Y")
@sign_off_url = Settings.sign_off_performance_profiles_url
@trainee_count = performance_profiles_trainees.count
end

format.csv do
Expand Down
2 changes: 1 addition & 1 deletion app/forms/bulk_update/bulk_add_trainees_submit_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(upload:)
def save
return false unless valid? && upload.validated?

upload.in_progress!
upload.submit!

BulkUpdate::AddTrainees::ImportRowsJob.perform_later(upload)
end
Expand Down
4 changes: 1 addition & 3 deletions app/forms/bulk_update/bulk_add_trainees_upload_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ def upload_attributes
end

def build_upload
BulkUpdate::TraineeUpload.new(
status: :pending,
)
BulkUpdate::TraineeUpload.new
end

def tempfile
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module BulkUpdate
module AddTrainees
class RemoveCancelledAndFailedJob < ApplicationJob
queue_as :default

def perform
return unless FeatureService.enabled?(:bulk_add_trainees)

RemoveUploads.call
end
end
end
end
36 changes: 33 additions & 3 deletions app/models/bulk_update/trainee_upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
#
# id :bigint not null, primary key
# number_of_trainees :integer
# status :string
# status :string default("pending")
# submitted_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# provider_id :bigint not null
#
# Indexes
#
# index_bulk_update_trainee_uploads_on_provider_id (provider_id)
# index_bulk_update_trainee_uploads_on_status (status)
#
# Foreign Keys
#
Expand All @@ -26,9 +28,33 @@ class BulkUpdate::TraineeUpload < ApplicationRecord
validated: "validated",
in_progress: "in_progress",
succeeded: "succeeded",
failed: "failed",
cancelled: "cancelled",
}
failed: "failed",
} do
event :process do
transition %i[pending] => :validated
end

event :submit do
before do
self.submitted_at = Time.current
end

transition %i[validated] => :in_progress
end

event :succeed do
transition %i[in_progress] => :succeeded
end

event :cancel do
transition %i[validated] => :cancelled
end

event :fail do
transition %i[pending validated in_progress] => :failed
end
end

belongs_to :provider
has_many :trainee_upload_rows,
Expand All @@ -42,6 +68,10 @@ class BulkUpdate::TraineeUpload < ApplicationRecord

delegate :filename, :download, :attach, to: :file

scope :current_academic_cycle, lambda {
where(created_at: AcademicCycle.current.start_date..AcademicCycle.current.end_date)
}

def total_rows_with_errors
trainee_upload_rows.with_errors.size
end
Expand Down
2 changes: 1 addition & 1 deletion app/policies/user_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def permitted_attributes_for_update
end

def drafts?
user.system_admin? || !user.lead_partner?
user.system_admin? || user.provider?
end

def bulk_recommend?
Expand Down
4 changes: 2 additions & 2 deletions app/serializers/api/v0_1/trainee_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def as_hash
provider_attributes,
diversity_attributes,
course_attributes,
school_attributes,
lead_partner_and_employing_school_attributes,
funding_attributes,
hesa_trainee_attributes,
sex: sex,
Expand Down Expand Up @@ -172,7 +172,7 @@ def recommended_for_award_at
@trainee.recommended_for_award_at&.iso8601
end

def school_attributes
def lead_partner_and_employing_school_attributes
{
employing_school_urn:,
lead_partner_ukprn:,
Expand Down
35 changes: 11 additions & 24 deletions app/services/api/v0_1/hesa_mapper/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,16 @@ def funding_entity_id
end

def lead_partner_attributes
if params[:lead_partner_urn].present?
if params.key?(:lead_partner_urn)
lead_partner_from_urn
elsif params[:lead_partner_ukprn].present?
elsif params.key?(:lead_partner_ukprn)
lead_partner_from_ukprn
else
{}
{ lead_partner_not_applicable: true } unless update
end
end

def lead_partner_from_urn
return { lead_partner_not_applicable: true } if lead_partner_not_applicable?

lead_partner_id = LeadPartner.find_by(urn: params[:lead_partner_urn])&.id
{
lead_partner_id: lead_partner_id,
Expand All @@ -220,27 +218,16 @@ def lead_partner_from_ukprn
}
end

def lead_partner_not_applicable?
NOT_APPLICABLE_SCHOOL_URNS.include?(params[:lead_partner_urn])
end

def employing_school_attributes
attrs = {}

if params[:employing_school_urn].present?
if NOT_APPLICABLE_SCHOOL_URNS.include?(params[:employing_school_urn])
attrs.merge!(employing_school_not_applicable: true)
else
employing_school_id = School.find_by(urn: params[:employing_school_urn])&.id

attrs.merge!(
employing_school_id: employing_school_id,
employing_school_not_applicable: employing_school_id.nil?,
)
end
if params.key?(:employing_school_urn)
employing_school_id = School.find_by(urn: params[:employing_school_urn])&.id
{
employing_school_id: employing_school_id,
employing_school_not_applicable: employing_school_id.nil?,
}
else
{ employing_school_not_applicable: true } unless update
end

attrs
end

def training_initiative_attributes
Expand Down
Loading

0 comments on commit 000cce2

Please sign in to comment.