Skip to content

Commit 0e7a042

Browse files
committed
Make my controller retrieve only user's own collections.
My controller used to get all collections from the system rather than just the ones belonging to the user. When adding files to a collection, this would give the user a list of all collections to choose from. The user couldn't add the files to someone else's collection anyway so those options were useless.
1 parent 35fcdfb commit 0e7a042

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

app/controllers/concerns/sufia/my_controller_behavior.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ module MyControllerBehavior
66
include Hydra::Catalog
77
include Hydra::BatchEditBehavior
88
include Hydra::Collections::SelectsCollections
9-
9+
1010
included do
1111
include Blacklight::Configurable
1212

1313
self.copy_blacklight_config_from(CatalogController)
1414
self.blacklight_config.search_builder_class = Sufia::MySearchBuilder
15-
15+
1616
before_filter :authenticate_user!
1717
before_filter :enforce_show_permissions, only: :show
1818
before_filter :enforce_viewing_context_for_show_requests, only: :show
19-
before_filter :find_collections, only: :index
19+
before_filter :find_collections_with_edit_access, only: :index
2020

2121
self.search_params_logic += [:add_access_controls_to_solr_params, :add_advanced_parse_q_to_solr]
2222

spec/controllers/my/files_controller_spec.rb

+16-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
describe My::FilesController, :type => :controller do
44

55
let(:my_collection) do
6-
Collection.new(title: 'test collection').tap do |c|
6+
Collection.create(title: 'test collection') do |c|
77
c.apply_depositor_metadata(user.user_key)
8-
c.save!
8+
end
9+
end
10+
11+
let(:other_collection) do
12+
Collection.create(title: 'other test collection') do |c|
13+
c.apply_depositor_metadata(another_user.user_key)
914
end
1015
end
1116

@@ -19,10 +24,13 @@
1924

2025
let(:user) { FactoryGirl.find_or_create(:archivist) }
2126

27+
let(:another_user) { FactoryGirl.find_or_create(:jill) }
28+
2229
before do
2330
sign_in user
2431
@my_file = FactoryGirl.create(:generic_file, depositor: user)
2532
@my_collection = my_collection
33+
@other_collection = other_collection
2634
@shared_file = shared_file
2735
@unrelated_file = FactoryGirl.create(:generic_file, depositor: FactoryGirl.create(:user))
2836
@wrong_type = Batch.create
@@ -56,6 +64,12 @@
5664
expect(assigns[:document_list].map(&:id)).to_not include(@wrong_type.id)
5765
end
5866

67+
it "has the correct collections" do
68+
get :index
69+
expect(assigns[:user_collections].map(&:id)).to include(@my_collection.id)
70+
expect(assigns[:user_collections].map(&:id)).to_not include(@other_collection.id)
71+
end
72+
5973
describe "batch processing" do
6074
include Sufia::Messages
6175
let(:batch_id) {"batch_id"}

0 commit comments

Comments
 (0)