From 5cbeffee482d6f4e936075ffdc132bde319499f7 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Mon, 20 Nov 2023 11:39:54 +0000 Subject: [PATCH 1/4] Add hidden_from_assessment column This adds a new column to application forms which captures whether an application will be hidden from assessment. --- app/models/application_form.rb | 1 + config/analytics_blocklist.yml | 2 ++ ...34_add_hidden_from_assessment_to_application_forms.rb | 9 +++++++++ db/schema.rb | 3 ++- spec/factories/application_forms.rb | 1 + spec/models/application_form_spec.rb | 1 + 6 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20231120105534_add_hidden_from_assessment_to_application_forms.rb diff --git a/app/models/application_form.rb b/app/models/application_form.rb index 74bea113d3..f510bdb1c0 100644 --- a/app/models/application_form.rb +++ b/app/models/application_form.rb @@ -24,6 +24,7 @@ # given_names :text default(""), not null # has_alternative_name :boolean # has_work_history :boolean +# hidden_from_assessment :boolean default(FALSE), not null # identification_document_status :string default("not_started"), not null # needs_registration_number :boolean not null # needs_work_history :boolean not null diff --git a/config/analytics_blocklist.yml b/config/analytics_blocklist.yml index 8fdf3ac0d4..e979f45ea5 100644 --- a/config/analytics_blocklist.yml +++ b/config/analytics_blocklist.yml @@ -21,6 +21,8 @@ - record_id - blob_id - created_at + :application_forms: + - hidden_from_assessment :sessions: - id - session_id diff --git a/db/migrate/20231120105534_add_hidden_from_assessment_to_application_forms.rb b/db/migrate/20231120105534_add_hidden_from_assessment_to_application_forms.rb new file mode 100644 index 0000000000..0d98d30b30 --- /dev/null +++ b/db/migrate/20231120105534_add_hidden_from_assessment_to_application_forms.rb @@ -0,0 +1,9 @@ +class AddHiddenFromAssessmentToApplicationForms < ActiveRecord::Migration[7.1] + def change + add_column :application_forms, + :hidden_from_assessment, + :boolean, + null: false, + default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 4218fdd95f..46d6d149ca 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2023_11_14_102513) do +ActiveRecord::Schema[7.1].define(version: 2023_11_20_105534) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -108,6 +108,7 @@ t.string "action_required_by", default: "none", null: false t.string "stage", default: "draft", null: false t.string "statuses", default: ["draft"], null: false, array: true + t.boolean "hidden_from_assessment", default: false, null: false t.index ["action_required_by"], name: "index_application_forms_on_action_required_by" t.index ["assessor_id"], name: "index_application_forms_on_assessor_id" t.index ["english_language_provider_id"], name: "index_application_forms_on_english_language_provider_id" diff --git a/spec/factories/application_forms.rb b/spec/factories/application_forms.rb index 3900fd9009..2f011356db 100644 --- a/spec/factories/application_forms.rb +++ b/spec/factories/application_forms.rb @@ -24,6 +24,7 @@ # given_names :text default(""), not null # has_alternative_name :boolean # has_work_history :boolean +# hidden_from_assessment :boolean default(FALSE), not null # identification_document_status :string default("not_started"), not null # needs_registration_number :boolean not null # needs_work_history :boolean not null diff --git a/spec/models/application_form_spec.rb b/spec/models/application_form_spec.rb index 4a7d6e3e8a..ebfe665180 100644 --- a/spec/models/application_form_spec.rb +++ b/spec/models/application_form_spec.rb @@ -24,6 +24,7 @@ # given_names :text default(""), not null # has_alternative_name :boolean # has_work_history :boolean +# hidden_from_assessment :boolean default(FALSE), not null # identification_document_status :string default("not_started"), not null # needs_registration_number :boolean not null # needs_work_history :boolean not null From 7195d83d0dd2b0560d319c77be51c00e372dbfb0 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Mon, 20 Nov 2023 11:53:02 +0000 Subject: [PATCH 2/4] Add hidden_from_assessment logic on submission --- app/services/submit_application_form.rb | 13 ++++- spec/services/submit_application_form_spec.rb | 58 +++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/app/services/submit_application_form.rb b/app/services/submit_application_form.rb index 94c6bd0335..4f1d6b7d09 100644 --- a/app/services/submit_application_form.rb +++ b/app/services/submit_application_form.rb @@ -13,10 +13,11 @@ def call ActiveRecord::Base.transaction do application_form.update!( - subjects: application_form.subjects.compact_blank, - working_days_since_submission: 0, + hidden_from_assessment:, requires_preliminary_check: region.requires_preliminary_check, + subjects: application_form.subjects.compact_blank, submitted_at: Time.zone.now, + working_days_since_submission: 0, ) assessment = AssessmentFactory.call(application_form:) @@ -75,4 +76,12 @@ def create_professional_standing_request(assessment) .create!(assessment:) .tap { |requestable| RequestRequestable.call(requestable:, user:) } end + + def hidden_from_assessment + region.country.code == "ZW" || + WorkHistoryDuration.for_application_form( + application_form, + consider_teaching_qualification: true, + ).count_months < 9 + end end diff --git a/spec/services/submit_application_form_spec.rb b/spec/services/submit_application_form_spec.rb index 5b67163257..b1417931e3 100644 --- a/spec/services/submit_application_form_spec.rb +++ b/spec/services/submit_application_form_spec.rb @@ -25,6 +25,64 @@ end end + describe "hidden_from_assessment column" do + context "when country is not Zimbabwe and work history is above 9 months" do + let(:region) { create(:region, :in_country, country_code: "FR") } + + before do + create( + :qualification, + application_form:, + certificate_date: Date.new(2019, 1, 1), + ) + create( + :work_history, + application_form:, + start_date: Date.new(2019, 1, 1), + end_date: Date.new(2020, 1, 1), + hours_per_week: 38, + ) + end + + it "doesn't hide the application form" do + expect { call }.to_not change(application_form, :hidden_from_assessment) + end + end + + context "when country is Zimbabwe" do + let(:region) { create(:region, :in_country, country_code: "ZW") } + + it "hides the application form" do + expect { call }.to change(application_form, :hidden_from_assessment).to( + true, + ) + end + end + + context "when work history considering qualification is less than 9 months" do + before do + create( + :qualification, + application_form:, + certificate_date: Date.new(2020, 1, 1), + ) + create( + :work_history, + application_form:, + start_date: Date.new(2019, 1, 1), + end_date: Date.new(2020, 1, 1), + hours_per_week: 38, + ) + end + + it "hides the application form" do + expect { call }.to change(application_form, :hidden_from_assessment).to( + true, + ) + end + end + end + describe "compacting blank subjects" do subject(:subjects) { application_form.subjects } From fcdd5a6a8ef58fc53052196192ae5d37207bcc8e Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Mon, 20 Nov 2023 11:58:07 +0000 Subject: [PATCH 3/4] Hide applications marked as hidden This ensures that applications which are marked as hidden are correctly not shown to assessors. --- app/models/application_form.rb | 18 ++++++++---------- spec/models/application_form_spec.rb | 8 ++++++++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/app/models/application_form.rb b/app/models/application_form.rb index f510bdb1c0..2c571f5e23 100644 --- a/app/models/application_form.rb +++ b/app/models/application_form.rb @@ -200,16 +200,14 @@ class ApplicationForm < ApplicationRecord scope :active, -> do - joins(region: :country) - .where.not(countries: { code: "ZW" }) - .merge( - assessable - .or(awarded_pending_checks) - .or(potential_duplicate_in_dqt) - .or(awarded.where("awarded_at >= ?", 90.days.ago)) - .or(declined.where("declined_at >= ?", 90.days.ago)) - .or(withdrawn.where("withdrawn_at >= ?", 90.days.ago)), - ) + where(hidden_from_assessment: false).merge( + assessable + .or(awarded_pending_checks) + .or(potential_duplicate_in_dqt) + .or(awarded.where("awarded_at >= ?", 90.days.ago)) + .or(declined.where("declined_at >= ?", 90.days.ago)) + .or(withdrawn.where("withdrawn_at >= ?", 90.days.ago)), + ) end scope :destroyable, diff --git a/spec/models/application_form_spec.rb b/spec/models/application_form_spec.rb index ebfe665180..76de498cf6 100644 --- a/spec/models/application_form_spec.rb +++ b/spec/models/application_form_spec.rb @@ -353,6 +353,14 @@ it { is_expected.to eq([application_form]) } end + + context "when hidden from assessment" do + before do + create(:application_form, :submitted, hidden_from_assessment: true) + end + + it { is_expected.to be_empty } + end end describe "#destroyable" do From 2056f5a7aaca21a21e431d1b6c014a8d187dd0fa Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Mon, 20 Nov 2023 12:14:02 +0000 Subject: [PATCH 4/4] Add application_forms:hidden_from_assessment task This is a task which updates the the value of the hidden_from_assessment column on applications which were already submitted and therefore didn't get the value set on submission. --- lib/tasks/application_forms.rake | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/tasks/application_forms.rake b/lib/tasks/application_forms.rake index 26448c1aab..bc05d4b29c 100644 --- a/lib/tasks/application_forms.rake +++ b/lib/tasks/application_forms.rake @@ -34,4 +34,36 @@ namespace :application_forms do puts "#{application_form.reference}: #{application_form.action_required_by} - #{application_form.status}" end end + + desc "Update hidden from assessment status for all application forms." + task update_hidden_from_assessment: :environment do |_task, _args| + zimbabwe_applications = + ApplicationForm.joins(region: :country).where(countries: { code: "ZW" }) + + puts "Zimbabwe: #{zimbabwe_applications.count}" + zimbabwe_applications.pluck(:reference).each { |reference| puts reference } + puts + + work_history_duration_applications = + ApplicationForm + .where(stage: %w[not_started pre_assessment], needs_work_history: true) + .select(&:created_under_new_regulations?) + .select do |application_form| + WorkHistoryDuration.for_application_form( + application_form, + consider_teaching_qualification: true, + ).count_months < 9 + end + + puts "Work history duration: #{work_history_duration_applications.count}" + work_history_duration_applications + .map(&:reference) + .each { |reference| puts reference } + + ApplicationForm.where( + id: + zimbabwe_applications.pluck(:id) + + work_history_duration_applications.map(&:id), + ).update_all(hidden_from_assessment: true) + end end