Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/api/tutorials_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class TutorialsApi < Grape::API
requires :meeting_location, type: String, desc: 'The tutorials location', allow_blank: false
requires :meeting_day, type: String, desc: 'Day of the tutorial', allow_blank: false
requires :meeting_time, type: String, desc: 'Time of the tutorial', allow_blank: false
optional :tutorial_stream_abbr, type: String, desc: 'Abbreviation of the associated tutorial stream', allow_blank: false
requires :tutorial_stream_abbr, type: String, desc: 'Abbreviation of the associated tutorial stream', allow_blank: false
end
end
post '/tutorials' do
Expand All @@ -83,6 +83,10 @@ class TutorialsApi < Grape::API
tutorial_stream_abbr = tut_params[:tutorial_stream_abbr]
tutorial_stream = unit.tutorial_streams.find_by!(abbreviation: tutorial_stream_abbr) unless tutorial_stream_abbr.nil?

unless tutorial_stream
error!({ error: 'Tutorial must belong to a tutorial stream' }, 403)
end

tutorial = unit.add_tutorial(tut_params[:meeting_day], tut_params[:meeting_time], tut_params[:meeting_location], tutor, campus, tut_params[:capacity], tut_params[:abbreviation], tutorial_stream)

present tutorial, with: Entities::TutorialEntity
Expand Down
5 changes: 4 additions & 1 deletion app/models/overseer_assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class OverseerAssessment < ApplicationRecord
# TODO: we might not have an overseerStepResult because a new test was added later

# Creates an OverseerAssessment object for a new submission
def self.create_for(task, test_submission)
def self.create_for(task, _timestamp, test_submission)
# Create only if:
# unit's assessment is enabled &&
# task's assessment is enabled &&
Expand Down Expand Up @@ -60,6 +60,7 @@ def has_submission_files?
end

def submission_zip_file_name
# /submission_history/{UNIT}/{USERNAME}/done/submission.zip
"#{output_path}/submission.zip"
end

Expand All @@ -77,6 +78,8 @@ def copy_latest_files_to_submission
task.compress_new_to_done zip_file_path: zip_file_path, rm_task_dir: false, rename_files: true
else
puts "Copying done file to submission at: #{zip_file_path}"
# TODO: here is where we might want to refactor submission history - enabling it separate from overseer
# TODO: so if "submission history" is enabled for an upload req,
task.copy_done_to zip_file_path
end
end
Expand Down
61 changes: 61 additions & 0 deletions app/models/submission_history.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
class SubmissionHistory < ApplicationRecord

# TODO: so a submission history is going to be created after AcceptSubmissionJob completes successfully

belongs_to :task, optional: false
has_one :project, through: :task

def self.create_for(task)
task_definition = task.task_definition
unit = task_definition.unit

result = SubmissionHistory.create!(
# task: task,
# status: :pre_queued,
submission_timestamp: Time.now.utc.to_i
)

# Create the submission folder and give access
FileUtils.mkdir_p result.output_path
result.grant_access_to_submission

result.copy_latest_files_to_submission

result
end

def has_submission_files?
File.exist? submission_zip_file_name
end

def submission_zip_file_name
# /submission_history/{UNIT}/{USERNAME}/done/submission.zip
"#{output_path}/submission.zip"
end

def grant_access_to_submission
# TODO: Use FACL instead in future.
`chmod o+w #{output_path}`
end

def copy_latest_files_to_submission
zip_file_path = submission_zip_file_name

if task.has_new_files?
puts "Copying new files to submission at: #{zip_file_path}"
# Generate a zip file for this particular submission with timestamp value and put it here
task.compress_new_to_done zip_file_path: zip_file_path, rm_task_dir: false, rename_files: true
else
puts "Copying done file to submission at: #{zip_file_path}"
# TODO: here is where we might want to refactor submission history - enabling it separate from overseer
# TODO: so if "submission history" is enabled for an upload req,
task.copy_done_to zip_file_path
end
end

# Path to where the submission and output are stored - includes the submission when it is to be processed
def output_path
FileHelper.task_submission_identifier_path_with_timestamp(:done, task, submission_timestamp)
end

end
11 changes: 7 additions & 4 deletions app/sidekiq/accept_submission_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ def perform(task_id, user_id, accepted_tii_eula, test_submission)
task.send_documents_to_tii(user, accepted_tii_eula: accepted_tii_eula)
end

if task.overseer_enabled? || test_submission
overseer_assessment = OverseerAssessment.create_for(task, test_submission)
# Save a snapshot of the submission files to view later
# TODO: enable historu for a task definition? or per upload requirement?
submission_history = SubmissionHistory.create_for(task)

if submission_history.present? && (task.overseer_enabled? || test_submission)
# TODO: pass the submission_history ID or timestamp to overseer, to access the submission_history directory
overseer_assessment = OverseerAssessment.create_for(submission_history.timestamp, task, test_submission)
if overseer_assessment.present?
logger.info "Launching Overseer assessment for task_def_id: #{task.task_definition.id} task_id: #{task.id}"

overseer_assessment.send_to_overseer(test_submission: test_submission)

else
logger.info "Overseer assessment for task_def_id: #{task.task_definition.id} task_id: #{task.id} was not performed #{overseer_assessment.inspect}"
end
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20260227012857_create_submission_histories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateSubmissionHistories < ActiveRecord::Migration[8.0]
def change
create_table :submission_histories do |t|
t.references :task
t.integer :submission_timestamp
t.timestamps
end
end
end
Loading
Loading