hydra-head 4.0.3 → 4.1.0
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.
- data/.gitignore +1 -0
- data/HISTORY.textile +17 -2
- data/app/assets/stylesheets/hydra/html_refactor.css +3 -30
- data/app/assets/stylesheets/hydra/styles.css +6 -64
- data/app/controllers/downloads_controller.rb +1 -1
- data/app/controllers/hydra/assets_controller.rb +10 -1
- data/app/controllers/hydra/contributors_controller.rb +15 -1
- data/app/controllers/hydra/file_assets_controller.rb +1 -1
- data/app/controllers/hydra/permissions_controller.rb +14 -0
- data/app/helpers/hydra/article_metadata_helper_behavior.rb +14 -1
- data/app/helpers/hydra/downloads_helper_behavior.rb +6 -0
- data/app/helpers/hydra/facets_helper_behavior.rb +7 -0
- data/app/helpers/hydra/generic_content_objects_helper_behavior.rb +6 -0
- data/app/helpers/hydra/hydra_assets_helper_behavior.rb +10 -0
- data/app/helpers/hydra/hydra_fedora_metadata_helper_behavior.rb +31 -0
- data/app/helpers/hydra/hydra_helper_behavior.rb +18 -7
- data/app/helpers/hydra/hydra_uploader_helper_behavior.rb +5 -0
- data/app/helpers/hydra/inline_editable_metadata_helper_behavior.rb +6 -0
- data/app/helpers/hydra/javascript_includes_helper_behavior.rb +7 -0
- data/app/helpers/hydra/personalization_helper_behavior.rb +5 -0
- data/app/helpers/hydra/release_process_helper_behavior.rb +5 -0
- data/app/models/generic_content.rb +3 -0
- data/app/models/generic_image.rb +3 -0
- data/app/models/superuser.rb +4 -2
- data/app/models/user_attribute.rb +7 -2
- data/app/views/_add_assets_links.html.erb +4 -4
- data/app/views/catalog/_index_partials/_default.html.erb +2 -2
- data/app/views/catalog/show.html.erb +1 -1
- data/app/views/generic_contents/_index.html.erb +2 -2
- data/app/views/generic_images/_edit.html.erb +1 -1
- data/app/views/generic_images/_index.html.erb +2 -2
- data/app/views/hydra/file_assets/_file_assets_form.html.erb +1 -1
- data/app/views/hydra/file_assets/_index.html.erb +2 -2
- data/app/views/hydra/file_assets/_result.html.erb +1 -1
- data/app/views/layouts/hydra-head.html.erb +4 -1
- data/app/views/mods_assets/_index_list.html.erb +1 -1
- data/app/views/mods_assets/_index_table.html.erb +2 -2
- data/app/views/mods_assets/_show.html.erb +1 -1
- data/app/views/mods_assets/_show_file_assets.html.erb +1 -1
- data/config/jetty.yml +1 -1
- data/config/locales/hydra.en.yml +7 -0
- data/config/solr.yml +1 -1
- data/config/solr_mappings.yml +2 -2
- data/hydra-head.gemspec +5 -4
- data/lib/generators/hydra/head_generator.rb +6 -5
- data/lib/generators/hydra/templates/config/fedora.yml +1 -1
- data/lib/generators/hydra/templates/config/solr.yml +1 -1
- data/lib/hydra-head/version.rb +1 -1
- data/lib/hydra.rb +13 -11
- data/lib/hydra/assets.rb +5 -135
- data/lib/hydra/catalog.rb +6 -44
- data/lib/hydra/controller.rb +10 -27
- data/lib/hydra/controller/assets_controller_behavior.rb +142 -0
- data/lib/hydra/controller/catalog_controller_behavior.rb +56 -0
- data/lib/hydra/controller/controller_behavior.rb +59 -0
- data/lib/hydra/controller/file_assets_behavior.rb +142 -0
- data/lib/hydra/controller/repository_controller_behavior.rb +119 -0
- data/lib/hydra/controller/upload_behavior.rb +139 -0
- data/lib/hydra/file_assets.rb +3 -138
- data/lib/hydra/file_assets_helper.rb +6 -133
- data/lib/hydra/generic_content.rb +15 -0
- data/lib/hydra/generic_image.rb +10 -0
- data/lib/hydra/global_configurable.rb +46 -0
- data/lib/hydra/model_methods.rb +3 -3
- data/lib/hydra/model_mixins.rb +1 -1
- data/lib/hydra/model_mixins/solr_document_extension.rb +24 -0
- data/lib/hydra/repository_controller.rb +4 -95
- data/lib/hydra/ui/controller.rb +1 -2
- data/lib/hydra/user.rb +13 -1
- data/lib/railties/hydra-fixtures.rake +1 -1
- data/tasks/hydra-head.rake +2 -0
- data/{app/models → test_support/etc}/common_metadata_asset.rb +1 -2
- data/test_support/features/mods_asset_show.feature +1 -1
- data/test_support/features/support/env.rb +2 -0
- data/test_support/features/support/paths.rb +2 -0
- data/test_support/spec/controllers/catalog_controller_spec.rb +8 -0
- data/test_support/spec/controllers/catalog_controller_viewing_context_spec.rb +10 -1
- data/test_support/spec/controllers/catalog_valid_html_spec.rb +8 -0
- data/test_support/spec/controllers/contributors_controller_spec.rb +10 -0
- data/test_support/spec/controllers/file_assets_controller_spec.rb +15 -3
- data/test_support/spec/controllers/hydra-assets_controller_spec.rb +11 -1
- data/test_support/spec/controllers/hydra_controller_spec.rb +15 -4
- data/test_support/spec/controllers/permissions_controller_spec.rb +8 -0
- data/test_support/spec/helpers/access_controls_enforcement_spec.rb +1 -2
- data/test_support/spec/helpers/file_assets_helper_spec.rb +1 -1
- data/test_support/spec/helpers/generic_content_objects_helper_spec.rb +10 -1
- data/test_support/spec/helpers/hydra-repository_controller_spec.rb +1 -1
- data/test_support/spec/helpers/hydra_assets_helper_spec.rb +8 -0
- data/test_support/spec/helpers/hydra_fedora_metadata_helper_spec.rb +11 -0
- data/test_support/spec/helpers/hydra_helper_spec.rb +18 -0
- data/test_support/spec/helpers/hydra_model_methods_spec.rb +0 -12
- data/test_support/spec/helpers/hydra_uploader_helper_spec.rb +8 -0
- data/test_support/spec/helpers/javascript_includes_helper_spec.rb +9 -1
- data/test_support/spec/lib/catalog_spec.rb +10 -3
- data/test_support/spec/lib/global_configurable_spec.rb +98 -0
- data/test_support/spec/lib/model_methods_spec.rb +29 -0
- data/test_support/spec/models/generic_content_spec.rb +11 -0
- data/test_support/spec/models/generic_image_spec.rb +15 -0
- data/test_support/spec/models/user_spec.rb +25 -0
- metadata +39 -37
- data/app/models/ability.rb +0 -5
- data/app/models/hydra/ability.rb +0 -137
- data/app/models/hydra/datastream/common_mods_index_methods.rb +0 -47
- data/app/models/hydra/datastream/mods_article.rb +0 -530
- data/app/models/hydra/datastream/mods_dataset.rb +0 -173
- data/app/models/hydra/datastream/mods_generic_content.rb +0 -498
- data/app/models/hydra/datastream/mods_image.rb +0 -497
- data/app/models/hydra/datastream/rights_metadata.rb +0 -191
- data/app/models/hydra/role_mapper_behavior.rb +0 -33
- data/app/models/role_mapper.rb +0 -6
- data/lib/hydra/access_controls_enforcement.rb +0 -237
- data/lib/hydra/access_controls_evaluation.rb +0 -38
- data/lib/hydra/common_mods_index_methods.rb +0 -46
- data/lib/hydra/model_mixins/mods_object.rb +0 -17
- data/lib/hydra/model_mixins/rights_metadata.rb +0 -357
- data/lib/hydra/mods_article.rb +0 -535
- data/lib/hydra/mods_dataset.rb +0 -177
- data/lib/hydra/mods_generic_content.rb +0 -500
- data/lib/hydra/mods_image.rb +0 -500
- data/lib/uva/mods_index_methods.rb +0 -30
- data/test_support/spec/lib/common_mods_index_methods_spec.rb +0 -26
- data/test_support/spec/models/ability_spec.rb +0 -40
- data/test_support/spec/models/hydra_rights_metadata_spec.rb +0 -175
- data/test_support/spec/models/role_mapper_spec.rb +0 -22
- data/test_support/spec/unit/rights_metadata_spec.rb +0 -80
@@ -0,0 +1,142 @@
|
|
1
|
+
# will move to lib/hydra/controller / file_assets_controller_behavior.rb in release 5.x
|
2
|
+
module Hydra::Controller::FileAssetsBehavior
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
include Hydra::AccessControlsEnforcement
|
7
|
+
include Hydra::AssetsControllerHelper
|
8
|
+
include Hydra::Controller::UploadBehavior
|
9
|
+
include Hydra::Controller::RepositoryControllerBehavior
|
10
|
+
include Hydra::UI::Controller
|
11
|
+
include Blacklight::SolrHelper
|
12
|
+
include Hydra::SubmissionWorkflow
|
13
|
+
include Blacklight::Configurable
|
14
|
+
copy_blacklight_config_from(CatalogController)
|
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}", :qt=>'standard'}
|
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.find(params[:asset_id], :cast=>true)
|
37
|
+
@solr_result = @container.parts(: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 edit_catalog_path(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 next_step(params[:id])
|
59
|
+
end
|
60
|
+
|
61
|
+
if params.has_key?(:Filedata)
|
62
|
+
notice = process_files
|
63
|
+
flash[:notice] = notice.join("<br/>".html_safe) unless notice.blank?
|
64
|
+
else
|
65
|
+
flash[:notice] = "You must specify a file to upload."
|
66
|
+
end
|
67
|
+
|
68
|
+
if params[:container_id]
|
69
|
+
redirect_to next_step(params[:container_id])
|
70
|
+
else
|
71
|
+
redirect_to catalog_index_path
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
def process_files
|
77
|
+
@file_assets = create_and_save_file_assets_from_params
|
78
|
+
notice = []
|
79
|
+
@file_assets.each do |file_asset|
|
80
|
+
apply_depositor_metadata(file_asset)
|
81
|
+
|
82
|
+
notice << render_to_string(:partial=>'hydra/file_assets/asset_saved_flash', :locals => { :file_asset => file_asset })
|
83
|
+
|
84
|
+
if !params[:container_id].nil?
|
85
|
+
associate_file_asset_with_container(file_asset,'info:fedora/' + params[:container_id])
|
86
|
+
end
|
87
|
+
|
88
|
+
## Apply any posted file metadata
|
89
|
+
unless params[:asset].nil?
|
90
|
+
logger.debug("applying submitted file metadata: #{@sanitized_params.inspect}")
|
91
|
+
apply_file_metadata
|
92
|
+
end
|
93
|
+
# If redirect_params has not been set, use {:action=>:index}
|
94
|
+
logger.debug "Created #{file_asset.pid}."
|
95
|
+
end
|
96
|
+
notice
|
97
|
+
end
|
98
|
+
|
99
|
+
# Common destroy method for all AssetsControllers
|
100
|
+
def destroy
|
101
|
+
ActiveFedora::Base.find(params[:id], :cast=>true).delete
|
102
|
+
|
103
|
+
flash[:notice] = "Deleted #{params[:id]} from #{params[:container_id]}."
|
104
|
+
|
105
|
+
if !params[:container_id].nil?
|
106
|
+
redirect_params = edit_catalog_path(params[:container_id], :anchor => "file_assets")
|
107
|
+
end
|
108
|
+
redirect_params ||= {:action => 'index', :q => nil , :f => nil}
|
109
|
+
|
110
|
+
redirect_to redirect_params
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
def show
|
116
|
+
begin
|
117
|
+
@file_asset = FileAsset.find(params[:id])
|
118
|
+
rescue ActiveFedora::ObjectNotFoundError
|
119
|
+
logger.warn("No such file asset: " + params[:id])
|
120
|
+
flash[:notice]= "No such file asset."
|
121
|
+
redirect_to(:action => 'index', :q => nil , :f => nil)
|
122
|
+
return
|
123
|
+
end
|
124
|
+
# get containing object for this FileAsset
|
125
|
+
pid = @file_asset.container_id
|
126
|
+
parent = ActiveFedora::Base.find(pid, :cast=>true)
|
127
|
+
@downloadable = false
|
128
|
+
# A FileAsset is downloadable iff the user has read or higher access to a parent
|
129
|
+
|
130
|
+
if can? :read, parent
|
131
|
+
# First try to use datastream_id value (set in FileAssetsHelper)
|
132
|
+
if @file_asset.datastreams.include?(datastream_id)
|
133
|
+
send_datastream @file_asset.datastreams[datastream_id]
|
134
|
+
elsif @file_asset.datastreams.include?("DS1")
|
135
|
+
send_datastream @file_asset.datastreams["DS1"]
|
136
|
+
end
|
137
|
+
else
|
138
|
+
raise Hydra::AccessDenied.new("You do not have sufficient access privileges to download this file.")
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
@@ -0,0 +1,119 @@
|
|
1
|
+
# Hydra-repository Contoller is a controller layer mixin. It is in the controller scope: request params, session etc.
|
2
|
+
#
|
3
|
+
# will move to lib/hydra/controller/repository_controller_behavior in release 5.x
|
4
|
+
#
|
5
|
+
# NOTE: Be careful when creating variables here as they may be overriding something that already exists.
|
6
|
+
# The ActionController docs: http://api.rubyonrails.org/classes/ActionController/Base.html
|
7
|
+
#
|
8
|
+
# Override these methods in your own controller for customizations:
|
9
|
+
#
|
10
|
+
# class HomeController < ActionController::Base
|
11
|
+
#
|
12
|
+
# include Stanford::SolrHelper
|
13
|
+
#
|
14
|
+
# def solr_search_params
|
15
|
+
# super.merge :per_page=>10
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
module Hydra::Controller::RepositoryControllerBehavior
|
21
|
+
|
22
|
+
def self.included(c)
|
23
|
+
if c.respond_to?(:helper_method)
|
24
|
+
c.helper_method :solr_name
|
25
|
+
c.helper_method :format_pid
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
#
|
31
|
+
# This method converts pid strings into xhtml safe IDs, since xhmlt expects namespaces to be defined.
|
32
|
+
# I.E. hydrus:123 = hydrus_123
|
33
|
+
def format_pid(pid)
|
34
|
+
pid.gsub(":", "_")
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
def solr_name(field_name, field_type = :text)
|
40
|
+
::ActiveFedora::SolrService.solr_name(field_name, field_type)
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
# Returns a list of datastreams for download.
|
45
|
+
# Uses user's roles and "mime_type" value in submitted params to decide what to return.
|
46
|
+
# if you pass the optional argument of :canonical=>true, it will return the canonical datastream for this object (a single object not a hash of datastreams)
|
47
|
+
def downloadables(fedora_object=@fedora_object, opts={})
|
48
|
+
if opts[:canonical]
|
49
|
+
mime_type = opts[:mime_type] ? opts[:mime_type] : "application/pdf"
|
50
|
+
result = filter_datastreams_for_mime_type(fedora_object.datastreams, mime_type).sort.first[1]
|
51
|
+
elsif can? :edit, fedora_object
|
52
|
+
if params["mime_type"] == "all"
|
53
|
+
result = fedora_object.datastreams
|
54
|
+
else
|
55
|
+
result = Hash[]
|
56
|
+
fedora_object.datastreams.each_pair do |dsid,ds|
|
57
|
+
if !ds.new_object?
|
58
|
+
mime_type = ds.mimeType ? ds.mimeType : ""
|
59
|
+
if mime_type.include?("pdf") || ds.label.include?("_TEXT.xml") || ds.label.include?("_METS.xml")
|
60
|
+
result[dsid] = ds
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
else
|
66
|
+
result = Hash[]
|
67
|
+
fedora_object.datastreams.each_pair do |dsid,ds|
|
68
|
+
if ds.mimeType.include?("pdf")
|
69
|
+
result[dsid] = ds
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
# puts "downloadables result: #{result}"
|
74
|
+
return result
|
75
|
+
end
|
76
|
+
|
77
|
+
protected
|
78
|
+
def load_document
|
79
|
+
@document = load_document_from_params
|
80
|
+
end
|
81
|
+
|
82
|
+
# Uses submitted params Hash to figure out what Model to load
|
83
|
+
# params should contain :content_type and :id
|
84
|
+
def load_document_from_params
|
85
|
+
af_model = retrieve_af_model(params[:content_type])
|
86
|
+
unless af_model
|
87
|
+
af_model = ModsAsset
|
88
|
+
end
|
89
|
+
return af_model.find(params[:id])
|
90
|
+
end
|
91
|
+
|
92
|
+
def retrieve_af_model(class_name, opts={})
|
93
|
+
if !class_name.nil?
|
94
|
+
klass = Module.const_get(class_name.camelcase)
|
95
|
+
else
|
96
|
+
klass = nil
|
97
|
+
end
|
98
|
+
if klass.is_a?(Class) && klass.superclass == ActiveFedora::Base
|
99
|
+
return klass
|
100
|
+
else
|
101
|
+
return opts.fetch(:default, false)
|
102
|
+
end
|
103
|
+
rescue NameError
|
104
|
+
return false
|
105
|
+
end
|
106
|
+
|
107
|
+
private
|
108
|
+
|
109
|
+
def filter_datastreams_for_mime_type(datastreams_hash, mime_type)
|
110
|
+
result = Hash[]
|
111
|
+
datastreams_hash.each_pair do |dsid,ds|
|
112
|
+
ds_mime_type = ds.mimeType ? ds.mimeType : ""
|
113
|
+
if ds_mime_type == mime_type
|
114
|
+
result[dsid] = ds
|
115
|
+
end
|
116
|
+
end
|
117
|
+
return result
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
# will move to lib/hydra/controller / upload_behavior.rb in release 5.x
|
2
|
+
module Hydra::Controller::UploadBehavior
|
3
|
+
|
4
|
+
# Creates a File Asset, adding the posted blob to the File Asset's datastreams and saves the File Asset
|
5
|
+
#
|
6
|
+
# @return [FileAsset] the File Asset
|
7
|
+
def create_and_save_file_assets_from_params
|
8
|
+
if params.has_key?(:Filedata)
|
9
|
+
@file_assets = []
|
10
|
+
params[:Filedata].each do |file|
|
11
|
+
@file_asset = create_asset_from_file(file)
|
12
|
+
add_posted_blob_to_asset(@file_asset,file)
|
13
|
+
@file_asset.save
|
14
|
+
@file_assets << @file_asset
|
15
|
+
end
|
16
|
+
return @file_assets
|
17
|
+
else
|
18
|
+
render :text => "400 Bad Request", :status => 400
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Puts the contents of params[:Filedata] (posted blob) into a datastream within the given @asset
|
23
|
+
# Sets asset label and title to filename if they're empty
|
24
|
+
#
|
25
|
+
# @param [FileAsset] asset the File Asset to add the blob to
|
26
|
+
# @return [FileAsset] file the File Asset
|
27
|
+
def add_posted_blob_to_asset(asset, file)
|
28
|
+
#file_name = filename_from_params
|
29
|
+
file_name = file.original_filename
|
30
|
+
options = {:label=>file_name, :mimeType=>mime_type(file_name)}
|
31
|
+
dsid = datastream_id #Only call this once so that it could be a sequence
|
32
|
+
options[:dsid] = dsid if dsid
|
33
|
+
asset.add_file_datastream(file, options)
|
34
|
+
asset.set_title_and_label( file_name, :only_if_blank=>true )
|
35
|
+
end
|
36
|
+
|
37
|
+
#Override this if you want to specify the datastream_id (dsID) for the created blob
|
38
|
+
def datastream_id
|
39
|
+
"content"
|
40
|
+
end
|
41
|
+
|
42
|
+
# Associate the new file asset with its container
|
43
|
+
def associate_file_asset_with_container(file_asset=nil, container_id=nil)
|
44
|
+
if container_id.nil?
|
45
|
+
container_id = params[:asset_id]
|
46
|
+
end
|
47
|
+
if file_asset.nil?
|
48
|
+
file_asset = @file_asset
|
49
|
+
end
|
50
|
+
file_asset.add_relationship(:is_part_of, container_id)
|
51
|
+
file_asset.datastreams["RELS-EXT"].dirty = true
|
52
|
+
file_asset.save
|
53
|
+
end
|
54
|
+
|
55
|
+
# Apply any posted file metadata to the file asset
|
56
|
+
def apply_posted_file_metadata
|
57
|
+
@metadata_update_response = update_document(@file_asset, @sanitized_params)
|
58
|
+
@file_asset.save
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
# The posted File
|
63
|
+
# @return [File] the posted file. Defaults to nil if no file was posted.
|
64
|
+
def posted_file
|
65
|
+
params[:Filedata]
|
66
|
+
end
|
67
|
+
|
68
|
+
# A best-guess filename based on POST params
|
69
|
+
# If Filename was submitted, it uses that. Otherwise, it calls +original_filename+ on the posted file
|
70
|
+
def filename_from_params
|
71
|
+
if !params[:Filename].nil?
|
72
|
+
file_name = params[:Filename]
|
73
|
+
else
|
74
|
+
file_name = posted_file.original_filename
|
75
|
+
params[:Filename] = file_name
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# Creates a File Asset and sets its label from params[:Filename]
|
80
|
+
#
|
81
|
+
# @return [FileAsset] the File Asset
|
82
|
+
def create_asset_from_params
|
83
|
+
file_asset = FileAsset.new
|
84
|
+
file_asset.label = params[:Filename]
|
85
|
+
|
86
|
+
return file_asset
|
87
|
+
end
|
88
|
+
|
89
|
+
# Creates a File Asset and sets its label from filename
|
90
|
+
#
|
91
|
+
# @return [FileAsset] the File Asset
|
92
|
+
def create_asset_from_file(file)
|
93
|
+
file_asset = FileAsset.new
|
94
|
+
file_asset.label = file.original_filename
|
95
|
+
|
96
|
+
return file_asset
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
# This is pre-Hydra code that created an AudioAsset, VideoAsset or ImageAsset based on the
|
101
|
+
# current params in the controller.
|
102
|
+
#
|
103
|
+
# @return [Constant] the recommended Asset class
|
104
|
+
def asset_class_from_params
|
105
|
+
if params.has_key?(:type)
|
106
|
+
chosen_type = case params[:type]
|
107
|
+
when "AudioAsset"
|
108
|
+
AudioAsset
|
109
|
+
when "VideoAsset"
|
110
|
+
VideoAsset
|
111
|
+
when "ImageAsset"
|
112
|
+
ImageAsset
|
113
|
+
else
|
114
|
+
FileAsset
|
115
|
+
end
|
116
|
+
elsif params.has_key?(:Filename)
|
117
|
+
chosen_type = choose_model_by_filename( params[:Filename] )
|
118
|
+
else
|
119
|
+
chosen_type = FileAsset
|
120
|
+
end
|
121
|
+
|
122
|
+
return chosen_type
|
123
|
+
end
|
124
|
+
|
125
|
+
def choose_model_by_filename(filename)
|
126
|
+
choose_model_by_filename_extension( File.extname(filename) )
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
private
|
131
|
+
# Return the mimeType for a given file name
|
132
|
+
# @param [String] file_name The filename to use to get the mimeType
|
133
|
+
# @return [String] mimeType for filename passed in. Default: application/octet-stream if mimeType cannot be determined
|
134
|
+
def mime_type file_name
|
135
|
+
mime_types = MIME::Types.of(file_name)
|
136
|
+
mime_type = mime_types.empty? ? "application/octet-stream" : mime_types.first.content_type
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
data/lib/hydra/file_assets.rb
CHANGED
@@ -1,146 +1,11 @@
|
|
1
1
|
# will move to lib/hydra/controller / file_assets_controller_behavior.rb in release 5.x
|
2
|
+
require 'deprecation'
|
2
3
|
module Hydra::FileAssets
|
3
4
|
extend ActiveSupport::Concern
|
4
5
|
|
5
6
|
included do
|
6
|
-
|
7
|
-
include Hydra::
|
8
|
-
include Hydra::FileAssetsHelper
|
9
|
-
include Hydra::RepositoryController
|
10
|
-
include Hydra::UI::Controller
|
11
|
-
include Blacklight::SolrHelper
|
12
|
-
include Hydra::SubmissionWorkflow
|
13
|
-
include Blacklight::Configurable
|
14
|
-
copy_blacklight_config_from(CatalogController)
|
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}", :qt=>'standard'}
|
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.find(params[:asset_id], :cast=>true)
|
37
|
-
@solr_result = @container.parts(: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 edit_catalog_path(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 next_step(params[:id])
|
59
|
-
end
|
60
|
-
|
61
|
-
if params.has_key?(:Filedata)
|
62
|
-
notice = process_files
|
63
|
-
flash[:notice] = notice.join("<br/>".html_safe) unless notice.blank?
|
64
|
-
else
|
65
|
-
flash[:notice] = "You must specify a file to upload."
|
66
|
-
end
|
67
|
-
|
68
|
-
if params[:container_id]
|
69
|
-
redirect_to next_step(params[:container_id])
|
70
|
-
else
|
71
|
-
redirect_to catalog_index_path
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
75
|
-
|
76
|
-
def process_files
|
77
|
-
@file_assets = create_and_save_file_assets_from_params
|
78
|
-
notice = []
|
79
|
-
@file_assets.each do |file_asset|
|
80
|
-
apply_depositor_metadata(file_asset)
|
81
|
-
|
82
|
-
notice << render_to_string(:partial=>'hydra/file_assets/asset_saved_flash', :locals => { :file_asset => file_asset })
|
83
|
-
|
84
|
-
if !params[:container_id].nil?
|
85
|
-
associate_file_asset_with_container(file_asset,'info:fedora/' + params[:container_id])
|
86
|
-
end
|
87
|
-
|
88
|
-
## Apply any posted file metadata
|
89
|
-
unless params[:asset].nil?
|
90
|
-
logger.debug("applying submitted file metadata: #{@sanitized_params.inspect}")
|
91
|
-
apply_file_metadata
|
92
|
-
end
|
93
|
-
# If redirect_params has not been set, use {:action=>:index}
|
94
|
-
logger.debug "Created #{file_asset.pid}."
|
95
|
-
end
|
96
|
-
notice
|
97
|
-
end
|
98
|
-
|
99
|
-
# Common destroy method for all AssetsControllers
|
100
|
-
def destroy
|
101
|
-
ActiveFedora::Base.find(params[:id], :cast=>true).delete
|
102
|
-
|
103
|
-
flash[:notice] = "Deleted #{params[:id]} from #{params[:container_id]}."
|
104
|
-
|
105
|
-
if !params[:container_id].nil?
|
106
|
-
redirect_params = edit_catalog_path(params[:container_id], :anchor => "file_assets")
|
107
|
-
end
|
108
|
-
redirect_params ||= {:action => 'index', :q => nil , :f => nil}
|
109
|
-
|
110
|
-
redirect_to redirect_params
|
111
|
-
|
112
|
-
end
|
113
|
-
|
114
|
-
|
115
|
-
def show
|
116
|
-
begin
|
117
|
-
@file_asset = FileAsset.find(params[:id])
|
118
|
-
rescue ActiveFedora::ObjectNotFoundError
|
119
|
-
logger.warn("No such file asset: " + params[:id])
|
120
|
-
flash[:notice]= "No such file asset."
|
121
|
-
redirect_to(:action => 'index', :q => nil , :f => nil)
|
122
|
-
return
|
123
|
-
end
|
124
|
-
# get containing object for this FileAsset
|
125
|
-
pid = @file_asset.container_id
|
126
|
-
parent = ActiveFedora::Base.find(pid, :cast=>true)
|
127
|
-
@downloadable = false
|
128
|
-
# A FileAsset is downloadable iff the user has read or higher access to a parent
|
129
|
-
if can? :read, parent
|
130
|
-
@downloadable = true
|
131
|
-
end
|
132
|
-
|
133
|
-
if @downloadable
|
134
|
-
# First try to use datastream_id value (set in FileAssetsHelper)
|
135
|
-
if @file_asset.datastreams.include?(datastream_id)
|
136
|
-
send_datastream @file_asset.datastreams[datastream_id]
|
137
|
-
elsif @file_asset.datastreams.include?("DS1")
|
138
|
-
send_datastream @file_asset.datastreams["DS1"]
|
139
|
-
end
|
140
|
-
else
|
141
|
-
flash[:notice]= "You do not have sufficient access privileges to download this file."
|
142
|
-
redirect_to :back
|
143
|
-
end
|
7
|
+
Deprecation.warn Hydra::FileAssets, "Hydra::FileAssets was moved to Hydra::Controller::FileAssetsBehavior"
|
8
|
+
include Hydra::Controller::FileAssetsBehavior
|
144
9
|
end
|
145
10
|
end
|
146
11
|
|