exclude deleted courses for users invited enrollments
fixes CNVS-34408 test plan - invite user into course - enrollment workflow_state should be invited or user should have an invite for course - delete course via sis import - invitation should not be visiable to user - enrollment workflow_state should still be invited Change-Id: I48dac59b94770f779ea69ffd21a19802a8d59e6d Reviewed-on: https://gerrit.instructure.com/99861 Reviewed-by: Simon Williams <simon@instructure.com> Tested-by: Jenkins QA-Review: Steven Shepherd <sshepherd@instructure.com> Product-Review: Rob Orton <rob@instructure.com>
This commit is contained in:
parent
e72202bb77
commit
66982308e7
|
@ -319,7 +319,7 @@ class User < ActiveRecord::Base
|
|||
after_save :self_enroll_if_necessary
|
||||
|
||||
def courses_for_enrollments(enrollment_scope)
|
||||
Course.joins(:all_enrollments).merge(enrollment_scope.except(:joins)).uniq
|
||||
Course.active.joins(:all_enrollments).merge(enrollment_scope.except(:joins)).uniq
|
||||
end
|
||||
|
||||
def courses
|
||||
|
@ -1720,10 +1720,13 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
|
||||
if association == :current_and_invited_courses
|
||||
if enrollment_uuid && pending_course = Course.
|
||||
select("courses.*, enrollments.type AS primary_enrollment, #{Enrollment.type_rank_sql} AS primary_enrollment_rank, enrollments.workflow_state AS primary_enrollment_state, enrollments.created_at AS primary_enrollment_date").
|
||||
if enrollment_uuid && (pending_course = Course.active.
|
||||
select("courses.*, enrollments.type AS primary_enrollment,
|
||||
#{Enrollment.type_rank_sql} AS primary_enrollment_rank,
|
||||
enrollments.workflow_state AS primary_enrollment_state,
|
||||
enrollments.created_at AS primary_enrollment_date").
|
||||
joins(:enrollments).
|
||||
where(:enrollments => { :uuid => enrollment_uuid, :workflow_state => 'invited' }).first
|
||||
where(enrollments: { uuid: enrollment_uuid, workflow_state: 'invited' }).first)
|
||||
res << pending_course
|
||||
res.uniq!
|
||||
end
|
||||
|
@ -1791,7 +1794,8 @@ class User < ActiveRecord::Base
|
|||
|
||||
def cached_invitations(opts={})
|
||||
enrollments = Rails.cache.fetch([self, 'invited_enrollments', ApplicationController.region ].cache_key) do
|
||||
self.enrollments.shard(in_region_associated_shards).invited_by_date.to_a
|
||||
self.enrollments.shard(in_region_associated_shards).invited_by_date.
|
||||
joins(:course).where.not(courses: {workflow_state: 'deleted'}).to_a
|
||||
end
|
||||
if opts[:include_enrollment_uuid] && !enrollments.find { |e| e.uuid == opts[:include_enrollment_uuid] } &&
|
||||
(pending_enrollment = Enrollment.invited_by_date.where(uuid: opts[:include_enrollment_uuid]).first)
|
||||
|
|
|
@ -566,6 +566,20 @@ describe User do
|
|||
expect(user2.courses_with_primary_enrollment.map(&:id)).to eq [c1.id, c2.id]
|
||||
end
|
||||
|
||||
it 'filters out enrollments for deleted courses' do
|
||||
student_in_course(active_course: true)
|
||||
expect(@user.current_and_invited_courses.count).to eq 1
|
||||
Course.where(id: @course).update_all(workflow_state: 'deleted')
|
||||
expect(@user.current_and_invited_courses.count).to eq 0
|
||||
end
|
||||
|
||||
it 'excludes deleted courses in cached_invitations' do
|
||||
student_in_course(active_course: true)
|
||||
expect(@user.cached_invitations.count).to eq 1
|
||||
Course.where(id: @course).update_all(workflow_state: 'deleted')
|
||||
expect(@user.cached_invitations.count).to eq 0
|
||||
end
|
||||
|
||||
describe 'with cross sharding' do
|
||||
specs_require_sharding
|
||||
|
||||
|
|
Loading…
Reference in New Issue