include needs_grading_count in assignments api json, if authorized
refs #3958 Change-Id: Ia42b08303f62912e6aceb2f07529c561a1bc3686 Reviewed-on: https://gerrit.instructure.com/2862 Reviewed-by: Zach Wily <zach@instructure.com> Tested-by: Hudson <hudson@instructure.com>
This commit is contained in:
parent
e4ab8c85af
commit
ea66fb1881
|
@ -75,7 +75,7 @@ class AssignmentGroupsController < ApplicationController
|
|||
hash = group.as_json(:include_root => false,
|
||||
:only => %w(id name position))
|
||||
if include_assignments
|
||||
hash['assignments'] = group.assignments.active.map { |a| assignment_json(a) }
|
||||
hash['assignments'] = group.assignments.active.map { |a| assignment_json(a, [], @context.user_is_teacher?(@current_user)) }
|
||||
end
|
||||
hash
|
||||
end
|
||||
|
|
|
@ -29,6 +29,7 @@ class AssignmentsApiController < ApplicationController
|
|||
#
|
||||
# @response_field id The unique identifier for the assignment.
|
||||
# @response_field name The name of the assignment.
|
||||
# @response_field needs_grading_count [Integer] If the requesting user has grading rights, the number of submissions that need grading.
|
||||
# @response_field position [Integer] The sorting order of this assignment in
|
||||
# the group.
|
||||
# @response_field points_possible The maximum possible points for the
|
||||
|
@ -104,7 +105,8 @@ class AssignmentsApiController < ApplicationController
|
|||
:include => [:assignment_group, :rubric_association, :rubric],
|
||||
:order => 'assignment_groups.position, assignments.position')
|
||||
|
||||
hashes = @assignments.map { |assignment| assignment_json(assignment) }
|
||||
hashes = @assignments.map { |assignment|
|
||||
assignment_json(assignment, [], @context.user_is_teacher?(@current_user)) }
|
||||
|
||||
render :json => hashes.to_json
|
||||
end
|
||||
|
@ -115,7 +117,7 @@ class AssignmentsApiController < ApplicationController
|
|||
@assignment = @context.active_assignments.find(params[:id],
|
||||
:include => [:assignment_group, :rubric_association, :rubric])
|
||||
|
||||
render :json => assignment_json(@assignment).to_json
|
||||
render :json => assignment_json(@assignment, [], @context.user_is_teacher?(@current_user)).to_json
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -146,7 +148,7 @@ class AssignmentsApiController < ApplicationController
|
|||
end
|
||||
|
||||
if @assignment.save
|
||||
render :json => assignment_json(@assignment).to_json, :status => 201
|
||||
render :json => assignment_json(@assignment, [], @context.user_is_teacher?(@current_user)).to_json, :status => 201
|
||||
else
|
||||
# TODO: we don't really have a strategy in the API yet for returning
|
||||
# errors.
|
||||
|
@ -172,7 +174,7 @@ class AssignmentsApiController < ApplicationController
|
|||
end
|
||||
|
||||
if @assignment.update_attributes(assignment_params)
|
||||
render :json => assignment_json(@assignment).to_json, :status => 201
|
||||
render :json => assignment_json(@assignment, [], @context.user_is_teacher?(@current_user)).to_json, :status => 201
|
||||
else
|
||||
# TODO: we don't really have a strategy in the API yet for returning
|
||||
# errors.
|
||||
|
|
|
@ -17,12 +17,16 @@
|
|||
#
|
||||
|
||||
module Api::V1::Assignment
|
||||
def assignment_json(assignment, includes = [])
|
||||
def assignment_json(assignment, includes = [], show_admin_fields = false)
|
||||
# no includes supported right now
|
||||
hash = assignment.as_json(:include_root => false, :only => %w(id grading_type points_possible position))
|
||||
|
||||
hash['name'] = assignment.title
|
||||
|
||||
if show_admin_fields
|
||||
hash['needs_grading_count'] = assignment.needs_grading_count
|
||||
end
|
||||
|
||||
hash['submission_types'] = assignment.submission_types.split(',')
|
||||
|
||||
if assignment.rubric_association
|
||||
|
|
|
@ -88,6 +88,7 @@ describe AssignmentGroupsController, :type => :integration do
|
|||
'name' => 'test3',
|
||||
'position' => 1,
|
||||
'points_possible' => 8,
|
||||
'needs_grading_count' => 0,
|
||||
"submission_types" => [
|
||||
"none",
|
||||
],
|
||||
|
@ -115,6 +116,7 @@ describe AssignmentGroupsController, :type => :integration do
|
|||
'name' => 'test4',
|
||||
'position' => 2,
|
||||
'points_possible' => 9,
|
||||
'needs_grading_count' => 0,
|
||||
"submission_types" => [
|
||||
"none",
|
||||
],
|
||||
|
@ -132,6 +134,7 @@ describe AssignmentGroupsController, :type => :integration do
|
|||
'name' => 'test1',
|
||||
'position' => 1,
|
||||
'points_possible' => 10,
|
||||
'needs_grading_count' => 0,
|
||||
"submission_types" => [
|
||||
"none",
|
||||
],
|
||||
|
@ -142,6 +145,7 @@ describe AssignmentGroupsController, :type => :integration do
|
|||
'name' => 'test2',
|
||||
'position' => 2,
|
||||
'points_possible' => 12,
|
||||
'needs_grading_count' => 0,
|
||||
"submission_types" => [
|
||||
"none",
|
||||
],
|
||||
|
|
|
@ -78,6 +78,7 @@ describe AssignmentsApiController, :type => :integration do
|
|||
'grading_type' => 'points',
|
||||
'use_rubric_for_grading' => true,
|
||||
'free_form_criterion_comments' => true,
|
||||
'needs_grading_count' => 0,
|
||||
'submission_types' => [
|
||||
"online_upload",
|
||||
"online_text_entry",
|
||||
|
@ -143,6 +144,7 @@ describe AssignmentsApiController, :type => :integration do
|
|||
'position' => 1,
|
||||
'points_possible' => 12,
|
||||
'grading_type' => 'points',
|
||||
'needs_grading_count' => 0,
|
||||
'submission_types' => [
|
||||
'none',
|
||||
],
|
||||
|
@ -178,6 +180,7 @@ describe AssignmentsApiController, :type => :integration do
|
|||
'position' => 1,
|
||||
'points_possible' => 15,
|
||||
'grading_type' => 'points',
|
||||
'needs_grading_count' => 0,
|
||||
'submission_types' => [
|
||||
'none',
|
||||
],
|
||||
|
|
Loading…
Reference in New Issue