create remote evaluation
This commit is contained in:
8
app/controllers/concerns/remote_evaluation_parameters.rb
Normal file
8
app/controllers/concerns/remote_evaluation_parameters.rb
Normal file
@ -0,0 +1,8 @@
|
||||
module RemoteEvaluationParameters
|
||||
include FileParameters
|
||||
|
||||
def remote_evaluation_params
|
||||
remote_evaluation_params = params[:remote_evaluation].permit(:validation_token, files_attributes: file_attributes)
|
||||
end
|
||||
private :remote_evaluation_params
|
||||
end
|
35
app/controllers/remote_evaluation_controller.rb
Normal file
35
app/controllers/remote_evaluation_controller.rb
Normal file
@ -0,0 +1,35 @@
|
||||
class RemoteEvaluationController < ApplicationController
|
||||
include RemoteEvaluationParameters
|
||||
include SubmissionScoring
|
||||
|
||||
skip_after_action :verify_authorized
|
||||
skip_before_action :verify_authenticity_token
|
||||
|
||||
# POST /evaluate
|
||||
# @param validation_token
|
||||
# @param files_attributes
|
||||
def evaluate
|
||||
|
||||
validation_token = remote_evaluation_params[:validation_token]
|
||||
files_attributes = remote_evaluation_params[:files_attributes] || []
|
||||
|
||||
# todo extra: validiere, ob files wirklich zur Übung gehören (wenn allowNewFiles-flag nicht gesetzt ist)
|
||||
if (remote_evaluation_mapping = RemoteEvaluationMapping.find_by(:validation_token => validation_token))
|
||||
puts remote_evaluation_mapping.exercise_id
|
||||
puts remote_evaluation_mapping.user_id
|
||||
|
||||
_params = remote_evaluation_params.except(:validation_token)
|
||||
_params[:exercise_id] = remote_evaluation_mapping.exercise_id
|
||||
_params[:user_id] = remote_evaluation_mapping.user_id
|
||||
_params[:cause] = "remoteAssess"
|
||||
_params[:user_type] = "ExternalUser"
|
||||
|
||||
@submission = Submission.create(_params)
|
||||
render json: score_submission(@submission)
|
||||
else
|
||||
# todo: better output
|
||||
# todo: check token expired?
|
||||
render json: "No exercise found for this validation_token! Please keep out!"
|
||||
end
|
||||
end
|
||||
end
|
@ -57,12 +57,29 @@ class SubmissionsController < ApplicationController
|
||||
# files = @submission.files.map{ }
|
||||
# zipline( files, 'submission.zip')
|
||||
# send_data(@file.content, filename: @file.name_with_extension)
|
||||
|
||||
id_file = create_remote_evaluation_mapping
|
||||
|
||||
require 'zip'
|
||||
stringio = Zip::OutputStream.write_buffer do |zio|
|
||||
@files.each do |file|
|
||||
zio.put_next_entry(file.name_with_extension)
|
||||
zio.put_next_entry(file.path.to_s == '' ? file.name_with_extension : File.join(file.path, file.name_with_extension))
|
||||
zio.write(file.content)
|
||||
end
|
||||
|
||||
# zip .co file
|
||||
zio.put_next_entry(File.basename id_file)
|
||||
zio.write(File.read id_file)
|
||||
File.delete(id_file) if File.exist?(id_file)
|
||||
|
||||
# zip client scripts
|
||||
scripts_path = 'app/assets/remote_scripts'
|
||||
Dir.foreach(scripts_path) do |file|
|
||||
next if file == '.' or file == '..'
|
||||
zio.put_next_entry(File.join('.scripts', File.basename(file)))
|
||||
zio.write(File.read File.join(scripts_path, file))
|
||||
end
|
||||
|
||||
end
|
||||
send_data(stringio.string, filename: @submission.exercise.title.tr(" ", "_") + ".zip")
|
||||
end
|
||||
@ -316,4 +333,23 @@ class SubmissionsController < ApplicationController
|
||||
server_sent_event.close
|
||||
end
|
||||
private :with_server_sent_events
|
||||
end
|
||||
|
||||
def create_remote_evaluation_mapping
|
||||
user_id = @submission.user_id
|
||||
exercise_id = @submission.exercise_id
|
||||
|
||||
remote_evaluation_mapping = RemoteEvaluationMapping.create(:user_id => user_id, :exercise_id => exercise_id)
|
||||
|
||||
# create id.co file
|
||||
path = "tmp/.co"
|
||||
content = "#{remote_evaluation_mapping.validation_token}\n"
|
||||
@submission.files.each do |file|
|
||||
file_path = file.path.to_s == '' ? file.name_with_extension : File.join(file.path, file.name_with_extension)
|
||||
content += "#{file_path}=#{file.id.to_s}\n"
|
||||
end
|
||||
File.open(path, "w+") do |f|
|
||||
f.write(content)
|
||||
end
|
||||
path
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user