Skip to content

Commit 2788b4c

Browse files
authored
Merge pull request #298 from projectblacklight/avoid_unpermitted_params_in_text_facet
hacky way to keep unpermitted params out of text range facet links
2 parents 87c5efc + be56b23 commit 2788b4c

File tree

3 files changed

+47
-10
lines changed

3 files changed

+47
-10
lines changed

app/presenters/blacklight_range_limit/facet_item_presenter.rb

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ def label
88
label_for_range || super
99
end
1010

11+
# Very hacky way to keep params used for ajax query for segments out
12+
# of our generated facet links. Sorry this seems to be the best way!
13+
#
14+
# https://github.com/projectblacklight/blacklight_range_limit/issues/296
15+
def href(path_options = {})
16+
override_to_nil = BlacklightRangeLimit::ControllerOverride::RANGE_LIMIT_FIELDS.collect { |f| [f, nil] }.to_h
17+
super(path_options.merge(override_to_nil))
18+
end
19+
1120
private
1221

1322
def label_for_range

lib/blacklight_range_limit/controller_override.rb

+7-10
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,18 @@ module ControllerOverride
88

99
RANGE_LIMIT_FIELDS = [:range_end, :range_field, :range_start].freeze
1010

11-
included do
12-
before_action do
13-
# Blacklight 7.25+: Allow range limit params if necessary
14-
if blacklight_config.search_state_fields
15-
missing_keys = RANGE_LIMIT_FIELDS - blacklight_config.search_state_fields
16-
blacklight_config.search_state_fields.concat(missing_keys)
17-
end
18-
end
19-
end
20-
2111
# Action method of our own!
2212
# Delivers a _partial_ that's a display of a single fields range facets.
2313
# Used when we need a second Solr query to get range facets, after the
2414
# first found min/max from result set.
2515
def range_limit
16+
# The builder in this action will need our special range_limit fields, so we
17+
# must allow them.
18+
if blacklight_config.search_state_fields
19+
missing_keys = RANGE_LIMIT_FIELDS - blacklight_config.search_state_fields
20+
blacklight_config.search_state_fields.concat(missing_keys)
21+
end
22+
2623
@facet = blacklight_config.facet_fields[params[:range_field]]
2724
raise ActionController::RoutingError, 'Not Found' unless @facet&.range
2825

spec/features/run_through_spec.rb

+31
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,35 @@
176176
end
177177
end
178178
end
179+
180+
context "Range Limit text facets" do
181+
# Make sure it works with strict permitted params
182+
around do |example|
183+
original = ActionController::Parameters.action_on_unpermitted_parameters
184+
ActionController::Parameters.action_on_unpermitted_parameters = :raise
185+
186+
example.run
187+
188+
ActionController::Parameters.action_on_unpermitted_parameters = original
189+
end
190+
191+
it "work with strict permitted params" do
192+
visit search_catalog_path
193+
194+
click_button 'Publication Date Sort'
195+
196+
from_val, to_val = nil, nil
197+
within ".facet-limit.blacklight-pub_date_si" do
198+
find("summary", text: "Range List").click
199+
200+
facet_link = first(".facet-values li a")
201+
from_val = facet_link.find("span[data-blrl-begin]")["data-blrl-begin"]
202+
to_val = facet_link.find("span[data-blrl-end]")["data-blrl-end"]
203+
204+
facet_link.click
205+
end
206+
207+
expect(page).to have_css(".applied-filter", text: /Publication Date Sort.*#{from_val} to #{to_val}/)
208+
end
209+
end
179210
end

0 commit comments

Comments
 (0)