fix exercise_file duplication bug
This commit is contained in:
@ -123,7 +123,7 @@ class ExercisesController < ApplicationController
|
|||||||
uuid = params[:uuid]
|
uuid = params[:uuid]
|
||||||
exercise = Exercise.find_by(uuid: uuid)
|
exercise = Exercise.find_by(uuid: uuid)
|
||||||
|
|
||||||
return render json: {exercise_found: false, message: 'no_exercise'} if exercise.nil?
|
return render json: {exercise_found: false, message: t('exercises.export_codeharbor.check.no_exercise')} if exercise.nil?
|
||||||
|
|
||||||
render json: {exercise_found: true, message: 'exercise found, be careful when overwriting or else!'}
|
render json: {exercise_found: true, message: 'exercise found, be careful when overwriting or else!'}
|
||||||
end
|
end
|
||||||
@ -136,13 +136,14 @@ class ExercisesController < ApplicationController
|
|||||||
user = user_for_oauth2_request
|
user = user_for_oauth2_request
|
||||||
return render json: {}, status: 401 if user.nil?
|
return render json: {}, status: 401 if user.nil?
|
||||||
|
|
||||||
exercise = ProformaService::Import.call(zip: tempfile, user: user)
|
exercise = nil
|
||||||
if exercise.save
|
ActiveRecord::Base.transaction do
|
||||||
render json: {}, status: 201
|
exercise = ::ProformaService::Import.call(zip: tempfile, user: user)
|
||||||
else
|
exercise.save!
|
||||||
logger.info(exercise.errors.full_messages)
|
return render json: {}, status: 201
|
||||||
render json: {}, status: 400
|
|
||||||
end
|
end
|
||||||
|
logger.info(exercise.errors.full_messages)
|
||||||
|
render json: {}, status: 400
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_for_oauth2_request
|
def user_for_oauth2_request
|
||||||
|
@ -7,6 +7,7 @@ module CodeOcean
|
|||||||
def validate(record)
|
def validate(record)
|
||||||
existing_files = File.where(name: record.name, path: record.path, file_type_id: record.file_type_id,
|
existing_files = File.where(name: record.name, path: record.path, file_type_id: record.file_type_id,
|
||||||
context_id: record.context_id, context_type: record.context_type).to_a
|
context_id: record.context_id, context_type: record.context_type).to_a
|
||||||
|
|
||||||
unless existing_files.empty?
|
unless existing_files.empty?
|
||||||
if (not record.context.is_a?(Exercise)) || (record.context.new_record?)
|
if (not record.context.is_a?(Exercise)) || (record.context.new_record?)
|
||||||
record.errors[:base] << 'Duplicate'
|
record.errors[:base] << 'Duplicate'
|
||||||
|
@ -35,13 +35,13 @@ class Exercise < ApplicationRecord
|
|||||||
validates :public, boolean_presence: true
|
validates :public, boolean_presence: true
|
||||||
validates :title, presence: true
|
validates :title, presence: true
|
||||||
validates :token, presence: true, uniqueness: true
|
validates :token, presence: true, uniqueness: true
|
||||||
|
validates_uniqueness_of :uuid
|
||||||
|
|
||||||
@working_time_statistics = nil
|
@working_time_statistics = nil
|
||||||
attr_reader :working_time_statistics
|
attr_reader :working_time_statistics
|
||||||
|
|
||||||
MAX_EXERCISE_FEEDBACKS = 20
|
MAX_EXERCISE_FEEDBACKS = 20
|
||||||
|
|
||||||
|
|
||||||
def average_percentage
|
def average_percentage
|
||||||
if average_score and maximum_score != 0.0 and submissions.exists?(cause: 'submit')
|
if average_score and maximum_score != 0.0 and submissions.exists?(cause: 'submit')
|
||||||
(average_score / maximum_score * 100).round(2)
|
(average_score / maximum_score * 100).round(2)
|
||||||
|
@ -11,8 +11,12 @@ module ProformaService
|
|||||||
if single_task?
|
if single_task?
|
||||||
importer = Proforma::Importer.new(@zip)
|
importer = Proforma::Importer.new(@zip)
|
||||||
@task = importer.perform
|
@task = importer.perform
|
||||||
exercise = ConvertTaskToExercise.call(task: @task, user: @user)
|
|
||||||
exercise.save!
|
exercise = Exercise.find_by(uuid: @task.uuid)
|
||||||
|
exercise_files = exercise&.files&.to_a
|
||||||
|
|
||||||
|
exercise = ConvertTaskToExercise.call(task: @task, user: @user, exercise: exercise)
|
||||||
|
exercise_files&.each(&:destroy) # feels suboptimal
|
||||||
|
|
||||||
exercise
|
exercise
|
||||||
else
|
else
|
||||||
|
@ -317,9 +317,11 @@ en:
|
|||||||
editor_file_tree:
|
editor_file_tree:
|
||||||
file_root: Files
|
file_root: Files
|
||||||
export_codeharbor:
|
export_codeharbor:
|
||||||
|
check:
|
||||||
|
no_exercise: No exercise found
|
||||||
|
fail: Failed to push the exercise to CodeHarbor.
|
||||||
label: Export to Codeharbor
|
label: Export to Codeharbor
|
||||||
success: Successfully pushed the exercise to CodeHarbor.
|
success: Successfully pushed the exercise to CodeHarbor.
|
||||||
fail: Failed to push the exercise to CodeHarbor.
|
|
||||||
file_form:
|
file_form:
|
||||||
hints:
|
hints:
|
||||||
feedback_message: This message is used as a hint for failing tests.
|
feedback_message: This message is used as a hint for failing tests.
|
||||||
|
Reference in New Issue
Block a user