From bc43a8ffe8595721950c48eb4bc564444e0f2503 Mon Sep 17 00:00:00 2001 From: Tricia Jenkins Date: Thu, 15 Oct 2015 16:25:22 -0600 Subject: [PATCH 1/7] Revert "WIP but I think this will fix it" This reverts commit 818c1bbee614816e8f65aaff45cdc32e79c7cc0e. --- .../concerns/hydranorth/collections_controller_behavior.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/concerns/hydranorth/collections_controller_behavior.rb b/app/controllers/concerns/hydranorth/collections_controller_behavior.rb index b6c21a1a..7fb97e3e 100755 --- a/app/controllers/concerns/hydranorth/collections_controller_behavior.rb +++ b/app/controllers/concerns/hydranorth/collections_controller_behavior.rb @@ -18,7 +18,7 @@ def collection_member_search_builder_class # 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}" + solr_parameters[:q] << "collection_tesim: #{collection.id}" end # override Sufia::CollectionsControllerBehavior#presenter to establish From 93837b01b9568bb60e21628d6fcae1d06b0e83a1 Mon Sep 17 00:00:00 2001 From: Tricia Jenkins Date: Thu, 15 Oct 2015 16:25:36 -0600 Subject: [PATCH 2/7] Revert "WIP - override default include_collection_ids_filter to replace the join query" This reverts commit efa623d9745e3f9b6b050ee0dd8315b17dc69f86. --- .../collections/selects_collections.rb | 5 --- .../collections_controller_behavior.rb | 15 ++----- .../hydranorth/search_builder.rb | 5 --- .../collections/search_behaviors.rb | 39 ------------------- 4 files changed, 4 insertions(+), 60 deletions(-) delete mode 100644 app/search_builders/hydranorth/search_builder.rb delete mode 100644 lib/hydranorth/collections/search_behaviors.rb diff --git a/app/controllers/concerns/hydranorth/collections/selects_collections.rb b/app/controllers/concerns/hydranorth/collections/selects_collections.rb index bbcc4b8e..9a72794b 100644 --- a/app/controllers/concerns/hydranorth/collections/selects_collections.rb +++ b/app/controllers/concerns/hydranorth/collections/selects_collections.rb @@ -25,9 +25,4 @@ def find_communities(access_level = nil) # return the user's collections (or public collections if no access_level is applied) @user_communities = response.documents 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 7fb97e3e..609913f2 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}" - end - # override Sufia::CollectionsControllerBehavior#presenter to establish # a link between the presenter and the view context in which it will # present 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 From 7de9e84b1f3d995ddcf99a9c0bf055cdce063c3b Mon Sep 17 00:00:00 2001 From: Tricia Jenkins Date: Thu, 15 Oct 2015 16:26:01 -0600 Subject: [PATCH 3/7] quick fix #724 --- app/models/search_builder.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/models/search_builder.rb b/app/models/search_builder.rb index 8631ff01..2ac4bc9c 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] << "collection_tesim:#{collection.id} OR hasCollectionId_ssim:#{collection.id}" + end end From 532516b3a9104d57e4f5a29b47b5aeb2c79b58c2 Mon Sep 17 00:00:00 2001 From: Peter Binkley Date: Thu, 15 Oct 2015 17:44:19 -0600 Subject: [PATCH 4/7] Retrieve collections using belongsToCommunity_tesim This will retrieve grandchild collections if we allow nesting. There is no nesting in old ERA, so this is not a problem with migrated data. --- app/models/search_builder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/search_builder.rb b/app/models/search_builder.rb index 2ac4bc9c..84119c8a 100644 --- a/app/models/search_builder.rb +++ b/app/models/search_builder.rb @@ -5,6 +5,6 @@ class SearchBuilder < Blacklight::SearchBuilder def include_collection_ids(solr_parameters) solr_parameters[:fq] ||= [] - solr_parameters[:fq] << "collection_tesim:#{collection.id} OR hasCollectionId_ssim:#{collection.id}" + solr_parameters[:fq] << "(active_fedora_model_ssi:Collection AND belongsToCommunity_tesim:#{collection.id}) OR hasCollectionId_ssim:#{collection.id}" end end From d379ca9a956054d0a68f7e596f89809b4362ca04 Mon Sep 17 00:00:00 2001 From: Weiwei Shi Date: Thu, 15 Oct 2015 23:45:56 -0600 Subject: [PATCH 5/7] added spec test for displaying children of a community/collection --- spec/features/collection/collection_spec.rb | 62 ++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/spec/features/collection/collection_spec.rb b/spec/features/collection/collection_spec.rb index 51ce5aa2..731bb719 100755 --- a/spec/features/collection/collection_spec.rb +++ b/spec/features/collection/collection_spec.rb @@ -17,7 +17,6 @@ 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) } @@ -244,5 +243,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'], 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) + expect(page).to have_content(collection2.title) + expect(page).to have_content(generic_file1.title) + expect(page).not_to have_content(generic_file2.title) + 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) + expect(page).to have_content(generic_file2.title) + end + + end end From 178007a906eeba6245e7fe2d327e9c9a2e8b417d Mon Sep 17 00:00:00 2001 From: Tricia Jenkins Date: Fri, 16 Oct 2015 11:59:07 -0600 Subject: [PATCH 6/7] some bug fixes related to #724 but one test still failing --- .../hydranorth/collections_controller_behavior.rb | 2 +- .../concerns/hydranorth/collection_behavior.rb | 2 +- spec/features/collection/collection_spec.rb | 15 ++++++++------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/controllers/concerns/hydranorth/collections_controller_behavior.rb b/app/controllers/concerns/hydranorth/collections_controller_behavior.rb index 609913f2..8b2c2bb6 100755 --- a/app/controllers/concerns/hydranorth/collections_controller_behavior.rb +++ b/app/controllers/concerns/hydranorth/collections_controller_behavior.rb @@ -84,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/spec/features/collection/collection_spec.rb b/spec/features/collection/collection_spec.rb index 731bb719..ab8a0319 100755 --- a/spec/features/collection/collection_spec.rb +++ b/spec/features/collection/collection_spec.rb @@ -11,6 +11,7 @@ let!(:community) do Collection.create( title: 'Community') do |c| c.apply_depositor_metadata(admin.user_key) + c.is_community = true end end @@ -275,7 +276,7 @@ end let!(:generic_file1) do - GenericFile.create( title: ['Test Item'], read_groups: ['public'] ) do |g| + 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] @@ -291,16 +292,16 @@ 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) - expect(page).to have_content(collection2.title) - expect(page).to have_content(generic_file1.title) - expect(page).not_to have_content(generic_file2.title) + 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) - expect(page).to have_content(generic_file2.title) + expect(page).not_to have_content(generic_file1.title.first) + expect(page).to have_content(generic_file2.title.first) end end From 6f5cafc4a9a2ab0e06fe3ec3257311bca6dcc881 Mon Sep 17 00:00:00 2001 From: Tricia Jenkins Date: Fri, 16 Oct 2015 12:30:41 -0600 Subject: [PATCH 7/7] fix setup for spec which tests the selection menu for files in a collection --- spec/features/collection/collection_spec.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/spec/features/collection/collection_spec.rb b/spec/features/collection/collection_spec.rb index ab8a0319..3337d8cc 100755 --- a/spec/features/collection/collection_spec.rb +++ b/spec/features/collection/collection_spec.rb @@ -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")