add uuid check
This commit is contained in:
1
Gemfile
1
Gemfile
@ -36,6 +36,7 @@ gem 'webpacker'
|
||||
gem 'rest-client'
|
||||
gem 'rubyzip'
|
||||
gem 'mnemosyne-ruby'
|
||||
gem 'faraday'
|
||||
gem 'proforma', git: 'git://github.com/openHPI/proforma.git' # use version not master
|
||||
gem 'whenever', require: false
|
||||
gem 'rails-timeago'
|
||||
|
@ -426,6 +426,7 @@ DEPENDENCIES
|
||||
docker-api
|
||||
eventmachine (= 1.0.9.1)
|
||||
factory_bot_rails
|
||||
faraday
|
||||
faye-websocket
|
||||
forgery
|
||||
headless
|
||||
|
@ -238,6 +238,48 @@ $(document).on('turbolinks:load', function() {
|
||||
|
||||
};
|
||||
|
||||
var observeExportStartButtons = function(){
|
||||
$('.export-start').on('click', function(e){
|
||||
e.preventDefault();
|
||||
$('#export-modal').modal({
|
||||
height: 250
|
||||
});
|
||||
$('#export-modal').modal('show');
|
||||
exportExerciseStart($(this).attr('data-exercise-id'));
|
||||
});
|
||||
}
|
||||
|
||||
var exportExerciseStart = function(exerciseID) {
|
||||
var $exerciseDiv = $('#export-exercise');
|
||||
// var accountLinkID = $exerciseDiv.attr('data-account-link');
|
||||
var $messageDiv = $exerciseDiv.children('.export-message');
|
||||
var $actionsDiv = $exerciseDiv.children('.export-exercise-actions');
|
||||
|
||||
$messageDiv.html('requesting status');
|
||||
$actionsDiv.html('spinning');
|
||||
|
||||
return $.ajax({
|
||||
type: 'POST',
|
||||
url: '/exercises/' + exerciseID + '/export_external_check',
|
||||
// data: {
|
||||
// account_link: accountLinkID
|
||||
// },
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
if (response.error) {
|
||||
$messageDiv.html(response.error);
|
||||
$actionsDiv.html('Retry?');
|
||||
}
|
||||
$messageDiv.html(response.message);
|
||||
return $actionsDiv.html(response.actions);
|
||||
},
|
||||
error: function(a, b, c) {
|
||||
return alert('error:' + c);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
var overrideTextareaTabBehavior = function() {
|
||||
$('.form-group textarea[name$="[content]"]').on('keydown', function(event) {
|
||||
if (event.which === TAB_KEY_CODE) {
|
||||
@ -293,6 +335,7 @@ $(document).on('turbolinks:load', function() {
|
||||
// ignore tags table since it is in the dom before other tables
|
||||
if ($('table:not(#tags-table)').isPresent()) {
|
||||
enableBatchUpdate();
|
||||
observeExportStartButtons();
|
||||
} else if ($('.edit_exercise, .new_exercise').isPresent()) {
|
||||
execution_environments = $('form').data('execution-environments');
|
||||
file_types = $('form').data('file-types');
|
||||
@ -303,6 +346,7 @@ $(document).on('turbolinks:load', function() {
|
||||
observeExecutionEnvironment();
|
||||
observeUnpublishedState();
|
||||
overrideTextareaTabBehavior();
|
||||
|
||||
} else if ($('#files.jstree').isPresent()) {
|
||||
var fileTypeSelect = $('#code_ocean_file_file_type_id');
|
||||
fileTypeSelect.on("change", function() {updateFileTemplates(fileTypeSelect.val())});
|
||||
|
@ -176,3 +176,30 @@ a.file-heading {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#export-modal {
|
||||
.modal-content {
|
||||
min-height: unset;
|
||||
height: 300px;
|
||||
}
|
||||
}
|
||||
|
||||
#export-exercise{
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.export-message {
|
||||
flex-grow: 1;
|
||||
font-size: 12px;
|
||||
padding-right: 5px;
|
||||
}
|
||||
|
||||
.export-exercise-actions {
|
||||
max-width: 110px;
|
||||
min-width: 110px;
|
||||
}
|
||||
|
||||
.export-button {
|
||||
font-size: 12px;
|
||||
width: 100%;
|
||||
}
|
||||
|
@ -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?
|
||||
|
@ -7,7 +7,7 @@ class ExercisePolicy < AdminOrAuthorPolicy
|
||||
define_method(action) { admin? || teacher? }
|
||||
end
|
||||
|
||||
[:clone?, :destroy?, :edit?, :statistics?, :update?, :feedback?, :push_proforma_xml?].each do |action|
|
||||
[:clone?, :destroy?, :edit?, :statistics?, :update?, :feedback?, :push_proforma_xml?, :export_external_check?].each do |action|
|
||||
define_method(action) { admin? || author? }
|
||||
end
|
||||
|
||||
|
20
app/views/exercises/_export_actions.html.slim
Normal file
20
app/views/exercises/_export_actions.html.slim
Normal file
@ -0,0 +1,20 @@
|
||||
- if error
|
||||
= button_tag type: 'button', class:'btn btn-primary pull-right export-button', onclick: "exportExerciseStart(#{exercise.id})" do
|
||||
i.fa.fa-refresh.confirm-icon
|
||||
= ' Retry'
|
||||
- else
|
||||
- if exercise_found
|
||||
- if update_right
|
||||
= button_tag type: 'button', class:'btn btn-primary pull-right export-action export-button', data: {'export-type' => 'export'} do
|
||||
i.fa.fa-check.confirm-icon
|
||||
= ' Overwrite'
|
||||
= button_tag type: 'button', class:'btn btn-primary pull-right export-action export-button', data: {'export-type' => 'create_new'} do
|
||||
i.fa.fa-check.confirm-icon-alt
|
||||
= ' Create new'
|
||||
- else
|
||||
= button_tag type: 'button', class:'btn btn-primary pull-right export-action export-button', data: {'export-type' => 'export'} do
|
||||
i.fa.fa-check.confirm-icon
|
||||
= ' Export'
|
||||
= button_tag type: 'submit', class:'btn btn-secondary pull-right export-button', data: {dismiss: 'modal'} do
|
||||
i.fa.fa-remove.abort-icon
|
||||
= ' Abort'
|
5
app/views/exercises/_export_dialogcontent.html.slim
Normal file
5
app/views/exercises/_export_dialogcontent.html.slim
Normal file
@ -0,0 +1,5 @@
|
||||
#export-exercise
|
||||
.export-message
|
||||
= 'This should not be seen'
|
||||
.export-exercise-actions
|
||||
= 'This neither'
|
@ -46,7 +46,9 @@ h1 = Exercise.model_name.human(count: 2)
|
||||
li = link_to(t('activerecord.models.user_exercise_feedback.other'), feedback_exercise_path(exercise), class: 'dropdown-item') if policy(exercise).feedback?
|
||||
li = link_to(t('shared.destroy'), exercise, data: {confirm: t('shared.confirm_destroy')}, method: :delete, class: 'dropdown-item') if policy(exercise).destroy?
|
||||
li = link_to(t('.clone'), clone_exercise_path(exercise), data: {confirm: t('shared.confirm_destroy')}, method: :post, class: 'dropdown-item') if policy(exercise).clone?
|
||||
li = link_to(t('exercises.export_codeharbor.label'), push_proforma_xml_exercise_path(exercise), method: :post, class: 'dropdown-item') if policy(exercise).push_proforma_xml?
|
||||
li = link_to(t('exercises.export_codeharbor.label'), '', class: 'dropdown-item export-start', data: {'exercise-id' => exercise.id}) if policy(exercise).push_proforma_xml?
|
||||
|
||||
= render('shared/pagination', collection: @exercises)
|
||||
p = render('shared/new_button', model: Exercise)
|
||||
|
||||
= render('shared/modal', id: 'export-modal', title: t('exercises.export_codeharbor.dialogtitle'), template: 'exercises/_export_dialogcontent')
|
||||
|
@ -326,6 +326,7 @@ en:
|
||||
fail: Failed to push the exercise to CodeHarbor.
|
||||
label: Export to Codeharbor
|
||||
success: Successfully pushed the exercise to CodeHarbor.
|
||||
dialogtitle: Export to Codeharbor
|
||||
file_form:
|
||||
hints:
|
||||
feedback_message: This message is used as a hint for failing tests.
|
||||
|
@ -82,10 +82,11 @@ Rails.application.routes.draw do
|
||||
post :search
|
||||
get :statistics
|
||||
get :feedback
|
||||
post :push_proforma_xml
|
||||
get :reload
|
||||
post :submit
|
||||
get 'study_group_dashboard/:study_group_id', to: 'exercises#study_group_dashboard'
|
||||
post :push_proforma_xml
|
||||
post :export_external_check
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1,7 +0,0 @@
|
||||
class AddPushUrlClientIdClientSecretToCodeharborLinks < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :codeharbor_links, :push_url, :string
|
||||
add_column :codeharbor_links, :client_id, :string
|
||||
add_column :codeharbor_links, :client_secret, :string
|
||||
end
|
||||
end
|
@ -0,0 +1,6 @@
|
||||
class AddPushUrlRenameOauth2tokenInCodeharborLinks < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :codeharbor_links, :push_url, :string
|
||||
rename_column :codeharbor_links, :oauth2token, :api_key
|
||||
end
|
||||
end
|
@ -29,13 +29,11 @@ ActiveRecord::Schema.define(version: 2019_10_08_163045) do
|
||||
end
|
||||
|
||||
create_table "codeharbor_links", force: :cascade do |t|
|
||||
t.string "oauth2token", limit: 255
|
||||
t.string "api_key", limit: 255
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "user_id"
|
||||
t.string "push_url"
|
||||
t.string "client_id"
|
||||
t.string "client_secret"
|
||||
t.index ["user_id"], name: "index_codeharbor_links_on_user_id"
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user