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 1 commit
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
27 changes: 24 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 @@
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) and @assessment.update(assessment_params)
flash[:success] = "Autograder saved."
begin
upload
Expand Down Expand Up @@ -78,6 +85,17 @@
end
end

def download_file
file_path = Pathname.new(params[:file_path])
if file_path.exist?
send_file(file_path, disposition: "attachment")
flash[:success] = "File downloaded"
else
flash[:error] = "File not found"
redirect_to(edit_course_assessment_path(@course, @assessment))
end
end

private

def set_autograder
Expand All @@ -88,4 +106,7 @@
def autograder_params
params[:autograder].permit(:autograde_timeout, :autograde_image, :release_score)
end
def assessment_params
params[:autograder][:assessment].permit(:disable_network)
end
end
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
24 changes: 22 additions & 2 deletions app/views/autograders/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,35 @@
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 %>
<% if @makefile_exists %>
<%= f.file_field :makefile, label_text: "Autograder Makefile", action: :upload, help_text: "This file exists, upload a file to override." %>
<% else %>
<%= f.file_field :makefile, label_text: "Autograder Makefile", action: :upload %>
<% end %>
<% if @tar_exists %>
<%= f.file_field :tar, label_text: "Autograder Tar", action: :upload, help_text: "This file exists, upload a file to override." %>
<% else %>
<%= f.file_field :tar, label_text: "Autograder Tar", action: :upload %>
<% end %>
<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) , class: "btn" %>
<% end %>

<% unless @tar_exists.nil? %>
<%= link_to "Download Tar", download_file_course_assessment_autograder_path(file_path: @tar_exists), 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 @@ -139,7 +139,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
Loading