add grouped parameter to SubmissionApiController#index
If an assignment is marked to be graded as a group, speedgrader will group the assignments accordingly, but in the API, submissions were being returned individually rather than being grouped. This adds a check for a 'grouped' param in the SubmissionApiController#index action so that a single assignment/submission object is returned per student group. fixes CNVS-23203 Test Plan: 1. Have a course with a few students enrolled 2. Create user groups and put at least two students in one group. 3. Create an assignment set to be graded as a group 4. Have a student from one of the groups submit to the assignment on behalf of the group. 5. With a teacher or admin token, ping the Submissions list API with params grouped = true Verify just a single assignment object is returned Change-Id: I3465b469533d6cff6b3b7c679d8868ceef3dee17 Reviewed-on: https://gerrit.instructure.com/65312 Reviewed-by: Spencer Olson <solson@instructure.com> Tested-by: Jenkins Product-Review: Spencer Olson <solson@instructure.com> QA-Review: Jason Carter <jcarter@instructure.com>
This commit is contained in:
parent
2ecc8d1aea
commit
ffed72a3fb
|
@ -155,6 +155,9 @@ class SubmissionsApiController < ApplicationController
|
|||
# @argument include[] [String, "submission_history"|"submission_comments"|"rubric_assessment"|"assignment"|"visibility"|"course"|"user"]
|
||||
# Associations to include with the group.
|
||||
#
|
||||
# @argument grouped [Boolean]
|
||||
# If this argument is true, the response will be grouped by student groups.
|
||||
#
|
||||
# @response_field assignment_id The unique identifier for the assignment.
|
||||
# @response_field user_id The id of the user who submitted the assignment.
|
||||
# @response_field grader_id The id of the user who graded the assignment.
|
||||
|
@ -177,6 +180,12 @@ class SubmissionsApiController < ApplicationController
|
|||
submissions = @assignment.submissions.where(:user_id => visible_student_ids)
|
||||
includes = Array.wrap(params[:include])
|
||||
|
||||
# this provides one assignment object(and submission object within), per user group
|
||||
if value_to_boolean(params[:grouped])
|
||||
user_groups_ids = @assignment.representatives(@current_user).map(&:id)
|
||||
submissions = Submission.where(user_id: user_groups_ids, assignment_id: @assignment.id)
|
||||
end
|
||||
|
||||
if includes.include?("visibility") && @context.feature_enabled?(:differentiated_assignments)
|
||||
json = bulk_process_submissions_for_visibility(submissions, includes)
|
||||
else
|
||||
|
|
|
@ -3318,4 +3318,57 @@ describe 'Submissions API', type: :request do
|
|||
end
|
||||
end
|
||||
end
|
||||
describe '#index' do
|
||||
context 'grouped_submissions' do
|
||||
let(:test_course) { course() }
|
||||
let(:teacher) { user(active_all: true) }
|
||||
let(:student1) { user(active_all: true) }
|
||||
let(:student2) { user(active_all: true) }
|
||||
let(:group) do
|
||||
group_category = test_course.group_categories.create(name: 'Engineering')
|
||||
test_course.groups.create(name: 'Group1', group_category: group_category)
|
||||
end
|
||||
let(:assignment) do
|
||||
test_course.assignments.create!(
|
||||
title: 'group assignment',
|
||||
grading_type: 'points',
|
||||
points_possible: 10,
|
||||
submission_types: 'online_text_entry',
|
||||
group_category: group.group_category
|
||||
)
|
||||
end
|
||||
|
||||
let!(:enroll_teacher_and_students) do
|
||||
test_course.enroll_teacher(teacher).accept!
|
||||
test_course.enroll_student(student1, enrollment_state: 'active')
|
||||
test_course.enroll_student(student2, enrollment_state: 'active')
|
||||
end
|
||||
let!(:add_students_to_group) do
|
||||
group.add_user(student1)
|
||||
group.add_user(student2)
|
||||
end
|
||||
let!(:submit_homework) { assignment.submit_homework(student1) }
|
||||
|
||||
let(:path) { "/api/v1/courses/#{test_course.id}/assignments/#{assignment.id}/submissions" }
|
||||
let(:params) do
|
||||
{
|
||||
controller: 'submissions_api', action: 'index',
|
||||
format: 'json', course_id: test_course.id.to_s,
|
||||
assignment_id: assignment.id.to_s
|
||||
}
|
||||
end
|
||||
|
||||
it 'should return two assignment and submission objects for a user group' do
|
||||
params[:grouped] = false
|
||||
json = api_call_as_user(teacher, :get, path, params)
|
||||
expect(json.size).to eq 2
|
||||
end
|
||||
|
||||
it 'should return a single assignment and submission object per user group' do
|
||||
params[:grouped] = true
|
||||
json = api_call_as_user(teacher, :get, path, params)
|
||||
expect(json.size).to eq 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue