Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 53 additions & 50 deletions app/controllers/assessment/handin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -253,46 +232,70 @@ 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."
return false
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
Expand Down
81 changes: 43 additions & 38 deletions app/models/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
40 changes: 2 additions & 38 deletions app/views/assessments/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -202,40 +202,6 @@
<% end %>

<% if @assessment.embedded_quiz %>
<script>
$.fn.serializeObject = function()
{
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};

$(function() {
$('form').submit(function() {
$('#results').text(JSON.stringify($('#quiz_form').serializeObject()));
showForm();
//return false;
});
});

function showForm() {
var save = document.getElementById('results').innerHTML;
console.log(save);
document.getElementById("submission_embedded_quiz_form_answer").value = save;
}

</script>

<% if @cud.instructor %>
<div class = "row">
<div class = "col s12 offset-s0">
Expand All @@ -247,9 +213,7 @@
<div class = "row">
<div class = "col s10 offset-s1">
<hr>
<%= form_for @submission, url: {action: :handin}, :html => {:id => "quiz_form", :onclick => "return validateIntegrity();"}, method: :post do |f| %>

<%= f.hidden_field :embedded_quiz_form_answer, value: "" %>
<%= form_for @submission, url: {action: :handin}, :html => {:id => "quiz_form"}, method: :post do |f| %>

<%# Render instructor's custom quiz form elements. %>
<p>
Expand All @@ -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.") %>

<div class = "row" style = "margin-top: 10px !important">
<input type="submit" class = "btn primary handin-btn" onclick = "setSubmitClicked()">
<input type="submit" class = "btn primary handin-btn">
<span id="submission_error" style = "margin-left: 10px !important; color: red"></span>
</div>

Expand Down