DA - remove deleted assignments from sql view

fixes CNVS-15511

test plan:
  - turn DA off and make an assignment then delete the assignment
  - note the assignment's id
  - open the rails console and run this
    - "AssignmentStudentVisibility.where(assignment_id: XXXXX)"
    - instead of XXXXX, you should write the assignment's id
    - the result of that command should be an empry array => []

Change-Id: I2f09560ce46bd4682e9bf671b4c116508a6f4b49
Reviewed-on: https://gerrit.instructure.com/41114
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Simon Williams <simon@instructure.com>
QA-Review: Amber Taniuchi <amber@instructure.com>
Product-Review: Simon Williams <simon@instructure.com>
This commit is contained in:
Michael Nomitch 2014-09-15 12:50:47 -05:00 committed by Mike Nomitch
parent c3edccbf07
commit a34b935850
2 changed files with 92 additions and 0 deletions

View File

@ -0,0 +1,88 @@
class RemoveDeletedFromAssignmentStudentVisibilityView < ActiveRecord::Migration
tag :predeploy
def up
self.connection.execute "DROP VIEW assignment_student_visibilities;"
self.connection.execute %Q(CREATE VIEW assignment_student_visibilities AS
SELECT DISTINCT a.id as assignment_id,
e.user_id as user_id,
c.id as course_id
FROM assignments a
JOIN courses c
ON a.context_id = c.id
AND a.context_type = 'Course'
JOIN enrollments e
ON e.course_id = c.id
AND e.type IN ('StudentEnrollment', 'StudentViewEnrollment')
AND e.workflow_state != 'deleted'
JOIN course_sections cs
ON cs.course_id = c.id
AND e.course_section_id = cs.id
LEFT JOIN assignment_overrides ao
ON ao.assignment_id = a.id
AND ao.workflow_state = 'active'
AND ao.set_type = 'CourseSection'
AND ao.set_id = cs.id
LEFT JOIN submissions s
ON s.user_id = e.user_id
AND s.assignment_id = a.id
AND s.score IS NOT NULL
WHERE a.workflow_state NOT IN ('deleted','unpublished')
AND(
( a.only_visible_to_overrides = 'true' AND (ao.id IS NOT NULL OR s.id IS NOT NULL))
OR (COALESCE(a.only_visible_to_overrides, 'false') = 'false')
)
)
end
def down
self.connection.execute "DROP VIEW assignment_student_visibilities;"
self.connection.execute %Q(CREATE VIEW assignment_student_visibilities AS
SELECT DISTINCT a.id as assignment_id,
e.user_id as user_id,
c.id as course_id
FROM assignments a
JOIN courses c
ON a.context_id = c.id
AND a.context_type = 'Course'
JOIN enrollments e
ON e.course_id = c.id
AND e.type IN ('StudentEnrollment', 'StudentViewEnrollment')
AND e.workflow_state != 'deleted'
JOIN course_sections cs
ON cs.course_id = c.id
AND e.course_section_id = cs.id
LEFT JOIN assignment_overrides ao
ON ao.assignment_id = a.id
AND ao.workflow_state = 'active'
AND ao.set_type = 'CourseSection'
AND ao.set_id = cs.id
LEFT JOIN submissions s
ON s.user_id = e.user_id
AND s.assignment_id = a.id
AND s.score IS NOT NULL
WHERE a.workflow_state NOT IN ('deleted','unpublished')
AND ( a.only_visible_to_overrides = 'true'
AND (ao.id IS NOT NULL
OR s.id IS NOT NULL
)
) OR (
COALESCE(a.only_visible_to_overrides, 'false') = 'false'
)
)
end
end

View File

@ -215,6 +215,10 @@ describe "differentiated_assignments" do
it "should show the assignment to the user" do
ensure_user_sees_assignment
end
it "should not show deleted assignments" do
@assignment.destroy
ensure_user_does_not_see_assignment
end
end
context "user in section with override" do
before{enroller_user_in_section(@section_foo)}