Editor: Allow file retrieval after code run

This commit is contained in:
Sebastian Serth
2022-10-04 15:17:16 +02:00
committed by Sebastian Serth
parent fb9672c7a4
commit 60078701f5
22 changed files with 311 additions and 8 deletions

View File

@ -18,6 +18,8 @@ module CodeOcean
before_validation :set_ancestor_values, if: :incomplete_descendent?
attr_writer :size
# These attributes are mainly used when retrieving files from a runner
attr_accessor :download_path
belongs_to :context, polymorphic: true
belongs_to :file, class_name: 'CodeOcean::File', optional: true # This is only required for submissions and is validated below
@ -100,6 +102,14 @@ module CodeOcean
end
end
def filepath_without_extension
if path.present?
::File.join(path, name)
else
name
end
end
def hash_content
self.hashed_content = Digest::MD5.new.hexdigest(read || '')
end
@ -114,6 +124,10 @@ module CodeOcean
name.to_s + (file_type&.file_extension || '')
end
def name_with_extension_and_size
"#{name_with_extension} (#{ActionController::Base.helpers.number_to_human_size(size)})"
end
def set_ancestor_values
%i[feedback_message file_type_id hidden name path read_only role weight].each do |attribute|
send(:"#{attribute}=", ancestor.send(attribute))