add all_dates to assignment api for mobile
fixes CNVS-17096 test plan: - call assignment api index for course - if you include "all_dates" in the include then each assignment has an all_dates field - if you dont include it the assignment doesnt - call assignment api a single assignment - if you include all_dates=true, you get dates - if not you dont - call assignment_groups api - all_dates works like the index api - as a teacher and user the right dates show up on the assignment index & individual assignment pages Change-Id: I172c21161f792ff0b272dec03e0eb29ec3f32503 Reviewed-on: https://gerrit.instructure.com/45196 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Simon Williams <simon@instructure.com> QA-Review: Sean Lewis <slewis@instructure.com> Product-Review: Simon Williams <simon@instructure.com>
This commit is contained in:
parent
5caf9007c3
commit
addc9cdc3e
|
@ -499,7 +499,7 @@ class AssignmentsApiController < ApplicationController
|
||||||
|
|
||||||
# @API List assignments
|
# @API List assignments
|
||||||
# Returns the list of assignments for the current context.
|
# Returns the list of assignments for the current context.
|
||||||
# @argument include[] [String, "submission"|"assignment_visibility"]
|
# @argument include[] [String, "submission"|"assignment_visibility"|"all_dates"]
|
||||||
# Associations to include with the assignment. The "assignment_visibility" option
|
# Associations to include with the assignment. The "assignment_visibility" option
|
||||||
# requires that the Differentiated Assignments course feature be turned on.
|
# requires that the Differentiated Assignments course feature be turned on.
|
||||||
# @argument search_term [String]
|
# @argument search_term [String]
|
||||||
|
@ -532,7 +532,9 @@ class AssignmentsApiController < ApplicationController
|
||||||
|
|
||||||
assignments = Api.paginate(scope, self, api_v1_course_assignments_url(@context))
|
assignments = Api.paginate(scope, self, api_v1_course_assignments_url(@context))
|
||||||
|
|
||||||
if Array(params[:include]).include?('submission')
|
include_params = Array(params[:include])
|
||||||
|
|
||||||
|
if include_params.include?('submission')
|
||||||
submissions = Hash[
|
submissions = Hash[
|
||||||
@context.submissions.
|
@context.submissions.
|
||||||
where(:assignment_id => assignments).
|
where(:assignment_id => assignments).
|
||||||
|
@ -543,15 +545,17 @@ class AssignmentsApiController < ApplicationController
|
||||||
submissions = {}
|
submissions = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
include_all_dates = include_params.include?('all_dates')
|
||||||
|
|
||||||
override_param = params[:override_assignment_dates] || true
|
override_param = params[:override_assignment_dates] || true
|
||||||
override_dates = value_to_boolean(override_param)
|
override_dates = value_to_boolean(override_param)
|
||||||
if override_dates
|
if override_dates || include_all_dates
|
||||||
ActiveRecord::Associations::Preloader.new(assignments, :assignment_overrides).run
|
ActiveRecord::Associations::Preloader.new(assignments, :assignment_overrides).run
|
||||||
assignments.select{ |a| a.assignment_overrides.size == 0 }.
|
assignments.select{ |a| a.assignment_overrides.size == 0 }.
|
||||||
each { |a| a.has_no_overrides = true }
|
each { |a| a.has_no_overrides = true }
|
||||||
end
|
end
|
||||||
|
|
||||||
include_visibility = Array(params[:include]).include?('assignment_visibility') && @context.grants_any_right?(@current_user, :read_as_admin, :manage_grades, :manage_assignments)
|
include_visibility = include_params.include?('assignment_visibility') && @context.grants_any_right?(@current_user, :read_as_admin, :manage_grades, :manage_assignments)
|
||||||
|
|
||||||
if include_visibility && da_enabled
|
if include_visibility && da_enabled
|
||||||
assignment_visibilities = AssignmentStudentVisibility.users_with_visibility_by_assignment(course_id: @context.id, assignment_id: assignments.map(&:id))
|
assignment_visibilities = AssignmentStudentVisibility.users_with_visibility_by_assignment(course_id: @context.id, assignment_id: assignments.map(&:id))
|
||||||
|
@ -567,7 +571,9 @@ class AssignmentsApiController < ApplicationController
|
||||||
submission: submission, override_dates: override_dates,
|
submission: submission, override_dates: override_dates,
|
||||||
include_visibility: include_visibility,
|
include_visibility: include_visibility,
|
||||||
assignment_visibilities: visibility_array,
|
assignment_visibilities: visibility_array,
|
||||||
needs_grading_count_by_section: needs_grading_count_by_section)
|
needs_grading_count_by_section: needs_grading_count_by_section,
|
||||||
|
include_all_dates: include_all_dates
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
render :json => hashes
|
render :json => hashes
|
||||||
|
@ -583,6 +589,8 @@ class AssignmentsApiController < ApplicationController
|
||||||
# Apply assignment overrides to the assignment, defaults to true.
|
# Apply assignment overrides to the assignment, defaults to true.
|
||||||
# @argument needs_grading_count_by_section [Boolean]
|
# @argument needs_grading_count_by_section [Boolean]
|
||||||
# Split up "needs_grading_count" by sections into the "needs_grading_count_by_section" key, defaults to false
|
# Split up "needs_grading_count" by sections into the "needs_grading_count_by_section" key, defaults to false
|
||||||
|
# @argument all_dates [Boolean]
|
||||||
|
# All dates associated with the assignment, if applicable
|
||||||
# @returns Assignment
|
# @returns Assignment
|
||||||
def show
|
def show
|
||||||
@assignment = @context.active_assignments.find(params[:id],
|
@assignment = @context.active_assignments.find(params[:id],
|
||||||
|
@ -595,6 +603,7 @@ class AssignmentsApiController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
include_visibility = Array(params[:include]).include?('assignment_visibility') && @context.grants_any_right?(@current_user, :read_as_admin, :manage_grades, :manage_assignments)
|
include_visibility = Array(params[:include]).include?('assignment_visibility') && @context.grants_any_right?(@current_user, :read_as_admin, :manage_grades, :manage_assignments)
|
||||||
|
include_all_dates = value_to_boolean(params[:all_dates] || false)
|
||||||
|
|
||||||
override_param = params[:override_assignment_dates] || true
|
override_param = params[:override_assignment_dates] || true
|
||||||
override_dates = value_to_boolean(override_param)
|
override_dates = value_to_boolean(override_param)
|
||||||
|
@ -607,7 +616,8 @@ class AssignmentsApiController < ApplicationController
|
||||||
submission: submission,
|
submission: submission,
|
||||||
override_dates: override_dates,
|
override_dates: override_dates,
|
||||||
include_visibility: include_visibility,
|
include_visibility: include_visibility,
|
||||||
needs_grading_count_by_section: needs_grading_count_by_section)
|
needs_grading_count_by_section: needs_grading_count_by_section,
|
||||||
|
include_all_dates: include_all_dates)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -66,9 +66,10 @@ module DatesOverridable
|
||||||
end
|
end
|
||||||
|
|
||||||
def all_due_dates
|
def all_due_dates
|
||||||
all_dates = assignment_overrides.active.overriding_due_at.map(&:as_hash)
|
due_at_overrides = assignment_overrides.loaded? ? assignment_overrides.select{|ao| ao.active? && ao.due_at_overridden} : assignment_overrides.active.overriding_due_at
|
||||||
all_dates << base_due_date_hash unless differentiated_assignments_applies?
|
dates = due_at_overrides.map(&:as_hash)
|
||||||
all_dates
|
dates << base_due_date_hash unless differentiated_assignments_applies?
|
||||||
|
dates
|
||||||
end
|
end
|
||||||
|
|
||||||
def all_dates_visible_to(user)
|
def all_dates_visible_to(user)
|
||||||
|
|
|
@ -410,6 +410,23 @@ describe AssignmentsApiController, type: :request do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "includes all_dates with include flag" do
|
||||||
|
course_with_student_logged_in(:active_all => true)
|
||||||
|
@course.assignments.create!(:title => "all_date_test", :submission_types => "online_url")
|
||||||
|
json = api_call(:get,
|
||||||
|
"/api/v1/courses/#{@course.id}/assignments.json",
|
||||||
|
{
|
||||||
|
:controller => 'assignments_api',
|
||||||
|
:action => 'index',
|
||||||
|
:format => 'json',
|
||||||
|
:course_id => @course.id.to_s
|
||||||
|
},
|
||||||
|
:include => ['all_dates']
|
||||||
|
)
|
||||||
|
assign = json.first
|
||||||
|
expect(assign['all_dates']).not_to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
it "returns due dates as they apply to the user" do
|
it "returns due dates as they apply to the user" do
|
||||||
course_with_student(:active_all => true)
|
course_with_student(:active_all => true)
|
||||||
|
@ -1788,6 +1805,18 @@ describe AssignmentsApiController, type: :request do
|
||||||
expect(json['lock_at']).to eq @assignment.lock_at.iso8601.to_s
|
expect(json['lock_at']).to eq @assignment.lock_at.iso8601.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "returns all_dates when requested" do
|
||||||
|
@assignment = @course.assignments.create!(:title => "Test Assignment",:description => "foo")
|
||||||
|
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,
|
||||||
|
:all_dates => true},
|
||||||
|
{:override_assignment_dates => 'false'})
|
||||||
|
expect(json['all_dates']).not_to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
it "does not fulfill requirements when description isn't returned" do
|
it "does not fulfill requirements when description isn't returned" do
|
||||||
@assignment = @course.assignments.create!(
|
@assignment = @course.assignments.create!(
|
||||||
:title => "Locked Assignment",
|
:title => "Locked Assignment",
|
||||||
|
|
Loading…
Reference in New Issue