From 16cc025390563867fce4478837204c6849242a59 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Thu, 15 Feb 2024 10:01:05 +0100 Subject: [PATCH 1/3] Add consent_method column This replaces the signed_consent_document_required column so we can capture the different types of consent methods. --- app/models/qualification_request.rb | 2 +- config/analytics.yml | 2 +- ...24_add_consent_method_to_qualification_requests.rb | 11 +++++++++++ db/schema.rb | 4 ++-- spec/factories/qualification_requests.rb | 2 +- spec/models/qualification_request_spec.rb | 2 +- 6 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20240215085624_add_consent_method_to_qualification_requests.rb diff --git a/app/models/qualification_request.rb b/app/models/qualification_request.rb index 32cce94642..8e7acf98d1 100644 --- a/app/models/qualification_request.rb +++ b/app/models/qualification_request.rb @@ -5,6 +5,7 @@ # Table name: qualification_requests # # id :bigint not null, primary key +# consent_method :string default("unknown"), not null # consent_received_at :datetime # consent_requested_at :datetime # expired_at :datetime @@ -14,7 +15,6 @@ # review_note :string default(""), not null # review_passed :boolean # reviewed_at :datetime -# signed_consent_document_required :boolean default(FALSE), not null # unsigned_consent_document_downloaded :boolean default(FALSE), not null # verified_at :datetime # verify_note :text default(""), not null diff --git a/config/analytics.yml b/config/analytics.yml index 62107a3d08..3107cf8314 100644 --- a/config/analytics.yml +++ b/config/analytics.yml @@ -208,6 +208,7 @@ - part_of_university_degree :qualification_requests: - assessment_id + - consent_method - consent_received_at - consent_requested_at - created_at @@ -220,7 +221,6 @@ - review_note - review_passed - reviewed_at - - signed_consent_document_required - unsigned_consent_document_downloaded - updated_at - verified_at diff --git a/db/migrate/20240215085624_add_consent_method_to_qualification_requests.rb b/db/migrate/20240215085624_add_consent_method_to_qualification_requests.rb new file mode 100644 index 0000000000..84ced9a870 --- /dev/null +++ b/db/migrate/20240215085624_add_consent_method_to_qualification_requests.rb @@ -0,0 +1,11 @@ +class AddConsentMethodToQualificationRequests < ActiveRecord::Migration[7.1] + def change + change_table :qualification_requests, bulk: true do |t| + t.remove :signed_consent_document_required, + type: :boolean, + default: false, + null: false + t.string :consent_method, default: "unknown", null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 70789b1b81..2331ab992b 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: 2024_02_08_101256) do +ActiveRecord::Schema[7.1].define(version: 2024_02_15_085624) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -292,7 +292,7 @@ t.boolean "unsigned_consent_document_downloaded", default: false, null: false t.datetime "consent_received_at" t.datetime "consent_requested_at" - t.boolean "signed_consent_document_required", default: false, null: false + t.string "consent_method", default: "unknown", null: false t.index ["assessment_id"], name: "index_qualification_requests_on_assessment_id" t.index ["qualification_id"], name: "index_qualification_requests_on_qualification_id" end diff --git a/spec/factories/qualification_requests.rb b/spec/factories/qualification_requests.rb index 04294bc49d..54dc5fa362 100644 --- a/spec/factories/qualification_requests.rb +++ b/spec/factories/qualification_requests.rb @@ -5,6 +5,7 @@ # Table name: qualification_requests # # id :bigint not null, primary key +# consent_method :string default("unknown"), not null # consent_received_at :datetime # consent_requested_at :datetime # expired_at :datetime @@ -14,7 +15,6 @@ # review_note :string default(""), not null # review_passed :boolean # reviewed_at :datetime -# signed_consent_document_required :boolean default(FALSE), not null # unsigned_consent_document_downloaded :boolean default(FALSE), not null # verified_at :datetime # verify_note :text default(""), not null diff --git a/spec/models/qualification_request_spec.rb b/spec/models/qualification_request_spec.rb index 45768f6c2f..003d4d864a 100644 --- a/spec/models/qualification_request_spec.rb +++ b/spec/models/qualification_request_spec.rb @@ -5,6 +5,7 @@ # Table name: qualification_requests # # id :bigint not null, primary key +# consent_method :string default("unknown"), not null # consent_received_at :datetime # consent_requested_at :datetime # expired_at :datetime @@ -14,7 +15,6 @@ # review_note :string default(""), not null # review_passed :boolean # reviewed_at :datetime -# signed_consent_document_required :boolean default(FALSE), not null # unsigned_consent_document_downloaded :boolean default(FALSE), not null # verified_at :datetime # verify_note :text default(""), not null From 8715d12fd9ac0eb59002b708da067e7d9c1a5eb2 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Thu, 15 Feb 2024 10:05:42 +0100 Subject: [PATCH 2/3] Define consent_method enum This ensures that the consent method enum is defined on the model. --- app/models/qualification_request.rb | 8 ++++++++ spec/models/qualification_request_spec.rb | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/app/models/qualification_request.rb b/app/models/qualification_request.rb index 8e7acf98d1..621ead6d8a 100644 --- a/app/models/qualification_request.rb +++ b/app/models/qualification_request.rb @@ -42,6 +42,14 @@ class QualificationRequest < ApplicationRecord belongs_to :qualification + enum consent_method: { + signed_ecctis: "signed_ecctis", + signed_institution: "signed_institution", + unknown: "unknown", + unsigned: "unsigned", + }, + _prefix: true + scope :consent_required, -> { where(signed_consent_document_required: true) } scope :consent_requested, -> { where.not(consent_requested_at: nil) } scope :consent_received, -> { where.not(consent_received_at: nil) } diff --git a/spec/models/qualification_request_spec.rb b/spec/models/qualification_request_spec.rb index 003d4d864a..e99ae97e22 100644 --- a/spec/models/qualification_request_spec.rb +++ b/spec/models/qualification_request_spec.rb @@ -45,6 +45,20 @@ subject { create(:qualification_request, :receivable) } end + describe "columns" do + it do + is_expected.to define_enum_for(:consent_method) + .with_values( + signed_ecctis: "signed_ecctis", + signed_institution: "signed_institution", + unknown: "unknown", + unsigned: "unsigned", + ) + .with_prefix + .backed_by_column_of_type(:string) + end + end + describe "validations" do it { is_expected.to_not validate_presence_of(:consent_requested_at) } it { is_expected.to_not validate_presence_of(:consent_received_at) } From 5e1294f8896bbc757c01c8ab855776dc0b6d4295 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Thu, 15 Feb 2024 10:12:50 +0100 Subject: [PATCH 3/3] Replace reference to signed_consent_document_required This column has gone now and been replaced with the consent_method column. --- app/mailers/teacher_mailer.rb | 12 ++++++++++-- app/models/document.rb | 2 +- app/models/qualification_request.rb | 10 +++++++++- .../application_form_view_object.rb | 2 +- spec/factories/qualification_requests.rb | 2 +- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/mailers/teacher_mailer.rb b/app/mailers/teacher_mailer.rb index 7c83828e3a..81898ed6e4 100644 --- a/app/mailers/teacher_mailer.rb +++ b/app/mailers/teacher_mailer.rb @@ -58,7 +58,11 @@ def application_received def consent_reminder @expires_at = - assessment.qualification_requests.consent_required.map(&:expires_at).max + assessment + .qualification_requests + .signed_consent_required + .map(&:expires_at) + .max view_mail( GOVUK_NOTIFY_TEMPLATE_ID, @@ -69,7 +73,11 @@ def consent_reminder def consent_requested @expires_at = - assessment.qualification_requests.consent_required.map(&:expires_at).max + assessment + .qualification_requests + .signed_consent_required + .map(&:expires_at) + .max view_mail( GOVUK_NOTIFY_TEMPLATE_ID, diff --git a/app/models/document.rb b/app/models/document.rb index 1179fd742c..1dd7acba80 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -68,7 +68,7 @@ def allow_multiple_uploads? end def optional? - (signed_consent? && !documentable.signed_consent_document_required) || + (signed_consent? && !documentable.signed_consent_required?) || (written_statement? && application_form.written_statement_optional) end diff --git a/app/models/qualification_request.rb b/app/models/qualification_request.rb index 621ead6d8a..5de3d25f54 100644 --- a/app/models/qualification_request.rb +++ b/app/models/qualification_request.rb @@ -50,7 +50,11 @@ class QualificationRequest < ApplicationRecord }, _prefix: true - scope :consent_required, -> { where(signed_consent_document_required: true) } + scope :signed_consent_required, + -> do + consent_method_signed_ecctis.or(consent_method_signed_institution) + end + scope :consent_requested, -> { where.not(consent_requested_at: nil) } scope :consent_received, -> { where.not(consent_received_at: nil) } scope :consent_respondable, @@ -70,6 +74,10 @@ def expires_after 6.weeks end + def signed_consent_required? + consent_method_signed_ecctis? || consent_method_signed_institution? + end + def consent_requested! update!(consent_requested_at: Time.zone.now) end diff --git a/app/view_objects/teacher_interface/application_form_view_object.rb b/app/view_objects/teacher_interface/application_form_view_object.rb index 46c87d7339..d826c0fb7a 100644 --- a/app/view_objects/teacher_interface/application_form_view_object.rb +++ b/app/view_objects/teacher_interface/application_form_view_object.rb @@ -156,7 +156,7 @@ def qualification_consent_submitted? return false if assessment.nil? required_qualification_requests = - qualification_requests.where(signed_consent_document_required: true) + qualification_requests.signed_consent_required return false if required_qualification_requests.empty? diff --git a/spec/factories/qualification_requests.rb b/spec/factories/qualification_requests.rb index 54dc5fa362..067f2b5d2b 100644 --- a/spec/factories/qualification_requests.rb +++ b/spec/factories/qualification_requests.rb @@ -40,7 +40,7 @@ association :qualification, :completed trait :consent_required do - signed_consent_document_required { true } + consent_method { %i[signed_ecctis signed_institution].sample } after(:create) do |qualification_request, _evaluator| create(