Module: Sufia::FilesControllerBehavior
- Extended by:
- ActiveSupport::Concern
- Included in:
- GenericFilesController
- Defined in:
- lib/sufia/files_controller_behavior.rb
Instance Method Summary collapse
-
#audit ⇒ Object
routed to /files/:id/audit (POST).
-
#citation ⇒ Object
routed to /files/:id/citation.
-
#create ⇒ Object
routed to /files (POST).
-
#destroy ⇒ Object
routed to /files/:id (DELETE).
-
#edit ⇒ Object
routed to /files/:id/edit.
-
#index ⇒ Object
routed to /files/:id.
-
#new ⇒ Object
routed to /files/new.
-
#show ⇒ Object
routed to /files/:id.
-
#update ⇒ Object
routed to /files/:id (PUT).
Instance Method Details
#audit ⇒ Object
routed to /files/:id/audit (POST)
114 115 116 |
# File 'lib/sufia/files_controller_behavior.rb', line 114 def audit render :json=>@generic_file.audit end |
#citation ⇒ Object
routed to /files/:id/citation
100 101 |
# File 'lib/sufia/files_controller_behavior.rb', line 100 def citation end |
#create ⇒ Object
routed to /files (POST)
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/sufia/files_controller_behavior.rb', line 75 def create begin # check error condition No files return json_error("Error! No file to save") if !params.has_key?(:files) file = params[:files].detect {|f| f.respond_to?(:original_filename) } if !file json_error "Error! No file for upload", 'unknown file', :status => :unprocessable_entity elsif (empty_file?(file)) json_error "Error! Zero Length File!", file.original_filename elsif (!terms_accepted?) json_error "You must accept the terms of service!", file.original_filename else process_file(file) end rescue => error logger.error "GenericFilesController::create rescued #{error.class}\n\t#{error.to_s}\n #{error.backtrace.join("\n")}\n\n" json_error "Error occurred while creating generic file." ensure # remove the tempfile (only if it is a temp file) file.tempfile.delete if file.respond_to?(:tempfile) end end |
#destroy ⇒ Object
routed to /files/:id (DELETE)
67 68 69 70 71 72 |
# File 'lib/sufia/files_controller_behavior.rb', line 67 def destroy pid = @generic_file.noid @generic_file.delete Sufia.queue.push(ContentDeleteEventJob.new(pid, current_user.user_key)) redirect_to sufia.dashboard_index_path, :notice => render_to_string(:partial=>'generic_files/asset_deleted_flash', :locals => { :generic_file => @generic_file }) end |
#edit ⇒ Object
routed to /files/:id/edit
55 56 57 58 |
# File 'lib/sufia/files_controller_behavior.rb', line 55 def edit initialize_fields(@generic_file) @groups = current_user.groups end |
#index ⇒ Object
routed to /files/:id
61 62 63 64 |
# File 'lib/sufia/files_controller_behavior.rb', line 61 def index @generic_files = ::GenericFile.find(:all, :rows => ::GenericFile.count) render :json => @generic_files.map(&:to_jq_upload).to_json end |
#new ⇒ Object
routed to /files/new
49 50 51 52 |
# File 'lib/sufia/files_controller_behavior.rb', line 49 def new @generic_file = ::GenericFile.new @batch_noid = Sufia::Noid.noidify(Sufia::IdService.mint) end |
#show ⇒ Object
routed to /files/:id
104 105 106 107 108 109 110 111 |
# File 'lib/sufia/files_controller_behavior.rb', line 104 def show respond_to do |format| format.html { @events = @generic_file.events(100) } format.endnote { render :text => @generic_file.export_as_endnote } end end |
#update ⇒ Object
routed to /files/:id (PUT)
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/sufia/files_controller_behavior.rb', line 119 def update version_event = false if params.has_key?(:revision) and params[:revision] != @generic_file.content.latest_version.versionID revision = @generic_file.content.get_version(params[:revision]) @generic_file.add_file_datastream(revision.content, :dsid => 'content') version_event = true Sufia.queue.push(ContentRestoredVersionEventJob.new(@generic_file.pid, current_user.user_key, params[:revision])) end if params.has_key?(:filedata) file = params[:filedata] return unless virus_check(file) == 0 @generic_file.add_file(file, datastream_id, file.original_filename) version_event = true Sufia.queue.push(ContentNewVersionEventJob.new(@generic_file.pid, current_user.user_key)) end # only update metadata if there is a generic_file object which is not the case for version updates if params[:generic_file] #always save the file so the new version or metadata gets recorded @generic_file.save! # do not trigger an update event if a version event has already been triggered Sufia.queue.push(ContentUpdateEventJob.new(@generic_file.pid, current_user.user_key)) unless version_event @generic_file.record_version_committer(current_user) redirect_to sufia.edit_generic_file_path(:tab => params[:redirect_tab]), :notice => render_to_string(:partial=>'generic_files/asset_updated_flash', :locals => { :generic_file => @generic_file }) end |