Skip to content

Commit f07ec28

Browse files
cbaudouinjrsemantic-release-botJeremyRudmandependabot[bot]
authored
fix(questionnaire): Fixes error when trying to view a questionnaire modified by a deleted admin (#238)
* fix(dashboard): Fixes security vulnerability that allowed event_tracking role to access Dashboard (#215) * chore(release): 1.22.3 [skip ci] ## [1.22.3](v1.22.2...v1.22.3) (2020-05-16) ### Bug Fixes * **dashboard:** Fixes security vulnerability that allowed event_tracking role to access Dashboard ([#215](#215)) ([](74a40ad)) ### Styles * **check-in:** Changes table header to be more descriptive ([#207](#207)) ([](889fbd0)) * **config:** Removes unused event_is_over flag ([#208](#208)) ([](0c73e66)) * build(deps): Upgrade yarn (#212) * build(deps): Upgrade yarn * build(deps): Upgrade gems * build(deps): Remove obsolete gems * v0.0.0 * build(deps): Update semantic-release * fix(questionnaire): visual bug in school autocomplete school dropdown the css was set for an "a" tag when the list was made up of divs so I switched the css to work for the "div" tag in the autocomplete * fix(questionnaire): visual bug in school autocomplete school dropdown the css was set for an "a" tag when the list was made up of divs so I switched the css to work for the "div" tag in the autocomplete. I also hide a element that was not present earlier * build(deps): Upgrades Rails to 5.2.4.3 * build(deps): Upgrades gems Co-authored-by: Jeremy Rudman <[email protected]> * build(deps): Bump puma from 4.3.4 to 4.3.5 (#219) Bumps [puma](https://github.com/puma/puma) from 4.3.4 to 4.3.5. - [Release notes](https://github.com/puma/puma/releases) - [Changelog](https://github.com/puma/puma/blob/master/History.md) - [Commits](https://github.com/puma/puma/commits) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): Upgrades Puma cache (#221) * fix(questionnaire): Fixes error when trying to view a questionnaire modified by a deleted admin * refactor(tests): Cleans verbage of tests to match Co-authored-by: semantic-release-bot <[email protected]> Co-authored-by: Jeremy Rudman <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent 2808058 commit f07ec28

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

app/helpers/audit_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ def display_audit_value(value, field)
33
return "(none)" if value.blank?
44
return Questionnaire::POSSIBLE_ACC_STATUS[value] if field == "acc_status"
55
return BusList.find(value)&.name || value if field == "bus_list_id"
6-
return User.find(value)&.full_name || value if field == "checked_in_by_id"
6+
return User.find_by_id(value)&.full_name || "(deleted user)" if field == "checked_in_by_id"
77
return value.join(", ") if value.is_a? Array
88
return display_datetime(value, relative: false) if value.is_a? Time
99

app/models/questionnaire.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def date_of_birth_formatted
159159

160160
def acc_status_author
161161
return unless acc_status_author_id.present?
162-
User.find(acc_status_author_id)
162+
User.find_by_id(acc_status_author_id)
163163
end
164164

165165
def checked_in?
@@ -172,7 +172,7 @@ def boarded_bus?
172172

173173
def checked_in_by
174174
return unless checked_in_by_id.present?
175-
User.find(checked_in_by_id)
175+
User.find_by_id(checked_in_by_id)
176176
end
177177

178178
def fips_code

app/views/manage/questionnaires/_checkin_card.html.haml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55
= render 'manage/questionnaires/check_in_badge'
66
- if @questionnaire.checked_in_at
77
%small
8-
= @questionnaire.checked_in_by_id ? @questionnaire.checked_in_by.email : "(never checked in)"
8+
- if @questionnaire.checked_in_by_id
9+
- if @questionnaire.checked_in_by
10+
= @questionnaire.checked_in_by.email
11+
- else
12+
= "(deleted user)"
13+
- else
14+
= "(never checked in)"
915
= @questionnaire.checked_in_at ? display_datetime(@questionnaire.checked_in_at, in_sentence: true) : "(not checked in)"
1016
- if [email protected]_in_at
1117
%p.card-text

app/views/manage/questionnaires/show.html.haml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@
3232
%p.card-text
3333
= render 'acc_status_badge'
3434
%small
35-
= @questionnaire.acc_status_author_id ? @questionnaire.acc_status_author.email : "(no author)"
35+
- if @questionnaire.acc_status_author_id
36+
- if @questionnaire.acc_status_author
37+
= @questionnaire.acc_status_author.email
38+
- else
39+
= "(deleted user)"
40+
- else
41+
= "(no author)"
3642
= @questionnaire.acc_status_date ? display_datetime(@questionnaire.acc_status_date, in_sentence: true) : "(no date)"
3743
- if current_user.admin?
3844
= bs_vertical_simple_form @questionnaire, url: url_for(action: "update_acc_status", controller: "questionnaires") do |f|

test/models/questionnaire_test.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,13 @@ class QuestionnaireTest < ActiveSupport::TestCase
204204
assert_nil questionnaire.acc_status_author
205205
end
206206

207+
should "return nil if author deleted" do
208+
user = create(:user, email: "[email protected]")
209+
questionnaire = create(:questionnaire, acc_status_author_id: user.id)
210+
user.destroy
211+
assert_nil questionnaire.acc_status_author
212+
end
213+
207214
should "return the questionnaire's user" do
208215
user = create(:user, email: "[email protected]")
209216
questionnaire = create(:questionnaire, acc_status_author_id: user.id)
@@ -396,12 +403,19 @@ class QuestionnaireTest < ActiveSupport::TestCase
396403
end
397404

398405
context "#checked_in_by" do
399-
should "return no one if not checked in" do
406+
should "return nil if not checked in" do
400407
questionnaire = create(:questionnaire)
401408
assert_nil questionnaire.checked_in_by
402409
assert_nil questionnaire.checked_in_by_id
403410
end
404411

412+
should "return nil if user who checked-in questionnaire is deleted" do
413+
user = create(:user)
414+
questionnaire = create(:questionnaire, checked_in_by_id: user.id)
415+
user.destroy
416+
assert_nil questionnaire.checked_in_by
417+
end
418+
405419
should "return user who checked in ther questionnaire" do
406420
user = create(:user)
407421
questionnaire = create(:questionnaire, checked_in_by_id: user.id)

0 commit comments

Comments
 (0)