Skip to content

Commit e8375c4

Browse files
committed
Fix label for MMR consent form download
This ensures that we use the "MMR" label and not "MMR(V)" as the consent form is specific to the MMR variant and cannot be used for MMRV. I've also refactored the code related to downloading consent forms to make it simpler. Jira-Issue: MAV-2963
1 parent 249132f commit e8375c4

6 files changed

Lines changed: 46 additions & 39 deletions

File tree

app/components/app_session_summary_component.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,9 @@ def online_consent_links
174174

175175
def download_consent_links
176176
session.programmes.map do |programme|
177-
link_to(
178-
"Download the #{programme.name} consent form (PDF)",
179-
consent_form_programme_path(programme)
180-
)
177+
name = I18n.t(programme.type, scope: :programme_types)
178+
label = "Download the #{name} consent form (PDF)"
179+
link_to(label, consent_form_programme_path(programme))
181180
end
182181
end
183182

app/controllers/programmes_controller.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ def index
99
@programmes = current_user.programmes
1010
end
1111

12+
CONSENT_FORM_TYPES = %w[flu hpv menacwy mmr td_ipv].freeze
13+
1214
def consent_form
13-
programme =
14-
authorize(current_user.programmes.find { it.type == params[:type] })
15-
16-
send_file(
17-
"public/consent_forms/#{programme.type}.pdf",
18-
filename: "#{programme.name} Consent Form.pdf",
19-
disposition: "attachment"
20-
)
15+
type = params[:type]
16+
17+
raise ActiveRecord::RecordNotFound unless CONSENT_FORM_TYPES.include?(type)
18+
19+
path = "public/consent_forms/#{type}.pdf"
20+
name = I18n.t(type, scope: :programme_types)
21+
filename = "#{name} Consent Form.pdf"
22+
23+
send_file(path, filename:, disposition: "attachment")
2124
end
2225
end

app/policies/programme_policy.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@ class ProgrammePolicy < ApplicationPolicy
44
def sessions? = index?
55

66
def patients = index?
7-
8-
def consent_form? = show?
97
end

config/brakeman.ignore

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,4 @@
11
{
2-
"ignored_warnings": [
3-
{
4-
"warning_type": "File Access",
5-
"warning_code": 16,
6-
"fingerprint": "d1c86d018389c98f1e79ce464b868fda33c00e382a08bd1eee9d678f2480e7fc",
7-
"check_name": "SendFile",
8-
"message": "Model attribute used in file name",
9-
"file": "app/controllers/programmes_controller.rb",
10-
"line": 14,
11-
"link": "https://brakemanscanner.org/docs/warning_types/file_access/",
12-
"code": "send_file(\"public/consent_forms/#{authorize(current_user.programmes.find do\n (it.type == params[:type])\n end).type}.pdf\", :filename => (\"#{authorize(current_user.programmes.find do\n (it.type == params[:type])\n end).name} Consent Form.pdf\"), :disposition => \"attachment\")",
13-
"render_path": null,
14-
"location": {
15-
"type": "method",
16-
"class": "ProgrammesController",
17-
"method": "consent_form"
18-
},
19-
"user_input": "current_user.programmes.find",
20-
"confidence": "Weak",
21-
"cwe_id": [
22-
22
23-
],
24-
"note": "Programme names/types come from a limited set of enums."
25-
}
26-
],
2+
"ignored_warnings": [],
273
"brakeman_version": "7.1.1"
284
}

spec/components/app_session_summary_component_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,13 @@
4949
)
5050
end
5151
end
52+
53+
context "for MMR(V) programme" do
54+
before { Flipper.enable(:mmrv) }
55+
56+
let(:programmes) { [Programme.mmr] }
57+
58+
it { should have_link("Download the MMR consent form (PDF)") }
59+
end
5260
end
5361
end

spec/requests/programmes_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
3+
describe "Programmes" do
4+
let(:team) { create(:team) }
5+
let(:nurse) { create(:nurse, teams: [team]) }
6+
7+
describe "downloading consent form" do
8+
let(:path) { "/programmes/mmr/consent-form" }
9+
10+
before do
11+
sign_in nurse
12+
2.times { follow_redirect! }
13+
end
14+
15+
it "downloads a PDF file with a suitable filename" do
16+
get path
17+
expect(response.headers["Content-Type"]).to eq("application/pdf")
18+
expect(response.headers["Content-Disposition"]).to include(
19+
"filename=\"MMR Consent Form.pdf\""
20+
)
21+
end
22+
end
23+
end

0 commit comments

Comments
 (0)