-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2687 from barmintor/7.x-delegate-normalization-to…
…-filters 7.x delegate normalization to filters
- Loading branch information
Showing
17 changed files
with
265 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# frozen_string_literal: true | ||
|
||
module Blacklight | ||
module Deprecations | ||
module SearchStateNormalization | ||
extend ActiveSupport::Concern | ||
|
||
class_methods do | ||
def facet_params_need_normalization(facet_params) | ||
Deprecation.warn(self, 'Calling `facet_params_need_normalization` on the Blacklight::SearchState ' \ | ||
'class is deprecated and will be removed in Blacklight 8. Delegate to #needs_normalization?(value_params) on the ' \ | ||
'filter fields of the search state object.') | ||
|
||
facet_params.is_a?(Hash) && facet_params.values.any? { |x| x.is_a?(Hash) } | ||
end | ||
|
||
def normalize_facet_params(facet_params) | ||
Deprecation.warn(self, 'Calling `normalize_facet_params` on the Blacklight::SearchState ' \ | ||
'class is deprecated and will be removed in Blacklight 8. Delegate to #normalize(value_params) on the ' \ | ||
'filter fields of the search state object.') | ||
|
||
facet_params.transform_values { |value| value.is_a?(Hash) ? value.values : value } | ||
end | ||
|
||
def normalize_params(untrusted_params = {}) | ||
Deprecation.warn(self, 'Calling `normalize_params` on the Blacklight::SearchState ' \ | ||
'class is deprecated and will be removed in Blacklight 8. Call #normalize_params on the ' \ | ||
'search state object.') | ||
params = untrusted_params | ||
|
||
if params.respond_to?(:to_unsafe_h) | ||
# This is the typical (not-ActionView::TestCase) code path. | ||
params = params.to_unsafe_h | ||
# In Rails 5 to_unsafe_h returns a HashWithIndifferentAccess, in Rails 4 it returns Hash | ||
params = params.with_indifferent_access if params.instance_of? Hash | ||
elsif params.is_a? Hash | ||
# This is an ActionView::TestCase workaround for Rails 4.2. | ||
params = params.dup.with_indifferent_access | ||
else | ||
params = params.dup.to_h.with_indifferent_access | ||
end | ||
|
||
# Normalize facet parameters mangled by facebook | ||
params[:f] = normalize_facet_params(params[:f]) if facet_params_need_normalization(params[:f]) | ||
params[:f_inclusive] = normalize_facet_params(params[:f_inclusive]) if facet_params_need_normalization(params[:f_inclusive]) | ||
|
||
params | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.