Allow viewing submissions without corresponding exercise

Fixes CODEOCEAN-S7
This commit is contained in:
Sebastian Serth
2023-11-06 00:24:51 +01:00
parent 920f2dcb38
commit 4537f2bf75
2 changed files with 3 additions and 3 deletions

View File

@ -57,7 +57,7 @@ class Submission < ApplicationRecord
def collect_files
@collect_files ||= begin
ancestors = build_files_hash(exercise.files.includes(:file_type), :id)
ancestors = build_files_hash(exercise&.files&.includes(:file_type), :id)
descendants = build_files_hash(files.includes(:file_type), :file_id)
ancestors.merge(descendants).values
end
@ -209,7 +209,7 @@ class Submission < ApplicationRecord
private
def build_files_hash(files, attribute)
files.map(&attribute.to_proc).zip(files).to_h
files&.map(&attribute.to_proc)&.zip(files)&.to_h || {}
end
def prepared_runner

View File

@ -7,7 +7,7 @@
h1 = @submission
= row(label: 'submission.exercise', value: link_to_if(policy(@submission.exercise).show?, @submission.exercise, @submission.exercise))
= row(label: 'submission.exercise', value: link_to_if(@submission.exercise && policy(@submission.exercise).show?, @submission.exercise, @submission.exercise))
= row(label: 'submission.contributor', value: link_to_if(policy(@submission.contributor).show?, @submission.contributor, @submission.contributor))
= row(label: 'submission.study_group', value: link_to_if(@submission.study_group.present? && policy(@submission.study_group).show?, @submission.study_group, @submission.study_group))
= row(label: 'submission.cause', value: t("submissions.causes.#{@submission.cause}"))