diff --git a/Changelog.md b/Changelog.md index c3656c2eb4..f9e0f49e40 100644 --- a/Changelog.md +++ b/Changelog.md @@ -26,6 +26,7 @@ - Check against mtime instead of atime for clean up of git repo directories in tmp folder (#7706) - Update Model: Fix level validation checks through use of a custom validator (#7696) - Fixed test group results table to display `extra_info` field from all test groups (#7710) +- Fixed syncing grades with Canvas to not include inactive students (#7759) ### 🔧 Internal changes - Updated Github Actions CI to use cache-apt-pkgs to speed up workflow runs (#7645) diff --git a/app/helpers/lti_helper.rb b/app/helpers/lti_helper.rb index 21c8fc2cf1..751fccb51e 100644 --- a/app/helpers/lti_helper.rb +++ b/app/helpers/lti_helper.rb @@ -117,6 +117,7 @@ def get_assignment_marks(lti_deployment, assignment) released_results = assignment.released_marks .joins(grouping: [{ accepted_student_memberships: { role: { user: :lti_users } } }]) .where('lti_users.lti_client': lti_deployment.lti_client) + .where(roles: { hidden: false }) .pluck('lti_users.lti_user_id', 'results.id') result_ids = released_results.pluck(1) grades = Result.get_total_marks(result_ids) diff --git a/spec/helpers/lti_helper_spec.rb b/spec/helpers/lti_helper_spec.rb index 429d5953c9..247657e60b 100644 --- a/spec/helpers/lti_helper_spec.rb +++ b/spec/helpers/lti_helper_spec.rb @@ -496,6 +496,49 @@ expect(get_assignment_marks(lti_deployment, assessment)).not_to be_empty end end + + context 'when some students are inactive (hidden)' do + let(:student1) { create(:student, course: course) } + let(:student2) { create(:student, course: course) } + let(:assignment) { create(:assignment, course: course) } + + let!(:grouping) do + create(:grouping, assignment: assignment).tap do |g| + create(:student_membership, + grouping: g, + role: student1, + membership_status: StudentMembership::STATUSES[:accepted]) + + create(:student_membership, + grouping: g, + role: student2, + membership_status: StudentMembership::STATUSES[:accepted]) + end + end + + before do + create(:result, + grouping: grouping, + released_to_students: true, + marking_state: Result::MARKING_STATES[:complete]) + + student2.update!(hidden: true) + + [student1.user, student2.user].each do |usr| + create(:lti_user, user: usr, lti_client: lti_deployment.lti_client) + end + end + + it 'does not include hidden students in the marks hash' do + marks = get_assignment_marks(lti_deployment, assignment) + + id1 = student1.user.lti_users.first.lti_user_id + id2 = student2.user.lti_users.first.lti_user_id + + expect(marks.keys).to include(id1) + expect(marks.keys).not_to include(id2) + end + end end describe '#get_grade_entry_form_marks' do