Skip to content

Commit

Permalink
Merge pull request #1231 from durham-university/fix_my_controller_use…
Browse files Browse the repository at this point in the history
…r_collections

Make my controller retrieve only user's own collections.
  • Loading branch information
mjgiarlo committed Jul 9, 2015
2 parents 35fcdfb + 0e7a042 commit cc429ac
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
6 changes: 3 additions & 3 deletions app/controllers/concerns/sufia/my_controller_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
18 changes: 16 additions & 2 deletions spec/controllers/my/files_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

0 comments on commit cc429ac

Please sign in to comment.