diff --git a/app/controllers/concerns/hydranorth/collections/selects_collections.rb b/app/controllers/concerns/hydranorth/collections/selects_collections.rb index acfa6bc5..80002c70 100644 --- a/app/controllers/concerns/hydranorth/collections/selects_collections.rb +++ b/app/controllers/concerns/hydranorth/collections/selects_collections.rb @@ -29,9 +29,4 @@ def find_communities(access_level = nil) d1.title <=> d2.title end end - - protected - def collections_search_builder_class - Hydranorth::SearchBuilder - end end diff --git a/app/controllers/concerns/hydranorth/collections_controller_behavior.rb b/app/controllers/concerns/hydranorth/collections_controller_behavior.rb index b6c21a1a..8b2c2bb6 100755 --- a/app/controllers/concerns/hydranorth/collections_controller_behavior.rb +++ b/app/controllers/concerns/hydranorth/collections_controller_behavior.rb @@ -4,23 +4,16 @@ module CollectionsControllerBehavior include Sufia::CollectionsControllerBehavior def show - self.search_params_logic -= [:add_access_controls_to_solr_params] + if current_user && current_user.admin? + self.search_params_logic -= [:add_access_controls_to_solr_params] + end + super presenter end protected - def collection_member_search_builder_class - Hydranorth::SearchBuilder - end - - # include filters into the query to only include the collection memebers - def include_hydranorth_hascollection(solr_parameters) - solr_parameters[:q] ||= [] - solr_parameters[:q] << "collection_tesim:#{collection.id} OR hasCollectionId_tesim:#{collection.id}" - end - # override Sufia::CollectionsControllerBehavior#presenter to establish # a link between the presenter and the view context in which it will # present @@ -91,7 +84,7 @@ def add_file_to_collection(file, collection) end def add_member_to_community(member, community) belongsToCommunity = member.belongsToCommunity - belongsToCommunity.push collection.id + belongsToCommunity.push community.id member.belongsToCommunity = belongsToCommunity member.save! end diff --git a/app/models/concerns/hydranorth/collection_behavior.rb b/app/models/concerns/hydranorth/collection_behavior.rb index 555e711c..44cd6689 100644 --- a/app/models/concerns/hydranorth/collection_behavior.rb +++ b/app/models/concerns/hydranorth/collection_behavior.rb @@ -44,7 +44,7 @@ def is_official? self.is_official ||= false end def is_community? - self.is_official ||= false + self.is_community ||= false end def belongsToCommunity? !self.belongsToCommunity.empty? diff --git a/app/models/search_builder.rb b/app/models/search_builder.rb index 8631ff01..84119c8a 100644 --- a/app/models/search_builder.rb +++ b/app/models/search_builder.rb @@ -2,4 +2,9 @@ class SearchBuilder < Blacklight::SearchBuilder include Blacklight::Solr::SearchBuilderBehavior include Hydra::AccessControlsEnforcement include Sufia::SearchBuilder + + def include_collection_ids(solr_parameters) + solr_parameters[:fq] ||= [] + solr_parameters[:fq] << "(active_fedora_model_ssi:Collection AND belongsToCommunity_tesim:#{collection.id}) OR hasCollectionId_ssim:#{collection.id}" + end end diff --git a/app/search_builders/hydranorth/search_builder.rb b/app/search_builders/hydranorth/search_builder.rb deleted file mode 100644 index 51acd839..00000000 --- a/app/search_builders/hydranorth/search_builder.rb +++ /dev/null @@ -1,5 +0,0 @@ -module Hydranorth - class SearchBuilder < Hydra::Collections::SearchBuilder - include Hydranorth::Collections::SearchBehaviors - end -end diff --git a/lib/hydranorth/collections/search_behaviors.rb b/lib/hydranorth/collections/search_behaviors.rb deleted file mode 100644 index 2984c0eb..00000000 --- a/lib/hydranorth/collections/search_behaviors.rb +++ /dev/null @@ -1,39 +0,0 @@ -module Hydranorth::Collections::SearchBehaviors - extend ActiveSupport::Concern - - include Hydra::Collections::SearchBehaviors - include BlacklightAdvancedSearch::AdvancedSearchBuilder - - included do - class_attribute :from_field - self.from_field = 'member_ids_ssim' - end - - def collection - scope.collection - end - - - def some_rows(solr_parameters) - solr_parameters[:rows] = '100' - end - - def add_collection_filter(solr_parameters) - solr_parameters[:fq] ||= [] - solr_parameters[:fq] << ActiveFedora::SolrQueryBuilder.construct_query_for_rel(has_model: ::Collection.to_class_uri) - end - - def discovery_perms= perms - @discovery_perms = perms - end - - def discovery_permissions - @discovery_perms || super - end - def include_collection_ids(solr_parameters) - solr_parameters[:fq] ||= [] - solr_parameters[:fq] << "#{Solrizer.solr_name('collection')}: scope.collection.id" - end - - -end diff --git a/spec/features/collection/collection_spec.rb b/spec/features/collection/collection_spec.rb index 51ce5aa2..3337d8cc 100755 --- a/spec/features/collection/collection_spec.rb +++ b/spec/features/collection/collection_spec.rb @@ -11,13 +11,13 @@ let!(:community) do Collection.create( title: 'Community') do |c| c.apply_depositor_metadata(admin.user_key) + c.is_community = true end end after :each do cleanup_jetty end - describe 'total item count for a collection with 1 public item and 1 private item' do let(:alice) { FactoryGirl.create(:alice) } @@ -188,14 +188,15 @@ end describe 'check collection for drop down menu options' do + let!(:collection_modify) do + Collection.create( title: 'Test Collection') do |c| + c.apply_depositor_metadata(admin.user_key) + end + end let!(:generic_file) do GenericFile.create( title: ['Test Item'], read_groups: ['public'] ) do |g| g.apply_depositor_metadata(admin.user_key) - end - end - let!(:collection_modify) do - Collection.create( title: 'Test Collection', members: [generic_file] ) do |c| - c.apply_depositor_metadata(admin.user_key) + g.hasCollectionId = [collection_modify.id] end end @@ -204,6 +205,7 @@ end it "should not see edit and delete options" do + expect(page).to have_content(generic_file.title.first) click_button("Select an action") expect(page).to have_content("Test Item") @@ -244,5 +246,66 @@ end end + describe 'community should show children collections' do + + let!(:community) do + Collection.create( title: 'Test Community') do |c| + c.apply_depositor_metadata(jill.user_key) + c.is_community = true + c.is_official = true + c.is_admin_set = false + end + end + + let!(:collection1) do + Collection.create( title: 'Test Collection 1') do |c| + c.apply_depositor_metadata(jill.user_key) + c.is_community = false + c.is_official = true + c.is_admin_set = false + c.belongsToCommunity = [community.id] + end + end + + let!(:collection2) do + Collection.create( title: 'Test Collection 2') do |c| + c.apply_depositor_metadata(jill.user_key) + c.is_community = false + c.is_official = true + c.is_admin_set = false + c.belongsToCommunity = [community.id] + end + end + + let!(:generic_file1) do + GenericFile.create( title: ['Test Item 1'], read_groups: ['public'] ) do |g| + g.apply_depositor_metadata(jill.user_key) + g.belongsToCommunity = [community.id] + g.hasCollectionId = [community.id] + end + end + let!(:generic_file2) do + GenericFile.create( title: ['Test Item 2'], read_groups: ['public'] ) do |g| + g.apply_depositor_metadata(jill.user_key) + g.hasCollectionId = [collection1.id] + g.belongsToCommunity = [community.id] + end + end + + it "should list 2 collections and 1 generic files on the community page" do + visit "/collections/#{community.id}" + expect(page).to have_content(collection1.title.first) + expect(page).to have_content(collection2.title.first) + expect(page).to have_content(generic_file1.title.first) + expect(page).not_to have_content(generic_file2.title.first) + end + + it "should list 1 generic file on the collection1 page " do + visit "/collections/#{collection1.id}" + expect(page).not_to have_content(generic_file1.title.first) + expect(page).to have_content(generic_file2.title.first) + end + + end end