diff --git a/app/controllers/gradebook_uploads_controller.rb b/app/controllers/gradebook_uploads_controller.rb index 2ac30e72bff..a526b4af811 100644 --- a/app/controllers/gradebook_uploads_controller.rb +++ b/app/controllers/gradebook_uploads_controller.rb @@ -22,19 +22,12 @@ class GradebookUploadsController < ApplicationController before_filter :require_context - def gradebook_upload - GradebookUpload.where( - course_id: @context, - user_id: @current_user - ).first - end - def new if authorized_action(@context, @current_user, :manage_grades) - # GradebookUpload is a singleton. If there is # already an instance we'll redirect to it or kill it - if previous_upload = gradebook_upload + previous_upload = gradebook_upload + if previous_upload if previous_upload.stale? previous_upload.destroy elsif previous_upload @@ -48,7 +41,6 @@ class GradebookUploadsController < ApplicationController def show if authorized_action(@context, @current_user, :manage_grades) - upload = gradebook_upload unless upload redirect_to new_course_gradebook_upload_path(@context) @@ -62,10 +54,16 @@ class GradebookUploadsController < ApplicationController def create if authorized_action(@context, @current_user, :manage_grades) - attachment = params[:gradebook_upload][:uploaded_data] - @progress = GradebookUpload.queue_from(@context, @current_user, attachment.read) - js_env gradebook_env(@progress) - render :show + if params[:gradebook_upload] + attachment = params[:gradebook_upload][:uploaded_data] + @progress = GradebookUpload.queue_from(@context, @current_user, attachment.read) + js_env gradebook_env(@progress) + render :show + else + flash[:error] = t(:no_file_attached, "We did not detect a CSV to "\ + "upload. Please select a CSV to upload and submit again.") + redirect_to action: :new + end end end @@ -79,6 +77,7 @@ class GradebookUploadsController < ApplicationController end end + private def gradebook_env(progress) { progress: progress_json(progress, @current_user, session), @@ -89,4 +88,11 @@ class GradebookUploadsController < ApplicationController new_gradebook_upload_path: new_course_gradebook_upload_path(@context), } end + + def gradebook_upload + GradebookUpload.where( + course_id: @context, + user_id: @current_user + ).first + end end