hydra-head 3.1.2 → 3.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
1
  module HydraHead
2
- VERSION = "3.1.2"
2
+ VERSION = "3.1.3"
3
3
  end
4
4
 
data/lib/hydra.rb CHANGED
@@ -5,6 +5,7 @@ module Hydra
5
5
  extend ActiveSupport::Autoload
6
6
  autoload :Configurable, 'blacklight/configurable'
7
7
  autoload :Assets
8
+ autoload :FileAssets
8
9
  end
9
10
 
10
11
 
@@ -0,0 +1,148 @@
1
+ module Hydra::FileAssets
2
+ extend ActiveSupport::Concern
3
+
4
+ include Hydra::AccessControlsEnforcement
5
+ include Hydra::AssetsControllerHelper
6
+ include Hydra::FileAssetsHelper
7
+ include Hydra::RepositoryController
8
+ include MediaShelf::ActiveFedoraHelper
9
+ include Blacklight::SolrHelper
10
+
11
+ included do
12
+ before_filter :require_solr, :only=>[:index, :create, :show, :destroy]
13
+ # need to include this after the :require_solr/fedora before filters because of the before filter that the workflow provides.
14
+ include Hydra::SubmissionWorkflow
15
+ prepend_before_filter :sanitize_update_params
16
+ helper :hydra_uploader
17
+ end
18
+
19
+ def index
20
+ if params[:layout] == "false"
21
+ layout = false
22
+ end
23
+
24
+ if params[:asset_id].nil?
25
+ @solr_result = FileAsset.find_by_solr(:all)
26
+ else
27
+ container_uri = "info:fedora/#{params[:asset_id]}"
28
+ escaped_uri = container_uri.gsub(/(:)/, '\\:')
29
+ extra_controller_params = {:q=>"is_part_of_s:#{escaped_uri}"}
30
+ @response, @document_list = get_search_results( extra_controller_params )
31
+
32
+ # Including this line so permissions tests can be run against the container
33
+ @container_response, @document = get_solr_response_for_doc_id(params[:asset_id])
34
+
35
+ # Including these lines for backwards compatibility (until we can use Rails3 callbacks)
36
+ @container = ActiveFedora::Base.load_instance(params[:asset_id])
37
+ @solr_result = @container.file_objects(:response_format=>:solr)
38
+ end
39
+
40
+ # Load permissions_solr_doc based on params[:asset_id]
41
+ load_permissions_from_solr(params[:asset_id])
42
+
43
+ render :action=>params[:action], :layout=>layout
44
+ end
45
+
46
+ def new
47
+ render :partial=>"new", :layout=>false
48
+ end
49
+
50
+ # Creates and Saves a File Asset to contain the the Uploaded file
51
+ # If container_id is provided:
52
+ # * the File Asset will use RELS-EXT to assert that it's a part of the specified container
53
+ # * the method will redirect to the container object's edit view after saving
54
+ def create
55
+ if params.has_key?(:number_of_files) and params[:number_of_files] != "0"
56
+ return redirect_to({:controller => "catalog", :action => "edit", :id => params[:id], :wf_step => :files, :number_of_files => params[:number_of_files]})
57
+ elsif params.has_key?(:number_of_files) and params[:number_of_files] == "0"
58
+ return redirect_to( {:controller => "catalog", :action => "edit", :id => params[:id]}.merge(params_for_next_step_in_wokflow) )
59
+ end
60
+
61
+ if params.has_key?(:Filedata)
62
+ @file_assets = create_and_save_file_assets_from_params
63
+ notice = []
64
+ @file_assets.each do |file_asset|
65
+ apply_depositor_metadata(file_asset)
66
+
67
+ notice << "The file #{file_asset.label} has been saved in <a href=\"#{asset_url(file_asset.pid)}\">#{file_asset.pid}</a>."
68
+
69
+ if !params[:container_id].nil?
70
+ associate_file_asset_with_container(file_asset,'info:fedora/' + params[:container_id])
71
+ end
72
+
73
+ ## Apply any posted file metadata
74
+ unless params[:asset].nil?
75
+ logger.debug("applying submitted file metadata: #{@sanitized_params.inspect}")
76
+ apply_file_metadata
77
+ end
78
+ # If redirect_params has not been set, use {:action=>:index}
79
+ logger.debug "Created #{file_asset.pid}."
80
+ end
81
+ flash[:notice] = notice.join("<br/>") unless notice.blank?
82
+ else
83
+ flash[:notice] = "You must specify a file to upload."
84
+ end
85
+
86
+ unless params[:container_id].nil?
87
+ redirect_params = {:controller => "catalog", :action => "edit", :id => params[:container_id]}.merge(params_for_next_step_in_wokflow)
88
+ end
89
+ redirect_params ||= {:controller => "catalog", :action => "index"}
90
+
91
+ redirect_to redirect_params
92
+ end
93
+
94
+ # Common destroy method for all AssetsControllers
95
+ def destroy
96
+ # The correct implementation, with garbage collection:
97
+ # if params.has_key?(:container_id)
98
+ # container = ActiveFedora::Base.load_instance(params[:container_id])
99
+ # container.file_objects_remove(params[:id])
100
+ # FileAsset.garbage_collect(params[:id])
101
+ # else
102
+
103
+ # The dirty implementation (leaves relationship in container object, deletes regardless of whether the file object has other containers)
104
+ ActiveFedora::Base.load_instance(params[:id]).delete
105
+
106
+ flash[:notice] = "Deleted #{params[:id]} from #{params[:container_id]}."
107
+
108
+ if !params[:container_id].nil?
109
+ redirect_params = {:controller => "catalog", :action => "edit", :id => params[:container_id], :anchor => "file_assets"}
110
+ end
111
+ redirect_params ||= {:action => 'index', :q => nil , :f => nil}
112
+
113
+ redirect_to redirect_params
114
+
115
+ end
116
+
117
+
118
+ def show
119
+ @file_asset = FileAsset.find(params[:id])
120
+ if (@file_asset.nil?)
121
+ logger.warn("No such file asset: " + params[:id])
122
+ flash[:notice]= "No such file asset."
123
+ redirect_to(:action => 'index', :q => nil , :f => nil)
124
+ else
125
+ # get array of parent (container) objects for this FileAsset
126
+ @id_array = @file_asset.containers(:response_format => :id_array)
127
+ @downloadable = false
128
+ # A FileAsset is downloadable iff the user has read or higher access to a parent
129
+ @id_array.each do |pid|
130
+ @response, @permissions_solr_document = get_solr_response_for_doc_id(pid)
131
+ if reader?
132
+ @downloadable = true
133
+ break
134
+ end
135
+ end
136
+
137
+ if @downloadable
138
+ if @file_asset.datastreams.include?("DS1")
139
+ send_datastream @file_asset.datastreams["DS1"]
140
+ end
141
+ else
142
+ flash[:notice]= "You do not have sufficient access privileges to download this document, which has been marked private."
143
+ redirect_to(:action => 'index', :q => nil , :f => nil)
144
+ end
145
+ end
146
+ end
147
+ end
148
+
@@ -32,14 +32,20 @@ namespace :hydra do
32
32
  app_root = File.join(File.dirname(__FILE__),"..")
33
33
  end
34
34
 
35
- fcfg = File.join(app_root,"fedora_conf","conf","fedora.fcfg")
36
- puts "PWD:: #{FileUtils.pwd}"
35
+ fcfg = File.join(app_root,"fedora_conf","conf","development","fedora.fcfg")
37
36
  if File.exists?(fcfg)
38
- puts "copying over fedora.fcfg"
37
+ puts "copying over development/fedora.fcfg"
39
38
  cp("#{fcfg}", 'jetty/fedora/default/server/config/', :verbose => true)
40
39
  else
41
40
  puts "#{fcfg} file not found -- skipping fedora config"
42
41
  end
42
+ fcfg = File.join(app_root,"fedora_conf","conf","test","fedora.fcfg")
43
+ if File.exists?(fcfg)
44
+ puts "copying over test/fedora.fcfg"
45
+ cp("#{fcfg}", 'jetty/fedora/test/server/config/', :verbose => true)
46
+ else
47
+ puts "#{fcfg} file not found -- skipping fedora config"
48
+ end
43
49
  end
44
50
 
45
51
  desc "Copies the default SOLR config files and starts up the fedora instance."
@@ -9,22 +9,6 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
9
9
  # rake cucumber
10
10
 
11
11
  describe PermissionsController do
12
- describe "index" do
13
- it "should retrieve the object's rightsMetadata datastream as a Hydra::RightsMetadata object and render the _index partial" do
14
- end
15
- end
16
- describe "show" do
17
- it"should render different partial based on the permission type" do
18
- pending
19
- renders "permissions/edit_individual"
20
- renders "permissions/edit_group"
21
- end
22
- end
23
- describe "edit" do
24
- end
25
- describe "new" do
26
- it "should render the _new partial"
27
- end
28
12
  describe "create" do
29
13
  it "should create a new permissions entry" do
30
14
  stub_solrizer = stub("solrizer", :solrize)
@@ -33,7 +17,6 @@ describe PermissionsController do
33
17
  Hydra::RightsMetadata.stubs(:from_xml)
34
18
  Hydra::RightsMetadata.stubs(:new).returns(mock_ds)
35
19
  mock_ds.expects(:permissions).with({"person" => "_person_id_"}, "read")
36
- # mock_ds.expects(:update_permissions).with({"person"=>{"_person_id_"=>"read"}})
37
20
  mock_ds.stubs(:content)
38
21
  mock_ds.stubs(:pid=)
39
22
  mock_ds.stubs(:dsid=)
@@ -47,9 +30,7 @@ describe PermissionsController do
47
30
  ActiveFedora::Base.expects(:load_instance).with("_pid_").returns(mock_object)
48
31
 
49
32
  post :create, :asset_id=>"_pid_", :permission => {"actor_id"=>"_person_id_","actor_type"=>"person","access_level"=>"read"}
50
- # post :create, :asset_id=>"_pid_", :permission => {"person"=>"_person_id_","level"=>"read"}
51
33
  end
52
- it "should rely on .update method"
53
34
  end
54
35
  describe "update" do
55
36
  it "should call Hydra::RightsMetadata properties setter" do
@@ -79,10 +60,5 @@ describe PermissionsController do
79
60
 
80
61
  post :update, :asset_id=>"_pid_", :permission => {"group"=>{"_group_id_"=>"discover"}}
81
62
  end
82
- it "should add a rightsMetadata datastream if it doesn't exist"
83
- it "should not cause the metadata to be indexed twice" do
84
- # should load the object as ActiveFedora::Base, initialize the rightsMetadata datastream as Hydra::RightsMetadata, update the datastream, save the datastream, and tell Solrizer to re-index the object from pid
85
- # re-indexing from pid rather than passing in the current object prevents double-indexing of the edited metadatata datastream
86
- end
87
63
  end
88
64
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-head
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
8
  - 1
9
- - 2
10
- version: 3.1.2
9
+ - 3
10
+ version: 3.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Zumwalt, Bess Sadler, Julie Meloni, Naomi Dushay, Jessie Keck, John Scofield, Justin Coyne & many more. See https://github.com/projecthydra/hydra-head/contributors
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-16 00:00:00 -06:00
18
+ date: 2011-11-17 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -935,7 +935,8 @@ files:
935
935
  - db/migrate/20101105214243_add_user_attributes_table.rb
936
936
  - db/migrate/20101108192527_create_superusers.rb
937
937
  - fedora/conf/fedora.fcfg
938
- - fedora_conf/conf/fedora.fcfg
938
+ - fedora_conf/conf/development/fedora.fcfg
939
+ - fedora_conf/conf/test/fedora.fcfg
939
940
  - hydra-head.gemspec
940
941
  - init.rb
941
942
  - install.rb
@@ -978,6 +979,7 @@ files:
978
979
  - lib/hydra/catalog.rb
979
980
  - lib/hydra/common_mods_index_methods.rb
980
981
  - lib/hydra/controller.rb
982
+ - lib/hydra/file_assets.rb
981
983
  - lib/hydra/file_assets_helper.rb
982
984
  - lib/hydra/generic_content.rb
983
985
  - lib/hydra/generic_image.rb
@@ -1096,7 +1098,6 @@ files:
1096
1098
  - test_support/spec/controllers/hydra_controller_spec.rb
1097
1099
  - test_support/spec/controllers/permissions_controller_spec.rb
1098
1100
  - test_support/spec/controllers/user_sessions_controller_spec.rb
1099
- - test_support/spec/generators/hydra-head_generator_spec.rb
1100
1101
  - test_support/spec/helpers/access_controls_enforcement_spec.rb
1101
1102
  - test_support/spec/helpers/access_controls_evaluation_spec.rb
1102
1103
  - test_support/spec/helpers/assets_controller_helper_spec.rb
@@ -1,14 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
- require "generators/hydra/head_generator"
4
- require "generators/blacklight/blacklight_generator"
5
-
6
- describe Hydra::HeadGenerator do
7
-
8
- it "should be tested, but it's not clear how..."
9
- it "should inject Hydra behaviors into User model by adding include Hydra::User" do
10
- pending "Not sure how to test this..."
11
- end
12
-
13
- end
14
-