Allow excluding users with no results

closes OUT-1859

test plan:
  - in a course, create about 10 outcomes and 10 student users
  - create an assignment, aligned to an outcome
  - submit to the assignment with two student users
  - assess the rubrics for each submission in speed grader
  - load LMGB, confirm that all students and outcomes appear,
    with the results of the two students
  - using a tool like Postman, perform an API call with an
    access to the following endpoint:

    http://canvas.docker/api/v1/courses/<course id>/outcome_rollups

  - confirm that a rollup appears for each student, and only scores
    appear for students whose assignments were assessed
  - append "?exclude[]=missing_user_rollups" to the request above
    and resubmit
  - confirm that only rollups with scores appears (should be two)
  - append "&include[]=outcomes" to the request above and resubmit
  - confirm that under the "linked" section, that "outcomes" contains
    all outcomes in the course

Change-Id: I399715093943455659ed5a05c39befca8dc2e801
Reviewed-on: https://gerrit.instructure.com/156247
QA-Review: Dariusz Dzien <ddzien@instructure.com>
Tested-by: Jenkins
Reviewed-by: Neil Gupta <ngupta@instructure.com>
Reviewed-by: Frank Murphy <fmurphy@instructure.com>
Product-Review: Michael Brewer-Davis <mbd@instructure.com>
This commit is contained in:
Augusto Callejas 2018-07-02 13:38:33 -10:00
parent 63d08a7784
commit dd867b5c6d
4 changed files with 44 additions and 3 deletions

View File

@ -265,6 +265,10 @@ class OutcomeResultsController < ApplicationController
# @argument include[] [String, "courses"|"outcomes"|"outcomes.alignments"|"outcome_groups"|"outcome_links"|"outcome_paths"|"users"]
# Specify additional collections to be side loaded with the result.
#
# @argument exclude[] [String, "missing_user_rollups"]
# Specify additional values to exclude. "missing_user_rollups" excludes
# rollups for users without results.
#
# @example_response
# {
# "rollups": [OutcomeRollup],
@ -320,8 +324,9 @@ class OutcomeResultsController < ApplicationController
end
def user_rollups(_opts = {})
excludes = Api.value_to_array(params[:exclude]).uniq
@results = find_results.preload(:user)
outcome_results_rollups(@results, @users)
outcome_results_rollups(@results, @users, excludes)
end
def user_rollups_json

View File

@ -68,13 +68,20 @@ module Outcomes
# users - (Optional) Ensure rollups are included for users in this list.
# A listed user with no results will have an empty score array.
#
# excludes - (Optional) Specify additional values to exclude. "missing_user_rollups" excludes
# rollups for users without results.
#
# Returns an Array of Rollup objects.
def outcome_results_rollups(results, users=[])
def outcome_results_rollups(results, users=[], excludes = [])
ActiveRecord::Associations::Preloader.new.preload(results, :learning_outcome)
rollups = results.chunk(&:user_id).map do |_, user_results|
Rollup.new(user_results.first.user, rollup_user_results(user_results))
end
add_missing_user_rollups(rollups, users)
if excludes.include? 'missing_user_rollups'
rollups
else
add_missing_user_rollups(rollups, users)
end
end
# Public: Calculates an average rollup for the specified results

View File

@ -200,5 +200,25 @@ describe OutcomeResultsController do
expect(json['outcome_results'].length).to eq 0
end
end
it 'exclude missing user rollups' do
user_session(@teacher)
# save a reference to the 1st student
student1 = @student
# create a 2nd student that is saved as @student
student_in_course(active_all: true, course: outcome_course)
get 'rollups', params: {:context_id => @course.id,
:course_id => @course.id,
:context_type => "Course",
:user_ids => [student1.id, @student.id],
:outcome_ids => [@outcome.id],
exclude: ['missing_user_rollups']},
format: "json"
json = JSON.parse(response.body.gsub("while(1);", ""))
# the rollups requests for both students, but excludes the 2nd student
# since they do not have any results, unlike the 1st student,
# which has a single result in `outcome_result`
expect(json['rollups'].length).to be 1
end
end
end

View File

@ -248,6 +248,15 @@ describe Outcomes::ResultAnalytics do
end
end
it 'excludes missing user rollups' do
results = [
outcome_from_score(5.0, {user: MockUser[20, 'b']})
]
users = [MockUser[10, 'a'], MockUser[30, 'c']]
rollups = ra.outcome_results_rollups(results, users, ['missing_user_rollups'])
expect(rollups.length).to eq 1
end
it 'returns hide_points value of true if all results have hide_points set to true' do
results = [
outcome_from_score(4.0,{hide_points: true}),