From 49d438cef8ed7ad0c1119f70414dd5019b7fdfff Mon Sep 17 00:00:00 2001 From: Karol Date: Tue, 24 Sep 2019 18:43:38 +0200 Subject: [PATCH] add endpoint to check for exercise uuid --- app/controllers/exercises_controller.rb | 15 ++++++++++++--- config/routes.rb | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 9e1c057d..750028c0 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -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') diff --git a/config/routes.rb b/config/routes.rb index 9277c4f0..52d33d3c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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