Module: Sufia::FilesControllerBehavior

Extended by:
ActiveSupport::Concern, Sufia::FilesController::UploadCompleteBehavior
Includes:
Breadcrumbs
Included in:
GenericFilesController
Defined in:
app/controllers/concerns/sufia/files_controller_behavior.rb

Instance Method Summary collapse

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

#auditObject

routed to /files/:id/audit (POST)



126
127
128
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 126

def audit
  render json: audit_service.audit
end

#citationObject

routed to /files/:id/citation



110
111
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 110

def citation
end

#createObject

routed to /files (POST)



83
84
85
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 83

def create
  create_from_upload(params)
end

#create_from_upload(params) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 87

def create_from_upload(params)
  # 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

#destroyObject

routed to /files/:id (DELETE)



76
77
78
79
80
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 76

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

#editObject

routed to /files/:id/edit



66
67
68
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 66

def edit
  set_variables_for_edit_form
end

#load_resource_from_solrObject

Load the GenericFile from solr instead of fedora this replaces the load_resource from CanCan that is usually called by load_and_authorize_resource



56
57
58
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 56

def load_resource_from_solr
  @generic_file = ::GenericFile.load_instance_from_solr(params[:id])
end

#newObject

routed to /files/new



61
62
63
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 61

def new
  @batch_id = ActiveFedora::Noid::Service.new.mint
end

#showObject

routed to /files/:id



114
115
116
117
118
119
120
121
122
123
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 114

def show
  respond_to do |format|
    format.html {
      @events = @generic_file.events(100)
      @presenter = presenter
      @audit_status = audit_service.human_readable_audit_status
    }
    format.endnote { render text: @generic_file.export_as_endnote }
  end
end

#statsObject

routed to /files/:id/stats



71
72
73
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 71

def stats
  @stats = FileUsage.new(params[:id])
end

#updateObject

routed to /files/:id (PUT)



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 131

def update
  success =
    if wants_to_revert?
      update_version
    elsif wants_to_upload_new_version?
      update_file
    elsif params.has_key? :generic_file
      
    elsif params.has_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