update gem

fix codeharbor endpoint usage and translations
This commit is contained in:
Karol
2021-12-09 20:36:57 +01:00
parent a006a477e0
commit 886a5b68f6
8 changed files with 27 additions and 29 deletions

View File

@ -24,7 +24,7 @@ gem 'net-http-persistent'
gem 'nokogiri' gem 'nokogiri'
gem 'pagedown-bootstrap-rails' gem 'pagedown-bootstrap-rails'
gem 'pg' gem 'pg'
gem 'proforma', github: 'openHPI/proforma', tag: 'v0.7' gem 'proforma', github: 'openHPI/proforma', tag: 'v0.7.1'
gem 'prometheus_exporter' gem 'prometheus_exporter'
gem 'pry-byebug' gem 'pry-byebug'
gem 'puma' gem 'puma'

View File

@ -17,12 +17,12 @@ GIT
GIT GIT
remote: https://github.com/openHPI/proforma.git remote: https://github.com/openHPI/proforma.git
revision: ff25d4994774af3ad6f55d94cd5192ea3d4ecba2 revision: cf61517a5cd765afb9d0d19ea1c692e18e3131d7
tag: v0.7 tag: v0.7.1
specs: specs:
proforma (0.7) proforma (0.7.1)
activemodel (>= 5.2.3, < 7.0.0) activemodel (>= 5.2.3, < 8.0.0)
activesupport (>= 5.2.3, < 7.0.0) activesupport (>= 5.2.3, < 8.0.0)
nokogiri (>= 1.10.2, < 2.0.0) nokogiri (>= 1.10.2, < 2.0.0)
rubyzip (>= 1.2.2, < 3.0.0) rubyzip (>= 1.2.2, < 3.0.0)

View File

@ -118,7 +118,7 @@ raise: false
partial: 'export_actions', partial: 'export_actions',
locals: { locals: {
exercise: @exercise, exercise: @exercise,
exercise_found: codeharbor_check[:exercise_found], exercise_found: codeharbor_check[:task_found],
update_right: codeharbor_check[:update_right], update_right: codeharbor_check[:update_right],
error: codeharbor_check[:error], error: codeharbor_check[:error],
exported: false, exported: false,

View File

@ -14,21 +14,20 @@ module ExerciseService
req.headers['Authorization'] = "Bearer #{@codeharbor_link.api_key}" req.headers['Authorization'] = "Bearer #{@codeharbor_link.api_key}"
req.body = {uuid: @uuid}.to_json req.body = {uuid: @uuid}.to_json
end 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, {error: false, message: message(response_hash[:task_found], response_hash[:update_right])}.merge(response_hash)
message: message(response_hash[:exercise_found], response_hash[:update_right])}.merge(response_hash)
rescue Faraday::Error, JSON::ParserError rescue Faraday::Error, JSON::ParserError
{error: true, message: I18n.t('exercises.export_codeharbor.error')} {error: true, message: I18n.t('exercises.export_codeharbor.error')}
end end
private private
def message(exercise_found, update_right) def message(task_found, update_right)
if exercise_found if task_found
update_right ? I18n.t('exercises.export_codeharbor.check.exercise_found') : I18n.t('exercises.export_codeharbor.check.exercise_found_no_right') update_right ? I18n.t('exercises.export_codeharbor.check.task_found') : I18n.t('exercises.export_codeharbor.check.task_found_no_right')
else else
I18n.t('exercises.export_codeharbor.check.no_exercise') I18n.t('exercises.export_codeharbor.check.no_task')
end end
end end

View File

@ -383,9 +383,9 @@ de:
close: Schließen close: Schließen
abort: Abbrechen abort: Abbrechen
check: 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. 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.
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. 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.
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. 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: file_form:
hints: hints:
feedback_message: Diese Nachricht wird als Hinweis zu fehlschlagenden Tests angezeigt. feedback_message: Diese Nachricht wird als Hinweis zu fehlschlagenden Tests angezeigt.

View File

@ -383,9 +383,9 @@ en:
close: Close close: Close
abort: Abort abort: Abort
check: 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. 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.
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.' 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.'
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. 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: 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.

View File

@ -42,25 +42,25 @@ describe ExerciseService::CheckExternal do
end end
context 'when response contains a JSON with expected keys' do 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 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 end
context 'with exercise_found: false and no update_right' do context 'with task_found: false and no update_right' do
let(:response) { {exercise_found: false}.to_json } let(:response) { {task_found: false}.to_json }
it 'returns the correct hash' do 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
end end
context 'with exercise_found: true and update_right: false' do context 'with task_found: true and update_right: false' do
let(:response) { {exercise_found: true, update_right: false}.to_json } let(:response) { {task_found: true, update_right: false}.to_json }
it 'returns the correct hash' do 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 end
end end

View File

@ -37,6 +37,5 @@ describe ProformaService::ExportTask do
export_task export_task
expect(exporter).to have_received(:perform) expect(exporter).to have_received(:perform)
end end
# TODO more tests?!
end end
end end