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