add api param to exclude assignment overrides

fixes PS-474

test plan

*teachers and admin users should be able to exclude assignment overrides on list and get in the api

Change-Id: Iad5b8399ff958d5983dba79ea163702b1138e519
Reviewed-on: https://gerrit.instructure.com/21952
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Cameron Matheson <cameron@instructure.com>
QA-Review: Adam Phillipps <adam@instructure.com>
Product-Review: Nathan Mills <nathanm@instructure.com>
This commit is contained in:
Nathan Mills 2013-07-02 09:10:40 -06:00
parent c95048e248
commit 234150131a
2 changed files with 76 additions and 6 deletions

View File

@ -290,8 +290,9 @@ class AssignmentsApiController < ApplicationController
# @API List assignments
# Returns the list of assignments for the current context.
# @argument include[] ["submission"] Associations to include with the
# assignment.
# @argument include[] ["submission"] Associations to include with the assignment.
# @argument override_assignment_dates [Optional, Boolean]
# Apply assignment overrides for each assignment, defaults to true.
# @returns [Assignment]
def index
if authorized_action(@context, @current_user, :read)
@ -303,6 +304,10 @@ class AssignmentsApiController < ApplicationController
fake = @context.assignments.new
fake.workflow_state = 'unpublished'
#default the assignment_overrides to true
override_param = params[:override_assignment_dates] || true
assignment_overrides = value_to_boolean(override_param)
if @domain_root_account.enable_draft? && !fake.grants_right?(@current_user, session, :read)
#user is a student and assignment is not published
@assignments = @assignments.published
@ -318,9 +323,10 @@ class AssignmentsApiController < ApplicationController
else
submissions = {}
end
hashes = @assignments.map do |assignment|
submission = submissions[assignment.id]
assignment_json(assignment, @current_user, session,true,submission)
assignment_json(assignment, @current_user, session, true, submission, assignment_overrides)
end
render :json => hashes.to_json
@ -329,9 +335,10 @@ class AssignmentsApiController < ApplicationController
# @API Get a single assignment
# Returns the assignment with the given id.
# @argument include[] ["submission"] Associations to include with the assignment.
# @argument override_assignment_dates [Optional, Boolean]
# Apply assignment overrides to the assignment, defaults to true.
# @returns Assignment
# @argument include[] ["submission"] Associations to include with the
# assignment.
def show
if authorized_action(@context, @current_user, :read)
@assignment = @context.active_assignments.find(params[:id],
@ -348,8 +355,13 @@ class AssignmentsApiController < ApplicationController
else
submission = nil
end
#default the assignment_overrides to true
override_param = params[:override_assignment_dates] || true
assignment_overrides = value_to_boolean(override_param)
@assignment.context_module_action(@current_user, :read) unless @assignment.locked_for?(@current_user, :check_policies => true)
render :json => assignment_json(@assignment, @current_user, session,true,submission)
render :json => assignment_json(@assignment, @current_user, session, true, submission, assignment_overrides)
end
end

View File

@ -277,6 +277,37 @@ describe AssignmentsApiController, :type => :integration do
json['lock_at'].should == override.lock_at.iso8601.to_s
end
it "returns original assignment due dates" do
course_with_student(:active_all => true)
@user = @teacher
@student.enrollments.map(&:destroy!)
@assignment = @course.assignments.create!(
:title => "Test Assignment",
:description => "public stuff",
:due_at => Time.zone.now + 1.days,
:unlock_at => Time.zone.now,
:lock_at => Time.zone.now + 2.days
)
@section = @course.course_sections.create! :name => "afternoon delight"
@course.enroll_user(@student,'StudentEnrollment',
:section => @section,
:enrollment_state => :active)
create_override_for_assignment
json = api_call(:get,
"/api/v1/courses/#{@course.id}/assignments.json",
{
:controller => 'assignments_api',
:action => 'index',
:format => 'json',
:course_id => @course.id.to_s
},
:override_assignment_dates => 'false'
).first
json['due_at'].should == @assignment.due_at.iso8601.to_s
json['unlock_at'].should == @assignment.unlock_at.iso8601.to_s
json['lock_at'].should == @assignment.lock_at.iso8601.to_s
end
describe "draft state" do
before do
@ -1108,6 +1139,33 @@ describe AssignmentsApiController, :type => :integration do
json['lock_at'].should == override.lock_at.iso8601.to_s
end
it "returns original assignment due dates" do
course_with_student(:active_all => true)
@user = @student
@student.enrollments.map(&:destroy!)
@assignment = @course.assignments.create!(
:title => "Test Assignment",
:description => "public stuff",
:due_at => Time.zone.now + 1.days,
:unlock_at => Time.zone.now,
:lock_at => Time.zone.now + 2.days
)
@section = @course.course_sections.create! :name => "afternoon delight"
@course.enroll_user(@student,'StudentEnrollment',
:section => @section,
:enrollment_state => :active)
create_override_for_assignment
json = api_call(:get,
"/api/v1/courses/#{@course.id}/assignments/#{@assignment.id}.json",
{ :controller => "assignments_api", :action => "show",
:format => "json", :course_id => @course.id.to_s,
:id => @assignment.id.to_s},
{:override_assignment_dates => 'false'})
json['due_at'].should == @assignment.due_at.iso8601.to_s
json['unlock_at'].should == @assignment.unlock_at.iso8601.to_s
json['lock_at'].should == @assignment.lock_at.iso8601.to_s
end
it "does not fulfill requirements when description isn't returned" do
course_with_student(:active_all => true)
@assignment = @course.assignments.create!(