diff --git a/app/controllers/assessment/handin.rb b/app/controllers/assessment/handin.rb index b30252e96..4b510202e 100755 --- a/app/controllers/assessment/handin.rb +++ b/app/controllers/assessment/handin.rb @@ -20,29 +20,8 @@ module AssessmentHandin # Any errors should be added to flash[:error] and return false or nil. def handin - if @assessment.embedded_quiz - - contents = params[:submission]["embedded_quiz_form_answer"].to_s - tmp_uuid = SecureRandom.hex 32 - out_file = File.new("/tmp/embedded_form_"+tmp_uuid, "w+") - out_file.puts(contents) - - params[:submission]["file"] = out_file - - end - - if @assessment.embedded_quiz - if @assessment.disable_handins? - flash[:error] = "Sorry, handins are disabled for this assessment." - redirect_to(action: :show) - return false - end - else - - # validate the handin - redirect_to(action: :show) && return unless validateHandin - end + redirect_to(action: :show) && return unless validateHandin # save the submissions begin @@ -253,7 +232,13 @@ def log_submit # submission file is okay to submit. # def validateHandin - if @assessment.has_custom_form + # Make sure that handins are allowed + if @assessment.disable_handins? + flash[:error] = "Sorry, handins are disabled for this assessment." + return false + end + + if @assessment.has_custom_form for i in 0..@assessment.getTextfields.size-1 if params[:submission][("formfield" + (i+1).to_s).to_sym].blank? flash[:error] = @assessment.getTextfields[i] + " is a required field." @@ -261,38 +246,56 @@ def validateHandin end end end - # Make sure that handins are allowed - if @assessment.disable_handins? - flash[:error] = "Sorry, handins are disabled for this assessment." - return false - end - # Check for if the submission is empty - if params[:submission].nil? - flash[:error] = "Submission was blank - please upload again." - return false - end + if @assessment.embedded_quiz + + if(params["integrity_checkbox"]) + contents = @assessment.embedded_quiz_form_data.scan(/\b(?<=name=\")[^"]+(?=\")/) + submission_data = {} + empty = true + for input in contents + empty = empty && params[input] == "" + submission_data[input] = params[input] + end + params[:submission] = JSON.generate(submission_data) + if empty + flash[:error] = "Submission Is Blank" + return false + end + else + flash[:error] = "Integrity Box Needs To Be Accepted" + return false + end - # check to see if file exists - if params[:submission]["file"].nil? - flash[:error] = "File was not found - please upload again." - return false - end - # Check if the file is too large - if params[:submission]["file"].size > @assessment.max_size * (2**20) - flash[:error] = "Your submission is larger than the max allowed " \ - "size (#{@assessment.max_size} MB) - please remove any " \ - "unnecessary logfiles and binaries." - return false - end + else + # Check for if the submission is empty + if params[:submission].nil? + flash[:error] = "Submission was blank - please upload again." + return false + end + + # check to see if file exists + if params[:submission]["file"].nil? + flash[:error] = "File was not found - please upload again." + return false + end - if @assessment.overwrites_method?(:checkMimeType) && !(@assessment.config_module.checkMimeType( - params[:submission]["file"].content_type, - params[:submission]["file"].original_filename)) + # Check if the file is too large + if params[:submission]["file"].size > @assessment.max_size * (2**20) + flash[:error] = "Your submission is larger than the max allowed " \ + "size (#{@assessment.max_size} MB) - please remove any " \ + "unnecessary logfiles and binaries." + return false + end - flash[:error] = "Submission failed Filetype Check. " + flash[:error] - return false + if @assessment.overwrites_method?(:checkMimeType) && !(@assessment.config_module.checkMimeType( + params[:submission]["file"].content_type, + params[:submission]["file"].original_filename)) + + flash[:error] = "Submission failed Filetype Check. " + flash[:error] + return false + end end validate_for_groups diff --git a/app/models/submission.rb b/app/models/submission.rb index 8136d2787..f0fbfb685 100755 --- a/app/models/submission.rb +++ b/app/models/submission.rb @@ -79,51 +79,56 @@ def save_file(upload) course_user_datum.course.name, assessment.name, directory, filename) - if upload["file"] - # Sanity! - upload["file"].rewind - File.open(path, "wb") { |f| f.write(upload["file"].read) } - elsif upload["local_submit_file"] - # local_submit_file is a path string to the temporary handin - # directory we create for local submissions - File.open(path, "wb") { |f| f.write(IO.read(upload["local_submit_file"], mode: File::RDONLY|File::NOFOLLOW)) } - elsif upload["tar"] - src = upload["tar"] - `mv #{src} #{path}` - end - - self.filename = filename - if upload["file"] - begin - self.mime_type = upload["file"].content_type - rescue - self.mime_type = nil + if(assessment.embedded_quiz) + File.open(path, "wb") { |f| f.write(upload) } + else + if upload["file"] + # Sanity! + upload["file"].rewind + File.open(path, "wb") { |f| f.write(upload["file"].read) } + elsif upload["local_submit_file"] + # local_submit_file is a path string to the temporary handin + # directory we create for local submissions + File.open(path, "wb") { |f| f.write(IO.read(upload["local_submit_file"], mode: File::RDONLY|File::NOFOLLOW)) } + elsif upload["tar"] + src = upload["tar"] + `mv #{src} #{path}` end - self.mime_type = "text/plain" unless mime_type - elsif upload["local_submit_file"] - self.mime_type = "text/plain" - elsif upload["tar"] - self.mime_type = "application/x-tgz" - end - if assessment.has_autograder? - self.grader = "Autolab" - else - self.grader = "Unassigned" + end + self.filename = filename + if upload["file"] + begin + self.mime_type = upload["file"].content_type + rescue + self.mime_type = nil + end + self.mime_type = "text/plain" unless mime_type + elsif upload["local_submit_file"] + self.mime_type = "text/plain" + elsif upload["tar"] + self.mime_type = "application/x-tgz" + end - save_additional_form_fields(upload) - self.save! - settings_file = course_user_datum.user.email + "_" + - version.to_s + "_" + assessment.handin_filename + - ".settings.json" + if assessment.has_autograder? + self.grader = "Autolab" + else + self.grader = "Unassigned" + end - settings_path = File.join(Rails.root, "courses", - course_user_datum.course.name, - assessment.name, directory, settings_file) + save_additional_form_fields(upload) + self.save! + settings_file = course_user_datum.user.email + "_" + + version.to_s + "_" + assessment.handin_filename + + ".settings.json" + + settings_path = File.join(Rails.root, "courses", + course_user_datum.course.name, + assessment.name, directory, settings_file) - File.open(settings_path, "wb") { |f| f.write(self.settings) } + File.open(settings_path, "wb") { |f| f.write(self.settings) } end def save_additional_form_fields(params) diff --git a/app/views/assessments/show.html.erb b/app/views/assessments/show.html.erb index 1f8a7e68d..7037026ce 100755 --- a/app/views/assessments/show.html.erb +++ b/app/views/assessments/show.html.erb @@ -202,40 +202,6 @@ <% end %> <% if @assessment.embedded_quiz %> - - <% if @cud.instructor %>
@@ -265,7 +229,7 @@ <%= label_tag(:integrity_checkbox, "I affirm that I have complied with this course's academic integrity policy as defined in the syllabus.") %>