canvas-lms/lib/gradebook_user_ids.rb

182 lines
6.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_rows_by, :section_id)
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
@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
add secondary sorting by sortable_name for user_ids closes CNVS-37707 test plan: * Create a course with at least four students, two of whom have the same name (we'll call them the twins) * Create two assignments, each with a maximum score of 10 * Go to Gradezilla * Sort the gradebook by Student Name from A-Z * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user names are in ascending alphabetical order * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Sort the gradebook by Student Name from Z-A * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user names are in descending alphabetical order * Verify that the twins' user_ids appear next to each other and are in decreasing order by user_id * Ensure all students have submissions for the first assignment * Assign grades to the students in assignment #1 and ensure both twins get the same grade * Sort the gradebook by the grade in assignment #1 (Low to High) * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user grades are in ascending order of name * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Sort the gradebook by the grade in assignment #1 (High to Low) * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user grades are in descending order * Verify that the twins' user_ids appear next to each other and are in decreasing order by user_id * Update assignment #1 to ensure three students have due dates in the past, thus making their submissions late * Sort the gradebook by "Late" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first 3 user_ids are for users with late submissions for that assignment and are in ascending order of name * Verify the last (fourth) user_id is for the student whose submission was on time * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Update assignment #1 to ensure only one student has a due date in the past, thus making only one student have a late submission. * Sort the gradebook by "Late" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first 3 user_ids are for users with timely submissions for that assignment and are in ascending order of name * Verify the last (fourth) user_id is for the student whose submission was on time * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Update assignment #2 to have a due date in the past * Ensure only one student (not one of the twins) has submitted their work for assignment #2 * Sort the gradebook by "Missing" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first 3 user_ids are for users with missing submissions for that assignment and are in ascending order of name * Verify the last (fourth) user_id is for the student who submitted their work * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Ensure both the twins now submit their work for assignment #2. This should leave just one student who is missing a submission for assignment #2 * Sort the gradebook by "Missing" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first user_id is for the student who still has not submitted their work * Verify the last 3 user_ids are for users with missing submissions for that assignment and are in ascending order of name * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id Change-Id: Id91e02fc7dc475177d1f8c09cc75015916375576 Reviewed-on: https://gerrit.instructure.com/117227 Reviewed-by: Cody Cutrer <cody@instructure.com> Reviewed-by: Keith T. Garner <kgarner@instructure.com> Tested-by: Jenkins QA-Review: Anju Reddy <areddy@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2017-06-28 06:37:54 +08:00
students.
order("#{Enrollment.table_name}.type = 'StudentViewEnrollment'").
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_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)
add secondary sorting by sortable_name for user_ids closes CNVS-37707 test plan: * Create a course with at least four students, two of whom have the same name (we'll call them the twins) * Create two assignments, each with a maximum score of 10 * Go to Gradezilla * Sort the gradebook by Student Name from A-Z * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user names are in ascending alphabetical order * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Sort the gradebook by Student Name from Z-A * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user names are in descending alphabetical order * Verify that the twins' user_ids appear next to each other and are in decreasing order by user_id * Ensure all students have submissions for the first assignment * Assign grades to the students in assignment #1 and ensure both twins get the same grade * Sort the gradebook by the grade in assignment #1 (Low to High) * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user grades are in ascending order of name * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Sort the gradebook by the grade in assignment #1 (High to Low) * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user grades are in descending order * Verify that the twins' user_ids appear next to each other and are in decreasing order by user_id * Update assignment #1 to ensure three students have due dates in the past, thus making their submissions late * Sort the gradebook by "Late" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first 3 user_ids are for users with late submissions for that assignment and are in ascending order of name * Verify the last (fourth) user_id is for the student whose submission was on time * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Update assignment #1 to ensure only one student has a due date in the past, thus making only one student have a late submission. * Sort the gradebook by "Late" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first 3 user_ids are for users with timely submissions for that assignment and are in ascending order of name * Verify the last (fourth) user_id is for the student whose submission was on time * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Update assignment #2 to have a due date in the past * Ensure only one student (not one of the twins) has submitted their work for assignment #2 * Sort the gradebook by "Missing" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first 3 user_ids are for users with missing submissions for that assignment and are in ascending order of name * Verify the last (fourth) user_id is for the student who submitted their work * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Ensure both the twins now submit their work for assignment #2. This should leave just one student who is missing a submission for assignment #2 * Sort the gradebook by "Missing" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first user_id is for the student who still has not submitted their work * Verify the last 3 user_ids are for users with missing submissions for that assignment and are in ascending order of name * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id Change-Id: Id91e02fc7dc475177d1f8c09cc75015916375576 Reviewed-on: https://gerrit.instructure.com/117227 Reviewed-by: Cody Cutrer <cody@instructure.com> Reviewed-by: Keith T. Garner <kgarner@instructure.com> Tested-by: Jenkins QA-Review: Anju Reddy <areddy@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2017-06-28 06:37:54 +08:00
students.
joins("LEFT JOIN #{Submission.quoted_table_name} ON submissions.user_id=users.id AND
submissions.workflow_state<>'deleted' AND submissions.assignment_id=#{assignment_id}").
add secondary sorting by sortable_name for user_ids closes CNVS-37707 test plan: * Create a course with at least four students, two of whom have the same name (we'll call them the twins) * Create two assignments, each with a maximum score of 10 * Go to Gradezilla * Sort the gradebook by Student Name from A-Z * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user names are in ascending alphabetical order * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Sort the gradebook by Student Name from Z-A * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user names are in descending alphabetical order * Verify that the twins' user_ids appear next to each other and are in decreasing order by user_id * Ensure all students have submissions for the first assignment * Assign grades to the students in assignment #1 and ensure both twins get the same grade * Sort the gradebook by the grade in assignment #1 (Low to High) * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user grades are in ascending order of name * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Sort the gradebook by the grade in assignment #1 (High to Low) * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user grades are in descending order * Verify that the twins' user_ids appear next to each other and are in decreasing order by user_id * Update assignment #1 to ensure three students have due dates in the past, thus making their submissions late * Sort the gradebook by "Late" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first 3 user_ids are for users with late submissions for that assignment and are in ascending order of name * Verify the last (fourth) user_id is for the student whose submission was on time * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Update assignment #1 to ensure only one student has a due date in the past, thus making only one student have a late submission. * Sort the gradebook by "Late" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first 3 user_ids are for users with timely submissions for that assignment and are in ascending order of name * Verify the last (fourth) user_id is for the student whose submission was on time * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Update assignment #2 to have a due date in the past * Ensure only one student (not one of the twins) has submitted their work for assignment #2 * Sort the gradebook by "Missing" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first 3 user_ids are for users with missing submissions for that assignment and are in ascending order of name * Verify the last (fourth) user_id is for the student who submitted their work * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Ensure both the twins now submit their work for assignment #2. This should leave just one student who is missing a submission for assignment #2 * Sort the gradebook by "Missing" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first user_id is for the student who still has not submitted their work * Verify the last 3 user_ids are for users with missing submissions for that assignment and are in ascending order of name * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id Change-Id: Id91e02fc7dc475177d1f8c09cc75015916375576 Reviewed-on: https://gerrit.instructure.com/117227 Reviewed-by: Cody Cutrer <cody@instructure.com> Reviewed-by: Keith T. Garner <kgarner@instructure.com> Tested-by: Jenkins QA-Review: Anju Reddy <areddy@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2017-06-28 06:37:54 +08:00
order("#{Enrollment.table_name}.type = 'StudentViewEnrollment'").
order("#{Submission.table_name}.score #{sort_direction} NULLS LAST").
order("#{Submission.table_name}.id IS NULL").
add secondary sorting by sortable_name for user_ids closes CNVS-37707 test plan: * Create a course with at least four students, two of whom have the same name (we'll call them the twins) * Create two assignments, each with a maximum score of 10 * Go to Gradezilla * Sort the gradebook by Student Name from A-Z * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user names are in ascending alphabetical order * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Sort the gradebook by Student Name from Z-A * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user names are in descending alphabetical order * Verify that the twins' user_ids appear next to each other and are in decreasing order by user_id * Ensure all students have submissions for the first assignment * Assign grades to the students in assignment #1 and ensure both twins get the same grade * Sort the gradebook by the grade in assignment #1 (Low to High) * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user grades are in ascending order of name * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Sort the gradebook by the grade in assignment #1 (High to Low) * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user grades are in descending order * Verify that the twins' user_ids appear next to each other and are in decreasing order by user_id * Update assignment #1 to ensure three students have due dates in the past, thus making their submissions late * Sort the gradebook by "Late" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first 3 user_ids are for users with late submissions for that assignment and are in ascending order of name * Verify the last (fourth) user_id is for the student whose submission was on time * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Update assignment #1 to ensure only one student has a due date in the past, thus making only one student have a late submission. * Sort the gradebook by "Late" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first 3 user_ids are for users with timely submissions for that assignment and are in ascending order of name * Verify the last (fourth) user_id is for the student whose submission was on time * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Update assignment #2 to have a due date in the past * Ensure only one student (not one of the twins) has submitted their work for assignment #2 * Sort the gradebook by "Missing" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first 3 user_ids are for users with missing submissions for that assignment and are in ascending order of name * Verify the last (fourth) user_id is for the student who submitted their work * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Ensure both the twins now submit their work for assignment #2. This should leave just one student who is missing a submission for assignment #2 * Sort the gradebook by "Missing" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first user_id is for the student who still has not submitted their work * Verify the last 3 user_ids are for users with missing submissions for that assignment and are in ascending order of name * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id Change-Id: Id91e02fc7dc475177d1f8c09cc75015916375576 Reviewed-on: https://gerrit.instructure.com/117227 Reviewed-by: Cody Cutrer <cody@instructure.com> Reviewed-by: Keith T. Garner <kgarner@instructure.com> Tested-by: Jenkins QA-Review: Anju Reddy <areddy@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2017-06-28 06:37:54 +08:00
order_by_sortable_name(direction: @direction.to_sym).
pluck(:id).
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
uniq
end
def sort_by_assignment_missing(assignment_id)
add secondary sorting by sortable_name for user_ids closes CNVS-37707 test plan: * Create a course with at least four students, two of whom have the same name (we'll call them the twins) * Create two assignments, each with a maximum score of 10 * Go to Gradezilla * Sort the gradebook by Student Name from A-Z * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user names are in ascending alphabetical order * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Sort the gradebook by Student Name from Z-A * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user names are in descending alphabetical order * Verify that the twins' user_ids appear next to each other and are in decreasing order by user_id * Ensure all students have submissions for the first assignment * Assign grades to the students in assignment #1 and ensure both twins get the same grade * Sort the gradebook by the grade in assignment #1 (Low to High) * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user grades are in ascending order of name * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Sort the gradebook by the grade in assignment #1 (High to Low) * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user grades are in descending order * Verify that the twins' user_ids appear next to each other and are in decreasing order by user_id * Update assignment #1 to ensure three students have due dates in the past, thus making their submissions late * Sort the gradebook by "Late" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first 3 user_ids are for users with late submissions for that assignment and are in ascending order of name * Verify the last (fourth) user_id is for the student whose submission was on time * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Update assignment #1 to ensure only one student has a due date in the past, thus making only one student have a late submission. * Sort the gradebook by "Late" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first 3 user_ids are for users with timely submissions for that assignment and are in ascending order of name * Verify the last (fourth) user_id is for the student whose submission was on time * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Update assignment #2 to have a due date in the past * Ensure only one student (not one of the twins) has submitted their work for assignment #2 * Sort the gradebook by "Missing" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first 3 user_ids are for users with missing submissions for that assignment and are in ascending order of name * Verify the last (fourth) user_id is for the student who submitted their work * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Ensure both the twins now submit their work for assignment #2. This should leave just one student who is missing a submission for assignment #2 * Sort the gradebook by "Missing" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first user_id is for the student who still has not submitted their work * Verify the last 3 user_ids are for users with missing submissions for that assignment and are in ascending order of name * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id Change-Id: Id91e02fc7dc475177d1f8c09cc75015916375576 Reviewed-on: https://gerrit.instructure.com/117227 Reviewed-by: Cody Cutrer <cody@instructure.com> Reviewed-by: Keith T. Garner <kgarner@instructure.com> Tested-by: Jenkins QA-Review: Anju Reddy <areddy@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2017-06-28 06:37:54 +08:00
sort_user_ids(Submission.missing.where(assignment_id: assignment_id))
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)
add secondary sorting by sortable_name for user_ids closes CNVS-37707 test plan: * Create a course with at least four students, two of whom have the same name (we'll call them the twins) * Create two assignments, each with a maximum score of 10 * Go to Gradezilla * Sort the gradebook by Student Name from A-Z * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user names are in ascending alphabetical order * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Sort the gradebook by Student Name from Z-A * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user names are in descending alphabetical order * Verify that the twins' user_ids appear next to each other and are in decreasing order by user_id * Ensure all students have submissions for the first assignment * Assign grades to the students in assignment #1 and ensure both twins get the same grade * Sort the gradebook by the grade in assignment #1 (Low to High) * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user grades are in ascending order of name * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Sort the gradebook by the grade in assignment #1 (High to Low) * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user grades are in descending order * Verify that the twins' user_ids appear next to each other and are in decreasing order by user_id * Update assignment #1 to ensure three students have due dates in the past, thus making their submissions late * Sort the gradebook by "Late" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first 3 user_ids are for users with late submissions for that assignment and are in ascending order of name * Verify the last (fourth) user_id is for the student whose submission was on time * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Update assignment #1 to ensure only one student has a due date in the past, thus making only one student have a late submission. * Sort the gradebook by "Late" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first 3 user_ids are for users with timely submissions for that assignment and are in ascending order of name * Verify the last (fourth) user_id is for the student whose submission was on time * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Update assignment #2 to have a due date in the past * Ensure only one student (not one of the twins) has submitted their work for assignment #2 * Sort the gradebook by "Missing" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first 3 user_ids are for users with missing submissions for that assignment and are in ascending order of name * Verify the last (fourth) user_id is for the student who submitted their work * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Ensure both the twins now submit their work for assignment #2. This should leave just one student who is missing a submission for assignment #2 * Sort the gradebook by "Missing" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first user_id is for the student who still has not submitted their work * Verify the last 3 user_ids are for users with missing submissions for that assignment and are in ascending order of name * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id Change-Id: Id91e02fc7dc475177d1f8c09cc75015916375576 Reviewed-on: https://gerrit.instructure.com/117227 Reviewed-by: Cody Cutrer <cody@instructure.com> Reviewed-by: Keith T. Garner <kgarner@instructure.com> Tested-by: Jenkins QA-Review: Anju Reddy <areddy@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2017-06-28 06:37:54 +08:00
sort_user_ids(Submission.late.where(assignment_id: assignment_id))
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
score_scope = grading_period_id ? "scores.grading_period_id=#{grading_period_id}" : "scores.course_score IS TRUE"
# In this query we need to jump through enrollments to go see if
# there are scores for the user. Because of some AR internal
# stuff, if we did students.joins("LEFT JOIN scores ON
# enrollments.id=scores.enrollment_id AND ...") as you'd expect,
# it plops the new join before the enrollments join and the
# database gets angry because it doesn't know what what this
# "enrollments" we're querying against is. Because of this, we
# have to WET up the method and hand do the enrollment join
# here. Without doing the score conditions in the join, we lose
# data, so it has to be this way... For example, we might lose
# concluded enrollments who don't have a Score.
#
# That is a super long way of saying, make sure this stays in sync
# with what happens in the students method below in reguards to
# enrollments and enrollments scoping.
User.joins("LEFT JOIN #{Enrollment.quoted_table_name} on users.id=enrollments.user_id
LEFT JOIN #{Score.quoted_table_name} ON scores.enrollment_id=enrollments.id AND
scores.workflow_state='active' AND #{score_scope}").
merge(student_enrollments_scope).
add secondary sorting by sortable_name for user_ids closes CNVS-37707 test plan: * Create a course with at least four students, two of whom have the same name (we'll call them the twins) * Create two assignments, each with a maximum score of 10 * Go to Gradezilla * Sort the gradebook by Student Name from A-Z * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user names are in ascending alphabetical order * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Sort the gradebook by Student Name from Z-A * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user names are in descending alphabetical order * Verify that the twins' user_ids appear next to each other and are in decreasing order by user_id * Ensure all students have submissions for the first assignment * Assign grades to the students in assignment #1 and ensure both twins get the same grade * Sort the gradebook by the grade in assignment #1 (Low to High) * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user grades are in ascending order of name * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Sort the gradebook by the grade in assignment #1 (High to Low) * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user grades are in descending order * Verify that the twins' user_ids appear next to each other and are in decreasing order by user_id * Update assignment #1 to ensure three students have due dates in the past, thus making their submissions late * Sort the gradebook by "Late" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first 3 user_ids are for users with late submissions for that assignment and are in ascending order of name * Verify the last (fourth) user_id is for the student whose submission was on time * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Update assignment #1 to ensure only one student has a due date in the past, thus making only one student have a late submission. * Sort the gradebook by "Late" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first 3 user_ids are for users with timely submissions for that assignment and are in ascending order of name * Verify the last (fourth) user_id is for the student whose submission was on time * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Update assignment #2 to have a due date in the past * Ensure only one student (not one of the twins) has submitted their work for assignment #2 * Sort the gradebook by "Missing" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first 3 user_ids are for users with missing submissions for that assignment and are in ascending order of name * Verify the last (fourth) user_id is for the student who submitted their work * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Ensure both the twins now submit their work for assignment #2. This should leave just one student who is missing a submission for assignment #2 * Sort the gradebook by "Missing" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first user_id is for the student who still has not submitted their work * Verify the last 3 user_ids are for users with missing submissions for that assignment and are in ascending order of name * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id Change-Id: Id91e02fc7dc475177d1f8c09cc75015916375576 Reviewed-on: https://gerrit.instructure.com/117227 Reviewed-by: Cody Cutrer <cody@instructure.com> Reviewed-by: Keith T. Garner <kgarner@instructure.com> Tested-by: Jenkins QA-Review: Anju Reddy <areddy@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2017-06-28 06:37:54 +08:00
order("#{Enrollment.table_name}.type = 'StudentViewEnrollment'").
order("#{Score.table_name}.unposted_current_score #{sort_direction} NULLS LAST").
add secondary sorting by sortable_name for user_ids closes CNVS-37707 test plan: * Create a course with at least four students, two of whom have the same name (we'll call them the twins) * Create two assignments, each with a maximum score of 10 * Go to Gradezilla * Sort the gradebook by Student Name from A-Z * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user names are in ascending alphabetical order * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Sort the gradebook by Student Name from Z-A * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user names are in descending alphabetical order * Verify that the twins' user_ids appear next to each other and are in decreasing order by user_id * Ensure all students have submissions for the first assignment * Assign grades to the students in assignment #1 and ensure both twins get the same grade * Sort the gradebook by the grade in assignment #1 (Low to High) * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user grades are in ascending order of name * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Sort the gradebook by the grade in assignment #1 (High to Low) * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user grades are in descending order * Verify that the twins' user_ids appear next to each other and are in decreasing order by user_id * Update assignment #1 to ensure three students have due dates in the past, thus making their submissions late * Sort the gradebook by "Late" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first 3 user_ids are for users with late submissions for that assignment and are in ascending order of name * Verify the last (fourth) user_id is for the student whose submission was on time * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Update assignment #1 to ensure only one student has a due date in the past, thus making only one student have a late submission. * Sort the gradebook by "Late" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first 3 user_ids are for users with timely submissions for that assignment and are in ascending order of name * Verify the last (fourth) user_id is for the student whose submission was on time * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Update assignment #2 to have a due date in the past * Ensure only one student (not one of the twins) has submitted their work for assignment #2 * Sort the gradebook by "Missing" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first 3 user_ids are for users with missing submissions for that assignment and are in ascending order of name * Verify the last (fourth) user_id is for the student who submitted their work * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Ensure both the twins now submit their work for assignment #2. This should leave just one student who is missing a submission for assignment #2 * Sort the gradebook by "Missing" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first user_id is for the student who still has not submitted their work * Verify the last 3 user_ids are for users with missing submissions for that assignment and are in ascending order of name * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id Change-Id: Id91e02fc7dc475177d1f8c09cc75015916375576 Reviewed-on: https://gerrit.instructure.com/117227 Reviewed-by: Cody Cutrer <cody@instructure.com> Reviewed-by: Keith T. Garner <kgarner@instructure.com> Tested-by: Jenkins QA-Review: Anju Reddy <areddy@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2017-06-28 06:37:54 +08:00
order_by_sortable_name(direction: @direction.to_sym).
pluck(:id).uniq
end
def all_user_ids
@all_user_ids ||= students.order_by_sortable_name(direction: @direction.to_sym).pluck(:id).uniq
end
def all_user_ids_index
@all_user_ids_index ||= index_user_ids(all_user_ids)
end
def fake_user_ids
student_enrollments_scope.where(type: "StudentViewEnrollment").pluck(:user_id).uniq
end
def sorted_fake_user_ids
@sorted_fake_user_ids ||= sort_using_index(fake_user_ids, all_user_ids_index)
end
def sorted_real_user_ids
@sorted_real_user_ids ||= sort_using_index(all_user_ids - sorted_fake_user_ids, all_user_ids_index)
end
def real_user_ids_from_submissions(submissions)
submissions.where(user_id: sorted_real_user_ids).pluck(:user_id)
end
def sorted_real_user_ids_from_submissions(submissions)
sort_using_index(real_user_ids_from_submissions(submissions), all_user_ids_index)
end
def sort_user_ids(submissions)
sorted_real_user_ids_from_submissions(submissions).concat(sorted_real_user_ids, sorted_fake_user_ids).uniq
end
def index_user_ids(user_ids)
user_ids_index = {}
# Traverse the array once and cache all indexes so we don't incur traversal costs at the end
user_ids.each_with_index { |item, idx| user_ids_index[item] = idx }
user_ids_index
end
def sort_using_index(user_ids, user_ids_index)
user_ids.sort_by { |item| user_ids_index[item] }
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 student_enrollments_scope
workflow_states = [:active, :invited]
workflow_states << :inactive if @include_inactive
workflow_states << :completed if @include_concluded || @course.concluded?
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
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
add secondary sorting by sortable_name for user_ids closes CNVS-37707 test plan: * Create a course with at least four students, two of whom have the same name (we'll call them the twins) * Create two assignments, each with a maximum score of 10 * Go to Gradezilla * Sort the gradebook by Student Name from A-Z * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user names are in ascending alphabetical order * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Sort the gradebook by Student Name from Z-A * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user names are in descending alphabetical order * Verify that the twins' user_ids appear next to each other and are in decreasing order by user_id * Ensure all students have submissions for the first assignment * Assign grades to the students in assignment #1 and ensure both twins get the same grade * Sort the gradebook by the grade in assignment #1 (Low to High) * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user grades are in ascending order of name * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Sort the gradebook by the grade in assignment #1 (High to Low) * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify that user_ids are returned in an order where the corresponding user grades are in descending order * Verify that the twins' user_ids appear next to each other and are in decreasing order by user_id * Update assignment #1 to ensure three students have due dates in the past, thus making their submissions late * Sort the gradebook by "Late" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first 3 user_ids are for users with late submissions for that assignment and are in ascending order of name * Verify the last (fourth) user_id is for the student whose submission was on time * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Update assignment #1 to ensure only one student has a due date in the past, thus making only one student have a late submission. * Sort the gradebook by "Late" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first 3 user_ids are for users with timely submissions for that assignment and are in ascending order of name * Verify the last (fourth) user_id is for the student whose submission was on time * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Update assignment #2 to have a due date in the past * Ensure only one student (not one of the twins) has submitted their work for assignment #2 * Sort the gradebook by "Missing" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first 3 user_ids are for users with missing submissions for that assignment and are in ascending order of name * Verify the last (fourth) user_id is for the student who submitted their work * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id * Ensure both the twins now submit their work for assignment #2. This should leave just one student who is missing a submission for assignment #2 * Sort the gradebook by "Missing" * As a teacher hit the user_ids API endpoint (GET /courses/:course_id/gradebook/user_ids) * Verify the first user_id is for the student who still has not submitted their work * Verify the last 3 user_ids are for users with missing submissions for that assignment and are in ascending order of name * Verify that the twins' user_ids appear next to each other and are in increasing order by user_id Change-Id: Id91e02fc7dc475177d1f8c09cc75015916375576 Reviewed-on: https://gerrit.instructure.com/117227 Reviewed-by: Cody Cutrer <cody@instructure.com> Reviewed-by: Keith T. Garner <kgarner@instructure.com> Tested-by: Jenkins QA-Review: Anju Reddy <areddy@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2017-06-28 06:37:54 +08:00
User.left_joins(:enrollments).merge(student_enrollments_scope)
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_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" || @section_section_id == "0"
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
@selected_section_id
end
end