add uuid check

This commit is contained in:
Karol
2019-10-16 19:19:28 +02:00
parent 9c009ee4ec
commit 4ab78c170e
14 changed files with 155 additions and 14 deletions

View File

@ -7,7 +7,7 @@ class ExercisesController < ApplicationController
before_action :handle_file_uploads, only: [:create, :update]
before_action :set_execution_environments, only: [:create, :edit, :new, :update]
before_action :set_exercise_and_authorize, only: MEMBER_ACTIONS + [:push_proforma_xml, :clone, :implement, :working_times, :intervention, :search, :run, :statistics, :submit, :reload, :feedback, :study_group_dashboard]
before_action :set_exercise_and_authorize, only: MEMBER_ACTIONS + [:push_proforma_xml, :clone, :implement, :working_times, :intervention, :search, :run, :statistics, :submit, :reload, :feedback, :study_group_dashboard, :export_external_check]
before_action :set_external_user_and_authorize, only: [:statistics]
before_action :set_file_types, only: [:create, :edit, :new, :update]
before_action :set_course_token, only: [:implement]
@ -119,6 +119,48 @@ class ExercisesController < ApplicationController
end
end
def export_external_check
@codeharbor_link = current_user.codeharbor_link
url = 'http://localhost:3001/import_uuid_check'
conn = Faraday.new(url: url) do |faraday|
faraday.options[:open_timeout] = 5
faraday.options[:timeout] = 5
faraday.adapter Faraday.default_adapter
end
error = false
response_hash = {}
message = ''
begin
response = conn.post do |req|
req.headers['Content-Type'] = 'application/json'
req.headers['Authorization'] = 'Bearer ' + @codeharbor_link.api_key
req.body = {uuid: @exercise.uuid}.to_json
end
response_hash = JSON.parse(response.body, symbolize_names: true)
message = response_hash[:message]
rescue Faraday::ClientError
message = 'an error occured'
error = true
end
render json: {
message: message,
actions: render_to_string(
partial: 'export_actions',
locals: {
exercise: @exercise,
exercise_found: response_hash[:exercise_found],
update_right: response_hash[:update_right],
error: error
}
)
}, status: 200
end
def import_uuid_check
user = user_for_oauth2_request
return render json: {}, status: 401 if user.nil?