hydra-core 11.0.7 → 12.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 48a71594d8de39dff69d7e47ef1ca37a64b01561a1dd5e3964aaa565fb6b1545
4
- data.tar.gz: 293035dce7f62b1d15d30b0d0eaa4b3c2eab19def07be5b47f8d80fb9541ad58
3
+ metadata.gz: 1526f51c35bb1860b0b6fffaf25efbab4e5fa98003f51c2b0fabea8a7e9344a2
4
+ data.tar.gz: b15fd6c31ddc3c984f37aa836b1b9c90328ba1a09eecc902d5321c0cbda57553
5
5
  SHA512:
6
- metadata.gz: ab58eb7d50b0041a7dfd0ee8d5f455948ad5ba905b7f201c1e3336cdb080f93368d548f31fa2e39a68b3166ad46b7e5a842fd60d873fd6cc4afdd3c0f6b78dfc
7
- data.tar.gz: 9db6a6c4c37550bdff0f4b34ae9c05708770ff2d2eff8043a5fee5769015fe86cf3145df7db16a7e6799436b0912d76f9c02fd11fcc76b8971797412dfd2c2e5
6
+ metadata.gz: 3bd1fb8901ad1cb6f8d5be069774d07812ff58a96dc6233fd0cdf4530950b57a048eaf756e4442cb20d2f034d6fb4bcf4a7966fa3c308969c447cd96cb53762d
7
+ data.tar.gz: 6b9c0cd70b5503eb9a9fb32ef7f5bbe8562cafa4cb055e84e8a3055002f0ea4b5e69b0e2146e60e78ff66c57b3ca2e7e2c5295da8d3bea6ffea61f8abd82deef
@@ -3,6 +3,10 @@ module Hydra::Catalog
3
3
  include Blacklight::Catalog
4
4
  include Blacklight::AccessControls::Catalog
5
5
 
6
+ included do
7
+ self.search_service_class = Hydra::SearchService if respond_to?(:search_service_class)
8
+ end
9
+
6
10
  # Action-specific enforcement
7
11
  # Controller "before" filter for enforcing access controls on show actions
8
12
  # @param [Hash] opts (optional, not currently used)
@@ -20,4 +24,13 @@ module Hydra::Catalog
20
24
 
21
25
  permissions_doc
22
26
  end
27
+
28
+ # @return [Hash] a hash of context information to pass through to the search service
29
+ def search_service_context
30
+ ((super if defined?(super)) || {}).merge(hydra_search_service_context)
31
+ end
32
+
33
+ def hydra_search_service_context
34
+ { current_ability: current_ability }
35
+ end
23
36
  end
@@ -80,7 +80,9 @@ module Hydra
80
80
  # Override this if you'd like a different filename
81
81
  # @return [String] the filename
82
82
  def file_name
83
- params[:filename] || file.original_name || (asset.respond_to?(:label) && asset.label) || file.id
83
+ fname = params[:filename] || file.original_name || (asset.respond_to?(:label) && asset.label) || file.id
84
+ fname = URI.unescape(fname) if Rails.version >= '6.0'
85
+ fname
84
86
  end
85
87
 
86
88
 
@@ -1,4 +1,5 @@
1
1
  module BlacklightHelper
2
+ include Blacklight::CatalogHelperBehavior
2
3
  include Hydra::BlacklightHelperBehavior
3
4
  end
4
5
 
@@ -16,11 +16,7 @@ module Hydra
16
16
  # => 'text_pdf'
17
17
  def type_field_to_partial_name(document, display_type)
18
18
  str = Array(display_type).join(' '.freeze).underscore
19
- if Rails.version >= '5.0.0'
20
- str.parameterize(separator: '_'.freeze)
21
- else
22
- str.parameterize('_'.freeze)
23
- end
19
+ str.parameterize(separator: '_'.freeze)
24
20
  end
25
21
  end
26
22
  end
@@ -0,0 +1,6 @@
1
+ module Hydra
2
+ class SearchBuilder < Blacklight::SearchBuilder
3
+ # Add a filter query to restrict the search to documents the current user has access to
4
+ include Hydra::AccessControlsEnforcement
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hydra
4
+ # Returns AdminSets that the current user has permission to use.
5
+ class SearchService < Blacklight::SearchService
6
+ def current_ability
7
+ context[:current_ability]
8
+ end
9
+ end
10
+ end
data/hydra-core.gemspec CHANGED
@@ -19,9 +19,9 @@ Gem::Specification.new do |gem|
19
19
  gem.required_ruby_version = '>= 2.4'
20
20
 
21
21
  gem.add_dependency 'hydra-access-controls', version
22
- gem.add_dependency "railties", '>= 4.0.0', '< 6'
22
+ gem.add_dependency "railties", '>= 5.2', '< 7'
23
23
 
24
24
  gem.add_development_dependency 'rails-controller-testing', '~> 1'
25
- gem.add_development_dependency 'rspec-rails', '~> 3.1'
25
+ gem.add_development_dependency 'rspec-rails', '~> 4.0'
26
26
  gem.add_development_dependency 'sqlite3', '~> 1.3'
27
27
  end
@@ -49,14 +49,6 @@ module Hydra
49
49
  end
50
50
  end
51
51
 
52
- # Add Hydra to the SearchBuilder
53
- def inject_hydra_search_builder_behavior
54
- insert_into_file "app/models/search_builder.rb", after: "include Blacklight::Solr::SearchBuilderBehavior\n" do
55
- " # Add a filter query to restrict the search to documents the current user has access to\n" \
56
- " include Hydra::AccessControlsEnforcement\n"
57
- end
58
- end
59
-
60
52
  # Copy all files in templates/config directory to host config
61
53
  def create_configuration_files
62
54
 
@@ -79,7 +71,7 @@ module Hydra
79
71
  def create_conneg_configuration
80
72
  file_path = "config/initializers/mime_types.rb"
81
73
  append_to_file file_path do
82
- "Mime::Type.register \"application/n-triples\", :nt\n" +
74
+ "Mime::Type.register \"application/n-triples\", :nt\n" +
83
75
  "Mime::Type.register \"application/ld+json\", :jsonld\n" +
84
76
  "Mime::Type.register \"text/turtle\", :ttl"
85
77
  end
@@ -89,7 +81,7 @@ module Hydra
89
81
  file_path = "app/models/solr_document.rb"
90
82
  if File.exists?(file_path)
91
83
  inject_into_file file_path, :before => /end\Z/ do
92
- "\n # Do content negotiation for AF models. \n" +
84
+ "\n # Do content negotiation for AF models. \n" +
93
85
  "\n use_extension( Hydra::ContentNegotiation )\n"
94
86
  end
95
87
  end
@@ -1,3 +1,3 @@
1
1
  module HydraHead
2
- VERSION = "11.0.7"
2
+ VERSION = "12.0.0"
3
3
  end
@@ -48,9 +48,19 @@ describe CatalogController do
48
48
  end
49
49
  context "with no asset" do
50
50
  it "returns a not found response code" do
51
- get 'show', params: { id: "test", format: :nt }
51
+ handled = false
52
+
53
+ begin
54
+ get 'show', params: { id: "test", format: :nt }
55
+ # blacklight 6
56
+ expect(response).to be_not_found
57
+ handled = true
58
+ rescue Blacklight::Exceptions::RecordNotFound
59
+ # blacklight 7
60
+ handled = true
61
+ end
52
62
 
53
- expect(response).to be_not_found
63
+ expect(handled).to eq true
54
64
  end
55
65
  end
56
66
  context "with an asset" do
@@ -69,7 +79,7 @@ describe CatalogController do
69
79
  it "is able to negotiate jsonld" do
70
80
  get 'show', params: { id: asset.id, format: :jsonld }
71
81
 
72
- expect(response).to be_success
82
+ expect(response).to be_successful
73
83
  expect(response.headers['Content-Type']).to include("application/ld+json")
74
84
  graph = RDF::Reader.for(:jsonld).new(response.body)
75
85
  expect(graph.statements.to_a.length).to eq 3
@@ -77,8 +87,8 @@ describe CatalogController do
77
87
 
78
88
  it "is able to negotiate ttl" do
79
89
  get 'show', params: { id: asset.id, format: :ttl }
80
-
81
- expect(response).to be_success
90
+
91
+ expect(response).to be_successful
82
92
  graph = RDF::Reader.for(:ttl).new(response.body)
83
93
  expect(graph.statements.to_a.length).to eq 3
84
94
  end
@@ -115,7 +125,11 @@ describe CatalogController do
115
125
  it "triggers enforce_show_permissions" do
116
126
  allow(controller).to receive(:current_user).and_return(nil)
117
127
  expect(controller).to receive(:enforce_show_permissions)
118
- get :show, params: { id: 'test:3' }
128
+ begin
129
+ get :show, params: { id: 'test:3' }
130
+ rescue Blacklight::Exceptions::RecordNotFound
131
+ # blacklight 7
132
+ end
119
133
  end
120
134
  end
121
135
  end
@@ -76,7 +76,7 @@ describe DownloadsController do
76
76
  get :show, params: { id: obj }
77
77
  expect(response).to be_successful
78
78
  expect(response.headers['Content-Type']).to start_with "image/png"
79
- expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"buzz.png\""
79
+ expect(response.headers["Content-Disposition"]).to start_with "inline; filename=\"buzz.png\""
80
80
  expect(response.body).to eq 'fizz'
81
81
  end
82
82
 
@@ -85,7 +85,7 @@ describe DownloadsController do
85
85
  get :show, params: { id: obj }
86
86
  expect(response).to be_successful
87
87
  expect(response.headers['Content-Type']).to start_with "image/png"
88
- expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"world.png\""
88
+ expect(response.headers["Content-Disposition"]).to start_with "inline; filename=\"world.png\""
89
89
  expect(response.body).to eq 'foobarfoobarfoobar'
90
90
  end
91
91
 
@@ -101,7 +101,7 @@ describe DownloadsController do
101
101
  get :show, params: { id: obj, file: "descMetadata" }
102
102
  expect(response).to be_successful
103
103
  expect(response.headers['Content-Type']).to start_with "text/plain"
104
- expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"metadata.xml\""
104
+ expect(response.headers["Content-Disposition"]).to start_with "inline; filename=\"metadata.xml\""
105
105
  expect(response.body).to eq "It's a stream"
106
106
  end
107
107
  end
@@ -111,7 +111,7 @@ describe DownloadsController do
111
111
  get :show, params: { id: obj, disposition: "inline" }
112
112
  expect(response).to be_successful
113
113
  expect(response.headers['Content-Type']).to start_with "image/png"
114
- expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"world.png\""
114
+ expect(response.headers["Content-Disposition"]).to start_with "inline; filename=\"world.png\""
115
115
  expect(response.body).to eq 'foobarfoobarfoobar'
116
116
  end
117
117
 
@@ -119,7 +119,8 @@ describe DownloadsController do
119
119
  get :show, params: { id: obj, "filename" => "my%20dog.png" }
120
120
  expect(response).to be_successful
121
121
  expect(response.headers['Content-Type']).to start_with "image/png"
122
- expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"my%20dog.png\""
122
+ expect(response.headers["Content-Disposition"]).to start_with "inline; filename="
123
+ expect(response.headers["Content-Disposition"]).to include "my%20dog.png"
123
124
  expect(response.body).to eq 'foobarfoobarfoobar'
124
125
  end
125
126
  end
@@ -148,7 +149,7 @@ describe DownloadsController do
148
149
  expect(response.headers["Content-Length"]).to eq '16'
149
150
  expect(response.headers['Accept-Ranges']).to eq 'bytes'
150
151
  expect(response.headers['Content-Type']).to start_with "video/webm"
151
- expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"MyVideo.webm\""
152
+ expect(response.headers["Content-Disposition"]).to start_with "inline; filename=\"MyVideo.webm\""
152
153
  expect(response.status).to eq 206
153
154
  end
154
155
 
@@ -12,11 +12,13 @@ describe BlacklightHelper do
12
12
 
13
13
  before do
14
14
  allow(helper).to receive(:blacklight_config).and_return(config)
15
+ allow(helper).to receive(:blacklight_configuration_context).and_return(helper)
16
+ allow(helper).to receive(:evaluate_if_unless_configuration).and_return(true)
15
17
  end
16
18
 
17
19
  it "changes camel case to underscored lowercase" do
18
20
  expect(helper.document_partial_name('has_model_s' => ["Presentation"])).to eq "presentation"
19
- expect(helper.document_partial_name('has_model_s' => ["GenericContent"])).to eq "generic_content"
21
+ expect(helper.document_partial_name('has_model_s' => ["GenericContent"])).to eq("generic_content")
20
22
  end
21
23
 
22
24
  context "with a single valued field" do
@@ -1,14 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe SearchBuilder do
4
- let(:processor_chain) { [:add_access_controls_to_solr_params] }
5
- let(:context) { double('context') }
3
+ RSpec.describe Hydra::SearchBuilder do
4
+ let(:context) { CatalogController.new }
6
5
  let(:user) { double('user', user_key: 'joe') }
7
6
  let(:current_ability) { double('ability', user_groups: [], current_user: user) }
8
7
  let(:search_builder) { described_class }
9
8
 
10
9
  subject do
11
- search_builder.new(processor_chain, context)
10
+ search_builder.new(context).with_ability(current_ability)
12
11
  end
13
12
 
14
13
  it "extends classes with the necessary Hydra modules" do
data/spec/spec_helper.rb CHANGED
@@ -12,6 +12,7 @@ require 'hydra-core'
12
12
 
13
13
  require 'simplecov'
14
14
  require 'coveralls'
15
+ require 'rails-controller-testing'
15
16
 
16
17
  SimpleCov.root(File.expand_path('../..', __dir__))
17
18
  SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
@@ -29,6 +30,9 @@ ActiveFedora::Base.logger = Logger.new(STDOUT)
29
30
  require 'active_fedora/cleaner'
30
31
  RSpec.configure do |config|
31
32
  config.include Devise::Test::ControllerHelpers, type: :controller
33
+ config.include ::Rails::Controller::Testing::TemplateAssertions, type: :controller
34
+ config.include ::Rails::Controller::Testing::TestProcess, type: :controller
35
+ config.include ::Rails::Controller::Testing::Integration, type: :controller
32
36
  config.use_transactional_fixtures = true
33
37
  config.infer_spec_type_from_file_location!
34
38
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 11.0.7
4
+ version: 12.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Zumwalt, Bess Sadler, Julie Meloni, Naomi Dushay, Jessie Keck, John Scofield,
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-05-17 00:00:00.000000000 Z
12
+ date: 2020-11-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hydra-access-controls
@@ -17,34 +17,34 @@ dependencies:
17
17
  requirements:
18
18
  - - '='
19
19
  - !ruby/object:Gem::Version
20
- version: 11.0.7
20
+ version: 12.0.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - '='
26
26
  - !ruby/object:Gem::Version
27
- version: 11.0.7
27
+ version: 12.0.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: railties
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: 4.0.0
34
+ version: '5.2'
35
35
  - - "<"
36
36
  - !ruby/object:Gem::Version
37
- version: '6'
37
+ version: '7'
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  requirements:
42
42
  - - ">="
43
43
  - !ruby/object:Gem::Version
44
- version: 4.0.0
44
+ version: '5.2'
45
45
  - - "<"
46
46
  - !ruby/object:Gem::Version
47
- version: '6'
47
+ version: '7'
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rails-controller-testing
50
50
  requirement: !ruby/object:Gem::Requirement
@@ -65,14 +65,14 @@ dependencies:
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '3.1'
68
+ version: '4.0'
69
69
  type: :development
70
70
  prerelease: false
71
71
  version_requirements: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '3.1'
75
+ version: '4.0'
76
76
  - !ruby/object:Gem::Dependency
77
77
  name: sqlite3
78
78
  requirement: !ruby/object:Gem::Requirement
@@ -113,6 +113,8 @@ files:
113
113
  - app/models/hydra/content_negotiation/fedora_uri_replacer.rb
114
114
  - app/models/hydra/content_negotiation/graph_finder.rb
115
115
  - app/models/hydra/content_negotiation/replacing_graph_finder.rb
116
+ - app/models/hydra/search_builder.rb
117
+ - app/services/hydra/search_service.rb
116
118
  - config/locales/hydra.en.yml
117
119
  - hydra-core.gemspec
118
120
  - lib/application_helper.rb
@@ -164,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
166
  - !ruby/object:Gem::Version
165
167
  version: '0'
166
168
  requirements: []
167
- rubygems_version: 3.1.4
169
+ rubygems_version: 3.1.2
168
170
  signing_key:
169
171
  specification_version: 4
170
172
  summary: Hydra-Head Rails Engine (requires Rails3)