add endpoint to check for exercise uuid
This commit is contained in:
@ -12,9 +12,9 @@ class ExercisesController < ApplicationController
|
||||
before_action :set_file_types, only: [:create, :edit, :new, :update]
|
||||
before_action :set_course_token, only: [:implement]
|
||||
|
||||
skip_before_action :verify_authenticity_token, only: [:import_proforma_xml]
|
||||
skip_after_action :verify_authorized, only: [:import_proforma_xml]
|
||||
skip_after_action :verify_policy_scoped, only: [:import_proforma_xml], raise: false
|
||||
skip_before_action :verify_authenticity_token, only: [:import_proforma_xml, :import_uuid_check]
|
||||
skip_after_action :verify_authorized, only: [:import_proforma_xml, :import_uuid_check]
|
||||
skip_after_action :verify_policy_scoped, only: [:import_proforma_xml, :import_uuid_check], raise: false
|
||||
|
||||
def authorize!
|
||||
authorize(@exercise || @exercises)
|
||||
@ -119,6 +119,15 @@ class ExercisesController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def import_uuid_check
|
||||
uuid = params[:uuid]
|
||||
exercise = Exercise.find_by(uuid: uuid)
|
||||
|
||||
return render json: {exercise_found: false, message: 'no_exercise'} if exercise.nil?
|
||||
|
||||
render json: {exercise_found: true, message: 'exercise found, be careful when overwriting or else!'}
|
||||
end
|
||||
|
||||
def import_proforma_xml
|
||||
tempfile = Tempfile.new('codeharbor_import.zip')
|
||||
tempfile.write request.body.read.force_encoding('UTF-8')
|
||||
|
@ -67,6 +67,7 @@ Rails.application.routes.draw do
|
||||
end
|
||||
|
||||
post '/import_proforma_xml' => 'exercises#import_proforma_xml'
|
||||
post '/import_uuid_check' => 'exercises#import_uuid_check'
|
||||
|
||||
resources :exercises do
|
||||
collection do
|
||||
|
Reference in New Issue
Block a user