hydra-batch-edit 1.1.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/.gitignore +2 -0
 - data/.rubocop.yml +21 -0
 - data/.rubocop_todo.yml +278 -0
 - data/.travis.yml +1 -5
 - data/Gemfile +35 -0
 - data/README.textile +8 -18
 - data/Rakefile +17 -48
 - data/app/assets/javascripts/{batch_edit.js.coffee → batch_edit/batch_edit.js.coffee} +0 -0
 - data/app/assets/stylesheets/{batch_edit.css.scss → batch_edit/batch_edit.scss} +0 -0
 - data/app/controllers/concerns/hydra/batch_edit_behavior.rb +2 -2
 - data/hydra-batch-edit.gemspec +8 -5
 - data/lib/generators/hydra_batch_edit/install_generator.rb +17 -0
 - data/lib/generators/hydra_batch_edit/templates/batch_edit.js +1 -0
 - data/lib/generators/hydra_batch_edit/templates/batch_edit.scss +1 -0
 - data/lib/hydra-batch-edit.rb +1 -1
 - data/lib/hydra/batch_edit.rb +0 -1
 - data/lib/hydra/batch_edit/version.rb +1 -1
 - data/spec/controllers/batch_edits_controller_spec.rb +43 -43
 - data/spec/helpers/batch_edit_helper_spec.rb +3 -3
 - data/spec/routing/batch_edit_routes_spec.rb +10 -10
 - data/spec/spec_helper.rb +7 -4
 - data/spec/support/config/initializers/hydra_config.rb +0 -28
 - data/spec/{support → test_app_templates}/app/models/sample.rb +0 -0
 - data/spec/{support → test_app_templates}/app/models/solr_document.rb +0 -0
 - data/spec/{support → test_app_templates}/db/migrate/20111101221803_create_searches.rb +0 -0
 - data/spec/test_app_templates/lib/generators/test_app_generator.rb +24 -0
 - metadata +81 -38
 - data/gemfiles/rails3.gemfile +0 -6
 - data/gemfiles/rails4.gemfile +0 -6
 - data/lib/hydra/batch_edit/search_service.rb +0 -62
 - data/spec/lib/search_service_spec.rb +0 -41
 
    
        data/gemfiles/rails3.gemfile
    DELETED
    
    
    
        data/gemfiles/rails4.gemfile
    DELETED
    
    
| 
         @@ -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
         
     |