blacklight 7.27.1 → 7.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: efe58070e4ce9981945726f50566d4f37929bb487ba5bc62b8e6763804b6e015
4
- data.tar.gz: c0974d656e3be670ebd765eb8b725ca37178e2ec3c5524c668a0e554f7553439
3
+ metadata.gz: d7e57b2c0a5ca770fa8fbc0560072609b5db93d10c952d33af0db3d69ae2dfc6
4
+ data.tar.gz: 231146a7df38ba031b116075b75bf9abe7f91e760485524fb8678a624d9be893
5
5
  SHA512:
6
- metadata.gz: 5480cf9c3ce04ce4aac87f206cedcc22055f268616cd9015b0c22a0a245d14f43dba53959f8e479a3beb79e80df1f6ebf1dd8934169dfd4f75c18ddaf40d3f80
7
- data.tar.gz: 25dc3a66c69247973770f8481b5969312bf37ec58f84e08458e7e69f9419f0ba2a758b9e0212d8c2839f02a785be6379365ea7d621560b8ea345822bc66f45bf
6
+ metadata.gz: 95bc567df4947b3a11b37749c0c9a123da3c5a20552e78195a77775638bc5075d1db2c6d11d8158864346a1346a29a296a3ce8a873b497a9946eb011cd53843f
7
+ data.tar.gz: 28efc83fd658e1e43a3f85c8bea5ec389ee913b540b413ce967925b98b48a5d4d9422a2df1fcbf14d905ba0e31cba3fe9267a3cee38e6371adaf83b963183f41
@@ -76,11 +76,11 @@ jobs:
76
76
  - name: Install dependencies
77
77
  run: bundle install
78
78
  env:
79
- RAILS_VERSION: 6.0.3.7
79
+ RAILS_VERSION: 6.0.5.1
80
80
  - name: Run tests
81
81
  run: bundle exec rake ci
82
82
  env:
83
- RAILS_VERSION: 6.0.3.7
83
+ RAILS_VERSION: 6.0.5.1
84
84
  ENGINE_CART_RAILS_OPTIONS: '--skip-git --skip-listen --skip-spring --skip-keeps --skip-action-cable --skip-coffee --skip-test'
85
85
  test_rails5_2:
86
86
  runs-on: ubuntu-latest
@@ -96,11 +96,11 @@ jobs:
96
96
  - name: Install dependencies
97
97
  run: bundle install
98
98
  env:
99
- RAILS_VERSION: 5.2.4.6
99
+ RAILS_VERSION: 5.2.8.1
100
100
  - name: Run tests
101
101
  run: bundle exec rake ci
102
102
  env:
103
- RAILS_VERSION: 5.2.4.6
103
+ RAILS_VERSION: 5.2.8.1
104
104
  ENGINE_CART_RAILS_OPTIONS: '--skip-git --skip-listen --skip-spring --skip-keeps --skip-action-cable --skip-coffee --skip-test'
105
105
 
106
106
  test_rails6_1:
@@ -117,11 +117,11 @@ jobs:
117
117
  - name: Install dependencies
118
118
  run: bundle install
119
119
  env:
120
- RAILS_VERSION: 6.1.5
120
+ RAILS_VERSION: 6.1.6.1
121
121
  - name: Run tests
122
122
  run: bundle exec rake ci
123
123
  env:
124
- RAILS_VERSION: 6.1.5
124
+ RAILS_VERSION: 6.1.6.1
125
125
  ENGINE_CART_RAILS_OPTIONS: '--skip-git --skip-keeps --skip-action-cable --skip-test'
126
126
  api_test:
127
127
  runs-on: ubuntu-latest
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.27.1
1
+ 7.28.0
data/app/models/search.rb CHANGED
@@ -3,7 +3,8 @@
3
3
  class Search < ApplicationRecord
4
4
  belongs_to :user, optional: true
5
5
 
6
- serialize :query_params
6
+ # use a backwards-compatible serializer until the Rails API stabilizes and we can evaluate for major-revision compatibility
7
+ serialize :query_params, Blacklight::SearchParamsYamlCoder
7
8
 
8
9
  # A Search instance is considered a saved search if it has a user_id.
9
10
  def saved?
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Blacklight
4
+ # This is a custom YAML coder for (de)serializing blacklight search parameters that
5
+ # supports deserializing HashWithIndifferentAccess parameters (as was historically done by Blacklight).
6
+ class SearchParamsYamlCoder
7
+ # Serializes an attribute value to a string that will be stored in the database.
8
+ def self.dump(obj)
9
+ # Convert HWIA to an ordinary hash so we have some hope of using the regular YAML encoder in the future
10
+ obj = obj.to_hash if obj.is_a?(ActiveSupport::HashWithIndifferentAccess)
11
+
12
+ YAML.dump(obj)
13
+ end
14
+
15
+ # Deserializes a string from the database to an attribute value.
16
+ def self.load(yaml)
17
+ return yaml unless yaml.is_a?(String) && yaml.start_with?("---")
18
+
19
+ params = yaml_load(yaml)
20
+
21
+ params.with_indifferent_access
22
+ end
23
+
24
+ # rubocop:disable Security/YAMLLoad
25
+ if YAML.respond_to?(:unsafe_load)
26
+ def self.yaml_load(payload)
27
+ if ActiveRecord.try(:use_yaml_unsafe_load) || ActiveRecord::Base.try(:use_yaml_unsafe_load)
28
+ YAML.unsafe_load(payload)
29
+ else
30
+ permitted_classes = (ActiveRecord.try(:yaml_column_permitted_classes) || ActiveRecord::Base.try(:yaml_column_permitted_classes) || []) +
31
+ Blacklight::Engine.config.blacklight.search_params_permitted_classes
32
+ YAML.safe_load(payload, permitted_classes: permitted_classes, aliases: true)
33
+ end
34
+ end
35
+ else
36
+ def self.yaml_load(payload)
37
+ if ActiveRecord.try(:use_yaml_unsafe_load) || ActiveRecord::Base.try(:use_yaml_unsafe_load)
38
+ YAML.load(payload)
39
+ else
40
+ permitted_classes = (ActiveRecord.try(:yaml_column_permitted_classes) || ActiveRecord::Base.try(:yaml_column_permitted_classes) || []) +
41
+ Blacklight::Engine.config.blacklight.search_params_permitted_classes
42
+ YAML.safe_load(payload, permitted_classes: permitted_classes, aliases: true)
43
+ end
44
+ end
45
+ end
46
+ # rubocop:enable Security/YAMLLoad
47
+ end
48
+ end
@@ -59,6 +59,8 @@ module Blacklight
59
59
  outer_window: 2
60
60
  }
61
61
 
62
+ bl_global_config.search_params_permitted_classes = [ActiveSupport::HashWithIndifferentAccess, Symbol]
63
+
62
64
  # Anything that goes into Blacklight::Engine.config is stored as a class
63
65
  # variable on Railtie::Configuration. we're going to encapsulate all the
64
66
  # Blacklight specific stuff in this single struct:
@@ -1,32 +1,51 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe Search do
4
+ let(:search) { described_class.new(user: user) }
4
5
  let(:user) { User.create! email: 'xyz@example.com', password: 'xyz12345' }
6
+ let(:hash_params) { { q: "query", f: { facet: "filter" } } }
7
+ let(:query_params) { hash_params }
5
8
 
6
9
  describe "query_params" do
7
- before do
8
- @search = described_class.new(user: user)
9
- @query_params = { q: "query", f: "facet" }
10
+ shared_examples "persisting query_params" do
11
+ it "can save and retrieve the hash" do
12
+ search.query_params = query_params
13
+ search.save!
14
+ expect(described_class.find(search.id).query_params).to eq query_params.with_indifferent_access
15
+ end
10
16
  end
11
17
 
12
- it "can save and retrieve the hash" do
13
- @search.query_params = @query_params
14
- @search.save!
15
- expect(described_class.find(@search.id).query_params).to eq @query_params
18
+ context "are an indifferent hash" do
19
+ include_context "persisting query_params" do
20
+ let(:query_params) { hash_params.with_indifferent_access }
21
+ end
22
+ end
23
+
24
+ context "are a string-keyed hash" do
25
+ include_context "persisting query_params" do
26
+ let(:query_params) { hash_params.with_indifferent_access.to_hash }
27
+ end
28
+ end
29
+
30
+ context "include symbol keys" do
31
+ include_context "persisting query_params" do
32
+ let(:query_params) { hash_params }
33
+ end
16
34
  end
17
35
  end
18
36
 
19
37
  describe "saved?" do
20
38
  it "is true when user_id is not NULL and greater than 0" do
21
- @search = described_class.new(user: user)
22
- @search.save!
23
-
24
- expect(@search).to be_saved
39
+ search.save!
40
+ expect(search).to be_saved
25
41
  end
26
42
 
27
- it "is false when user_id is NULL or less than 1" do
28
- @search = described_class.create
29
- expect(@search).not_to be_saved
43
+ context "when user_id is NULL or less than 1" do
44
+ let(:search) { described_class.create }
45
+
46
+ it "is false" do
47
+ expect(search).not_to be_saved
48
+ end
30
49
  end
31
50
  end
32
51
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blacklight
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.27.1
4
+ version: 7.28.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Rochkind
@@ -14,10 +14,10 @@ authors:
14
14
  - Dan Funk
15
15
  - Naomi Dushay
16
16
  - Justin Coyne
17
- autorequire:
17
+ autorequire:
18
18
  bindir: exe
19
19
  cert_chain: []
20
- date: 2022-07-07 00:00:00.000000000 Z
20
+ date: 2022-07-13 00:00:00.000000000 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: rails
@@ -577,6 +577,7 @@ files:
577
577
  - app/presenters/blacklight/thumbnail_presenter.rb
578
578
  - app/services/blacklight/document_factory.rb
579
579
  - app/services/blacklight/field_retriever.rb
580
+ - app/services/blacklight/search_params_yaml_coder.rb
580
581
  - app/services/blacklight/search_service.rb
581
582
  - app/values/blacklight/types.rb
582
583
  - app/views/blacklight/nav/_bookmark.html.erb
@@ -933,7 +934,7 @@ homepage: http://projectblacklight.org/
933
934
  licenses:
934
935
  - Apache 2.0
935
936
  metadata: {}
936
- post_install_message:
937
+ post_install_message:
937
938
  rdoc_options: []
938
939
  require_paths:
939
940
  - lib
@@ -948,8 +949,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
948
949
  - !ruby/object:Gem::Version
949
950
  version: '0'
950
951
  requirements: []
951
- rubygems_version: 3.1.2
952
- signing_key:
952
+ rubygems_version: 3.2.32
953
+ signing_key:
953
954
  specification_version: 4
954
955
  summary: Blacklight provides a discovery interface for any Solr (http://lucene.apache.org/solr)
955
956
  index.