hydra-batch-edit 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 88b816f49539deda36c4029d5fc68148e23436d7
4
- data.tar.gz: 138ecb568f0749a34cfa497918004646b6110fd9
3
+ metadata.gz: 041fb6c8cbceea532367e5b77b7283243abb98f2
4
+ data.tar.gz: 21100df59111000878aee65687e56d9bd6bde753
5
5
  SHA512:
6
- metadata.gz: 7a270792034acf9c454750ee27b20a7dbcb159919e8a417d8d8dc99d7987311800bbba87a7a5bc7eb26a968cf25c1234c8b10fa92c5f661b36eafcd2a889ae05
7
- data.tar.gz: 9707ec9d4c52ae144f5a27aec51a6c013acfaf326675db7379fd20012acb595fb2e1c98dfa709f73f372a27f968ef0ffa5441bd14a4615843b0ebb753118460b
6
+ metadata.gz: ab5feb6defd561b0e8224d98253ce8a15c62bb05a8a586294515215195a484a70dff7df0082435ca88b381964259e07cb613e3ba5873d8432c6fbdf840090b96
7
+ data.tar.gz: ffe4e1e1e4689578978802ddc210675e1c3492df589d2e9f54f524e6c0a613b89f904d82d740f70a5e1b1b78343ebee98e0ae3fdfdea12bc0089e6cc4fdadefa
data/.gitignore CHANGED
@@ -1,5 +1,10 @@
1
1
  *.gem
2
2
  Gemfile.lock
3
+ .rvmrc
4
+ .ruby-version
5
+ .ruby-gemset
6
+ ruby-version
7
+ ruby-gemset
3
8
  *.rbc
4
9
  .bundle
5
10
  .config
data/Rakefile CHANGED
@@ -7,12 +7,17 @@ ENV["RAILS_ROOT"] ||= 'spec/internal'
7
7
  desc 'Default: run specs.'
8
8
  task :default => :spec
9
9
 
10
- desc "Run specs"
11
- RSpec::Core::RakeTask.new(:spec => :generate) do |t|
12
- t.rspec_opts = "--colour"
10
+
11
+ task :spec => [:generate] do |t|
12
+ focused_spec = ENV['SPEC'] ? " SPEC=#{File.join(GEM_ROOT, ENV['SPEC'])}" : ''
13
+ within_test_app do
14
+ system "rake myspec#{focused_spec}"
15
+ abort "Error running hydra-batch-edit" unless $?.success?
16
+ end
13
17
  end
14
18
 
15
19
 
20
+
16
21
  desc "Create the test rails app"
17
22
  task :generate do
18
23
  unless File.exists?('spec/internal/Rakefile')
@@ -23,15 +28,15 @@ task :generate do
23
28
  puts "Copying generator"
24
29
  `cp -r spec/support/lib/generators spec/internal/lib`
25
30
 
26
- FileUtils.cd('spec/internal')
27
- puts "Bundle install"
28
- `bundle install`
29
- puts "running generator"
30
- puts `rails generate test_app`
31
+ within_test_app do
32
+ puts "Bundle install"
33
+ puts `bundle install`
34
+ puts "running generator"
35
+ puts `rails generate test_app`
31
36
 
32
- puts "running migrations"
33
- puts `rake db:migrate db:test:prepare`
34
- FileUtils.cd('../..')
37
+ puts "running migrations"
38
+ puts `rake db:migrate db:test:prepare`
39
+ end
35
40
  end
36
41
  puts "Running specs"
37
42
  end
@@ -41,3 +46,11 @@ task :clean do
41
46
  puts "Removing sample rails app"
42
47
  `rm -rf spec/internal`
43
48
  end
49
+
50
+ def within_test_app
51
+ FileUtils.cd('spec/internal')
52
+ Bundler.with_clean_env do
53
+ yield
54
+ end
55
+ FileUtils.cd('../..')
56
+ end
@@ -4,7 +4,6 @@ module Hydra
4
4
  include Blacklight::Configurable
5
5
  include Blacklight::SolrHelper
6
6
 
7
-
8
7
  def initialize(session, user_key)
9
8
  @session = session
10
9
  @user_key = user_key
@@ -13,37 +12,46 @@ module Hydra
13
12
 
14
13
  solr_search_params_logic << :apply_gated_search
15
14
 
16
- def last_search_documents
15
+ def last_search_documents
17
16
  return [] if @session[:history].blank?
18
17
  last_search_id = @session[:history].first
19
- search = Search.find(last_search_id)
20
- result, document_list = get_search_results(search.query_params, :fl=>'id', :rows=>1000)
18
+ search = Search.find(last_search_id)
19
+ _, document_list = get_search_results(search.query_params, :fl=>'id', :rows=>1000)
21
20
  document_list
22
21
  end
23
22
 
24
23
  # filter that sets up access-controlled lucene query in order to provide gated search behavior
25
24
  # @param solr_parameters the current solr parameters
26
- # @param user_parameters the current user-subitted parameters
25
+ # @param user_parameters the current user-submitted parameters
27
26
  def apply_gated_search(solr_parameters, user_parameters)
28
27
  solr_parameters[:fq] ||= []
28
+
29
29
  # Grant access to public content
30
30
  user_access_filters = []
31
-
32
- user_access_filters << "edit_access_group_t:public"
33
-
31
+ user_access_filters << "#{solr_access_control_suffix(:group)}:public"
32
+
34
33
  # Grant access based on user id & role
35
- unless @user_key.nil?
34
+ unless @user_key.blank?
36
35
  # for roles
37
- ::RoleMapper.roles(@user_key).each_with_index do |role, i|
38
- user_access_filters << "edit_access_group_t:#{role}"
36
+ ::RoleMapper.roles(@user_key).each do |role|
37
+ user_access_filters << "#{solr_access_control_suffix(:group)}:#{escape_slashes(role)}"
39
38
  end
40
39
  # for individual person access
41
- user_access_filters << "edit_access_person_t:#{@user_key}"
40
+ user_access_filters << "#{solr_access_control_suffix(:individual)}:#{escape_slashes(@user_key)}"
42
41
  end
43
- solr_parameters[:fq] << user_access_filters.join(" OR ")
44
- logger.debug("Solr parameters: #{ solr_parameters.inspect }")
45
- end
42
+ solr_parameters[:fq] << user_access_filters.join(' OR ')
43
+ solr_parameters
44
+ end
45
+
46
+ def escape_slashes(value)
47
+ value.gsub('/', '\/')
48
+ end
46
49
 
50
+ # @param [Symbol] key The permission type to return. Must be `:group` or `:individual`
51
+ def solr_access_control_suffix(key)
52
+ raise ArgumentError, "you must provide :group or :individual" unless [:group, :individual].include?(key)
53
+ Hydra.config[:permissions][:edit][key]
54
+ end
47
55
  end
48
56
  end
49
57
  end
@@ -1,5 +1,5 @@
1
1
  module Hydra
2
2
  module BatchEdit
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -1,11 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe BatchEditsController do
4
- before :all do
5
- module ActiveFedora
6
- module Base; end
7
- end
8
- end
9
4
  before(:each) do
10
5
  request.env["HTTP_REFERER"] = "/"
11
6
  end
@@ -1,17 +1,41 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Hydra::BatchEdit::SearchService do
4
-
5
4
  before do
5
+ @login = 'vanessa'
6
6
  @session = {:history => [17, 14, 12, 9]}
7
- @service = Hydra::BatchEdit::SearchService.new(@session, 'vanessa')
7
+ @service = Hydra::BatchEdit::SearchService.new(@session, @login)
8
8
  end
9
9
 
10
10
  it "should get the documents for the first history entry" do
11
11
  Search.should_receive(:find).with(17).and_return(Search.new(:query_params=>{:q=>"World Peace"}))
12
12
  @service.should_receive(:get_search_results).and_return([:one, [:doc1, :doc2]])
13
13
  @service.last_search_documents.should == [:doc1, :doc2]
14
-
15
14
  end
16
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
17
41
  end
@@ -6,6 +6,7 @@ gem 'rails'
6
6
  # gem 'rails', :git => 'git://github.com/rails/rails.git'
7
7
 
8
8
  gem 'sqlite3'
9
+ gem 'hydra-head'
9
10
 
10
11
 
11
12
  # Gems used only for assets and not required
@@ -15,7 +16,7 @@ group :assets do
15
16
  gem 'coffee-rails', '~> 3.2.1'
16
17
 
17
18
  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
18
- gem 'therubyracer', :platforms => :ruby
19
+ #gem 'therubyracer', :platforms => :ruby
19
20
 
20
21
  gem 'uglifier', '>= 1.0.3'
21
22
  end
@@ -0,0 +1,28 @@
1
+ # The following lines determine which user attributes your hydrangea app will use
2
+ # This configuration allows you to use the out of the box ActiveRecord associations between users and user_attributes
3
+ # It also allows you to specify your own user attributes
4
+ # The easiest way to override these methods would be to create your own module to include in User
5
+ # For example you could create a module for your local LDAP instance called MyLocalLDAPUserAttributes:
6
+ # User.send(:include, MyLocalLDAPAttributes)
7
+ # As long as your module includes methods for full_name, affiliation, and photo the personalization_helper should function correctly
8
+ #
9
+
10
+ # windows doesn't properly require hydra-head (from the gemfile), so we need to require it explicitly here:
11
+ require 'hydra/head' unless defined? Hydra
12
+
13
+ if Hydra.respond_to?(:configure)
14
+ Hydra.configure(:shared) do |config|
15
+ # This specifies the solr field names of permissions-related fields.
16
+ # You only need to change these values if you've indexed permissions by some means other than the Hydra's built-in tooling.
17
+ # If you change these, you must also update the permissions request handler in your solrconfig.xml to return those values
18
+ indexer = Solrizer::Descriptor.new(:string, :stored, :indexed, :multivalued)
19
+ config[:permissions] = {
20
+ :discover => {:group =>ActiveFedora::SolrService.solr_name("discover_access_group", indexer), :individual=>ActiveFedora::SolrService.solr_name("discover_access_person", indexer)},
21
+ :read => {:group =>ActiveFedora::SolrService.solr_name("read_access_group", indexer), :individual=>ActiveFedora::SolrService.solr_name("read_access_person", indexer)},
22
+ :edit => {:group =>ActiveFedora::SolrService.solr_name("edit_access_group", indexer), :individual=>ActiveFedora::SolrService.solr_name("edit_access_person", indexer)},
23
+ :owner => ActiveFedora::SolrService.solr_name("depositor", indexer),
24
+ :embargo_release_date => ActiveFedora::SolrService.solr_name("embargo_release_date", Solrizer::Descriptor.new(:date, :stored, :indexed))
25
+ }
26
+
27
+ end
28
+ end
@@ -16,4 +16,12 @@ class TestAppGenerator < Rails::Generators::Base
16
16
  copy_file "app/models/solr_document.rb"
17
17
  copy_file "db/migrate/20111101221803_create_searches.rb"
18
18
  end
19
+
20
+ def copy_rspec_rake_task
21
+ copy_file "lib/tasks/rspec.rake"
22
+ end
23
+
24
+ def copy_hydra_config
25
+ copy_file "config/initializers/hydra_config.rb"
26
+ end
19
27
  end
@@ -0,0 +1,9 @@
1
+ require 'rspec/core/rake_task'
2
+ desc "run the hydra-batch-edit gem spec"
3
+ gem_home = File.expand_path('../../../../..', __FILE__)
4
+ RSpec::Core::RakeTask.new(:myspec) do |t|
5
+ t.pattern = gem_home + '/spec/**/*_spec.rb'
6
+ t.rspec_opts = "--colour"
7
+ t.ruby_opts = "-I#{gem_home}/spec"
8
+ end
9
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-batch-edit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-15 00:00:00.000000000 Z
12
+ date: 2013-04-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: blacklight
@@ -107,8 +107,10 @@ files:
107
107
  - spec/support/Gemfile
108
108
  - spec/support/app/models/sample.rb
109
109
  - spec/support/app/models/solr_document.rb
110
+ - spec/support/config/initializers/hydra_config.rb
110
111
  - spec/support/db/migrate/20111101221803_create_searches.rb
111
112
  - spec/support/lib/generators/test_app_generator.rb
113
+ - spec/support/lib/tasks/rspec.rake
112
114
  homepage: https://github.com/projecthydra/hydra-batch-edit
113
115
  licenses: []
114
116
  metadata: {}
@@ -128,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
130
  version: '0'
129
131
  requirements: []
130
132
  rubyforge_project:
131
- rubygems_version: 2.0.0
133
+ rubygems_version: 2.0.3
132
134
  signing_key:
133
135
  specification_version: 4
134
136
  summary: Rails engine to do batch editing with hydra-head
@@ -142,6 +144,7 @@ test_files:
142
144
  - spec/support/Gemfile
143
145
  - spec/support/app/models/sample.rb
144
146
  - spec/support/app/models/solr_document.rb
147
+ - spec/support/config/initializers/hydra_config.rb
145
148
  - spec/support/db/migrate/20111101221803_create_searches.rb
146
149
  - spec/support/lib/generators/test_app_generator.rb
147
- has_rdoc:
150
+ - spec/support/lib/tasks/rspec.rake