Skip to content

Commit b64c45c

Browse files
authored
Fix inaccurate access logging in timeline ops tool
The access log entries were being recorded as an after_action. In conjunction with other logic which redirected with default parameters if some parameters were unset, this led to extra log entries being recorded, with incorrect details. This has been fixed by adjusting the sequencing of the access log recording, putting it inside the controller.
2 parents 0672d1f + 68cf1ab commit b64c45c

2 files changed

Lines changed: 19 additions & 13 deletions

File tree

app/controllers/inspect/timeline/patients_controller.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ class Inspect::Timeline::PatientsController < ApplicationController
66
skip_after_action :verify_policy_scoped
77
before_action :ensure_ops_tools_feature_enabled
88
before_action :set_patient
9-
after_action :record_access_log_entry
109

1110
layout "full"
1211

@@ -27,13 +26,12 @@ class Inspect::Timeline::PatientsController < ApplicationController
2726
def show
2827
set_pii_settings
2928

30-
params.reverse_merge!(event_names: DEFAULT_EVENT_NAMES)
3129
params[:audit_config] ||= {}
3230

33-
event_names = params[:event_names]
3431
compare_option = params[:compare_option] || nil
3532

36-
if params[:detail_config].blank?
33+
# Set default values if none present
34+
if params[:detail_config].blank? && params[:event_names].blank?
3735
default_details = TimelineRecords::DEFAULT_DETAILS_CONFIG
3836
new_params = params.to_unsafe_h.merge("detail_config" => default_details)
3937
redirect_to inspect_timeline_patient_path(new_params) and return
@@ -46,6 +44,13 @@ def show
4644
params[:audit_config][:include_filtered_audit_changes]
4745
}
4846

47+
@compare_patient = sample_patient(params[:compare_option]) if compare_option
48+
49+
record_access_log_entry
50+
51+
params.reverse_merge!(event_names: DEFAULT_EVENT_NAMES)
52+
event_names = params[:event_names]
53+
4954
@patient_timeline =
5055
TimelineRecords.new(
5156
@patient,
@@ -56,8 +61,6 @@ def show
5661

5762
@no_events_message = true if @patient_timeline.empty?
5863

59-
@compare_patient = sample_patient(params[:compare_option]) if compare_option
60-
6164
if @compare_patient == :invalid_patient
6265
@invalid_patient_id = true
6366
elsif @compare_patient
@@ -144,7 +147,7 @@ def pii_accessed?
144147
end
145148

146149
def audit_pii_accessed?
147-
true if @show_pii && params[:event_names].include?("audits")
150+
true if @show_pii && params[:event_names]&.include?("audits")
148151
end
149152

150153
def record_access_log_entry

spec/features/inspect_timeline_pii_access_logging_spec.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ def when_i_login_as_a_support_user_with_pii_access
9999
end
100100

101101
def and_i_visit_a_patient_timeline_with_pii_enabled
102-
visit inspect_timeline_patient_path(id: @patient.id, show_pii: "true")
102+
visit inspect_timeline_patient_path(
103+
id: @patient.id,
104+
show_pii: "true",
105+
event_names: ["audits"]
106+
)
103107
expect(page).to have_content("Customise timeline")
104108
end
105109

@@ -108,15 +112,14 @@ def and_i_visit_a_patient_timeline_with_pii_enabled_and_a_comparison_patient
108112
id: @patient.id,
109113
show_pii: "true",
110114
compare_option: "manual_entry",
111-
manual_patient_id: @compare_patient.id.to_s
115+
manual_patient_id: @compare_patient.id.to_s,
116+
event_names: ["audits"]
112117
)
113118
expect(page).to have_content("Customise timeline")
114119
end
115120

116121
def then_an_access_log_entry_is_created_for_the_patient
117-
# Two calls are made on first page load, so in this case (since we are visiting with show_pii: true),
118-
# two logs are created
119-
expect(@patient.access_log_entries.count).to eq(2)
122+
expect(@patient.access_log_entries.count).to eq(1)
120123
end
121124

122125
def and_the_access_log_entry_has_correct_attributes
@@ -125,7 +128,7 @@ def and_the_access_log_entry_has_correct_attributes
125128

126129
def then_access_log_entries_are_created_for_both_patients
127130
# Check main patient log
128-
expect(@patient.access_log_entries.count).to eq(2)
131+
expect(@patient.access_log_entries.count).to eq(1)
129132
verify_log_entry(@patient.access_log_entries.last)
130133

131134
# Check comparison patient log

0 commit comments

Comments
 (0)