Merge branch 'master' into refactor_proforma_import_export

# Conflicts:
#	spec/controllers/exercises_controller_spec.rb
This commit is contained in:
Karol
2022-01-11 22:20:18 +01:00
122 changed files with 1558 additions and 1424 deletions

View File

@ -29,16 +29,17 @@ class CommunitySolutionsController < ApplicationController
if last_contribution.blank?
last_contribution = @community_solution.exercise
new_readme_file = {content: '', file_type: FileType.find_by(file_extension: '.txt'), hidden: false, read_only: false, name: 'ReadMe', role: 'regular_file', context: @community_solution}
@files << CodeOcean::File.create!(new_readme_file)
# If the first user did not save, the ReadMe file already exists
@files << CodeOcean::File.find_or_create_by!(new_readme_file)
end
all_visible_files = last_contribution.files.select(&:visible)
# Add the ReadMe file first
@files += all_visible_files.select {|f| CodeOcean::File.find_by(id: f.file_id).context_type == 'CommunitySolution' }
@files += all_visible_files.select {|f| CodeOcean::File.find_by(id: f.file_id)&.context_type == 'CommunitySolution' }
# Then, add all remaining files and sort them by name with extension
@files += (all_visible_files - @files).sort_by(&:name_with_extension)
@files += (all_visible_files - @files).sort_by(&:filepath)
# Own Submission as a reference
@own_files = @submission.collect_files.select(&:visible).sort_by(&:name_with_extension)
@own_files = @submission.collect_files.select(&:visible).sort_by(&:filepath)
# Remove the file_id from the second graph. Otherwise, the comparison and file-tree selection does not work as expected
@own_files.map do |file|
file.file_id = nil

View File

@ -5,7 +5,7 @@ module RedirectBehavior
def redirect_after_submit
Rails.logger.debug { "Redirecting user with score:s #{@submission.normalized_score}" }
if @submission.normalized_score.to_d == 1.0.to_d
if @submission.normalized_score.to_d == BigDecimal('1.0')
if redirect_to_community_solution?
redirect_to_community_solution
return

View File

@ -4,7 +4,7 @@ class ExecutionEnvironmentsController < ApplicationController
include CommonBehavior
before_action :set_docker_images, only: %i[create edit new update]
before_action :set_execution_environment, only: MEMBER_ACTIONS + %i[execute_command shell statistics]
before_action :set_execution_environment, only: MEMBER_ACTIONS + %i[execute_command shell statistics sync_to_runner_management]
before_action :set_testing_framework_adapters, only: %i[create edit new update]
def authorize!
@ -166,6 +166,20 @@ class ExecutionEnvironmentsController < ApplicationController
update_and_respond(object: @execution_environment, params: execution_environment_params)
end
def sync_to_runner_management
return unless Runner.management_active?
begin
Runner.strategy_class.sync_environment(@execution_environment)
rescue Runner::Error => e
Rails.logger.debug { "Runner error while synchronizing execution environment with id #{@execution_environment.id}: #{e.message}" }
Sentry.capture_exception(e)
redirect_to @execution_environment, alert: t('execution_environments.index.synchronize.failure', error: e.message)
else
redirect_to @execution_environment, notice: t('execution_environments.index.synchronize.success')
end
end
def sync_all_to_runner_management
authorize ExecutionEnvironment
@ -179,6 +193,7 @@ class ExecutionEnvironmentsController < ApplicationController
success << true
rescue Runner::Error => e
Rails.logger.debug { "Runner error while getting all execution environments: #{e.message}" }
Sentry.capture_exception(e)
environments_to_remove = []
success << false
end
@ -189,6 +204,7 @@ class ExecutionEnvironmentsController < ApplicationController
Runner.strategy_class.sync_environment(execution_environment)
rescue Runner::Error => e
Rails.logger.debug { "Runner error while synchronizing execution environment with id #{execution_environment.id}: #{e.message}" }
Sentry.capture_exception(e)
false
end
@ -198,6 +214,7 @@ class ExecutionEnvironmentsController < ApplicationController
Runner.strategy_class.remove_environment(execution_environment)
rescue Runner::Error => e
Rails.logger.debug { "Runner error while deleting execution environment with id #{execution_environment.id}: #{e.message}" }
Sentry.capture_exception(e)
false
end

View File

@ -59,7 +59,7 @@ raise: false
end
def collect_paths(files)
unique_paths = files.map(&:path).reject(&:blank?).uniq
unique_paths = files.map(&:path).compact_blank.uniq
subpaths = unique_paths.map do |path|
Array.new((path.split('/').length + 1)) do |n|
path.split('/').shift(n).join('/')
@ -321,7 +321,7 @@ raise: false
@search = Search.new
@search.exercise = @exercise
@submission = current_user.submissions.where(exercise_id: @exercise.id).order('created_at DESC').first
@files = (@submission ? @submission.collect_files : @exercise.files).select(&:visible).sort_by(&:name_with_extension)
@files = (@submission ? @submission.collect_files : @exercise.files).select(&:visible).sort_by(&:filepath)
@paths = collect_paths(@files)
@user_id = if current_user.respond_to? :external_id

View File

@ -15,8 +15,9 @@ class PingController < ApplicationController
private
def postgres_connected!
# any unhandled exception leads to a HTTP 500 response.
ApplicationRecord.establish_connection
ApplicationRecord.connection
ApplicationRecord.connected?
raise ActiveRecord::ConnectionNotEstablished unless ApplicationRecord.connected?
end
end

View File

@ -24,7 +24,7 @@ class ProxyExercisesController < ApplicationController
def create
myparams = proxy_exercise_params
myparams[:exercises] = Exercise.find(myparams[:exercise_ids].reject(&:empty?))
myparams[:exercises] = Exercise.find(myparams[:exercise_ids].compact_blank)
@proxy_exercise = ProxyExercise.new(myparams)
authorize!
@ -78,7 +78,7 @@ class ProxyExercisesController < ApplicationController
def update
myparams = proxy_exercise_params
myparams[:exercises] = Exercise.find(myparams[:exercise_ids].reject(&:blank?))
myparams[:exercises] = Exercise.find(myparams[:exercise_ids].compact_blank)
update_and_respond(object: @proxy_exercise, params: myparams)
end
end

View File

@ -23,7 +23,7 @@ class StudyGroupsController < ApplicationController
def update
myparams = study_group_params
myparams[:external_users] =
StudyGroupMembership.find(myparams[:study_group_membership_ids].reject(&:empty?)).map(&:user)
StudyGroupMembership.find(myparams[:study_group_membership_ids].compact_blank).map(&:user)
myparams.delete(:study_group_membership_ids)
update_and_respond(object: @study_group, params: myparams)
end

View File

@ -27,12 +27,7 @@ class SubmissionsController < ApplicationController
stringio = Zip::OutputStream.write_buffer do |zio|
@files.each do |file|
zio.put_next_entry(if file.path.to_s == ''
file.name_with_extension
else
File.join(file.path,
file.name_with_extension)
end)
zio.put_next_entry(file.filepath)
zio.write(file.content.presence || file.native_file.read)
end
@ -247,12 +242,9 @@ class SubmissionsController < ApplicationController
# parse remote request url
content += "#{request.base_url}/evaluate\n"
@submission.files.each do |file|
file_path = file.path.to_s == '' ? file.name_with_extension : File.join(file.path, file.name_with_extension)
content += "#{file_path}=#{file.file_id}\n"
end
File.open(path, 'w+') do |f|
f.write(content)
content += "#{file.filepath}=#{file.file_id}\n"
end
File.write(path, content)
path
end
@ -317,7 +309,7 @@ class SubmissionsController < ApplicationController
# @files contains all visible files for the user
# @file contains the specific file requested for run / test / render / ...
set_files
@file = @files.detect {|file| file.name_with_extension == sanitize_filename }
@file = @files.detect {|file| file.filepath == sanitize_filename }
head :not_found unless @file
end

View File

@ -39,7 +39,7 @@ class UserExerciseFeedbacksController < ApplicationController
authorize!
if validate_inputs(uef_params)
path =
if rfc && submission && submission.normalized_score.to_d == 1.0.to_d
if rfc && submission && submission.normalized_score.to_d == BigDecimal('1.0')
request_for_comment_path(rfc)
else
implement_exercise_path(@exercise)
@ -82,7 +82,7 @@ class UserExerciseFeedbacksController < ApplicationController
authorize!
if @exercise && validate_inputs(uef_params)
path =
if rfc && submission && submission.normalized_score.to_d == 1.0.to_d
if rfc && submission && submission.normalized_score.to_d == BigDecimal('1.0')
request_for_comment_path(rfc)
else
implement_exercise_path(@exercise)