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:
Brian Palmer 2011-03-29 14:38:53 -06:00
parent e4ab8c85af
commit ea66fb1881
5 changed files with 19 additions and 6 deletions

View File

@ -75,7 +75,7 @@ class AssignmentGroupsController < ApplicationController
hash = group.as_json(:include_root => false, hash = group.as_json(:include_root => false,
:only => %w(id name position)) :only => %w(id name position))
if include_assignments 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 end
hash hash
end end

View File

@ -29,6 +29,7 @@ class AssignmentsApiController < ApplicationController
# #
# @response_field id The unique identifier for the assignment. # @response_field id The unique identifier for the assignment.
# @response_field name The name of 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 # @response_field position [Integer] The sorting order of this assignment in
# the group. # the group.
# @response_field points_possible The maximum possible points for the # @response_field points_possible The maximum possible points for the
@ -104,7 +105,8 @@ class AssignmentsApiController < ApplicationController
:include => [:assignment_group, :rubric_association, :rubric], :include => [:assignment_group, :rubric_association, :rubric],
:order => 'assignment_groups.position, assignments.position') :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 render :json => hashes.to_json
end end
@ -115,7 +117,7 @@ class AssignmentsApiController < ApplicationController
@assignment = @context.active_assignments.find(params[:id], @assignment = @context.active_assignments.find(params[:id],
:include => [:assignment_group, :rubric_association, :rubric]) :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
end end
@ -146,7 +148,7 @@ class AssignmentsApiController < ApplicationController
end end
if @assignment.save 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 else
# TODO: we don't really have a strategy in the API yet for returning # TODO: we don't really have a strategy in the API yet for returning
# errors. # errors.
@ -172,7 +174,7 @@ class AssignmentsApiController < ApplicationController
end end
if @assignment.update_attributes(assignment_params) 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 else
# TODO: we don't really have a strategy in the API yet for returning # TODO: we don't really have a strategy in the API yet for returning
# errors. # errors.

View File

@ -17,12 +17,16 @@
# #
module Api::V1::Assignment module Api::V1::Assignment
def assignment_json(assignment, includes = []) def assignment_json(assignment, includes = [], show_admin_fields = false)
# no includes supported right now # no includes supported right now
hash = assignment.as_json(:include_root => false, :only => %w(id grading_type points_possible position)) hash = assignment.as_json(:include_root => false, :only => %w(id grading_type points_possible position))
hash['name'] = assignment.title hash['name'] = assignment.title
if show_admin_fields
hash['needs_grading_count'] = assignment.needs_grading_count
end
hash['submission_types'] = assignment.submission_types.split(',') hash['submission_types'] = assignment.submission_types.split(',')
if assignment.rubric_association if assignment.rubric_association

View File

@ -88,6 +88,7 @@ describe AssignmentGroupsController, :type => :integration do
'name' => 'test3', 'name' => 'test3',
'position' => 1, 'position' => 1,
'points_possible' => 8, 'points_possible' => 8,
'needs_grading_count' => 0,
"submission_types" => [ "submission_types" => [
"none", "none",
], ],
@ -115,6 +116,7 @@ describe AssignmentGroupsController, :type => :integration do
'name' => 'test4', 'name' => 'test4',
'position' => 2, 'position' => 2,
'points_possible' => 9, 'points_possible' => 9,
'needs_grading_count' => 0,
"submission_types" => [ "submission_types" => [
"none", "none",
], ],
@ -132,6 +134,7 @@ describe AssignmentGroupsController, :type => :integration do
'name' => 'test1', 'name' => 'test1',
'position' => 1, 'position' => 1,
'points_possible' => 10, 'points_possible' => 10,
'needs_grading_count' => 0,
"submission_types" => [ "submission_types" => [
"none", "none",
], ],
@ -142,6 +145,7 @@ describe AssignmentGroupsController, :type => :integration do
'name' => 'test2', 'name' => 'test2',
'position' => 2, 'position' => 2,
'points_possible' => 12, 'points_possible' => 12,
'needs_grading_count' => 0,
"submission_types" => [ "submission_types" => [
"none", "none",
], ],

View File

@ -78,6 +78,7 @@ describe AssignmentsApiController, :type => :integration do
'grading_type' => 'points', 'grading_type' => 'points',
'use_rubric_for_grading' => true, 'use_rubric_for_grading' => true,
'free_form_criterion_comments' => true, 'free_form_criterion_comments' => true,
'needs_grading_count' => 0,
'submission_types' => [ 'submission_types' => [
"online_upload", "online_upload",
"online_text_entry", "online_text_entry",
@ -143,6 +144,7 @@ describe AssignmentsApiController, :type => :integration do
'position' => 1, 'position' => 1,
'points_possible' => 12, 'points_possible' => 12,
'grading_type' => 'points', 'grading_type' => 'points',
'needs_grading_count' => 0,
'submission_types' => [ 'submission_types' => [
'none', 'none',
], ],
@ -178,6 +180,7 @@ describe AssignmentsApiController, :type => :integration do
'position' => 1, 'position' => 1,
'points_possible' => 15, 'points_possible' => 15,
'grading_type' => 'points', 'grading_type' => 'points',
'needs_grading_count' => 0,
'submission_types' => [ 'submission_types' => [
'none', 'none',
], ],