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
|
||||
|
Reference in New Issue
Block a user