Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add consent fields to qualification requests #1976

Merged
merged 2 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/models/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def allow_multiple_uploads?
end

def optional?
written_statement? && application_form.written_statement_optional
(signed_consent? && !documentable.signed_consent_document_required) ||
(written_statement? && application_form.written_statement_optional)
end

def for_further_information_request?
Expand Down
30 changes: 30 additions & 0 deletions app/models/qualification_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
# Table name: qualification_requests
#
# id :bigint not null, primary key
# consent_received_at :datetime
# consent_requested_at :datetime
# expired_at :datetime
# location_note :text default(""), not null
# received_at :datetime
# requested_at :datetime
# 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 @@ -39,10 +42,37 @@ class QualificationRequest < ApplicationRecord

belongs_to :qualification

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) }
scope :consent_respondable,
-> do
consent_required
.consent_requested
.where(consent_received_at: nil)
.merge(ApplicationForm.assessable)
end

scope :order_by_role, -> { order("qualifications.start_date": :desc) }
scope :order_by_user, -> { order("qualifications.created_at": :asc) }

def expires_after
6.weeks
end

def consent_requested!
update!(consent_requested_at: Time.zone.now)
end

def consent_requested?
consent_requested_at != nil
end

def consent_received!
update!(consent_received_at: Time.zone.now)
end

def consent_received?
consent_received_at != nil
end
end
3 changes: 3 additions & 0 deletions config/analytics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@
- part_of_university_degree
:qualification_requests:
- assessment_id
- consent_received_at
- consent_requested_at
- created_at
- expired_at
- id
Expand All @@ -218,6 +220,7 @@
- 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,9 @@
class AddConsentToQualificationRequests < ActiveRecord::Migration[7.1]
def change
change_table :qualification_requests, bulk: true do |t|
t.datetime :consent_received_at
t.datetime :consent_requested_at
t.boolean :signed_consent_document_required, default: false, null: false
end
end
end
5 changes: 4 additions & 1 deletion db/schema.rb

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

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
custom_key: "Custom key value",
nil_value: nil,
boolean: true,
document: create(:document, :with_upload),
document: create(:document, :with_upload, document_type: :identification),
array: %w[a b c],
translatable_document:,
)
Expand Down
3 changes: 3 additions & 0 deletions spec/factories/qualification_requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
# Table name: qualification_requests
#
# id :bigint not null, primary key
# consent_received_at :datetime
# consent_requested_at :datetime
# expired_at :datetime
# location_note :text default(""), not null
# received_at :datetime
# requested_at :datetime
# 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
30 changes: 30 additions & 0 deletions spec/models/qualification_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
# Table name: qualification_requests
#
# id :bigint not null, primary key
# consent_received_at :datetime
# consent_requested_at :datetime
# expired_at :datetime
# location_note :text default(""), not null
# received_at :datetime
# requested_at :datetime
# 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 @@ -43,6 +46,9 @@
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) }

context "when received" do
subject { build(:qualification_request, :received) }

Expand All @@ -54,4 +60,28 @@
subject(:expires_after) { described_class.new.expires_after }
it { is_expected.to eq(6.weeks) }
end

describe "#consent_requested!" do
let(:call) { subject.consent_requested! }

it "sets the consent requested at date" do
freeze_time do
expect { call }.to change(subject, :consent_requested_at).from(nil).to(
Time.zone.now,
)
end
end
end

describe "#consent_received!" do
let(:call) { subject.consent_received! }

it "sets the consent received at date" do
freeze_time do
expect { call }.to change(subject, :consent_received_at).from(nil).to(
Time.zone.now,
)
end
end
end
end
Loading