remove create_new functionality, when exercise exists on CH but is not editable
This commit is contained in:
@ -251,7 +251,7 @@ $(document).on('turbolinks:load', function() {
|
||||
exportExerciseStart($(this).data().exerciseId);
|
||||
});
|
||||
$('body').on('click', '.export-action', function(){
|
||||
exportExerciseConfirm($(this).data().exerciseId, $(this).data().exportType);
|
||||
exportExerciseConfirm($(this).data().exerciseId);
|
||||
});
|
||||
}
|
||||
|
||||
@ -279,7 +279,7 @@ $(document).on('turbolinks:load', function() {
|
||||
});
|
||||
};
|
||||
|
||||
var exportExerciseConfirm = function(exerciseID, pushType) {
|
||||
var exportExerciseConfirm = function(exerciseID) {
|
||||
var $exerciseDiv = $('#export-exercise');
|
||||
var $messageDiv = $exerciseDiv.children('.export-message');
|
||||
var $actionsDiv = $exerciseDiv.children('.export-exercise-actions');
|
||||
@ -287,9 +287,6 @@ $(document).on('turbolinks:load', function() {
|
||||
return $.ajax({
|
||||
type: 'POST',
|
||||
url: '/exercises/' + exerciseID + '/export_external_confirm',
|
||||
data: {
|
||||
push_type: pushType
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
$messageDiv.html(response.message)
|
||||
|
@ -129,7 +129,7 @@ class ExercisesController < ApplicationController
|
||||
partial: 'export_actions',
|
||||
locals: {
|
||||
exercise: @exercise,
|
||||
# exercise_found: codeharbor_check[:exercise_found],
|
||||
exercise_found: codeharbor_check[:exercise_found],
|
||||
update_right: codeharbor_check[:update_right],
|
||||
error: codeharbor_check[:error],
|
||||
exported: false
|
||||
@ -139,11 +139,7 @@ class ExercisesController < ApplicationController
|
||||
end
|
||||
|
||||
def export_external_confirm
|
||||
push_type = params[:push_type]
|
||||
|
||||
return render json: {}, status: 500 unless %w[create_new export].include? push_type
|
||||
|
||||
@exercise.uuid = SecureRandom.uuid if push_type == 'create_new'
|
||||
@exercise.uuid = SecureRandom.uuid if @exercise.uuid.nil?
|
||||
|
||||
error = ExerciseService::PushExternal.call(
|
||||
zip: ProformaService::ExportTask.call(exercise: @exercise),
|
||||
@ -155,6 +151,7 @@ class ExercisesController < ApplicationController
|
||||
message: t('exercises.export_codeharbor.successfully_exported', id: @exercise.id, title: @exercise.title),
|
||||
actions: render_to_string(partial: 'export_actions', locals: {exercise: @exercise, exported: true, error: error})
|
||||
}
|
||||
@exercise.save
|
||||
else
|
||||
render json: {
|
||||
status: 'fail',
|
||||
@ -171,10 +168,10 @@ class ExercisesController < ApplicationController
|
||||
uuid = params[:uuid]
|
||||
exercise = Exercise.find_by(uuid: uuid)
|
||||
|
||||
return render json: {exercise_found: false, message: t('exercises.import_codeharbor.check.no_exercise')} if exercise.nil?
|
||||
return render json: {exercise_found: true, update_right: false, message: t('exercises.import_codeharbor.check.exercise_found_no_right')} unless ExercisePolicy.new(user, exercise).update?
|
||||
return render json: {exercise_found: false} if exercise.nil?
|
||||
return render json: {exercise_found: true, update_right: false} unless ExercisePolicy.new(user, exercise).update?
|
||||
|
||||
render json: {exercise_found: true, update_right: true, message: t('exercises.import_codeharbor.check.exercise_found')}
|
||||
render json: {exercise_found: true, update_right: true}
|
||||
end
|
||||
|
||||
def import_exercise
|
||||
|
@ -14,8 +14,13 @@ module ExerciseService
|
||||
req.body = {uuid: @uuid}.to_json
|
||||
end
|
||||
response_hash = JSON.parse(response.body, symbolize_names: true)
|
||||
message = if response_hash[:exercise_found]
|
||||
response_hash[:update_right] ? I18n.t('exercises.export_codeharbor.check.exercise_found') : I18n.t('exercises.export_codeharbor.check.exercise_found_no_right')
|
||||
else
|
||||
I18n.t('exercises.export_codeharbor.check.no_exercise')
|
||||
end
|
||||
|
||||
{error: false}.merge(response_hash.slice(:message, :exercise_found, :update_right))
|
||||
{error: false, message: message}.merge(response_hash.slice(:exercise_found, :update_right))
|
||||
rescue Faraday::Error, JSON::ParserError
|
||||
{error: true, message: I18n.t('exercises.export_codeharbor.error')}
|
||||
end
|
||||
|
@ -4,14 +4,10 @@
|
||||
= t('exercises.export_codeharbor.buttons.retry')
|
||||
- else
|
||||
- unless exported
|
||||
- if update_right
|
||||
= button_tag type: 'button', class:'btn btn-primary pull-right export-action export-button', data: {exercise_id: exercise.id, export_type: 'export'} do
|
||||
- if !exercise_found || update_right
|
||||
= button_tag type: 'button', class:'btn btn-primary pull-right export-action export-button', data: {exercise_id: exercise.id} do
|
||||
i.fa.fa-check.confirm-icon
|
||||
= t('exercises.export_codeharbor.buttons.export')
|
||||
- else
|
||||
= button_tag type: 'button', class:'btn btn-primary pull-right export-action export-button', data: {exercise_id: exercise.id, export_type: 'create_new'} do
|
||||
i.fa.fa-check.confirm-icon
|
||||
= t('exercises.export_codeharbor.buttons.create_new')
|
||||
|
||||
= button_tag type: 'submit', class:'btn btn-secondary pull-right export-button', data: {dismiss: 'modal'} do
|
||||
i.fa.fa-remove.abort-icon
|
||||
|
@ -311,10 +311,6 @@ de:
|
||||
editor_file_tree:
|
||||
file_root: Dateien
|
||||
import_codeharbor:
|
||||
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.
|
||||
import_errors:
|
||||
invalid: Fehlerhafte Aufgabe
|
||||
internal_error: Beim Import der Aufgabe ist ein interner Fehler aufgetreten.
|
||||
@ -328,9 +324,12 @@ de:
|
||||
buttons:
|
||||
retry: Erneut probieren
|
||||
export: Export
|
||||
create_new: Neu erstellen
|
||||
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.
|
||||
file_form:
|
||||
hints:
|
||||
feedback_message: Diese Nachricht wird als Tipp zu fehlschlagenden Tests angezeigt.
|
||||
|
@ -311,10 +311,9 @@ en:
|
||||
editor_file_tree:
|
||||
file_root: Files
|
||||
import_codeharbor:
|
||||
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.
|
||||
import_errors:
|
||||
invalid: Invalid exercise
|
||||
internal_error: An internal error occurred on Codeharbor while importing the exercise.
|
||||
export_codeharbor:
|
||||
label: Export to Codeharbor
|
||||
dialogtitle: Export to Codeharbor
|
||||
@ -325,12 +324,12 @@ en:
|
||||
buttons:
|
||||
retry: Retry
|
||||
export: Export
|
||||
create_new: Create new
|
||||
close: Close
|
||||
abort: Abort
|
||||
export_errors:
|
||||
invalid: Invalid exercise
|
||||
internal_error: An internal error occurred on Codeharbor while importing the exercise.
|
||||
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.
|
||||
file_form:
|
||||
hints:
|
||||
feedback_message: This message is used as a hint for failing tests.
|
||||
|
@ -350,7 +350,7 @@ describe ExercisesController do
|
||||
include('button').and(include('Abort')).and(include('Retry'))
|
||||
)
|
||||
expect(JSON.parse(response.body).symbolize_keys[:actions]).to(
|
||||
not_include('Create new').and(not_include('Export')).and(not_include('Hide'))
|
||||
not_include('Export').and(not_include('Hide'))
|
||||
)
|
||||
end
|
||||
end
|
||||
@ -362,7 +362,7 @@ describe ExercisesController do
|
||||
post_request
|
||||
expect(JSON.parse(response.body).symbolize_keys[:message]).to eq('message')
|
||||
expect(JSON.parse(response.body).symbolize_keys[:actions]).to(
|
||||
include('button').and(include('Abort')).and(include('Create new'))
|
||||
include('button').and(include('Abort'))
|
||||
)
|
||||
expect(JSON.parse(response.body).symbolize_keys[:actions]).to(
|
||||
not_include('Retry').and(not_include('Export')).and(not_include('Hide'))
|
||||
@ -375,8 +375,7 @@ describe ExercisesController do
|
||||
render_views
|
||||
|
||||
let!(:codeharbor_link) { FactoryBot.create(:codeharbor_link, user: user) }
|
||||
let(:post_request) { post :export_external_confirm, params: {push_type: push_type, id: exercise.id, codeharbor_link: codeharbor_link.id} }
|
||||
let(:push_type) { 'create_new' }
|
||||
let(:post_request) { post :export_external_confirm, params: {id: exercise.id, codeharbor_link: codeharbor_link.id} }
|
||||
let(:error) {}
|
||||
let(:zip) { 'zip' }
|
||||
|
||||
@ -407,15 +406,6 @@ describe ExercisesController do
|
||||
expect(JSON.parse(response.body).symbolize_keys[:actions]).to(not_include('Abort'))
|
||||
end
|
||||
end
|
||||
|
||||
context 'without push_type' do
|
||||
let(:push_type) {}
|
||||
|
||||
it 'responds with status 500' do
|
||||
post_request
|
||||
expect(response).to have_http_status(:internal_server_error)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#import_uuid_check' do
|
||||
@ -433,7 +423,6 @@ describe ExercisesController do
|
||||
|
||||
expect(JSON.parse(response.body).symbolize_keys[:exercise_found]).to be true
|
||||
expect(JSON.parse(response.body).symbolize_keys[:update_right]).to be true
|
||||
expect(JSON.parse(response.body).symbolize_keys[:message]).to(include('has been found').and(include('Overwrite')))
|
||||
end
|
||||
|
||||
context 'when api_key is incorrect' do
|
||||
@ -445,7 +434,7 @@ describe ExercisesController do
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the user is cannot update the exercise' do
|
||||
context 'when the user cannot update the exercise' do
|
||||
let(:codeharbor_link) { FactoryBot.create(:codeharbor_link, api_key: 'anotherkey') }
|
||||
|
||||
it 'renders correct response' do
|
||||
@ -454,7 +443,6 @@ describe ExercisesController do
|
||||
|
||||
expect(JSON.parse(response.body).symbolize_keys[:exercise_found]).to be true
|
||||
expect(JSON.parse(response.body).symbolize_keys[:update_right]).to be false
|
||||
expect(JSON.parse(response.body).symbolize_keys[:message]).to(include('has been found').and(not_include('Overwrite')))
|
||||
end
|
||||
end
|
||||
|
||||
@ -466,7 +454,6 @@ describe ExercisesController do
|
||||
expect(response).to have_http_status(:success)
|
||||
|
||||
expect(JSON.parse(response.body).symbolize_keys[:exercise_found]).to be false
|
||||
expect(JSON.parse(response.body).symbolize_keys[:message]).to(include('No corresponding exercise'))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -42,17 +42,25 @@ describe ExerciseService::CheckExternal do
|
||||
end
|
||||
|
||||
context 'when response contains a JSON with expected keys' do
|
||||
let(:response) { {message: 'message', exercise_found: true, update_right: true}.to_json }
|
||||
let(:response) { {exercise_found: true, update_right: true}.to_json }
|
||||
|
||||
it 'returns the correct hash' do
|
||||
expect(check_external_service).to eql(error: false, message: 'message', exercise_found: true, update_right: true)
|
||||
expect(check_external_service).to eql(error: false, message: I18n.t('exercises.export_codeharbor.check.exercise_found'), exercise_found: true, update_right: true)
|
||||
end
|
||||
|
||||
context 'with different values' do
|
||||
let(:response) { {message: 'message', exercise_found: false, update_right: false}.to_json }
|
||||
context 'with exercise_found: false and no update_right' do
|
||||
let(:response) { {exercise_found: false}.to_json }
|
||||
|
||||
it 'returns the correct hash' do
|
||||
expect(check_external_service).to eql(error: false, message: 'message', exercise_found: false, update_right: false)
|
||||
expect(check_external_service).to eql(error: false, message: I18n.t('exercises.export_codeharbor.check.no_exercise'), exercise_found: false)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with exercise_found: true and update_right: false' do
|
||||
let(:response) { {exercise_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)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user