forked from autolab/Autolab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autograders_controller.rb
executable file
·68 lines (59 loc) · 2.04 KB
/
autograders_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
##
# Each Assessment can have an autograder, which is modified with this controller
#
class AutogradersController < ApplicationController
before_action :set_assessment
before_action :set_assessment_breadcrumb, only: [:edit]
before_action :set_autograder, except: [:create]
action_auth_level :create, :instructor
def create
@autograder = Autograder.new do |a|
a.assessment_id = @assessment.id
a.autograde_timeout = 180
a.autograde_image = "autograding_image"
a.release_score = true
end
flash[:info] = "Autograder Created" if @autograder.save
redirect_to([:edit, @course, @assessment, :autograder]) && return
end
action_auth_level :edit, :instructor
def edit
end
action_auth_level :update, :instructor
def update
flash[:info] = "Saved!" if @autograder.update(autograder_params)
upload
redirect_to([:edit, @course, @assessment, :autograder]) && return
end
action_auth_level :destroy, :instructor
def destroy
flash[:info] = "Destroyed!" if @autograder.destroy
redirect_to([:edit, @course, @assessment]) && return
end
action_auth_level :upload, :instructor
def upload
uploaded_makefile = params[:autograder][:makefile]
uploaded_tar = params[:autograder][:tar]
if not uploaded_makefile.nil?
File.open(Rails.root.join('courses', @course.name, @assessment.name, 'autograde-Makefile'), 'wb') do |file|
file.write(uploaded_makefile.read) unless uploaded_makefile.nil?
end
end
if not uploaded_tar.nil?
File.open(Rails.root.join('courses', @course.name, @assessment.name, 'autograde.tar'), 'wb') do |file|
file.write(uploaded_tar.read) unless uploaded_tar.nil?
end
end
end
private
def set_assessment_breadcrumb
@breadcrumbs << (view_context.link_to "Edit Assessment", [:edit, @course, @assessment])
end
def set_autograder
@autograder = @assessment.autograder
redirect_to([@course, @assessment]) if @autograder.nil?
end
def autograder_params
params[:autograder].permit(:autograde_timeout, :autograde_image, :release_score)
end
end