From 0e7a0427c319159827f37992395ed1e80b89aaf5 Mon Sep 17 00:00:00 2001 From: Olli Lyytinen Date: Thu, 9 Jul 2015 15:12:11 +0100 Subject: [PATCH] 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. --- .../concerns/sufia/my_controller_behavior.rb | 6 +++--- spec/controllers/my/files_controller_spec.rb | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app/controllers/concerns/sufia/my_controller_behavior.rb b/app/controllers/concerns/sufia/my_controller_behavior.rb index ed243ddb46..f5ad9d7f34 100644 --- a/app/controllers/concerns/sufia/my_controller_behavior.rb +++ b/app/controllers/concerns/sufia/my_controller_behavior.rb @@ -6,17 +6,17 @@ module MyControllerBehavior include Hydra::Catalog include Hydra::BatchEditBehavior include Hydra::Collections::SelectsCollections - + included do include Blacklight::Configurable self.copy_blacklight_config_from(CatalogController) self.blacklight_config.search_builder_class = Sufia::MySearchBuilder - + before_filter :authenticate_user! before_filter :enforce_show_permissions, only: :show before_filter :enforce_viewing_context_for_show_requests, only: :show - before_filter :find_collections, only: :index + before_filter :find_collections_with_edit_access, only: :index self.search_params_logic += [:add_access_controls_to_solr_params, :add_advanced_parse_q_to_solr] diff --git a/spec/controllers/my/files_controller_spec.rb b/spec/controllers/my/files_controller_spec.rb index 9018dd181f..eb0afcb5a2 100644 --- a/spec/controllers/my/files_controller_spec.rb +++ b/spec/controllers/my/files_controller_spec.rb @@ -3,9 +3,14 @@ describe My::FilesController, :type => :controller do let(:my_collection) do - Collection.new(title: 'test collection').tap do |c| + Collection.create(title: 'test collection') do |c| c.apply_depositor_metadata(user.user_key) - c.save! + end + end + + let(:other_collection) do + Collection.create(title: 'other test collection') do |c| + c.apply_depositor_metadata(another_user.user_key) end end @@ -19,10 +24,13 @@ let(:user) { FactoryGirl.find_or_create(:archivist) } + let(:another_user) { FactoryGirl.find_or_create(:jill) } + before do sign_in user @my_file = FactoryGirl.create(:generic_file, depositor: user) @my_collection = my_collection + @other_collection = other_collection @shared_file = shared_file @unrelated_file = FactoryGirl.create(:generic_file, depositor: FactoryGirl.create(:user)) @wrong_type = Batch.create @@ -56,6 +64,12 @@ expect(assigns[:document_list].map(&:id)).to_not include(@wrong_type.id) end + it "has the correct collections" do + get :index + expect(assigns[:user_collections].map(&:id)).to include(@my_collection.id) + expect(assigns[:user_collections].map(&:id)).to_not include(@other_collection.id) + end + describe "batch processing" do include Sufia::Messages let(:batch_id) {"batch_id"}