Skip to content

Commit 73aa481

Browse files
committed
calendar events api: include user_submitted on assignments
refs CNVS-16237 test plan: * open your browser console * load the calendar * open the type=assignment API request * verify that each assignment returned has user_submitted (on the inner assignment hash) * verify that user_submitted corresponds to having a submission Change-Id: I41f99d3239e040fd6775f13aea88f4ce50b3b33e Reviewed-on: https://gerrit.instructure.com/42747 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Brian Palmer <brianp@instructure.com> Reviewed-by: Matthew Wheeler <mwheeler@instructure.com> QA-Review: August Thornton <august@instructure.com> Product-Review: Braden Anderson <braden@instructure.com>
1 parent 9407689 commit 73aa481

4 files changed

Lines changed: 33 additions & 1 deletion

File tree

app/controllers/calendar_events_api_controller.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ def index
306306
events = Api.paginate(scope, self, api_v1_calendar_events_url)
307307
ActiveRecord::Associations::Preloader.new(events, :child_events).run if @type == :event
308308
events = apply_assignment_overrides(events) if @type == :assignment
309+
mark_submitted_assignments(@current_user, events) if @type == :assignment
309310

310311
if @errors.empty?
311312
render :json => events.map { |event| event_json(event, @current_user, session) }
@@ -824,6 +825,15 @@ def apply_assignment_overrides(events)
824825
events
825826
end
826827

828+
def mark_submitted_assignments(user, assignments)
829+
submitted_ids = Submission.where("submission_type IS NOT NULL").
830+
where(user_id: user, assignment_id: assignments).
831+
pluck(:assignment_id)
832+
assignments.each do |assignment|
833+
assignment.user_submitted = submitted_ids.include? assignment.id
834+
end
835+
end
836+
827837
def manageable_appointment_group_codes
828838
return [] unless @current_user
829839

app/models/assignment.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Assignment < ActiveRecord::Base
5454
:rubric, :context, :grading_standard, :group_category
5555
]
5656

57-
attr_accessor :previous_id, :updating_user, :copying
57+
attr_accessor :previous_id, :updating_user, :copying, :user_submitted
5858

5959
attr_reader :assignment_changed
6060

lib/api/v1/assignment.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ def assignment_json(assignment, user, session, opts = {})
7575
hash['submission_types'] = assignment.submission_types_array
7676
hash['has_submitted_submissions'] = assignment.has_submitted_submissions?
7777

78+
if !assignment.user_submitted.nil?
79+
hash['user_submitted'] = assignment.user_submitted
80+
end
81+
7882
if assignment.context && assignment.context.turnitin_enabled?
7983
hash['turnitin_enabled'] = assignment.turnitin_enabled
8084
hash['turnitin_settings'] = turnitin_settings_json(assignment)

spec/apis/v1/calendar_events_api_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,24 @@ def prepare(as_student = false)
859859
json.first['due_at'].should be_nil
860860
end
861861

862+
it 'should mark assignments with user_submitted' do
863+
e1 = @course.assignments.create(:title => '1', :due_at => '2012-01-07 12:00:00')
864+
e2 = @course.assignments.create(:title => '2', :due_at => '2012-01-08 12:00:00')
865+
866+
sub = e1.find_or_create_submission(@user)
867+
sub.submission_type = 'online_quiz'
868+
sub.workflow_state = 'submitted'
869+
sub.save!
870+
871+
json = api_call(:get, "/api/v1/calendar_events?type=assignment&start_date=2012-01-06&end_date=2012-01-09&context_codes[]=course_#{@course.id}", {
872+
:controller => 'calendar_events_api', :action => 'index', :format => 'json', :type => 'assignment',
873+
:context_codes => ["course_#{@course.id}"], :start_date => '2012-01-06', :end_date => '2012-01-09'})
874+
875+
expect(json.size).to eql 2
876+
expect(json[0]['assignment']['user_submitted']).to be_truthy
877+
expect(json[1]['assignment']['user_submitted']).to be_falsy
878+
end
879+
862880
context 'unpublished assignments' do
863881
before :once do
864882
@course1 = @course

0 commit comments

Comments
 (0)