Skip to content
This repository has been archived by the owner on Jan 5, 2019. It is now read-only.

Commit

Permalink
Merge pull request #777 from ualbertalib/724_associated_collections
Browse files Browse the repository at this point in the history
724 associated collections
  • Loading branch information
pbinkley committed Oct 16, 2015
2 parents 2bf4c6d + 6f5cafc commit cdc7101
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/hydranorth/collection_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
5 changes: 5 additions & 0 deletions app/models/search_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 0 additions & 5 deletions app/search_builders/hydranorth/search_builder.rb

This file was deleted.

39 changes: 0 additions & 39 deletions lib/hydranorth/collections/search_behaviors.rb

This file was deleted.

75 changes: 69 additions & 6 deletions spec/features/collection/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down Expand Up @@ -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

Expand All @@ -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")
Expand Down Expand Up @@ -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

0 comments on commit cdc7101

Please sign in to comment.