From 886a5b68f670cb7e876174a461574a402c91c090 Mon Sep 17 00:00:00 2001 From: Karol Date: Thu, 9 Dec 2021 20:36:57 +0100 Subject: [PATCH] update gem fix codeharbor endpoint usage and translations --- Gemfile | 2 +- Gemfile.lock | 10 +++++----- app/controllers/exercises_controller.rb | 2 +- app/services/exercise_service/check_external.rb | 13 ++++++------- config/locales/de.yml | 6 +++--- config/locales/en.yml | 6 +++--- .../exercise_service/check_external_spec.rb | 16 ++++++++-------- .../proforma_service/export_task_spec.rb | 1 - 8 files changed, 27 insertions(+), 29 deletions(-) diff --git a/Gemfile b/Gemfile index 677b072a..c761f07e 100644 --- a/Gemfile +++ b/Gemfile @@ -24,7 +24,7 @@ gem 'net-http-persistent' gem 'nokogiri' gem 'pagedown-bootstrap-rails' gem 'pg' -gem 'proforma', github: 'openHPI/proforma', tag: 'v0.7' +gem 'proforma', github: 'openHPI/proforma', tag: 'v0.7.1' gem 'prometheus_exporter' gem 'pry-byebug' gem 'puma' diff --git a/Gemfile.lock b/Gemfile.lock index e2122867..e4ebea24 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -17,12 +17,12 @@ GIT GIT remote: https://github.com/openHPI/proforma.git - revision: ff25d4994774af3ad6f55d94cd5192ea3d4ecba2 - tag: v0.7 + revision: cf61517a5cd765afb9d0d19ea1c692e18e3131d7 + tag: v0.7.1 specs: - proforma (0.7) - activemodel (>= 5.2.3, < 7.0.0) - activesupport (>= 5.2.3, < 7.0.0) + proforma (0.7.1) + activemodel (>= 5.2.3, < 8.0.0) + activesupport (>= 5.2.3, < 8.0.0) nokogiri (>= 1.10.2, < 2.0.0) rubyzip (>= 1.2.2, < 3.0.0) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 7e0a5435..37be0aa2 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, - exercise_found: codeharbor_check[:exercise_found], + exercise_found: codeharbor_check[:task_found], update_right: codeharbor_check[:update_right], error: codeharbor_check[:error], exported: false, diff --git a/app/services/exercise_service/check_external.rb b/app/services/exercise_service/check_external.rb index 79836a44..ab7f0db9 100644 --- a/app/services/exercise_service/check_external.rb +++ b/app/services/exercise_service/check_external.rb @@ -14,21 +14,20 @@ module ExerciseService req.headers['Authorization'] = "Bearer #{@codeharbor_link.api_key}" req.body = {uuid: @uuid}.to_json end - response_hash = JSON.parse(response.body, symbolize_names: true).slice(:exercise_found, :update_right) + response_hash = JSON.parse(response.body, symbolize_names: true).slice(:task_found, :update_right) - {error: false, -message: message(response_hash[:exercise_found], response_hash[:update_right])}.merge(response_hash) + {error: false, message: message(response_hash[:task_found], response_hash[:update_right])}.merge(response_hash) rescue Faraday::Error, JSON::ParserError {error: true, message: I18n.t('exercises.export_codeharbor.error')} end private - def message(exercise_found, update_right) - if exercise_found - update_right ? I18n.t('exercises.export_codeharbor.check.exercise_found') : I18n.t('exercises.export_codeharbor.check.exercise_found_no_right') + def message(task_found, update_right) + if task_found + update_right ? I18n.t('exercises.export_codeharbor.check.task_found') : I18n.t('exercises.export_codeharbor.check.task_found_no_right') else - I18n.t('exercises.export_codeharbor.check.no_exercise') + I18n.t('exercises.export_codeharbor.check.no_task') end end diff --git a/config/locales/de.yml b/config/locales/de.yml index ba767d3a..bbbd11a2 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -383,9 +383,9 @@ de: close: Schließen abort: Abbrechen check: - no_exercise: Auf CodeHarbor wurde keine entsprechende Aufgabe gefunden. Mit dem Export der Aufgabe wird eine neue auf CodeHarbor angelegt, die mit dieser verbunden ist. Anschließend können Veränderungen an der Aufgabe von beiden Systemen aus jeweils in das andere Übertragen werden. - exercise_found: Auf CodeHarbor wurde eine entsprechende Aufgabe gefunden. Mit dem Export der Aufgabe werden alle Veränderungen, die auf Codeocean vorgenommen wurden, exportiert und die Aufgabe auf CodeHarbor überschrieben. - exercise_found_no_right: Auf CodeHarbor wurde eine entsprechende Aufgabe gefunden, Sie haben aber keine Rechte sie zu bearbeiten. Bitte wenden Sie sich an einen Admin, wenn Sie denken, dass Sie die Rechte dazu besitzen sollten. + no_task: Auf CodeHarbor wurde keine entsprechende Aufgabe gefunden. Mit dem Export der Aufgabe wird eine neue auf CodeHarbor angelegt, die mit dieser verbunden ist. Anschließend können Veränderungen an der Aufgabe von beiden Systemen aus jeweils in das andere Übertragen werden. + task_found: Auf CodeHarbor wurde eine entsprechende Aufgabe gefunden. Mit dem Export der Aufgabe werden alle Veränderungen, die auf Codeocean vorgenommen wurden, exportiert und die Aufgabe auf CodeHarbor überschrieben. + task_found_no_right: Auf CodeHarbor wurde eine entsprechende Aufgabe gefunden, Sie haben aber keine Rechte sie zu bearbeiten. Bitte wenden Sie sich an einen Admin, wenn Sie denken, dass Sie die Rechte dazu besitzen sollten. file_form: hints: feedback_message: Diese Nachricht wird als Hinweis zu fehlschlagenden Tests angezeigt. diff --git a/config/locales/en.yml b/config/locales/en.yml index 33eb6adc..a40632a5 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -383,9 +383,9 @@ en: close: Close abort: Abort check: - no_exercise: No corresponding exercise found on CodeHarbor. Pushing this exercise will create a new exercise on CodeHarbor, which will be linked to this one on Codeocean. Any changes to either one can be pushed to the respective other platform. - exercise_found: 'A corresponding exercise has been found on CodeHarbor. You can export the exercise to transfer all changes made on Codeocean to CodeHarbor. Careful: This will overwrite all potential changes made on CodeHarbor.' - exercise_found_no_right: A corresponding exercise has been found on CodeHarbor, but you don't have the rights to edit it. Please contact an Admin if you think you should be able to edit the exercise on CodeHarbor. + no_task: No corresponding task found on CodeHarbor. Pushing this exercise will create a new task on CodeHarbor, which will be linked to this one on Codeocean. Any changes to either one can be pushed to the respective other platform. + task_found: 'A corresponding task has been found on CodeHarbor. You can export the exercise to transfer all changes made on Codeocean to Codeharbor. Careful: This will overwrite all potential changes made on Codeharbor.' + task_found_no_right: A corresponding task has been found on CodeHarbor, but you don't have the rights to edit it. Please contact an Admin if you think you should be able to edit the task on CodeHarbor. file_form: hints: feedback_message: This message is used as a hint for failing tests. diff --git a/spec/services/exercise_service/check_external_spec.rb b/spec/services/exercise_service/check_external_spec.rb index f5ee4b97..a4b0997c 100644 --- a/spec/services/exercise_service/check_external_spec.rb +++ b/spec/services/exercise_service/check_external_spec.rb @@ -42,25 +42,25 @@ describe ExerciseService::CheckExternal do end context 'when response contains a JSON with expected keys' do - let(:response) { {exercise_found: true, update_right: true}.to_json } + let(:response) { {task_found: true, update_right: true}.to_json } it 'returns the correct hash' do - expect(check_external_service).to eql(error: false, message: I18n.t('exercises.export_codeharbor.check.exercise_found'), exercise_found: true, update_right: true) + expect(check_external_service).to eql(error: false, message: I18n.t('exercises.export_codeharbor.check.task_found'), task_found: true, update_right: true) end - context 'with exercise_found: false and no update_right' do - let(:response) { {exercise_found: false}.to_json } + context 'with task_found: false and no update_right' do + let(:response) { {task_found: false}.to_json } it 'returns the correct hash' do - expect(check_external_service).to eql(error: false, message: I18n.t('exercises.export_codeharbor.check.no_exercise'), exercise_found: false) + expect(check_external_service).to eql(error: false, message: I18n.t('exercises.export_codeharbor.check.no_task'), task_found: false) end end - context 'with exercise_found: true and update_right: false' do - let(:response) { {exercise_found: true, update_right: false}.to_json } + context 'with task_found: true and update_right: false' do + let(:response) { {task_found: true, update_right: false}.to_json } it 'returns the correct hash' do - expect(check_external_service).to eql(error: false, message: I18n.t('exercises.export_codeharbor.check.exercise_found_no_right'), exercise_found: true, update_right: false) + expect(check_external_service).to eql(error: false, message: I18n.t('exercises.export_codeharbor.check.task_found_no_right'), task_found: true, update_right: false) end end end diff --git a/spec/services/proforma_service/export_task_spec.rb b/spec/services/proforma_service/export_task_spec.rb index 331a7ec7..1d010a2f 100644 --- a/spec/services/proforma_service/export_task_spec.rb +++ b/spec/services/proforma_service/export_task_spec.rb @@ -37,6 +37,5 @@ describe ProformaService::ExportTask do export_task expect(exporter).to have_received(:perform) end - # TODO more tests?! end end