Module: Sufia::FilesControllerBehavior
- Extended by:
- ActiveSupport::Concern, Sufia::FilesController::UploadCompleteBehavior
- Includes:
- Hydra::Catalog, Hydra::Collections::SelectsCollections, Breadcrumbs
- Included in:
- GenericFilesController
- Defined in:
- app/controllers/concerns/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).
- #create_from_upload(params) ⇒ Object
-
#destroy ⇒ Object
routed to /files/:id (DELETE).
-
#edit ⇒ Object
routed to /files/:id/edit.
-
#load_resource_from_solr ⇒ Object
Load the GenericFile from solr instead of fedora this replaces the load_resource from CanCan that is usually called by load_and_authorize_resource.
-
#new ⇒ Object
routed to /files/new.
-
#show ⇒ Object
routed to /files/:id.
-
#stats ⇒ Object
routed to /files/:id/stats.
-
#update ⇒ Object
routed to /files/:id (PUT).
Methods included from Sufia::FilesController::UploadCompleteBehavior
destroy_complete_path, upload_complete_path
Methods included from Breadcrumbs
#add_breadcrumb_for_action, #add_breadcrumb_for_controller, #build_breadcrumbs, #default_trail, #trail_from_referer
Instance Method Details
#audit ⇒ Object
routed to /files/:id/audit (POST)
132 133 134 |
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 132 def audit render json: audit_service.audit end |
#citation ⇒ Object
routed to /files/:id/citation
116 117 |
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 116 def citation end |
#create ⇒ Object
routed to /files (POST)
89 90 91 |
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 89 def create create_from_upload(params) end |
#create_from_upload(params) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 93 def create_from_upload(params) # check error condition No files return json_error("Error! No file to save") unless params.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}\n #{error.backtrace.join("\n")}\n\n" json_error "Error occurred while creating generic file.", file.original_filename ensure # remove the tempfile (only if it is a temp file) file.tempfile.delete if file.respond_to?(:tempfile) end |
#destroy ⇒ Object
routed to /files/:id (DELETE)
82 83 84 85 86 |
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 82 def destroy actor.destroy redirect_to self.class.destroy_complete_path(params), notice: render_to_string(partial: 'generic_files/asset_deleted_flash', locals: { generic_file: @generic_file }) end |
#edit ⇒ Object
routed to /files/:id/edit
72 73 74 |
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 72 def edit set_variables_for_edit_form end |
#load_resource_from_solr ⇒ Object
Load the GenericFile from solr instead of fedora this replaces the load_resource from CanCan that is usually called by load_and_authorize_resource
61 62 63 |
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 61 def load_resource_from_solr @generic_file = ::GenericFile.load_instance_from_solr(params[:id]) end |
#new ⇒ Object
routed to /files/new
66 67 68 69 |
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 66 def new set_variables_for_new_form @batch_id = ActiveFedora::Noid::Service.new.mint end |
#show ⇒ Object
routed to /files/:id
120 121 122 123 124 125 126 127 128 129 |
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 120 def show respond_to do |format| format.html do @events = @generic_file.events(100) @presenter = presenter @audit_status = audit_service.human_readable_audit_status end format.endnote { render text: @generic_file.export_as_endnote } end end |
#stats ⇒ Object
routed to /files/:id/stats
77 78 79 |
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 77 def stats @stats = FileUsage.new(params[:id]) end |
#update ⇒ Object
routed to /files/:id (PUT)
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 137 def update success = if wants_to_revert? update_version elsif wants_to_upload_new_version? update_file elsif params.key? :generic_file elsif params.key? :visibility update_visibility end if success 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 }) else flash[:error] ||= 'Update was unsuccessful.' set_variables_for_edit_form render action: 'edit' end end |