Skip to content

Commit

Permalink
Merge pull request #1995 from DFE-Digital/consent-method
Browse files Browse the repository at this point in the history
Capture consent method more accurately
  • Loading branch information
thomasleese authored Feb 15, 2024
2 parents a6255d6 + 5e1294f commit 3dfcb47
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 12 deletions.
12 changes: 10 additions & 2 deletions app/mailers/teacher_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion app/models/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 18 additions & 2 deletions app/models/qualification_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -42,7 +42,19 @@ class QualificationRequest < ApplicationRecord

belongs_to :qualification

scope :consent_required, -> { where(signed_consent_document_required: true) }
enum consent_method: {
signed_ecctis: "signed_ecctis",
signed_institution: "signed_institution",
unknown: "unknown",
unsigned: "unsigned",
},
_prefix: 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,
Expand All @@ -62,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down
2 changes: 1 addition & 1 deletion config/analytics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
- part_of_university_degree
:qualification_requests:
- assessment_id
- consent_method
- consent_received_at
- consent_requested_at
- created_at
Expand All @@ -220,7 +221,6 @@
- review_note
- review_passed
- reviewed_at
- signed_consent_document_required
- unsigned_consent_document_downloaded
- updated_at
- verified_at
Expand Down
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions spec/factories/qualification_requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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(
Expand Down
16 changes: 15 additions & 1 deletion spec/models/qualification_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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) }
Expand Down

0 comments on commit 3dfcb47

Please sign in to comment.