curation_concerns 1.6.0 → 1.6.1

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
  SHA1:
3
- metadata.gz: a18cbc58262bda78bbccb7fcc5e263e09675b574
4
- data.tar.gz: fb6ff7b4b9ad80ff9f2ccb26dbfa2ce93b35b585
3
+ metadata.gz: 9058b4420919bb0e097ce662820daa18c23f734c
4
+ data.tar.gz: 50bd609db11df6df2f7e62ff29974e1677760d30
5
5
  SHA512:
6
- metadata.gz: df0282909989ce292b1dbaa07ae83497e0bb7a8cd253120c5dc3d6d5d9d085a539aefacb701fd13e8fa70bef726b008fd2e5937faad7a6cc96b1808af0bb6695
7
- data.tar.gz: 7bc806d8693440c4e17958531be96a56af544878796081521339bfa7ae261672f537900337035a29ae79b1a7385693b0f5403f82ae37a29fd0e8f493d8f94ad5
6
+ metadata.gz: 0fa3bcd75d29b7778eca8b8afb90fd26f084b207e60c38d1c066fcaac83380b121c556be34cfd98f0c5727218c9ba2a8118d255249d22871e9e623079a2f37f7
7
+ data.tar.gz: 3a21293ef1519ae15d4fdd87fbf8fc292657c88f23cfa4abe9f842f08d71e8023980bbf408ce58b5292df218d47271151c07a0e2a991d0e1945d0a845ad0fdd1
@@ -74,6 +74,7 @@ module CurationConcerns
74
74
 
75
75
  def edit
76
76
  query_collection_members
77
+ # this is used to populate the "add to a collection" action for the members
77
78
  @user_collections = find_collections_for_form
78
79
  form
79
80
  end
@@ -163,15 +164,10 @@ module CurationConcerns
163
164
 
164
165
  protected
165
166
 
166
- # TODO: This method could become a collection service.
167
- # TODO: It seems suspicious that this is returning collections with read
168
- # access rather than collections with edit access
169
- # run a solr query to get the collections the user has access to read
167
+ # run a solr query to get the collections the user has access to edit
170
168
  # @return [Array] a list of the user's collections
171
169
  def find_collections_for_form
172
- query = list_search_builder.with(q: '').query
173
- response = repository.search(query)
174
- response.documents
170
+ CurationConcerns::CollectionsService.new(self).search_results(:edit)
175
171
  end
176
172
 
177
173
  def remove_select_something_first_flash
@@ -86,17 +86,14 @@ module CurationConcerns::CollectionsHelper
86
86
  if current_user.respond_to?(:collections)
87
87
  return current_user.collections.map { |c| [c.title.join(', '), c.id] }
88
88
  end
89
- convert_solr_docs_to_select_options(
90
- ::Collection.search_with_conditions({},
91
- fl: 'title_tesim id',
92
- rows: 1000)
93
- )
89
+ service = CurationConcerns::CollectionsService.new(controller)
90
+ convert_solr_docs_to_select_options(service.search_results(:edit))
94
91
  end
95
92
 
96
93
  def convert_solr_docs_to_select_options(results)
97
94
  option_values = results.map do |r|
98
- title = SolrDocument.new(r).title
99
- [title.present? ? title.join(', ') : nil, r['id']]
95
+ title = r.title
96
+ [title.present? ? title.join(', ') : nil, r.id]
100
97
  end
101
98
  option_values.sort do |a, b|
102
99
  if a.first && b.first
@@ -34,12 +34,4 @@ module CurationConcerns::WorkBehavior
34
34
  end
35
35
  end
36
36
  end
37
-
38
- def to_s
39
- if title.present?
40
- title.join(' | ')
41
- else
42
- 'No Title'
43
- end
44
- end
45
37
  end
@@ -19,7 +19,7 @@ module CurationConcerns
19
19
  if parsed_uri.nil?
20
20
  ERB::Util.h(value)
21
21
  else
22
- %(<a href=#{ERB::Util.h(value)} target="_blank">#{RightsService.label(value)}</a>)
22
+ %(<a href=#{ERB::Util.h(value)} target="_blank">#{CurationConcerns::LicenseService.new.label(value)}</a>)
23
23
  end
24
24
  end
25
25
  end
@@ -0,0 +1,28 @@
1
+ module CurationConcerns
2
+ class CollectionsService
3
+ attr_reader :context
4
+
5
+ class_attribute :list_search_builder_class
6
+ self.list_search_builder_class = CurationConcerns::CollectionSearchBuilder
7
+
8
+ # @param [#repository,#blacklight_config,#current_ability] context
9
+ def initialize(context)
10
+ @context = context
11
+ end
12
+
13
+ # @param [Symbol] access :read or :edit
14
+ def search_results(access)
15
+ builder = list_search_builder(access)
16
+ response = context.repository.search(builder)
17
+ response.documents
18
+ end
19
+
20
+ private
21
+
22
+ def list_search_builder(access)
23
+ list_search_builder_class.new(context).tap do |builder|
24
+ builder.discovery_perms = [access]
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module CurationConcerns
2
- VERSION = '1.6.0'.freeze
2
+ VERSION = '1.6.1'.freeze
3
3
  end
@@ -12,9 +12,9 @@ describe CollectionsController do
12
12
  user: user,
13
13
  depositor: user.user_key) }
14
14
  let(:asset3) { build(:generic_work, title: ['Third of the Assets']) }
15
- let!(:asset4) { create(:generic_work,
16
- title: ['Fourth of the Assets'],
17
- user: user) }
15
+ let(:asset4) { create(:generic_work,
16
+ title: ['Fourth of the Assets'],
17
+ user: user) }
18
18
  let(:bogus_depositor_asset) { create(:generic_work,
19
19
  title: ['Bogus Asset'],
20
20
  depositor: 'abc') }
@@ -245,11 +245,20 @@ describe CollectionsController do
245
245
  end
246
246
 
247
247
  describe '#edit' do
248
- before { sign_in user }
248
+ let!(:my_collection) { create(:collection, user: user) }
249
+
250
+ before do
251
+ # We expect to not see this collection in the list
252
+ create(:collection, :public)
253
+ sign_in user
254
+ end
249
255
 
250
- it 'does not show flash' do
256
+ it 'is successful' do
251
257
  get :edit, params: { id: collection }
252
258
  expect(flash[:notice]).to be_nil
259
+ # a list of collections I can add items to:
260
+ expect(assigns[:user_collections].map(&:id)).to match_array [collection.id,
261
+ my_collection.id]
253
262
  end
254
263
  end
255
264
  end
@@ -34,27 +34,27 @@ describe CurationConcerns::CollectionsHelper do
34
34
  describe '#collection_options_for_select' do
35
35
  let(:user) { create(:user) }
36
36
  let(:collection2) { double(id: '02870w10j') }
37
- let(:doc1) { { "id" => "k930bx31t", "title_tesim" => ["One"] } }
38
- let(:doc2) { { "id" => "02870w10j", "title_tesim" => ["Two"] } }
39
- let(:doc3) { { "id" => "z029p500w", "title_tesim" => ["Three"] } }
37
+ let(:doc1) { SolrDocument.new("id" => "k930bx31t", "title_tesim" => ["One"]) }
38
+ let(:doc2) { SolrDocument.new("id" => "02870w10j", "title_tesim" => ["Two"]) }
39
+ let(:doc3) { SolrDocument.new("id" => "z029p500w", "title_tesim" => ["Three"]) }
40
+ let(:service) { instance_double(CurationConcerns::CollectionsService) }
40
41
 
41
42
  before do
42
43
  allow(helper).to receive(:current_user).and_return(user)
43
- allow(Collection).to receive(:search_with_conditions)
44
- .with({}, fl: 'title_tesim id', rows: 1000)
45
- .and_return([doc1, doc2, doc3])
44
+ allow(CurationConcerns::CollectionsService).to receive(:new).with(controller).and_return(service)
45
+ expect(service).to receive(:search_results).with(:edit).and_return([doc1, doc2, doc3])
46
46
  end
47
47
 
48
48
  subject { helper.collection_options_for_select(collection2) }
49
49
 
50
50
  it 'excludes the passed in collection' do
51
- expect(subject).to eq "<option value=\"#{doc1['id']}\">One</option>\n<option value=\"#{doc3['id']}\">Three</option>"
51
+ expect(subject).to eq "<option value=\"#{doc1.id}\">One</option>\n<option value=\"#{doc3.id}\">Three</option>"
52
52
  end
53
53
 
54
54
  context "when one of the documents doesn't have title_tesim" do
55
- let(:doc1) { { "id" => "k930bx31t" } }
55
+ let(:doc1) { SolrDocument.new("id" => "k930bx31t") }
56
56
  it 'puts the collections without titles last' do
57
- expect(subject).to eq "<option value=\"#{doc3['id']}\">Three</option>\n<option value=\"#{doc1['id']}\"></option>"
57
+ expect(subject).to eq "<option value=\"#{doc3.id}\">Three</option>\n<option value=\"#{doc1.id}\"></option>"
58
58
  end
59
59
  end
60
60
  end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe CurationConcerns::CollectionsService do
4
+ let(:controller) { ::CatalogController.new }
5
+
6
+ let(:context) do
7
+ double(current_ability: Ability.new(user),
8
+ repository: controller.repository,
9
+ blacklight_config: controller.blacklight_config)
10
+ end
11
+
12
+ let(:service) { described_class.new(context) }
13
+ let(:user) { create(:user) }
14
+
15
+ describe "#search_results" do
16
+ subject { service.search_results(access) }
17
+ let!(:collection1) { create(:collection, :public, title: ['foo']) }
18
+ let!(:collection2) { create(:collection, :public, title: ['bar']) }
19
+ let!(:collection3) { create(:collection, :public, edit_users: [user.user_key], title: ['baz']) }
20
+ before do
21
+ create(:admin_set, :public) # this should never be returned.
22
+ end
23
+
24
+ context "with read access" do
25
+ let(:access) { :read }
26
+ it "returns three collections" do
27
+ expect(subject.map(&:id)).to match_array [collection1.id, collection2.id, collection3.id]
28
+ end
29
+ end
30
+
31
+ context "with edit access" do
32
+ let(:access) { :edit }
33
+ it "returns one collections" do
34
+ expect(subject.map(&:id)).to match_array [collection3.id]
35
+ end
36
+ end
37
+ end
38
+ end
@@ -24,6 +24,7 @@ describe 'catalog/index.html.erb' do
24
24
  allow(view).to receive(:document_counter_with_offset).and_return(5)
25
25
  allow(view).to receive(:type_tab).and_return("TYPE")
26
26
  allow(view).to receive(:search_state).and_return(search_state)
27
+ allow(view).to receive(:collection_options_for_select)
27
28
 
28
29
  params[:view] = 'gallery'
29
30
 
@@ -3,8 +3,10 @@ require 'spec_helper'
3
3
  describe 'curation_concerns/base/show_actions' do
4
4
  let(:model) { double('model', persisted?: true, to_param: '123', model_name: GenericWork.model_name) }
5
5
  let(:presenter) { double("presenter", human_readable_type: 'Image', id: '123', to_model: model, valid_child_concerns: [GenericWork]) }
6
+
6
7
  before do
7
8
  assign(:presenter, presenter)
9
+ allow(view).to receive(:collection_options_for_select)
8
10
  render 'curation_concerns/base/show_actions.html.erb', collector: collector, editor: editor
9
11
  end
10
12
 
@@ -15,6 +17,7 @@ describe 'curation_concerns/base/show_actions' do
15
17
  expect(rendered).to have_link 'Add to a Collection'
16
18
  end
17
19
  end
20
+
18
21
  context "as an editor" do
19
22
  let(:editor) { true }
20
23
  let(:collector) { true }
@@ -26,6 +26,7 @@ describe 'curation_concerns/base/show.html.erb' do
26
26
  before do
27
27
  allow(view).to receive(:can?).with(:edit, String).and_return(true)
28
28
  allow(view).to receive(:can?).with(:collect, String).and_return(true)
29
+ allow(view).to receive(:collection_options_for_select)
29
30
  assign(:presenter, presenter)
30
31
  render
31
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: curation_concerns
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Zumwalt
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-09-14 00:00:00.000000000 Z
13
+ date: 2016-09-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: hydra-head
@@ -854,6 +854,7 @@ files:
854
854
  - app/search_builders/curation_concerns/work_search_builder.rb
855
855
  - app/services/curation_concerns/actors/actor_factory.rb
856
856
  - app/services/curation_concerns/admin_set_service.rb
857
+ - app/services/curation_concerns/collections_service.rb
857
858
  - app/services/curation_concerns/contextual_path.rb
858
859
  - app/services/curation_concerns/curation_concern.rb
859
860
  - app/services/curation_concerns/derivative_path.rb
@@ -1247,6 +1248,7 @@ files:
1247
1248
  - spec/search_builders/resource_types_service_spec.rb
1248
1249
  - spec/services/curation_concern_spec.rb
1249
1250
  - spec/services/curation_concerns/admin_set_service_spec.rb
1251
+ - spec/services/curation_concerns/collections_service_spec.rb
1250
1252
  - spec/services/curation_concerns/license_service_spec.rb
1251
1253
  - spec/services/curation_concerns/rights_statements_spec.rb
1252
1254
  - spec/services/derivative_path_spec.rb
@@ -1469,6 +1471,7 @@ test_files:
1469
1471
  - spec/search_builders/resource_types_service_spec.rb
1470
1472
  - spec/services/curation_concern_spec.rb
1471
1473
  - spec/services/curation_concerns/admin_set_service_spec.rb
1474
+ - spec/services/curation_concerns/collections_service_spec.rb
1472
1475
  - spec/services/curation_concerns/license_service_spec.rb
1473
1476
  - spec/services/curation_concerns/rights_statements_spec.rb
1474
1477
  - spec/services/derivative_path_spec.rb