canvas-lms/lib/gradebook_user_ids.rb

133 lines
4.6 KiB
Ruby
Raw Normal View History

add user_ids endpoint to gradebooks_controller Add endpoint to gradebooks controller which returns user ids sorted according to the user's gradebook sort preferences. closes CNVS-37608 Test Plan: 1. Create a course that has some active students, inactive students, and concluded students. Enable New Gradebook and go to the gradebook. 2. Click on the student header and select 'Inactive enrollments' and 'Concluded enrollments'. Then select 'Sort by -> A-Z'. 2. As a student in the course, hit the new endpoint to get user IDs (GET /courses/:course_id/gradebook/user_ids). Verify you get a 401 unauthorized response. 3. As a teacher in the course, hit the user_ids endpoint and verify you get a list of user IDs back. The user IDs should be ordered such that their corresponding users' names are in alpha ascending order. The list of user IDs should also include inactive and concluded students' IDs. 4. Go to the gradebook and click on the student header. Select 'Sort by -> Z-A'. 5. Hit the user_ids endpoint and verify the returned user IDs are now ordered such that their corresponding users' names are in alpha descending order. The list of user IDs should also include inactive and concluded students' IDs. 6. Go to the gradebook and click on the student column header. Deselect the 'Inactive enrollments' and 'Concluded enrollments' options. 7. Hit the user_ids endpoint and verify the returned user IDs no longer include IDs for inactive or concluded students. The IDs should still be ordered such that their corresponding users' names are in alpha descending order. 8. Go to the gradebook and click on the total grade header. Select 'Sort by Grade -> Low to High' 9. Hit the user_ids endpoint and verify the returned user IDs are ordered such that their corresponding users' current total grades are in ascending order. 10. Go to the gradebook and click on the total grade header. Select 'Sort by Grade -> High to Low' 11. Hit the user_ids endpoint and verify the returned user IDs are ordered such that their corresponding users' current total grades are in descending order. 12. In the same manner as the steps above, make sure changing the following settings in the gradebook causes the user_ids endpoint to return an array of IDs ordered according to the gradebook sort preferences: a) Assignment column header -> Sort by Grade -> Low to High b) Assignment column header -> Sort by Grade -> High to Low c) Assignment column header -> Sort by -> Missing (the user_ids endpoint should return all users with a missing submission for that assignment first) d) Assignment column header -> Sort by -> Late (the user_ids endpoint shoudl return all users with a late submission for that assignment first) e) Select a grading period and sort by total grade. The user_ids endpoint should return user IDs that are ordered such that their corresponding users' grades are in ascending or descending order for the selected grading period. * Note: Sorting by assignment group totals is not currently supported. Change-Id: I4a36aa5b82d87f49d2396bbc16e1cc56e89eba0f Reviewed-on: https://gerrit.instructure.com/116491 Reviewed-by: Shahbaz Javeed <sjaveed@instructure.com> Tested-by: Jenkins Reviewed-by: Keith T. Garner <kgarner@instructure.com> QA-Review: Anju Reddy <areddy@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2017-06-17 06:37:46 +08:00
#
# Copyright (C) 2017 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
class GradebookUserIds
def initialize(course, user)
settings = (user.preferences.dig(:gradebook_settings, course.id) || {}).with_indifferent_access
@course = course
@include_inactive = settings[:show_inactive_enrollments] == "true"
@include_concluded = settings[:show_concluded_enrollments] == "true"
@column = settings[:sort_rows_by_column_id] || "student"
@sort_by = settings[:sort_rows_by_setting_key] || "name"
@selected_grading_period_id = settings.dig(:filter_columns_by, :grading_period_id)
@selected_section_id = settings.dig(:filter_columns_by, :section_id)
@direction = settings[:sort_rows_by_direction] || "ascending"
end
def user_ids
if @column == "student"
sort_by_student_name
elsif @column&.include?("assignment")
assignment_id = @column[/\d+$/]
send("sort_by_assignment_#{@sort_by}", assignment_id)
elsif @column == "total_grade"
sort_by_total_grade
else
sort_by_student_name
end
end
private
def sort_by_student_name
new gradebook: fake student ids always sort last closes CNVS-37752 Test Plan: 1. Create a course that has some active students, inactive students, concluded students, and a fake student. Enable New Gradebook and go to the gradebook. 2. Click on the student header and select 'Inactive enrollments' and 'Concluded enrollments'. Then select 'Sort by -> A-Z'. 3. As a teacher in the course, hit the user_ids endpoint and verify you get a list of user IDs back. The user IDs should be ordered such that their corresponding users' names are in alpha ascending order. The list of user IDs should also include inactive and concluded students' IDs. The fake student's ID should always be last. 4. Go to the gradebook and click on the student header. Select 'Sort by -> Z-A'. 5. Hit the user_ids endpoint and verify the returned user IDs are now ordered such that their corresponding users' names are in alpha descending order. The list of user IDs should also include inactive and concluded students' IDs. The fake student's ID should be last. 6. Go to the gradebook and click on the student column header. Deselect the 'Inactive enrollments' and 'Concluded enrollments' options. 7. Hit the user_ids endpoint and verify the returned user IDs no longer include IDs for inactive or concluded students. The IDs should still be ordered such that their corresponding users' names are in alpha descending order. The fake student's ID should be last. 8. Go to the gradebook and click on the total grade header. Select 'Sort by Grade -> Low to High' 9. Hit the user_ids endpoint and verify the returned user IDs are ordered such that their corresponding users' current total grades are in ascending order. The fake student's ID should be last. 10. Go to the gradebook and click on the total grade header. Select 'Sort by Grade -> High to Low' 11. Hit the user_ids endpoint and verify the returned user IDs are ordered such that their corresponding users' current total grades are in descending order. The fake student's ID should be last. 12. In the same manner as the steps above, make sure changing the following settings in the gradebook causes the user_ids endpoint to return an array of IDs ordered according to the gradebook sort preferences, with the fake student's ID sorted last: a) Assignment column header -> Sort by Grade -> Low to High b) Assignment column header -> Sort by Grade -> High to Low c) Assignment column header -> Sort by -> Missing (the user_ids endpoint should return all users with a missing submission for that assignment first) d) Assignment column header -> Sort by -> Late (the user_ids endpoint shoudl return all users with a late submission for that assignment first) e) Select a grading period and sort by total grade. The user_ids endpoint should return user IDs that are ordered such that their corresponding users' grades are in ascending or descending order for the selected grading period. 13. Conclude the course. Hit the user_ids endpoint as the teacher and verify you do not get a 401 response. * Note: Sorting by assignment group totals is not currently supported. Change-Id: I6c4b16b72e051d46cc7b7521949d5c82b92960b9 Reviewed-on: https://gerrit.instructure.com/116698 Reviewed-by: Keith T. Garner <kgarner@instructure.com> Reviewed-by: Jeremy Neander <jneander@instructure.com> Tested-by: Jenkins QA-Review: KC Naegle <knaegle@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2017-06-23 08:17:41 +08:00
students.joins(:enrollments).
order("enrollments.type = 'StudentViewEnrollment'").
order_by_sortable_name(direction: @direction.to_sym).
pluck(:id).
uniq
add user_ids endpoint to gradebooks_controller Add endpoint to gradebooks controller which returns user ids sorted according to the user's gradebook sort preferences. closes CNVS-37608 Test Plan: 1. Create a course that has some active students, inactive students, and concluded students. Enable New Gradebook and go to the gradebook. 2. Click on the student header and select 'Inactive enrollments' and 'Concluded enrollments'. Then select 'Sort by -> A-Z'. 2. As a student in the course, hit the new endpoint to get user IDs (GET /courses/:course_id/gradebook/user_ids). Verify you get a 401 unauthorized response. 3. As a teacher in the course, hit the user_ids endpoint and verify you get a list of user IDs back. The user IDs should be ordered such that their corresponding users' names are in alpha ascending order. The list of user IDs should also include inactive and concluded students' IDs. 4. Go to the gradebook and click on the student header. Select 'Sort by -> Z-A'. 5. Hit the user_ids endpoint and verify the returned user IDs are now ordered such that their corresponding users' names are in alpha descending order. The list of user IDs should also include inactive and concluded students' IDs. 6. Go to the gradebook and click on the student column header. Deselect the 'Inactive enrollments' and 'Concluded enrollments' options. 7. Hit the user_ids endpoint and verify the returned user IDs no longer include IDs for inactive or concluded students. The IDs should still be ordered such that their corresponding users' names are in alpha descending order. 8. Go to the gradebook and click on the total grade header. Select 'Sort by Grade -> Low to High' 9. Hit the user_ids endpoint and verify the returned user IDs are ordered such that their corresponding users' current total grades are in ascending order. 10. Go to the gradebook and click on the total grade header. Select 'Sort by Grade -> High to Low' 11. Hit the user_ids endpoint and verify the returned user IDs are ordered such that their corresponding users' current total grades are in descending order. 12. In the same manner as the steps above, make sure changing the following settings in the gradebook causes the user_ids endpoint to return an array of IDs ordered according to the gradebook sort preferences: a) Assignment column header -> Sort by Grade -> Low to High b) Assignment column header -> Sort by Grade -> High to Low c) Assignment column header -> Sort by -> Missing (the user_ids endpoint should return all users with a missing submission for that assignment first) d) Assignment column header -> Sort by -> Late (the user_ids endpoint shoudl return all users with a late submission for that assignment first) e) Select a grading period and sort by total grade. The user_ids endpoint should return user IDs that are ordered such that their corresponding users' grades are in ascending or descending order for the selected grading period. * Note: Sorting by assignment group totals is not currently supported. Change-Id: I4a36aa5b82d87f49d2396bbc16e1cc56e89eba0f Reviewed-on: https://gerrit.instructure.com/116491 Reviewed-by: Shahbaz Javeed <sjaveed@instructure.com> Tested-by: Jenkins Reviewed-by: Keith T. Garner <kgarner@instructure.com> QA-Review: Anju Reddy <areddy@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2017-06-17 06:37:46 +08:00
end
def sort_by_assignment_grade(assignment_id)
student_enrollments_scope.
joins("
LEFT JOIN #{Submission.quoted_table_name}
ON submissions.user_id = enrollments.user_id
AND submissions.assignment_id = #{assignment_id}
").
new gradebook: fake student ids always sort last closes CNVS-37752 Test Plan: 1. Create a course that has some active students, inactive students, concluded students, and a fake student. Enable New Gradebook and go to the gradebook. 2. Click on the student header and select 'Inactive enrollments' and 'Concluded enrollments'. Then select 'Sort by -> A-Z'. 3. As a teacher in the course, hit the user_ids endpoint and verify you get a list of user IDs back. The user IDs should be ordered such that their corresponding users' names are in alpha ascending order. The list of user IDs should also include inactive and concluded students' IDs. The fake student's ID should always be last. 4. Go to the gradebook and click on the student header. Select 'Sort by -> Z-A'. 5. Hit the user_ids endpoint and verify the returned user IDs are now ordered such that their corresponding users' names are in alpha descending order. The list of user IDs should also include inactive and concluded students' IDs. The fake student's ID should be last. 6. Go to the gradebook and click on the student column header. Deselect the 'Inactive enrollments' and 'Concluded enrollments' options. 7. Hit the user_ids endpoint and verify the returned user IDs no longer include IDs for inactive or concluded students. The IDs should still be ordered such that their corresponding users' names are in alpha descending order. The fake student's ID should be last. 8. Go to the gradebook and click on the total grade header. Select 'Sort by Grade -> Low to High' 9. Hit the user_ids endpoint and verify the returned user IDs are ordered such that their corresponding users' current total grades are in ascending order. The fake student's ID should be last. 10. Go to the gradebook and click on the total grade header. Select 'Sort by Grade -> High to Low' 11. Hit the user_ids endpoint and verify the returned user IDs are ordered such that their corresponding users' current total grades are in descending order. The fake student's ID should be last. 12. In the same manner as the steps above, make sure changing the following settings in the gradebook causes the user_ids endpoint to return an array of IDs ordered according to the gradebook sort preferences, with the fake student's ID sorted last: a) Assignment column header -> Sort by Grade -> Low to High b) Assignment column header -> Sort by Grade -> High to Low c) Assignment column header -> Sort by -> Missing (the user_ids endpoint should return all users with a missing submission for that assignment first) d) Assignment column header -> Sort by -> Late (the user_ids endpoint shoudl return all users with a late submission for that assignment first) e) Select a grading period and sort by total grade. The user_ids endpoint should return user IDs that are ordered such that their corresponding users' grades are in ascending or descending order for the selected grading period. 13. Conclude the course. Hit the user_ids endpoint as the teacher and verify you do not get a 401 response. * Note: Sorting by assignment group totals is not currently supported. Change-Id: I6c4b16b72e051d46cc7b7521949d5c82b92960b9 Reviewed-on: https://gerrit.instructure.com/116698 Reviewed-by: Keith T. Garner <kgarner@instructure.com> Reviewed-by: Jeremy Neander <jneander@instructure.com> Tested-by: Jenkins QA-Review: KC Naegle <knaegle@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2017-06-23 08:17:41 +08:00
order("enrollments.type = 'StudentViewEnrollment'", "submissions.score #{sort_direction} NULLS LAST").
add user_ids endpoint to gradebooks_controller Add endpoint to gradebooks controller which returns user ids sorted according to the user's gradebook sort preferences. closes CNVS-37608 Test Plan: 1. Create a course that has some active students, inactive students, and concluded students. Enable New Gradebook and go to the gradebook. 2. Click on the student header and select 'Inactive enrollments' and 'Concluded enrollments'. Then select 'Sort by -> A-Z'. 2. As a student in the course, hit the new endpoint to get user IDs (GET /courses/:course_id/gradebook/user_ids). Verify you get a 401 unauthorized response. 3. As a teacher in the course, hit the user_ids endpoint and verify you get a list of user IDs back. The user IDs should be ordered such that their corresponding users' names are in alpha ascending order. The list of user IDs should also include inactive and concluded students' IDs. 4. Go to the gradebook and click on the student header. Select 'Sort by -> Z-A'. 5. Hit the user_ids endpoint and verify the returned user IDs are now ordered such that their corresponding users' names are in alpha descending order. The list of user IDs should also include inactive and concluded students' IDs. 6. Go to the gradebook and click on the student column header. Deselect the 'Inactive enrollments' and 'Concluded enrollments' options. 7. Hit the user_ids endpoint and verify the returned user IDs no longer include IDs for inactive or concluded students. The IDs should still be ordered such that their corresponding users' names are in alpha descending order. 8. Go to the gradebook and click on the total grade header. Select 'Sort by Grade -> Low to High' 9. Hit the user_ids endpoint and verify the returned user IDs are ordered such that their corresponding users' current total grades are in ascending order. 10. Go to the gradebook and click on the total grade header. Select 'Sort by Grade -> High to Low' 11. Hit the user_ids endpoint and verify the returned user IDs are ordered such that their corresponding users' current total grades are in descending order. 12. In the same manner as the steps above, make sure changing the following settings in the gradebook causes the user_ids endpoint to return an array of IDs ordered according to the gradebook sort preferences: a) Assignment column header -> Sort by Grade -> Low to High b) Assignment column header -> Sort by Grade -> High to Low c) Assignment column header -> Sort by -> Missing (the user_ids endpoint should return all users with a missing submission for that assignment first) d) Assignment column header -> Sort by -> Late (the user_ids endpoint shoudl return all users with a late submission for that assignment first) e) Select a grading period and sort by total grade. The user_ids endpoint should return user IDs that are ordered such that their corresponding users' grades are in ascending or descending order for the selected grading period. * Note: Sorting by assignment group totals is not currently supported. Change-Id: I4a36aa5b82d87f49d2396bbc16e1cc56e89eba0f Reviewed-on: https://gerrit.instructure.com/116491 Reviewed-by: Shahbaz Javeed <sjaveed@instructure.com> Tested-by: Jenkins Reviewed-by: Keith T. Garner <kgarner@instructure.com> QA-Review: Anju Reddy <areddy@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2017-06-17 06:37:46 +08:00
pluck(:user_id).
uniq
end
def sort_by_assignment_missing(assignment_id)
all_user_ids = student_enrollments_scope.pluck(:user_id)
new gradebook: fake student ids always sort last closes CNVS-37752 Test Plan: 1. Create a course that has some active students, inactive students, concluded students, and a fake student. Enable New Gradebook and go to the gradebook. 2. Click on the student header and select 'Inactive enrollments' and 'Concluded enrollments'. Then select 'Sort by -> A-Z'. 3. As a teacher in the course, hit the user_ids endpoint and verify you get a list of user IDs back. The user IDs should be ordered such that their corresponding users' names are in alpha ascending order. The list of user IDs should also include inactive and concluded students' IDs. The fake student's ID should always be last. 4. Go to the gradebook and click on the student header. Select 'Sort by -> Z-A'. 5. Hit the user_ids endpoint and verify the returned user IDs are now ordered such that their corresponding users' names are in alpha descending order. The list of user IDs should also include inactive and concluded students' IDs. The fake student's ID should be last. 6. Go to the gradebook and click on the student column header. Deselect the 'Inactive enrollments' and 'Concluded enrollments' options. 7. Hit the user_ids endpoint and verify the returned user IDs no longer include IDs for inactive or concluded students. The IDs should still be ordered such that their corresponding users' names are in alpha descending order. The fake student's ID should be last. 8. Go to the gradebook and click on the total grade header. Select 'Sort by Grade -> Low to High' 9. Hit the user_ids endpoint and verify the returned user IDs are ordered such that their corresponding users' current total grades are in ascending order. The fake student's ID should be last. 10. Go to the gradebook and click on the total grade header. Select 'Sort by Grade -> High to Low' 11. Hit the user_ids endpoint and verify the returned user IDs are ordered such that their corresponding users' current total grades are in descending order. The fake student's ID should be last. 12. In the same manner as the steps above, make sure changing the following settings in the gradebook causes the user_ids endpoint to return an array of IDs ordered according to the gradebook sort preferences, with the fake student's ID sorted last: a) Assignment column header -> Sort by Grade -> Low to High b) Assignment column header -> Sort by Grade -> High to Low c) Assignment column header -> Sort by -> Missing (the user_ids endpoint should return all users with a missing submission for that assignment first) d) Assignment column header -> Sort by -> Late (the user_ids endpoint shoudl return all users with a late submission for that assignment first) e) Select a grading period and sort by total grade. The user_ids endpoint should return user IDs that are ordered such that their corresponding users' grades are in ascending or descending order for the selected grading period. 13. Conclude the course. Hit the user_ids endpoint as the teacher and verify you do not get a 401 response. * Note: Sorting by assignment group totals is not currently supported. Change-Id: I6c4b16b72e051d46cc7b7521949d5c82b92960b9 Reviewed-on: https://gerrit.instructure.com/116698 Reviewed-by: Keith T. Garner <kgarner@instructure.com> Reviewed-by: Jeremy Neander <jneander@instructure.com> Tested-by: Jenkins QA-Review: KC Naegle <knaegle@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2017-06-23 08:17:41 +08:00
fake_user_ids = student_enrollments_scope.where(type: "StudentViewEnrollment").pluck(:user_id)
real_user_ids = all_user_ids - fake_user_ids
user_ids_for_missing = Submission.missing.
where(assignment_id: assignment_id, user_id: real_user_ids).
pluck(:user_id)
user_ids_for_missing.concat(real_user_ids).concat(fake_user_ids).uniq
add user_ids endpoint to gradebooks_controller Add endpoint to gradebooks controller which returns user ids sorted according to the user's gradebook sort preferences. closes CNVS-37608 Test Plan: 1. Create a course that has some active students, inactive students, and concluded students. Enable New Gradebook and go to the gradebook. 2. Click on the student header and select 'Inactive enrollments' and 'Concluded enrollments'. Then select 'Sort by -> A-Z'. 2. As a student in the course, hit the new endpoint to get user IDs (GET /courses/:course_id/gradebook/user_ids). Verify you get a 401 unauthorized response. 3. As a teacher in the course, hit the user_ids endpoint and verify you get a list of user IDs back. The user IDs should be ordered such that their corresponding users' names are in alpha ascending order. The list of user IDs should also include inactive and concluded students' IDs. 4. Go to the gradebook and click on the student header. Select 'Sort by -> Z-A'. 5. Hit the user_ids endpoint and verify the returned user IDs are now ordered such that their corresponding users' names are in alpha descending order. The list of user IDs should also include inactive and concluded students' IDs. 6. Go to the gradebook and click on the student column header. Deselect the 'Inactive enrollments' and 'Concluded enrollments' options. 7. Hit the user_ids endpoint and verify the returned user IDs no longer include IDs for inactive or concluded students. The IDs should still be ordered such that their corresponding users' names are in alpha descending order. 8. Go to the gradebook and click on the total grade header. Select 'Sort by Grade -> Low to High' 9. Hit the user_ids endpoint and verify the returned user IDs are ordered such that their corresponding users' current total grades are in ascending order. 10. Go to the gradebook and click on the total grade header. Select 'Sort by Grade -> High to Low' 11. Hit the user_ids endpoint and verify the returned user IDs are ordered such that their corresponding users' current total grades are in descending order. 12. In the same manner as the steps above, make sure changing the following settings in the gradebook causes the user_ids endpoint to return an array of IDs ordered according to the gradebook sort preferences: a) Assignment column header -> Sort by Grade -> Low to High b) Assignment column header -> Sort by Grade -> High to Low c) Assignment column header -> Sort by -> Missing (the user_ids endpoint should return all users with a missing submission for that assignment first) d) Assignment column header -> Sort by -> Late (the user_ids endpoint shoudl return all users with a late submission for that assignment first) e) Select a grading period and sort by total grade. The user_ids endpoint should return user IDs that are ordered such that their corresponding users' grades are in ascending or descending order for the selected grading period. * Note: Sorting by assignment group totals is not currently supported. Change-Id: I4a36aa5b82d87f49d2396bbc16e1cc56e89eba0f Reviewed-on: https://gerrit.instructure.com/116491 Reviewed-by: Shahbaz Javeed <sjaveed@instructure.com> Tested-by: Jenkins Reviewed-by: Keith T. Garner <kgarner@instructure.com> QA-Review: Anju Reddy <areddy@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2017-06-17 06:37:46 +08:00
end
def sort_by_assignment_late(assignment_id)
all_user_ids = student_enrollments_scope.pluck(:user_id)
new gradebook: fake student ids always sort last closes CNVS-37752 Test Plan: 1. Create a course that has some active students, inactive students, concluded students, and a fake student. Enable New Gradebook and go to the gradebook. 2. Click on the student header and select 'Inactive enrollments' and 'Concluded enrollments'. Then select 'Sort by -> A-Z'. 3. As a teacher in the course, hit the user_ids endpoint and verify you get a list of user IDs back. The user IDs should be ordered such that their corresponding users' names are in alpha ascending order. The list of user IDs should also include inactive and concluded students' IDs. The fake student's ID should always be last. 4. Go to the gradebook and click on the student header. Select 'Sort by -> Z-A'. 5. Hit the user_ids endpoint and verify the returned user IDs are now ordered such that their corresponding users' names are in alpha descending order. The list of user IDs should also include inactive and concluded students' IDs. The fake student's ID should be last. 6. Go to the gradebook and click on the student column header. Deselect the 'Inactive enrollments' and 'Concluded enrollments' options. 7. Hit the user_ids endpoint and verify the returned user IDs no longer include IDs for inactive or concluded students. The IDs should still be ordered such that their corresponding users' names are in alpha descending order. The fake student's ID should be last. 8. Go to the gradebook and click on the total grade header. Select 'Sort by Grade -> Low to High' 9. Hit the user_ids endpoint and verify the returned user IDs are ordered such that their corresponding users' current total grades are in ascending order. The fake student's ID should be last. 10. Go to the gradebook and click on the total grade header. Select 'Sort by Grade -> High to Low' 11. Hit the user_ids endpoint and verify the returned user IDs are ordered such that their corresponding users' current total grades are in descending order. The fake student's ID should be last. 12. In the same manner as the steps above, make sure changing the following settings in the gradebook causes the user_ids endpoint to return an array of IDs ordered according to the gradebook sort preferences, with the fake student's ID sorted last: a) Assignment column header -> Sort by Grade -> Low to High b) Assignment column header -> Sort by Grade -> High to Low c) Assignment column header -> Sort by -> Missing (the user_ids endpoint should return all users with a missing submission for that assignment first) d) Assignment column header -> Sort by -> Late (the user_ids endpoint shoudl return all users with a late submission for that assignment first) e) Select a grading period and sort by total grade. The user_ids endpoint should return user IDs that are ordered such that their corresponding users' grades are in ascending or descending order for the selected grading period. 13. Conclude the course. Hit the user_ids endpoint as the teacher and verify you do not get a 401 response. * Note: Sorting by assignment group totals is not currently supported. Change-Id: I6c4b16b72e051d46cc7b7521949d5c82b92960b9 Reviewed-on: https://gerrit.instructure.com/116698 Reviewed-by: Keith T. Garner <kgarner@instructure.com> Reviewed-by: Jeremy Neander <jneander@instructure.com> Tested-by: Jenkins QA-Review: KC Naegle <knaegle@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2017-06-23 08:17:41 +08:00
fake_user_ids = student_enrollments_scope.where(type: "StudentViewEnrollment").pluck(:user_id)
real_user_ids = all_user_ids - fake_user_ids
user_ids_for_late = Submission.late.where(assignment_id: assignment_id, user_id: real_user_ids).pluck(:user_id)
user_ids_for_late.concat(real_user_ids).concat(fake_user_ids).uniq
add user_ids endpoint to gradebooks_controller Add endpoint to gradebooks controller which returns user ids sorted according to the user's gradebook sort preferences. closes CNVS-37608 Test Plan: 1. Create a course that has some active students, inactive students, and concluded students. Enable New Gradebook and go to the gradebook. 2. Click on the student header and select 'Inactive enrollments' and 'Concluded enrollments'. Then select 'Sort by -> A-Z'. 2. As a student in the course, hit the new endpoint to get user IDs (GET /courses/:course_id/gradebook/user_ids). Verify you get a 401 unauthorized response. 3. As a teacher in the course, hit the user_ids endpoint and verify you get a list of user IDs back. The user IDs should be ordered such that their corresponding users' names are in alpha ascending order. The list of user IDs should also include inactive and concluded students' IDs. 4. Go to the gradebook and click on the student header. Select 'Sort by -> Z-A'. 5. Hit the user_ids endpoint and verify the returned user IDs are now ordered such that their corresponding users' names are in alpha descending order. The list of user IDs should also include inactive and concluded students' IDs. 6. Go to the gradebook and click on the student column header. Deselect the 'Inactive enrollments' and 'Concluded enrollments' options. 7. Hit the user_ids endpoint and verify the returned user IDs no longer include IDs for inactive or concluded students. The IDs should still be ordered such that their corresponding users' names are in alpha descending order. 8. Go to the gradebook and click on the total grade header. Select 'Sort by Grade -> Low to High' 9. Hit the user_ids endpoint and verify the returned user IDs are ordered such that their corresponding users' current total grades are in ascending order. 10. Go to the gradebook and click on the total grade header. Select 'Sort by Grade -> High to Low' 11. Hit the user_ids endpoint and verify the returned user IDs are ordered such that their corresponding users' current total grades are in descending order. 12. In the same manner as the steps above, make sure changing the following settings in the gradebook causes the user_ids endpoint to return an array of IDs ordered according to the gradebook sort preferences: a) Assignment column header -> Sort by Grade -> Low to High b) Assignment column header -> Sort by Grade -> High to Low c) Assignment column header -> Sort by -> Missing (the user_ids endpoint should return all users with a missing submission for that assignment first) d) Assignment column header -> Sort by -> Late (the user_ids endpoint shoudl return all users with a late submission for that assignment first) e) Select a grading period and sort by total grade. The user_ids endpoint should return user IDs that are ordered such that their corresponding users' grades are in ascending or descending order for the selected grading period. * Note: Sorting by assignment group totals is not currently supported. Change-Id: I4a36aa5b82d87f49d2396bbc16e1cc56e89eba0f Reviewed-on: https://gerrit.instructure.com/116491 Reviewed-by: Shahbaz Javeed <sjaveed@instructure.com> Tested-by: Jenkins Reviewed-by: Keith T. Garner <kgarner@instructure.com> QA-Review: Anju Reddy <areddy@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2017-06-17 06:37:46 +08:00
end
def sort_by_total_grade
student_enrollments_scope.
joins("
LEFT JOIN #{Score.quoted_table_name}
ON enrollments.id = scores.enrollment_id
AND scores.grading_period_id #{grading_period_id ? "= #{grading_period_id}" : 'IS NULL'}
").
new gradebook: fake student ids always sort last closes CNVS-37752 Test Plan: 1. Create a course that has some active students, inactive students, concluded students, and a fake student. Enable New Gradebook and go to the gradebook. 2. Click on the student header and select 'Inactive enrollments' and 'Concluded enrollments'. Then select 'Sort by -> A-Z'. 3. As a teacher in the course, hit the user_ids endpoint and verify you get a list of user IDs back. The user IDs should be ordered such that their corresponding users' names are in alpha ascending order. The list of user IDs should also include inactive and concluded students' IDs. The fake student's ID should always be last. 4. Go to the gradebook and click on the student header. Select 'Sort by -> Z-A'. 5. Hit the user_ids endpoint and verify the returned user IDs are now ordered such that their corresponding users' names are in alpha descending order. The list of user IDs should also include inactive and concluded students' IDs. The fake student's ID should be last. 6. Go to the gradebook and click on the student column header. Deselect the 'Inactive enrollments' and 'Concluded enrollments' options. 7. Hit the user_ids endpoint and verify the returned user IDs no longer include IDs for inactive or concluded students. The IDs should still be ordered such that their corresponding users' names are in alpha descending order. The fake student's ID should be last. 8. Go to the gradebook and click on the total grade header. Select 'Sort by Grade -> Low to High' 9. Hit the user_ids endpoint and verify the returned user IDs are ordered such that their corresponding users' current total grades are in ascending order. The fake student's ID should be last. 10. Go to the gradebook and click on the total grade header. Select 'Sort by Grade -> High to Low' 11. Hit the user_ids endpoint and verify the returned user IDs are ordered such that their corresponding users' current total grades are in descending order. The fake student's ID should be last. 12. In the same manner as the steps above, make sure changing the following settings in the gradebook causes the user_ids endpoint to return an array of IDs ordered according to the gradebook sort preferences, with the fake student's ID sorted last: a) Assignment column header -> Sort by Grade -> Low to High b) Assignment column header -> Sort by Grade -> High to Low c) Assignment column header -> Sort by -> Missing (the user_ids endpoint should return all users with a missing submission for that assignment first) d) Assignment column header -> Sort by -> Late (the user_ids endpoint shoudl return all users with a late submission for that assignment first) e) Select a grading period and sort by total grade. The user_ids endpoint should return user IDs that are ordered such that their corresponding users' grades are in ascending or descending order for the selected grading period. 13. Conclude the course. Hit the user_ids endpoint as the teacher and verify you do not get a 401 response. * Note: Sorting by assignment group totals is not currently supported. Change-Id: I6c4b16b72e051d46cc7b7521949d5c82b92960b9 Reviewed-on: https://gerrit.instructure.com/116698 Reviewed-by: Keith T. Garner <kgarner@instructure.com> Reviewed-by: Jeremy Neander <jneander@instructure.com> Tested-by: Jenkins QA-Review: KC Naegle <knaegle@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2017-06-23 08:17:41 +08:00
order("enrollments.type = 'StudentViewEnrollment'", "scores.current_score #{sort_direction} NULLS LAST").
add user_ids endpoint to gradebooks_controller Add endpoint to gradebooks controller which returns user ids sorted according to the user's gradebook sort preferences. closes CNVS-37608 Test Plan: 1. Create a course that has some active students, inactive students, and concluded students. Enable New Gradebook and go to the gradebook. 2. Click on the student header and select 'Inactive enrollments' and 'Concluded enrollments'. Then select 'Sort by -> A-Z'. 2. As a student in the course, hit the new endpoint to get user IDs (GET /courses/:course_id/gradebook/user_ids). Verify you get a 401 unauthorized response. 3. As a teacher in the course, hit the user_ids endpoint and verify you get a list of user IDs back. The user IDs should be ordered such that their corresponding users' names are in alpha ascending order. The list of user IDs should also include inactive and concluded students' IDs. 4. Go to the gradebook and click on the student header. Select 'Sort by -> Z-A'. 5. Hit the user_ids endpoint and verify the returned user IDs are now ordered such that their corresponding users' names are in alpha descending order. The list of user IDs should also include inactive and concluded students' IDs. 6. Go to the gradebook and click on the student column header. Deselect the 'Inactive enrollments' and 'Concluded enrollments' options. 7. Hit the user_ids endpoint and verify the returned user IDs no longer include IDs for inactive or concluded students. The IDs should still be ordered such that their corresponding users' names are in alpha descending order. 8. Go to the gradebook and click on the total grade header. Select 'Sort by Grade -> Low to High' 9. Hit the user_ids endpoint and verify the returned user IDs are ordered such that their corresponding users' current total grades are in ascending order. 10. Go to the gradebook and click on the total grade header. Select 'Sort by Grade -> High to Low' 11. Hit the user_ids endpoint and verify the returned user IDs are ordered such that their corresponding users' current total grades are in descending order. 12. In the same manner as the steps above, make sure changing the following settings in the gradebook causes the user_ids endpoint to return an array of IDs ordered according to the gradebook sort preferences: a) Assignment column header -> Sort by Grade -> Low to High b) Assignment column header -> Sort by Grade -> High to Low c) Assignment column header -> Sort by -> Missing (the user_ids endpoint should return all users with a missing submission for that assignment first) d) Assignment column header -> Sort by -> Late (the user_ids endpoint shoudl return all users with a late submission for that assignment first) e) Select a grading period and sort by total grade. The user_ids endpoint should return user IDs that are ordered such that their corresponding users' grades are in ascending or descending order for the selected grading period. * Note: Sorting by assignment group totals is not currently supported. Change-Id: I4a36aa5b82d87f49d2396bbc16e1cc56e89eba0f Reviewed-on: https://gerrit.instructure.com/116491 Reviewed-by: Shahbaz Javeed <sjaveed@instructure.com> Tested-by: Jenkins Reviewed-by: Keith T. Garner <kgarner@instructure.com> QA-Review: Anju Reddy <areddy@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2017-06-17 06:37:46 +08:00
pluck(:user_id).
uniq
end
def student_enrollments_scope
workflow_states = [:active, :invited]
workflow_states << :inactive if @include_inactive
workflow_states << :completed if @include_concluded
student_enrollments = @course.enrollments.where(
workflow_state: workflow_states,
type: [:StudentEnrollment, :StudentViewEnrollment]
)
return student_enrollments.where(course_section_id: section_id) if section_id
student_enrollments
end
def students
User.where(id: student_enrollments_scope.select(:user_id))
end
def sort_direction
@direction == "ascending" ? :asc : :desc
end
def grading_period_id
return nil unless @course.grading_periods?
return nil if @selected_grading_period_id == "0"
if @selected_grading_period_id.nil? || @selected_grading_period_id == "null"
GradingPeriod.current_period_for(@course)&.id
else
@selected_grading_period_id
end
end
def section_id
return nil if @selected_section_id.nil? || @selected_section_id == "null"
@selected_section_id
end
end