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/overseer_steps_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,12 @@ class OverseerStepsApi < Grape::API
end

unit = project.unit
task_definition = unit.task_definitions.find(params[:task_def_id])
task = project.task_for_task_definition(task_definition)

overseer_assessment = OverseerAssessment.find(params[:id])
overseer_assessment = OverseerAssessment
.where(submission_history_id: task.related_submission_histories.select(:id))
.find(params[:id])
present overseer_assessment.overseer_step_results, with: Entities::OverseerStepResultEntity, my_role: unit.role_for(current_user)
end
end
14 changes: 9 additions & 5 deletions app/api/submission/portfolio_evidence_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ def self.logger
error!({ error: "A submission for this task definition have never been created" }, 401)
end

result = OverseerAssessment.where(task_id: task.id).order(submission_timestamp: :desc).limit(10)
result = OverseerAssessment.where(submission_history_id: task.related_submission_histories.select(:id))
.order(submission_timestamp: :desc)
.limit(10)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

limit 10?

present result, with: Entities::OverseerAssessmentEntity
end

Expand All @@ -199,7 +201,7 @@ def self.logger
error!({ error: 'A submission for this task definition has never been created' }, 404)
end

present task.submission_histories.order(submission_timestamp: :desc),
present task.related_submission_histories.order(submission_timestamp: :desc),
with: Entities::SubmissionHistoryEntity
end

Expand All @@ -213,7 +215,7 @@ def self.logger
end

task = project.task_for_task_definition(task_definition)
history = task&.submission_histories&.find_by(id: params[:history_id])
history = task&.related_submission_histories&.find_by(id: params[:history_id])
error!({ error: 'Submission history was not found' }, 404) unless history
error!({ error: 'Submission history files are not available' }, 404) unless history.has_submission_files?

Expand Down Expand Up @@ -244,7 +246,9 @@ def self.logger

oa_id = timestamp = params[:oa_id]

oa = task.overseer_assessments.find(oa_id)
oa = OverseerAssessment
.where(submission_history_id: task.related_submission_histories.select(:id))
.find(oa_id)
response = oa.send_to_overseer
if response[:error].present?
error!({ error: response[:error] }, 403)
Expand Down Expand Up @@ -325,7 +329,7 @@ def self.logger
error!({ error: 'A submission for this task definition have never been created' }, 401)
end

history = task.submission_histories.find_by(submission_timestamp: params[:timestamp])
history = task.related_submission_histories.find_by(submission_timestamp: params[:timestamp])
unless history
error!({ error: "No submission history found for timestamp '#{params[:timestamp]}'" }, 404)
end
Expand Down
6 changes: 6 additions & 0 deletions app/models/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,12 @@ def group_task?
!group_submission.nil? || !task_definition.group_set.nil?
end

def related_submission_histories
return submission_histories unless group_submission

SubmissionHistory.where(task_id: group_submission.tasks.select(:id))
end

def active_overflow_task_claim
claim = overflow_task_claim
return nil unless claim
Expand Down
62 changes: 62 additions & 0 deletions test/api/submission_history_api_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require 'test_helper'

class SubmissionHistoryApiTest < ActiveSupport::TestCase
include Rack::Test::Methods
include TestHelpers::AuthHelper
include TestHelpers::JsonHelper

def app
Rails.application
end

def test_group_member_can_view_submission_history_and_overseer_assessment
setup_group_submission
history = FactoryBot.create(:submission_history, task: @tasks.first.reload)
assessment = FactoryBot.create(
:overseer_assessment,
task: @tasks.first,
submission_history: history,
submission_timestamp: history.submission_timestamp
)
add_auth_header_for(user: @projects.second.student)

get submission_histories_path(@projects.second)

assert_equal 200, last_response.status, last_response.body
assert_equal [history.id], last_response_body.pluck('id')

get overseer_assessments_path(@projects.second)

assert_equal 200, last_response.status, last_response.body
assert_equal [assessment.id], last_response_body.pluck('id')
end

private

def setup_group_submission
unit = FactoryBot.create(:unit, student_count: 3, task_count: 1)
@projects = unit.active_projects.first(3)
@task_definition = unit.task_definitions.first
group_set = FactoryBot.create(:group_set, unit: unit)
@task_definition.update!(group_set: group_set)
@group = FactoryBot.create(:group, group_set: group_set, tutorial: unit.tutorials.first)
@tasks = @projects.first(2).map do |project|
@group.add_member(project)
project.task_for_task_definition(@task_definition)
end
@group.create_submission(
@tasks.first,
'Group submission',
@tasks.map { |task| { project: task.project, pct: 50, pts: 3 } }
)
@tasks
end

def submission_histories_path(project)
"/api/projects/#{project.id}/task_def_id/#{@task_definition.id}/submission_histories"
end

def overseer_assessments_path(project)
"/api/projects/#{project.id}/task_def_id/#{@task_definition.id}/submissions/timestamps"
end
end
Loading