hydra-collections 4.0.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/.travis.yml +0 -3
- data/Gemfile +6 -1
- data/app/controllers/concerns/hydra/collections/selects_collections.rb +30 -33
- data/app/controllers/concerns/hydra/collections_controller_behavior.rb +39 -17
- data/app/models/concerns/hydra/collection.rb +5 -76
- data/app/models/concerns/hydra/collections/actions.rb +22 -0
- data/app/models/concerns/hydra/collections/metadata.rb +62 -0
- data/app/models/concerns/hydra/collections/relations.rb +8 -0
- data/app/search_builders/hydra/collections/search_builder.rb +31 -0
- data/app/views/collections/_bookmark_control.html.erb +2 -0
- data/app/views/collections/_document_list.html.erb +1 -1
- data/app/views/collections/_index_default.html.erb +2 -0
- data/app/views/collections/_index_header_default.html.erb +2 -0
- data/app/views/collections/_paginate_compact.html.erb +1 -0
- data/app/views/collections/_results_pagination.html.erb +9 -0
- data/app/views/collections/_search_results.html.erb +23 -0
- data/app/views/collections/_thumbnail_default.html.erb +2 -0
- data/app/views/collections/index.html.erb +9 -0
- data/app/views/collections/show.html.erb +3 -3
- data/app/views/layouts/collections.html.erb +48 -0
- data/config/routes.rb +3 -3
- data/hydra-collections.gemspec +3 -2
- data/lib/hydra/collections/collectible.rb +1 -0
- data/lib/hydra/collections/search_service.rb +2 -2
- data/lib/hydra/collections/version.rb +1 -1
- data/spec/controllers/collections_controller_spec.rb +37 -51
- data/spec/controllers/other_collections_controller_spec.rb +25 -57
- data/spec/controllers/selects_collections_spec.rb +14 -30
- data/spec/helpers/collections_helper_spec.rb +5 -5
- data/spec/lib/collectible_spec.rb +1 -0
- data/spec/models/collection_spec.rb +7 -34
- data/spec/spec_helper.rb +7 -11
- data/spec/test_app_templates/Gemfile.extra +1 -0
- data/spec/test_app_templates/app/controllers/other_collections_controller.rb +8 -0
- data/spec/test_app_templates/app/views/catalog/_sort_and_per_page.html.erb +3 -8
- data/spec/test_app_templates/config/blacklight.yml +22 -0
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +17 -9
- data/spec/views/collections/_thumbnail_default.html.erb_spec.rb +25 -0
- data/spec/views/collections/show.html.erb_spec.rb +32 -0
- metadata +44 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef2d245ae222f9d4aa4164e6e6293facd7ae8af7
|
4
|
+
data.tar.gz: 2e785a983145507e7ca33cf38b0deabd4bfd0f68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9975569dca4f4f8b6b7c5b426cb24045e0d8c07669af92982378f629cc02b8f2c56efeceb8101c7dcaf2a1dc8fd39f5aec8a059332ce5ad6c7bf1214ab4e68ba
|
7
|
+
data.tar.gz: 7c3d2f47293e9899e300fae0e5bbe82492518e7825a2565ba05a8c7c04ab43ec6e7d04ea8921ad6201214d88c8751cb05c371c5a883e4f1b3cca1656ca4b3d85
|
data/.rspec
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -3,16 +3,21 @@ source 'https://rubygems.org'
|
|
3
3
|
# Specify your gem's dependencies in hydra-collections.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
+
gem 'kaminari', github: 'harai/kaminari', branch: 'route_prefix_prototype'
|
7
|
+
|
6
8
|
group :development, :test do
|
7
9
|
gem 'sqlite3'
|
8
10
|
gem "factory_girl_rails"
|
9
11
|
gem 'devise'
|
10
12
|
gem 'capybara'
|
11
13
|
gem 'jettywrapper'
|
12
|
-
gem 'byebug', require: false
|
14
|
+
gem 'byebug', require: false unless ENV['CI']
|
13
15
|
gem 'coveralls', require: false
|
16
|
+
gem 'rspec-activemodel-mocks'
|
14
17
|
end
|
15
18
|
|
19
|
+
gem 'slop', '~> 3.6' # because rails installs byebug in the Gemfile
|
20
|
+
|
16
21
|
file = File.expand_path("Gemfile", ENV['ENGINE_CART_DESTINATION'] || ENV['RAILS_ROOT'] || File.expand_path("../spec/internal", __FILE__))
|
17
22
|
if File.exists?(file)
|
18
23
|
puts "Loading #{file} ..." if $DEBUG # `ruby -d` or `bundle -v`
|
@@ -1,9 +1,15 @@
|
|
1
1
|
module Hydra::Collections::SelectsCollections
|
2
2
|
extend ActiveSupport::Concern
|
3
|
-
|
3
|
+
|
4
|
+
included do
|
5
|
+
configure_blacklight do |config|
|
6
|
+
config.search_builder_class = Hydra::Collections::SearchBuilder
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
4
10
|
def access_levels
|
5
11
|
{ read: [:read, :edit], edit: [:edit] }
|
6
|
-
end
|
12
|
+
end
|
7
13
|
|
8
14
|
# add one of the following methods as a before filter on any page that shows the form_for_select_collection
|
9
15
|
def find_collections_with_read_access
|
@@ -13,44 +19,35 @@ module Hydra::Collections::SelectsCollections
|
|
13
19
|
def find_collections_with_edit_access
|
14
20
|
find_collections(:edit)
|
15
21
|
end
|
16
|
-
|
17
|
-
#
|
18
|
-
def find_collections (access_level=
|
22
|
+
|
23
|
+
#
|
24
|
+
def find_collections (access_level = nil)
|
19
25
|
# need to know the user if there is an access level applied otherwise we are just doing public collections
|
20
26
|
authenticate_user! unless access_level.blank?
|
21
|
-
|
22
|
-
# update the permission filters for the query of need be
|
23
|
-
original_permissions = discovery_permissions
|
24
|
-
self.class.send(:define_method, "discovery_permissions") { access_levels[access_level] } unless access_level.blank?
|
25
|
-
|
26
|
-
# Blacklight doesn't let you explicitly pass your own solr_search_params_logic when running searches --
|
27
|
-
# You have to set the controller's solr_search_params_logic class attribute. So this method temporarily sets solr_search_params_logic to collection_search_params_logic then switches it back.
|
28
|
-
|
29
|
-
# temporarily set solr_search_params_logic to collection_search_params_logic
|
30
|
-
orig_solr_search_params_logic = self.class.solr_search_params_logic
|
31
|
-
self.class.solr_search_params_logic = collection_search_params_logic
|
32
|
-
logger.debug "Collection Search logic: "+ self.class.solr_search_params_logic.inspect
|
27
|
+
|
33
28
|
# run the solr query to find the collections
|
34
|
-
|
35
|
-
|
36
|
-
#reset to original solr logic
|
37
|
-
self.class.send(:define_method, "discovery_permissions") { original_permissions } unless access_level.blank?
|
38
|
-
self.class.solr_search_params_logic = orig_solr_search_params_logic
|
29
|
+
query = collections_search_builder(access_level).with({q: ''}).query
|
30
|
+
response = repository.search(query)
|
39
31
|
|
40
32
|
# return the user's collections (or public collections if no access_level is applied)
|
41
|
-
@user_collections =
|
33
|
+
@user_collections = response.documents
|
42
34
|
end
|
43
|
-
|
44
|
-
def
|
45
|
-
|
46
|
-
|
35
|
+
|
36
|
+
def collections_search_builder_class
|
37
|
+
Hydra::Collections::SearchBuilder
|
38
|
+
end
|
39
|
+
|
40
|
+
def collections_search_builder(access_level = nil)
|
41
|
+
@collections_search_builder ||= collections_search_builder_class.new(collection_search_params_logic, self).tap do |builder|
|
42
|
+
builder.current_ability = current_ability
|
43
|
+
builder.discovery_perms = access_levels[access_level] if access_level
|
44
|
+
end
|
47
45
|
end
|
48
|
-
|
49
|
-
# Defines which
|
46
|
+
|
47
|
+
# Defines which search_params_logic should be used when searching for Collections
|
50
48
|
def collection_search_params_logic
|
51
|
-
|
52
|
-
|
53
|
-
base_logic
|
49
|
+
[:default_solr_parameters, :add_query_to_solr, :add_access_controls_to_solr_params,
|
50
|
+
:add_collection_filter, :some_rows]
|
54
51
|
end
|
55
|
-
|
52
|
+
|
56
53
|
end
|
@@ -2,16 +2,16 @@ module Hydra
|
|
2
2
|
module CollectionsControllerBehavior
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
include Blacklight::SolrHelper
|
5
|
+
include Blacklight::Base
|
6
|
+
include Hydra::Collections::SelectsCollections
|
8
7
|
|
8
|
+
included do
|
9
9
|
include Hydra::Collections::AcceptsBatches
|
10
|
-
include Hydra::Collections::SelectsCollections
|
11
10
|
|
12
11
|
# This is needed as of BL 3.7
|
13
12
|
self.copy_blacklight_config_from(CatalogController)
|
14
13
|
|
14
|
+
|
15
15
|
# Catch permission errors
|
16
16
|
rescue_from Hydra::AccessDenied, CanCan::AccessDenied do |exception|
|
17
17
|
if exception.action == :edit
|
@@ -28,8 +28,14 @@ module Hydra
|
|
28
28
|
before_filter :authenticate_user!, :except => [:show]
|
29
29
|
load_and_authorize_resource :except=>[:index], instance_name: :collection
|
30
30
|
|
31
|
-
|
32
|
-
|
31
|
+
layout 'collections'
|
32
|
+
end
|
33
|
+
|
34
|
+
def index
|
35
|
+
# run the solr query to find the collections
|
36
|
+
query = collections_search_builder.with(params).query
|
37
|
+
@response = repository.search(query)
|
38
|
+
@document_list = @response.documents
|
33
39
|
end
|
34
40
|
|
35
41
|
def new
|
@@ -88,8 +94,7 @@ module Hydra
|
|
88
94
|
|
89
95
|
def update
|
90
96
|
process_member_changes
|
91
|
-
@collection.
|
92
|
-
if @collection.save
|
97
|
+
if @collection.update(collection_params.except(:members))
|
93
98
|
after_update
|
94
99
|
else
|
95
100
|
after_update_error
|
@@ -118,8 +123,17 @@ module Hydra
|
|
118
123
|
end
|
119
124
|
end
|
120
125
|
|
126
|
+
def collection
|
127
|
+
@collection
|
128
|
+
end
|
129
|
+
|
121
130
|
protected
|
122
131
|
|
132
|
+
# Defines which search_params_logic should be used when searching for Collection members
|
133
|
+
def collection_member_search_logic
|
134
|
+
search_params_logic + [:include_collection_ids]
|
135
|
+
end
|
136
|
+
|
123
137
|
def collection_params
|
124
138
|
params.require(:collection).permit(:part_of, :contributor, :creator, :title,
|
125
139
|
:description, :publisher, :date_created, :subject, :language, :rights,
|
@@ -129,13 +143,22 @@ module Hydra
|
|
129
143
|
# Queries Solr for members of the collection.
|
130
144
|
# Populates @response and @member_docs similar to Blacklight Catalog#index populating @response and @documents
|
131
145
|
def query_collection_members
|
132
|
-
|
146
|
+
solr_params = params.symbolize_keys.merge(q: params[:cq])
|
147
|
+
|
148
|
+
# run the solr query to find the collection members
|
149
|
+
query = collection_member_search_builder.with(solr_params).query
|
150
|
+
@response = repository.search(query)
|
151
|
+
@member_docs = @response.documents
|
152
|
+
end
|
133
153
|
|
134
|
-
|
135
|
-
|
154
|
+
def collection_member_search_builder_class
|
155
|
+
Hydra::Collections::SearchBuilder
|
156
|
+
end
|
136
157
|
|
137
|
-
|
138
|
-
(
|
158
|
+
def collection_member_search_builder
|
159
|
+
@collection_member_search_builder ||= collection_member_search_builder_class.new(collection_member_search_logic, self).tap do |builder|
|
160
|
+
builder.current_ability = current_ability
|
161
|
+
end
|
139
162
|
end
|
140
163
|
|
141
164
|
def process_member_changes
|
@@ -172,10 +195,9 @@ module Hydra
|
|
172
195
|
end
|
173
196
|
end
|
174
197
|
|
175
|
-
#
|
176
|
-
def
|
177
|
-
|
178
|
-
solr_parameters[:fq] << Solrizer.solr_name(:collection, :facetable)+':"'+@collection.id+'"'
|
198
|
+
# Override rails path for the views
|
199
|
+
def _prefixes
|
200
|
+
@_prefixes ||= super + ['catalog']
|
179
201
|
end
|
180
202
|
end # module CollectionsControllerBehavior
|
181
203
|
end # module Hydra
|
@@ -1,96 +1,25 @@
|
|
1
1
|
module Hydra
|
2
2
|
module Collection
|
3
3
|
extend ActiveSupport::Concern
|
4
|
-
extend
|
4
|
+
extend Deprecation
|
5
5
|
include Hydra::WithDepositor # for access to apply_depositor_metadata
|
6
6
|
include Hydra::AccessControls::Permissions
|
7
7
|
include Hydra::Collections::Collectible
|
8
|
-
|
9
|
-
|
10
|
-
has_and_belongs_to_many :members, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.hasCollectionMember, class_name: "ActiveFedora::Base" , after_remove: :update_member
|
11
|
-
|
12
|
-
property :depositor, predicate: ::RDF::URI.new("http://id.loc.gov/vocabulary/relators/dpt"), multiple: false do |index|
|
13
|
-
index.as :symbol, :stored_searchable
|
14
|
-
end
|
15
|
-
|
16
|
-
property :part_of, predicate: RDF::DC.isPartOf
|
17
|
-
property :contributor, predicate: RDF::DC.contributor do |index|
|
18
|
-
index.as :stored_searchable, :facetable
|
19
|
-
end
|
20
|
-
property :creator, predicate: RDF::DC.creator do |index|
|
21
|
-
index.as :stored_searchable, :facetable
|
22
|
-
end
|
23
|
-
property :title, predicate: RDF::DC.title, multiple: false do |index|
|
24
|
-
index.as :stored_searchable
|
25
|
-
end
|
26
|
-
property :description, predicate: RDF::DC.description, multiple: false do |index|
|
27
|
-
index.type :text
|
28
|
-
index.as :stored_searchable
|
29
|
-
end
|
30
|
-
property :publisher, predicate: RDF::DC.publisher do |index|
|
31
|
-
index.as :stored_searchable, :facetable
|
32
|
-
end
|
33
|
-
property :date_created, predicate: RDF::DC.created do |index|
|
34
|
-
index.as :stored_searchable
|
35
|
-
end
|
36
|
-
property :date_uploaded, predicate: RDF::DC.dateSubmitted, multiple: false do |index|
|
37
|
-
index.type :date
|
38
|
-
index.as :stored_sortable
|
39
|
-
end
|
40
|
-
property :date_modified, predicate: RDF::DC.modified, multiple: false do |index|
|
41
|
-
index.type :date
|
42
|
-
index.as :stored_sortable
|
43
|
-
end
|
44
|
-
property :subject, predicate: RDF::DC.subject do |index|
|
45
|
-
index.as :stored_searchable, :facetable
|
46
|
-
end
|
47
|
-
property :language, predicate: RDF::DC.language do |index|
|
48
|
-
index.as :stored_searchable, :facetable
|
49
|
-
end
|
50
|
-
property :rights, predicate: RDF::DC.rights do |index|
|
51
|
-
index.as :stored_searchable
|
52
|
-
end
|
53
|
-
property :resource_type, predicate: RDF::DC.type do |index|
|
54
|
-
index.as :stored_searchable, :facetable
|
55
|
-
end
|
56
|
-
property :identifier, predicate: RDF::DC.identifier do |index|
|
57
|
-
index.as :stored_searchable
|
58
|
-
end
|
59
|
-
property :based_near, predicate: RDF::FOAF.based_near do |index|
|
60
|
-
index.as :stored_searchable, :facetable
|
61
|
-
end
|
62
|
-
property :tag, predicate: RDF::DC.relation do |index|
|
63
|
-
index.as :stored_searchable, :facetable
|
64
|
-
end
|
65
|
-
property :related_url, predicate: RDF::RDFS.seeAlso
|
66
|
-
|
67
|
-
before_create :set_date_uploaded
|
68
|
-
before_save :set_date_modified
|
69
|
-
before_destroy :update_all_members
|
70
|
-
|
71
|
-
after_save :update_all_members
|
72
|
-
end
|
8
|
+
include Hydra::Collections::Metadata
|
9
|
+
include Hydra::Collections::Relations
|
73
10
|
|
74
11
|
def update_all_members
|
12
|
+
Deprecation.warn(Collection, 'update_all_members is deprecated and will be removed in version 5.0')
|
75
13
|
self.members.collect { |m| update_member(m) }
|
76
14
|
end
|
77
15
|
|
78
16
|
# TODO: Use solr atomic updates to accelerate this process
|
79
17
|
def update_member member
|
18
|
+
Deprecation.warn(Collection, 'update_member is deprecated and will be removed in version 5.0')
|
80
19
|
# because the member may have its collections cached, reload that cache so that it indexes the correct fields.
|
81
20
|
member.collections(true) if member.respond_to? :collections
|
82
21
|
member.update_index
|
83
22
|
end
|
84
23
|
|
85
|
-
private
|
86
|
-
|
87
|
-
def set_date_uploaded
|
88
|
-
self.date_uploaded = Date.today
|
89
|
-
end
|
90
|
-
|
91
|
-
def set_date_modified
|
92
|
-
self.date_modified = Date.today
|
93
|
-
end
|
94
|
-
|
95
24
|
end
|
96
25
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Hydra::Collections
|
2
|
+
module Actions
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
Deprecation.warn(Actions, "Hydra::Collections::Actions is deprecated and will be removed in 6.0.0")
|
7
|
+
before_create :set_date_uploaded
|
8
|
+
before_save :set_date_modified
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def set_date_uploaded
|
14
|
+
self.date_uploaded = Date.today
|
15
|
+
end
|
16
|
+
|
17
|
+
def set_date_modified
|
18
|
+
self.date_modified = Date.today
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Hydra::Collections
|
2
|
+
module Metadata
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
included do
|
5
|
+
property :depositor, predicate: ::RDF::URI.new("http://id.loc.gov/vocabulary/relators/dpt"), multiple: false do |index|
|
6
|
+
index.as :symbol, :stored_searchable
|
7
|
+
end
|
8
|
+
|
9
|
+
property :part_of, predicate: RDF::DC.isPartOf
|
10
|
+
property :contributor, predicate: RDF::DC.contributor do |index|
|
11
|
+
index.as :stored_searchable, :facetable
|
12
|
+
end
|
13
|
+
property :creator, predicate: RDF::DC.creator do |index|
|
14
|
+
index.as :stored_searchable, :facetable
|
15
|
+
end
|
16
|
+
property :title, predicate: RDF::DC.title, multiple: false do |index|
|
17
|
+
index.as :stored_searchable
|
18
|
+
end
|
19
|
+
property :description, predicate: RDF::DC.description, multiple: false do |index|
|
20
|
+
index.type :text
|
21
|
+
index.as :stored_searchable
|
22
|
+
end
|
23
|
+
property :publisher, predicate: RDF::DC.publisher do |index|
|
24
|
+
index.as :stored_searchable, :facetable
|
25
|
+
end
|
26
|
+
property :date_created, predicate: RDF::DC.created do |index|
|
27
|
+
index.as :stored_searchable
|
28
|
+
end
|
29
|
+
property :date_uploaded, predicate: RDF::DC.dateSubmitted, multiple: false do |index|
|
30
|
+
index.type :date
|
31
|
+
index.as :stored_sortable
|
32
|
+
end
|
33
|
+
property :date_modified, predicate: RDF::DC.modified, multiple: false do |index|
|
34
|
+
index.type :date
|
35
|
+
index.as :stored_sortable
|
36
|
+
end
|
37
|
+
property :subject, predicate: RDF::DC.subject do |index|
|
38
|
+
index.as :stored_searchable, :facetable
|
39
|
+
end
|
40
|
+
property :language, predicate: RDF::DC.language do |index|
|
41
|
+
index.as :stored_searchable, :facetable
|
42
|
+
end
|
43
|
+
property :rights, predicate: RDF::DC.rights do |index|
|
44
|
+
index.as :stored_searchable
|
45
|
+
end
|
46
|
+
property :resource_type, predicate: RDF::DC.type do |index|
|
47
|
+
index.as :stored_searchable, :facetable
|
48
|
+
end
|
49
|
+
property :identifier, predicate: RDF::DC.identifier do |index|
|
50
|
+
index.as :stored_searchable
|
51
|
+
end
|
52
|
+
property :based_near, predicate: RDF::FOAF.based_near do |index|
|
53
|
+
index.as :stored_searchable, :facetable
|
54
|
+
end
|
55
|
+
property :tag, predicate: RDF::DC.relation do |index|
|
56
|
+
index.as :stored_searchable, :facetable
|
57
|
+
end
|
58
|
+
property :related_url, predicate: RDF::RDFS.seeAlso
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Hydra::Collections
|
2
|
+
class SearchBuilder < Hydra::SearchBuilder
|
3
|
+
|
4
|
+
def collection
|
5
|
+
scope.collection
|
6
|
+
end
|
7
|
+
|
8
|
+
# include filters into the query to only include the collection memebers
|
9
|
+
def include_collection_ids(solr_parameters)
|
10
|
+
solr_parameters[:fq] ||= []
|
11
|
+
solr_parameters[:fq] << "{!join from=hasCollectionMember_ssim to=id}id:#{collection.id}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def some_rows(solr_parameters)
|
15
|
+
solr_parameters[:rows] = '100'
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_collection_filter(solr_parameters)
|
19
|
+
solr_parameters[:fq] ||= []
|
20
|
+
solr_parameters[:fq] << ActiveFedora::SolrQueryBuilder.construct_query_for_rel(has_model: ::Collection.to_class_uri)
|
21
|
+
end
|
22
|
+
|
23
|
+
def discovery_perms= perms
|
24
|
+
@discovery_perms = perms
|
25
|
+
end
|
26
|
+
|
27
|
+
def discovery_permissions
|
28
|
+
@discovery_perms || super
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|