From 6094767a654265fafe7c1409e96267892d3b4d04 Mon Sep 17 00:00:00 2001 From: Karol Date: Sat, 20 Aug 2022 22:17:20 +0200 Subject: [PATCH] - rename parameter to be more generic - fix splatting of service args - add file role depending on parent object of file - add default feedback_message for imports --- app/controllers/exercises_controller.rb | 8 ++++---- .../proforma_service/convert_task_to_exercise.rb | 15 ++++++++++++--- app/services/service_base.rb | 4 ++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index b484d4b6..f3de2c20 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -118,7 +118,7 @@ raise: false partial: 'export_actions', locals: { exercise: @exercise, - task_found: codeharbor_check[:task_found], + task_found: codeharbor_check[:uuid_found], update_right: codeharbor_check[:update_right], error: codeharbor_check[:error], exported: false, @@ -159,10 +159,10 @@ raise: false uuid = params[:uuid] exercise = Exercise.find_by(uuid: uuid) - return render json: {exercise_found: false} if exercise.nil? - return render json: {exercise_found: true, update_right: false} unless ExercisePolicy.new(user, exercise).update? + return render json: {uuid_found: false} if exercise.nil? + return render json: {uuid_found: true, update_right: false} unless ExercisePolicy.new(user, exercise).update? - render json: {exercise_found: true, update_right: true} + render json: {uuid_found: true, update_right: true} end def import_exercise diff --git a/app/services/proforma_service/convert_task_to_exercise.rb b/app/services/proforma_service/convert_task_to_exercise.rb index f4ac2e63..35e62180 100644 --- a/app/services/proforma_service/convert_task_to_exercise.rb +++ b/app/services/proforma_service/convert_task_to_exercise.rb @@ -27,14 +27,23 @@ module ProformaService end def files - test_files + task_files.values + model_solution_files + test_files + task_files.values end def test_files @task.tests.map do |test_object| task_files.delete(test_object.files.first.id).tap do |file| file.weight = 1.0 - file.feedback_message = test_object.meta_data[:CodeOcean]&.dig(:'feedback-message') + file.feedback_message = test_object.meta_data[:CodeOcean]&.dig(:'feedback-message').presence || 'Feedback' + file.role = 'teacher_defined_test' + end + end + end + + def model_solution_files + @task.model_solutions.map do |model_solution_object| + task_files.delete(model_solution_object.files.first.id).tap do |file| + file.role = 'reference_implementation' end end end @@ -53,7 +62,7 @@ module ProformaService hidden: file.visible == 'no', name: File.basename(file.filename, '.*'), read_only: file.usage_by_lms != 'edit', - role: file.internal_description, + role: 'regular_file', path: File.dirname(file.filename).in?(['.', '']) ? nil : File.dirname(file.filename) ) if file.binary diff --git a/app/services/service_base.rb b/app/services/service_base.rb index 39010bb7..902944f3 100644 --- a/app/services/service_base.rb +++ b/app/services/service_base.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class ServiceBase - def self.call(*args) - new(*args).execute + def self.call(**args) + new(**args).execute end end