hydra-file-access 5.0.0.pre11 → 5.0.0.pre12

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.
@@ -15,11 +15,11 @@ Gem::Specification.new do |gem|
15
15
  gem.name = "hydra-file-access"
16
16
  gem.require_paths = ["lib"]
17
17
  gem.version = version
18
- # gem.required_ruby_version = '>= 1.9.3'
18
+ gem.required_ruby_version = '>= 1.9.3'
19
19
 
20
20
 
21
21
  gem.add_dependency "rails", '~>3.2.3'
22
- gem.add_dependency "blacklight", '~>3.4'
22
+ gem.add_dependency "blacklight"
23
23
  gem.add_dependency "devise"
24
24
  gem.add_dependency "active-fedora"
25
25
  gem.add_dependency 'RedCloth', '=4.2.9'
@@ -34,6 +34,6 @@ Gem::Specification.new do |gem|
34
34
  gem.add_development_dependency 'jettywrapper', ">=1.3.0"
35
35
  gem.add_development_dependency 'rspec-rails'
36
36
  gem.add_development_dependency 'cucumber-rails', '>=1.2.0'
37
- gem.add_development_dependency 'factory_girl_rails', '<2.0.0' #>=2.0.0 requires ruby 1.9
37
+ gem.add_development_dependency 'factory_girl_rails'
38
38
  gem.add_development_dependency 'solrizer-fedora', '>=2.1.0'
39
39
  end
@@ -0,0 +1,36 @@
1
+ # -*- encoding : utf-8 -*-
2
+ # Copy Blacklight assets to public folder in current app.
3
+ # If you want to do this on application startup, you can
4
+ # add this next line to your one of your environment files --
5
+ # generally you'd only want to do this in 'development', and can
6
+ # add it to environments/development.rb:
7
+ # require File.join(Hydra.root, "lib", "generators", "hydra", "assets_generator.rb")
8
+ # Hydra::Assets.start(["--force", "--quiet"])
9
+
10
+
11
+ # Need the requires here so we can call the generator from environment.rb
12
+ # as suggested above.
13
+ require 'rails/generators'
14
+ require 'rails/generators/base'
15
+ module Hydra
16
+ class AssetsGenerator < Rails::Generators::Base
17
+ source_root File.expand_path('../templates', __FILE__)
18
+
19
+ def assets
20
+ insert_into_file "app/assets/stylesheets/application.css", :after => " *= require_self" do
21
+ %q{
22
+ *
23
+ * Required by Hydra
24
+ *= require 'hydra/styles'
25
+ }
26
+ end
27
+
28
+ insert_into_file "app/assets/javascripts/application.js", :after => "//= require jquery_ujs" do
29
+ %q{
30
+ // Required by Hydra
31
+ //= require 'jquery.ui.datepicker.js'
32
+ }
33
+ end
34
+ end
35
+ end
36
+ end
@@ -33,8 +33,8 @@ module Hydra::Controller::FileAssetsBehavior
33
33
  @solr_result = FileAsset.find_with_conditions({})
34
34
  else
35
35
  container_uri = "info:fedora/#{params[:asset_id]}"
36
- escaped_uri = container_uri.gsub(/(:)/, '\\:')
37
- extra_controller_params = {:q=>"is_part_of_s:#{escaped_uri}", :qt=>'standard'}
36
+ escaped_uri = ActiveFedora::SolrService.escape_uri_for_query(container_uri)
37
+ extra_controller_params = {:q=>"is_part_of_s:#{escaped_uri}", 'qf'=>'is_part_of_s', 'qt'=>'standard', :rows=>10}.with_indifferent_access
38
38
  @response, @document_list = get_search_results( extra_controller_params )
39
39
 
40
40
  # Including this line so permissions tests can be run against the container
@@ -66,6 +66,8 @@ module Hydra::Controller::FileAssetsBehavior
66
66
  return redirect_to next_step(params[:id])
67
67
  end
68
68
 
69
+ authorize! :edit, (params[:container_id] || params[:id])
70
+
69
71
  if params.has_key?(:Filedata)
70
72
  notice = process_files
71
73
  flash[:notice] = notice.join("<br/>".html_safe) unless notice.blank?
@@ -106,6 +108,7 @@ module Hydra::Controller::FileAssetsBehavior
106
108
 
107
109
  # Common destroy method for all AssetsControllers
108
110
  def destroy
111
+ authorize! :destroy, params[:id]
109
112
  ActiveFedora::Base.find(params[:id], :cast=>true).delete
110
113
 
111
114
  flash[:notice] = "Deleted #{params[:id]} from #{params[:container_id]}."
@@ -27,8 +27,7 @@ describe Hydra::FileAssetsController do
27
27
  assigns[:solr_result].should == "solr result"
28
28
  end
29
29
  it "should find all file assets belonging to a given container object if asset_id is provided" do
30
- pid = 'hydrangea:fixture_mods_article3'
31
- xhr :get, :index, :asset_id=>pid
30
+ xhr :get, :index, :asset_id=>'hydrangea:fixture_mods_article3'
32
31
  assigns[:response][:response][:docs].first["id"].should == "hydrangea:fixture_file_asset1"
33
32
  assigns[:document_list].first.id.should == "hydrangea:fixture_file_asset1"
34
33
 
@@ -77,13 +76,17 @@ describe Hydra::FileAssetsController do
77
76
 
78
77
  describe "create" do
79
78
  it "should create and save a file asset from the given params" do
79
+ # stub out authorize! call
80
+ controller.should_receive(:authorize!).with(:edit, "example:invalid_object").and_return(true)
80
81
  mock_fa = double("FileAsset")
81
82
  mock_file = double("File")
82
83
  mock_fa.stub(:pid).and_return("foo:pid")
83
84
  controller.should_receive(:create_and_save_file_assets_from_params).and_return([mock_fa])
84
- xhr :post, :create, :Filedata=>[mock_file], :Filename=>"Foo File"
85
+ xhr :post, :create, :Filedata=>[mock_file], :Filename=>"Foo File", :id => "example:invalid_object"
85
86
  end
86
87
  it "if container_id is provided, should associate the created file asset wtih the container" do
88
+ # stub out authorize! call
89
+ controller.should_receive(:authorize!).with(:edit, "_PID_").and_return(true)
87
90
  stub_fa = double("FileAsset")
88
91
  stub_fa.stub(:pid).and_return("foo:pid")
89
92
  stub_fa.stub(:label).and_return("Foo File")
@@ -93,20 +96,29 @@ describe Hydra::FileAssetsController do
93
96
  xhr :post, :create, :Filedata=>[mock_file], :Filename=>"Foo File", :container_id=>"_PID_"
94
97
  end
95
98
  it "should redirect back to edit view if no Filedata is provided but container_id is provided" do
99
+ # stub out authorize! call
100
+ controller.should_receive(:authorize!).with(:edit, "_PID_").and_return(true)
96
101
  controller.should_receive(:model_config).at_least(:once).and_return(controller.workflow_config[:mods_assets])
97
102
  xhr :post, :create, :container_id=>"_PID_", :wf_step=>"files"
98
103
  response.should redirect_to catalog_path("_PID_", :wf_step=>"permissions")
99
104
  request.flash[:notice].should == "You must specify a file to upload."
100
105
  end
101
106
  it "should display a message that you need to select a file to upload if no Filedata is provided" do
107
+ # stub out authorize! call
108
+ controller.should_receive(:authorize!).and_return(true)
102
109
  xhr :post, :create
103
110
  request.flash[:notice].include?("You must specify a file to upload.").should be_true
104
111
  end
112
+ it "should throw an error if you don't have the ability to edit the parent object" do
113
+ lambda{xhr :post, :create, :id => "hydrangea:fixture_mods_article3"}.should raise_error(CanCan::AccessDenied)
114
+ end
105
115
 
106
116
  end
107
117
 
108
118
  describe "destroy" do
109
119
  it "should delete the asset identified by pid" do
120
+ # stub out authorize! call
121
+ controller.should_receive(:authorize!).and_return(true)
110
122
  mock_obj = double("asset")
111
123
  mock_obj.should_receive(:delete)
112
124
  ActiveFedora::Base.should_receive(:find).with("__PID__", :cast=>true).and_return(mock_obj)
@@ -114,6 +126,8 @@ describe Hydra::FileAssetsController do
114
126
  end
115
127
  it "should remove container relationship and perform proper garbage collection" do
116
128
  pending "relies on ActiveFedora implementing Base.file_objects_remove"
129
+ # stub out authorize! call
130
+ controller.should_receive(:authorize!).and_return(true)
117
131
  mock_container = mock("asset")
118
132
  mock_container.should_receive(:file_objects_remove).with("_file_asset_pid_")
119
133
  FileAsset.should_receive(:garbage_collect).with("_file_asset_pid_")
@@ -167,6 +181,8 @@ describe Hydra::FileAssetsController do
167
181
  end
168
182
 
169
183
  it "should set is_part_of relationship on the new File Asset pointing back at the container" do
184
+ # stub out authorize! call
185
+ controller.should_receive(:authorize!).and_return(true)
170
186
  test_file = fixture_file_upload('spec/fixtures/small_file.txt', 'text/plain')
171
187
  filename = "My File Name"
172
188
  post :create, {:Filedata=>[test_file], :Filename=>filename, :container_id=>@test_container.pid}
data/tasks/rspec.rake CHANGED
@@ -20,7 +20,7 @@ task :fixtures do
20
20
  end
21
21
 
22
22
 
23
- describe "Create the test rails app"
23
+ desc "Create the test rails app"
24
24
  task :generate do
25
25
  unless File.exists?('spec/internal/Rakefile')
26
26
  puts "Generating rails app"
@@ -42,7 +42,7 @@ task :generate do
42
42
  puts "Running specs"
43
43
  end
44
44
 
45
- describe "Clean out the test rails app"
45
+ desc "Clean out the test rails app"
46
46
  task :clean do
47
47
  puts "Removing sample rails app"
48
48
  `rm -rf spec/internal`
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-file-access
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0.pre11
4
+ version: 5.0.0.pre12
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-10-31 00:00:00.000000000 Z
13
+ date: 2012-11-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -33,17 +33,17 @@ dependencies:
33
33
  requirement: !ruby/object:Gem::Requirement
34
34
  none: false
35
35
  requirements:
36
- - - ~>
36
+ - - ! '>='
37
37
  - !ruby/object:Gem::Version
38
- version: '3.4'
38
+ version: '0'
39
39
  type: :runtime
40
40
  prerelease: false
41
41
  version_requirements: !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
- - - ~>
44
+ - - ! '>='
45
45
  - !ruby/object:Gem::Version
46
- version: '3.4'
46
+ version: '0'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: devise
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -163,7 +163,7 @@ dependencies:
163
163
  requirements:
164
164
  - - '='
165
165
  - !ruby/object:Gem::Version
166
- version: 5.0.0.pre11
166
+ version: 5.0.0.pre12
167
167
  type: :runtime
168
168
  prerelease: false
169
169
  version_requirements: !ruby/object:Gem::Requirement
@@ -171,7 +171,7 @@ dependencies:
171
171
  requirements:
172
172
  - - '='
173
173
  - !ruby/object:Gem::Version
174
- version: 5.0.0.pre11
174
+ version: 5.0.0.pre12
175
175
  - !ruby/object:Gem::Dependency
176
176
  name: sqlite3
177
177
  requirement: !ruby/object:Gem::Requirement
@@ -257,17 +257,17 @@ dependencies:
257
257
  requirement: !ruby/object:Gem::Requirement
258
258
  none: false
259
259
  requirements:
260
- - - <
260
+ - - ! '>='
261
261
  - !ruby/object:Gem::Version
262
- version: 2.0.0
262
+ version: '0'
263
263
  type: :development
264
264
  prerelease: false
265
265
  version_requirements: !ruby/object:Gem::Requirement
266
266
  none: false
267
267
  requirements:
268
- - - <
268
+ - - ! '>='
269
269
  - !ruby/object:Gem::Version
270
- version: 2.0.0
270
+ version: '0'
271
271
  - !ruby/object:Gem::Dependency
272
272
  name: solrizer-fedora
273
273
  requirement: !ruby/object:Gem::Requirement
@@ -424,6 +424,7 @@ files:
424
424
  - app/views/shared/_delete_asset_confirmation.html.erb
425
425
  - config/jetty.yml
426
426
  - hydra-file-access.gemspec
427
+ - lib/generators/hydra/assets_generator.rb
427
428
  - lib/hydra-file-access.rb
428
429
  - lib/hydra/assets.rb
429
430
  - lib/hydra/assets_controller_helper.rb
@@ -472,7 +473,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
472
473
  requirements:
473
474
  - - ! '>='
474
475
  - !ruby/object:Gem::Version
475
- version: '0'
476
+ version: 1.9.3
476
477
  required_rubygems_version: !ruby/object:Gem::Requirement
477
478
  none: false
478
479
  requirements: