Use file name with file path as identifier
This commit is contained in:
@ -36,10 +36,10 @@ class CommunitySolutionsController < ApplicationController
|
|||||||
# Add the ReadMe file first
|
# 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
|
# 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 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
|
# 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|
|
@own_files.map do |file|
|
||||||
file.file_id = nil
|
file.file_id = nil
|
||||||
|
@ -321,7 +321,7 @@ raise: false
|
|||||||
@search = Search.new
|
@search = Search.new
|
||||||
@search.exercise = @exercise
|
@search.exercise = @exercise
|
||||||
@submission = current_user.submissions.where(exercise_id: @exercise.id).order('created_at DESC').first
|
@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)
|
@paths = collect_paths(@files)
|
||||||
|
|
||||||
@user_id = if current_user.respond_to? :external_id
|
@user_id = if current_user.respond_to? :external_id
|
||||||
|
@ -27,12 +27,7 @@ class SubmissionsController < ApplicationController
|
|||||||
|
|
||||||
stringio = Zip::OutputStream.write_buffer do |zio|
|
stringio = Zip::OutputStream.write_buffer do |zio|
|
||||||
@files.each do |file|
|
@files.each do |file|
|
||||||
zio.put_next_entry(if file.path.to_s == ''
|
zio.put_next_entry(file.filepath)
|
||||||
file.name_with_extension
|
|
||||||
else
|
|
||||||
File.join(file.path,
|
|
||||||
file.name_with_extension)
|
|
||||||
end)
|
|
||||||
zio.write(file.content.presence || file.native_file.read)
|
zio.write(file.content.presence || file.native_file.read)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -247,8 +242,7 @@ class SubmissionsController < ApplicationController
|
|||||||
# parse remote request url
|
# parse remote request url
|
||||||
content += "#{request.base_url}/evaluate\n"
|
content += "#{request.base_url}/evaluate\n"
|
||||||
@submission.files.each do |file|
|
@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.filepath}=#{file.file_id}\n"
|
||||||
content += "#{file_path}=#{file.file_id}\n"
|
|
||||||
end
|
end
|
||||||
File.open(path, 'w+') do |f|
|
File.open(path, 'w+') do |f|
|
||||||
f.write(content)
|
f.write(content)
|
||||||
@ -317,7 +311,7 @@ class SubmissionsController < ApplicationController
|
|||||||
# @files contains all visible files for the user
|
# @files contains all visible files for the user
|
||||||
# @file contains the specific file requested for run / test / render / ...
|
# @file contains the specific file requested for run / test / render / ...
|
||||||
set_files
|
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
|
head :not_found unless @file
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ module CodeOcean
|
|||||||
private :incomplete_descendent?
|
private :incomplete_descendent?
|
||||||
|
|
||||||
def name_with_extension
|
def name_with_extension
|
||||||
name + (file_type.file_extension || '')
|
name.to_s + (file_type&.file_extension || '')
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_ancestor_values
|
def set_ancestor_values
|
||||||
|
@ -160,7 +160,7 @@ class Submission < ApplicationRecord
|
|||||||
# @raise [Runner::Error] if the code could not be run due to a failure with the runner.
|
# @raise [Runner::Error] if the code could not be run due to a failure with the runner.
|
||||||
# See the specific type and message for more details.
|
# See the specific type and message for more details.
|
||||||
def run(file, &block)
|
def run(file, &block)
|
||||||
run_command = command_for execution_environment.run_command, file.name_with_extension
|
run_command = command_for execution_environment.run_command, file.filepath
|
||||||
durations = {}
|
durations = {}
|
||||||
prepared_runner do |runner, waiting_duration|
|
prepared_runner do |runner, waiting_duration|
|
||||||
durations[:execution_duration] = runner.attach_to_execution(run_command, &block)
|
durations[:execution_duration] = runner.attach_to_execution(run_command, &block)
|
||||||
@ -185,7 +185,7 @@ class Submission < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def run_test_file(file, runner, waiting_duration)
|
def run_test_file(file, runner, waiting_duration)
|
||||||
test_command = command_for execution_environment.test_command, file.name_with_extension
|
test_command = command_for execution_environment.test_command, file.filepath
|
||||||
result = {file_role: file.role, waiting_for_container_time: waiting_duration}
|
result = {file_role: file.role, waiting_for_container_time: waiting_duration}
|
||||||
output = runner.execute_command(test_command, raise_exception: false)
|
output = runner.execute_command(test_command, raise_exception: false)
|
||||||
result.merge(output)
|
result.merge(output)
|
||||||
@ -222,7 +222,7 @@ class Submission < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def command_for(template, file)
|
def command_for(template, file)
|
||||||
filepath = collect_files.find {|f| f.name_with_extension == file }.filepath
|
filepath = collect_files.find {|f| f.filepath == file }.filepath
|
||||||
template % command_substitutions(filepath)
|
template % command_substitutions(filepath)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -255,7 +255,7 @@ class Submission < ApplicationRecord
|
|||||||
waiting_for_container_time: output[:waiting_for_container_time]
|
waiting_for_container_time: output[:waiting_for_container_time]
|
||||||
)
|
)
|
||||||
|
|
||||||
filename = file.name_with_extension
|
filename = file.filepath
|
||||||
|
|
||||||
if file.teacher_defined_linter?
|
if file.teacher_defined_linter?
|
||||||
LinterCheckRun.create_from(testrun, assessment)
|
LinterCheckRun.create_from(testrun, assessment)
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
json.extract! @file, :id, :name_with_extension
|
json.extract! @file, :id, :filepath
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
div class=(defined?(own_solution) ? "own-frame" : "frame") data-executable=file.file_type.executable? data-filename=file.name_with_extension data-renderable=file.file_type.renderable? data-role=file.role data-binary=file.file_type.binary? data-context-type=file.context_type data-read-only=file.read_only
|
div class=(defined?(own_solution) ? "own-frame" : "frame") data-executable=file.file_type.executable? data-filename=file.filepath data-renderable=file.file_type.renderable? data-role=file.role data-binary=file.file_type.binary? data-context-type=file.context_type data-read-only=file.read_only
|
||||||
- if file.file_type.binary?
|
- if file.file_type.binary?
|
||||||
.binary-file data-file-id=file.ancestor_id
|
.binary-file data-file-id=file.ancestor_id
|
||||||
- if file.file_type.renderable?
|
- if file.file_type.renderable?
|
||||||
|
@ -7,10 +7,7 @@ li.card.mt-2
|
|||||||
a class=['file-heading', collapsed_class] data-toggle="collapse" href="#collapse#{f.index}" aria-expanded="#{aria_expanded}"
|
a class=['file-heading', collapsed_class] data-toggle="collapse" href="#collapse#{f.index}" aria-expanded="#{aria_expanded}"
|
||||||
div.clearfix role="button"
|
div.clearfix role="button"
|
||||||
i class="fa" aria-hidden="true"
|
i class="fa" aria-hidden="true"
|
||||||
- if f.object.name.present? && f.object.file_type.present?
|
span = f.object.filepath
|
||||||
span = f.object.name_with_extension
|
|
||||||
- else
|
|
||||||
span = f.object.name
|
|
||||||
.card-collapse.collapse class=('in' if f.object.name.nil?) id="collapse#{f.index}" role="tabpanel"
|
.card-collapse.collapse class=('in' if f.object.name.nil?) id="collapse#{f.index}" role="tabpanel"
|
||||||
.card-body
|
.card-body
|
||||||
- if policy(f.object).destroy? && id.present?
|
- if policy(f.object).destroy? && id.present?
|
||||||
|
@ -65,9 +65,9 @@ h1
|
|||||||
td.align-middle
|
td.align-middle
|
||||||
-this.testruns.includes(:file).order("files.name").each do |run|
|
-this.testruns.includes(:file).order("files.name").each do |run|
|
||||||
- if run.passed
|
- if run.passed
|
||||||
.unit-test-result.positive-result title=[run.file&.name_with_extension, run.output].join("\n").strip
|
.unit-test-result.positive-result title=[run.file&.filepath, run.output].join("\n").strip
|
||||||
- else
|
- else
|
||||||
.unit-test-result.unknown-result title=[run.file&.name_with_extension, run.output].join("\n").strip
|
.unit-test-result.unknown-result title=[run.file&.filepath, run.output].join("\n").strip
|
||||||
td = @working_times_until[index] if index > 0 if policy(@exercise).detailed_statistics?
|
td = @working_times_until[index] if index > 0 if policy(@exercise).detailed_statistics?
|
||||||
- elsif this.is_a? UserExerciseIntervention
|
- elsif this.is_a? UserExerciseIntervention
|
||||||
td = this.created_at.strftime("%F %T")
|
td = this.created_at.strftime("%F %T")
|
||||||
|
@ -49,7 +49,7 @@ ul.list-unstyled#files
|
|||||||
a.file-heading.collapsed data-toggle="collapse" data-parent="#files" href=".collapse#{file.id}"
|
a.file-heading.collapsed data-toggle="collapse" data-parent="#files" href=".collapse#{file.id}"
|
||||||
div.clearfix role="button"
|
div.clearfix role="button"
|
||||||
i class="fa" aria-hidden="true"
|
i class="fa" aria-hidden="true"
|
||||||
span = file.name_with_extension
|
span = file.filepath
|
||||||
.card-collapse.collapse class="collapse#{file.id}" role="tabpanel"
|
.card-collapse.collapse class="collapse#{file.id}" role="tabpanel"
|
||||||
.card-body
|
.card-body
|
||||||
- if policy(file).destroy?
|
- if policy(file).destroy?
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
FILENAME_REGEXP = /[\w.]+/.freeze unless Kernel.const_defined?(:FILENAME_REGEXP)
|
FILENAME_REGEXP = %r{[\w./]+}.freeze unless Kernel.const_defined?(:FILENAME_REGEXP)
|
||||||
|
|
||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
resources :community_solutions, only: %i[index edit update]
|
resources :community_solutions, only: %i[index edit update]
|
||||||
|
Reference in New Issue
Block a user