Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autograder improvements #2209

Merged
merged 7 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
5 changes: 5 additions & 0 deletions app/assets/stylesheets/style.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,11 @@ input[type="search"] {
margin-bottom: 2px;
}

div.file-field.input-field {
padding-top: 0;
margin-top: -0.5rem !important;
}

.flatpickr-input.form-control.input {
color: black;
}
Expand Down
36 changes: 33 additions & 3 deletions app/controllers/autograders_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
##
# Each Assessment can have an autograder, which is modified with this controller
#

require 'pathname'

class AutogradersController < ApplicationController
before_action :set_assessment
before_action :set_assessment_breadcrumb, only: [:edit]
Expand All @@ -27,11 +29,16 @@ def create
end

action_auth_level :edit, :instructor
def edit; end
def edit
makefile_path = Rails.root.join("courses", @course.name, @assessment.name, "autograde-Makefile")
tar_path = Rails.root.join("courses", @course.name, @assessment.name, "autograde.tar")
@makefile_exists = File.exist?(makefile_path) ? makefile_path : nil
@tar_exists = File.exist?(tar_path) ? tar_path : nil
end

action_auth_level :update, :instructor
def update
if @autograder.update(autograder_params)
if @autograder.update(autograder_params) && @assessment.update(assessment_params)
flash[:success] = "Autograder saved."
begin
upload
Expand Down Expand Up @@ -78,6 +85,25 @@ def upload
end
end

action_auth_level :download_file, :instructor
def download_file
allowed_files = {
'makefile' => Rails.root.join('courses', @course.name, @assessment.name,
'autograde-Makefile'),
'tar' => Rails.root.join('courses', @course.name, @assessment.name, 'autograde.tar')
}

file_key = params[:file_key]
file_path = allowed_files[file_key]

if file_path && File.exist?(file_path)
send_file(file_path, disposition: 'attachment')
else
flash[:error] = 'File not found'
redirect_to(edit_course_assessment_autograder_path(@course, @assessment))
end
end

private

def set_autograder
Expand All @@ -88,4 +114,8 @@ def set_autograder
def autograder_params
params[:autograder].permit(:autograde_timeout, :autograde_image, :release_score)
end

def assessment_params
params.fetch(:autograder, {}).fetch(:assessment, {}).permit(:disable_network)
end
end
14 changes: 11 additions & 3 deletions app/form_builders/form_builder_with_date_time_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def score_adjustment_input(name, *args)
options = args.extract_options!

fields = fields_for name do |f|
(f.vanilla_text_field :value, class: "score-box", placeholder: options[:placeholder] || "", disabled: options[:disabled]) +
(f.vanilla_text_field :value, class: "score-box", placeholder: options[:placeholder] || "",
disabled: options[:disabled]) +
(@template.content_tag :div do
f.select(:kind, { "points" => "points", "%" => "percent" }, {},
class: "carrot", disabled: options[:disabled])
Expand Down Expand Up @@ -82,8 +83,15 @@ def file_field(name, *args)
vanilla_file_field(name, options)
end) +
(@template.content_tag :div, class: "file-path-wrapper" do
(@template.content_tag :input, nil, class: "file-path validate", type: "text", value: "No file selected") +
help_text(name, options[:help_text])
if options.include?(:file_exists) && options.include?(:file_exists_text) && options[:file_exists]
(@template.content_tag :input, nil, class: "file-path validate", type: "text",
value: options[:file_exists_text]) +
help_text(name, options[:help_text])
else
(@template.content_tag :input, nil, class: "file-path validate", type: "text",
value: "No file selected") +
help_text(name, options[:help_text])
end
end)
end
end
Expand Down
1 change: 0 additions & 1 deletion app/views/assessments/_edit_advanced.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
local machines will be copied." %>
<% end %>

<%= f.check_box :disable_network, help_text: "Disable network access for autograding containers." %>
<%= f.check_box :allow_unofficial,
help_text: "Allow unofficial submission. Unless you know what you're doing, leave this unchecked." %>
<%= f.check_box :embedded_quiz,
Expand Down
18 changes: 16 additions & 2 deletions app/views/autograders/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,29 @@
display_name: "Release Scores?",
help_text: "Check to release autograded scores to students immediately after autograding (strongly recommended)." %>

<%= f.file_field :makefile, label_text: "Autograder Makefile", action: :upload %>
<%= f.file_field :tar, label_text: "Autograder Tar", action: :upload %>
<% help_tar_text = "Tar file exists, upload a file to override." %>
<% help_makefile_text = "Makefile exists, upload a file to override." %>
<%= f.file_field :makefile, label_text: "Autograder Makefile", action: :upload, file_exists_text: help_makefile_text, class: "form-file-field", file_exists: @makefile_exists %>
<%= f.file_field :tar, label_text: "Autograder Tar", action: :upload, file_exists_text: help_tar_text, class: "form-file-field", file_exists: @tar_exists %>
<p class="help-block">
Both of the above files will be renamed upon upload.
</p>

<%= f.fields_for :assessment, @assessment do |af| %>
<%= af.check_box :disable_network, help_text: "Disable network access for autograding containers." %>
<% end %>

<%= f.submit "Save Settings" %>

<%= link_to "Delete Autograder", course_assessment_autograder_path(@course, @assessment),
method: :delete, class: "btn danger",
data: { confirm: "Are you sure you want to delete the Autograder for this assesssment?" } %>

<% unless @makefile_exists.nil? %>
<%= link_to "Download Makefile", download_file_course_assessment_autograder_path(file_path: @makefile_exists, file_key: 'makefile'), class: "btn" %>
<% end %>

<% unless @tar_exists.nil? %>
<%= link_to "Download Tar", download_file_course_assessment_autograder_path(file_path: @tar_exists, file_key: 'tar'), class: "btn" %>
<% end %>
<% end %>
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@
resources :attachments

resources :assessments, param: :name, except: :update do
resource :autograder, except: [:new, :show]
resource :autograder, except: [:new, :show] do
get "download_file"
end
resources :assessment_user_data, only: [:edit, :update]
resources :attachments
resources :extensions, only: [:index, :create, :destroy]
Expand Down