Skip to content

Commit 2fa170c

Browse files
authored
5240 Fix flash cookie overflow when uploading CSV with many invalid NDBN members (#5283)
* Add memflash to prevent flash message cookie overflow * Update flash partial to support Memflash by using key-based access * Test error rendering on invalid CSV upload
1 parent 99478f9 commit 2fa170c

File tree

5 files changed

+39
-8
lines changed

5 files changed

+39
-8
lines changed

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ gem "filterrific"
6161
gem "jbuilder"
6262
# Pagination of models for use in views.
6363
gem "kaminari"
64+
# Prevents cookie overflow errors when storing large flash messages.
65+
gem 'memflash'
6466
# Web-based authorization framework.
6567
gem "omniauth"
6668
# Required to avoid authentication issues with Rails.

Gemfile.lock

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,11 @@ GEM
385385
net-smtp
386386
marcel (1.0.4)
387387
matrix (0.4.2)
388+
memflash (2.6.0)
389+
actionpack (>= 7.0)
388390
memory_profiler (1.1.0)
389391
method_source (1.1.0)
390392
mini_mime (1.1.5)
391-
mini_portile2 (2.8.9)
392393
minitest (5.25.5)
393394
monetize (1.12.0)
394395
money (~> 6.12)
@@ -419,9 +420,6 @@ GEM
419420
net-protocol
420421
newrelic_rpm (9.16.0)
421422
nio4r (2.7.4)
422-
nokogiri (1.18.8)
423-
mini_portile2 (~> 2.8.2)
424-
racc (~> 1.4)
425423
nokogiri (1.18.8-arm64-darwin)
426424
racc (~> 1.4)
427425
nokogiri (1.18.8-x86_64-darwin)
@@ -745,7 +743,6 @@ GEM
745743

746744
PLATFORMS
747745
arm64-darwin
748-
ruby
749746
x86_64-darwin
750747
x86_64-linux
751748
x86_64-linux-gnu
@@ -796,6 +793,7 @@ DEPENDENCIES
796793
lograge
797794
magic_test
798795
matrix
796+
memflash
799797
memory_profiler
800798
money-rails
801799
newrelic_rpm
@@ -843,4 +841,4 @@ DEPENDENCIES
843841
webmock (~> 3.25)
844842

845843
BUNDLED WITH
846-
2.6.9
844+
2.7.0

app/views/shared/_flash.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<%= turbo_frame_tag "flash" do %>
2-
<% flash.each do |key, message| %>
2+
<% flash.keys.each do |key| %>
33
<div
44
class="<%= flash_class(key) %> alert-dismissible"
55
role="alert"
6-
style="white-space: pre-line;"><%= message %></div>
6+
style="white-space: pre-line;"><%= flash[key] %></div>
77
<% end %>
88
<% end %>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
NDBN Member Number,Member Name
2+
,
3+
,
4+
,
5+
,
6+
,
7+
,
8+
,
9+
,
10+
,
11+
,
12+
,
13+
,
14+
,
15+
,
16+
,
17+
,

spec/system/admin/ndbn_members_system_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,18 @@
1010

1111
expect(page).to have_content("NDBN Members have been updated!")
1212
end
13+
14+
context "when uploading a CSV with many errors" do
15+
it "renders all error messages without cookie overflow" do
16+
user = create(:super_admin)
17+
sign_in(user)
18+
visit admin_ndbn_members_path
19+
20+
import_path = "#{Rails.root}/spec/fixtures/ndbn-many-errors-import.csv"
21+
attach_file("member_file", import_path)
22+
click_button "Upload"
23+
24+
expect(page).to have_content("NDBN member can't be blank")
25+
end
26+
end
1327
end

0 commit comments

Comments
 (0)