hydra-batch-edit 1.1.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +21 -0
  4. data/.rubocop_todo.yml +278 -0
  5. data/.travis.yml +1 -5
  6. data/Gemfile +35 -0
  7. data/README.textile +8 -18
  8. data/Rakefile +17 -48
  9. data/app/assets/javascripts/{batch_edit.js.coffee → batch_edit/batch_edit.js.coffee} +0 -0
  10. data/app/assets/stylesheets/{batch_edit.css.scss → batch_edit/batch_edit.scss} +0 -0
  11. data/app/controllers/concerns/hydra/batch_edit_behavior.rb +2 -2
  12. data/hydra-batch-edit.gemspec +8 -5
  13. data/lib/generators/hydra_batch_edit/install_generator.rb +17 -0
  14. data/lib/generators/hydra_batch_edit/templates/batch_edit.js +1 -0
  15. data/lib/generators/hydra_batch_edit/templates/batch_edit.scss +1 -0
  16. data/lib/hydra-batch-edit.rb +1 -1
  17. data/lib/hydra/batch_edit.rb +0 -1
  18. data/lib/hydra/batch_edit/version.rb +1 -1
  19. data/spec/controllers/batch_edits_controller_spec.rb +43 -43
  20. data/spec/helpers/batch_edit_helper_spec.rb +3 -3
  21. data/spec/routing/batch_edit_routes_spec.rb +10 -10
  22. data/spec/spec_helper.rb +7 -4
  23. data/spec/support/config/initializers/hydra_config.rb +0 -28
  24. data/spec/{support → test_app_templates}/app/models/sample.rb +0 -0
  25. data/spec/{support → test_app_templates}/app/models/solr_document.rb +0 -0
  26. data/spec/{support → test_app_templates}/db/migrate/20111101221803_create_searches.rb +0 -0
  27. data/spec/test_app_templates/lib/generators/test_app_generator.rb +24 -0
  28. metadata +81 -38
  29. data/gemfiles/rails3.gemfile +0 -6
  30. data/gemfiles/rails4.gemfile +0 -6
  31. data/lib/hydra/batch_edit/search_service.rb +0 -62
  32. data/spec/lib/search_service_spec.rb +0 -41
@@ -1,6 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Please see hydra-batch-edit.gemspec for dependency information.
4
- gemspec :path=>"../"
5
-
6
- gem 'rails', "~> 3.2"
@@ -1,6 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Please see hydra-batch-edit.gemspec for dependency information.
4
- gemspec :path=>"../"
5
-
6
- gem 'rails', '~> 4.0.0'
@@ -1,62 +0,0 @@
1
- module Hydra
2
- module BatchEdit
3
- class SearchService
4
- include Blacklight::Configurable
5
- include Blacklight::SolrHelper
6
-
7
- def initialize(session, user_key)
8
- @session = session
9
- @user_key = user_key
10
- self.class.copy_blacklight_config_from(::CatalogController)
11
- end
12
-
13
- def blacklight_solr
14
- Blacklight.solr
15
- end
16
-
17
- solr_search_params_logic << :apply_gated_search
18
-
19
- def last_search_documents
20
- return [] if @session[:history].blank?
21
- last_search_id = @session[:history].first
22
- search = Search.find(last_search_id)
23
- _, document_list = get_search_results(search.query_params, :fl=>'id', :rows=>1000)
24
- document_list
25
- end
26
-
27
- # filter that sets up access-controlled lucene query in order to provide gated search behavior
28
- # @param solr_parameters the current solr parameters
29
- # @param user_parameters the current user-submitted parameters
30
- def apply_gated_search(solr_parameters, user_parameters)
31
- solr_parameters[:fq] ||= []
32
-
33
- # Grant access to public content
34
- user_access_filters = []
35
- user_access_filters << "#{solr_access_control_suffix(:group)}:public"
36
-
37
- # Grant access based on user id & role
38
- unless @user_key.blank?
39
- # for roles
40
- ::RoleMapper.roles(@user_key).each do |role|
41
- user_access_filters << "#{solr_access_control_suffix(:group)}:#{escape_slashes(role)}"
42
- end
43
- # for individual person access
44
- user_access_filters << "#{solr_access_control_suffix(:individual)}:#{escape_slashes(@user_key)}"
45
- end
46
- solr_parameters[:fq] << user_access_filters.join(' OR ')
47
- solr_parameters
48
- end
49
-
50
- def escape_slashes(value)
51
- value.gsub('/', '\/')
52
- end
53
-
54
- # @param [Symbol] key The permission type to return. Must be `:group` or `:individual`
55
- def solr_access_control_suffix(key)
56
- raise ArgumentError, "you must provide :group or :individual" unless [:group, :individual].include?(key)
57
- Hydra.config[:permissions][:edit][key]
58
- end
59
- end
60
- end
61
- end
62
-
@@ -1,41 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Hydra::BatchEdit::SearchService do
4
- before do
5
- @login = 'vanessa'
6
- @session = {:history => [17, 14, 12, 9]}
7
- @service = Hydra::BatchEdit::SearchService.new(@session, @login)
8
- end
9
-
10
- it "should get the documents for the first history entry" do
11
- Search.should_receive(:find).with(17).and_return(Search.new(:query_params=>{:q=>"World Peace"}))
12
- @service.should_receive(:get_search_results).and_return([:one, [:doc1, :doc2]])
13
- @service.last_search_documents.should == [:doc1, :doc2]
14
- end
15
-
16
- describe 'apply_gated_search' do
17
- before(:each) do
18
- RoleMapper.stub(:roles).with(@login).and_return(['umg/test.group.1'])
19
- params = @service.apply_gated_search({}, {})
20
- @group_query = params[:fq].first.split(' OR ')[1]
21
- end
22
- it "should escape slashes in groups" do
23
- @group_query.should == 'edit_access_group_ssim:umg\/test.group.1'
24
- end
25
- it "should allow overriding Solr's access control suffix" do
26
- module Hydra
27
- module BatchEdit
28
- class SearchService
29
- def solr_access_control_suffix(key)
30
- "edit_#{key}_customfield"
31
- end
32
- end
33
- end
34
- end
35
- @service = Hydra::BatchEdit::SearchService.new({}, '')
36
- params = @service.apply_gated_search({}, {})
37
- @public_query = params[:fq].first.split(' OR ')[0]
38
- @public_query.should == 'edit_group_customfield:public'
39
- end
40
- end
41
- end