Account for unassign_item in ASV/QSV views
closes LF-681 closes LF-682 flag=differentiated_modules test plan: - with the flag on - have an assignment/quiz with different types of overrides - the only overrides with unassign_item as true are section and ADHOC overrides - run assignment.assignment_student_visibilities or quiz.quiz_student_visibilities with different scenarios - assignment has an adhoc unassigned override - assignment has a section unassigned override - assignment has an assigned adhoc override with an unassigned section override (student should still have visibility) - assignment has an unassigned adhoc override with an assigned section override (student should not have visibility) - test out including the assignment in a module with overrides as well (the module itself should not have unassigned overrides) Change-Id: Ia2e62b3dac069c37c18babc9c5dbae34ca11c52b Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/333103 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Migration-Review: Aaron Ogata <aogata@instructure.com> Migration-Review: Jackson Howe <jackson.howe@instructure.com> Product-Review: Sarah Gerard <sarah.gerard@instructure.com> Reviewed-by: Jackson Howe <jackson.howe@instructure.com> QA-Review: Jackson Howe <jackson.howe@instructure.com>
This commit is contained in:
parent
0b5ac4ffc4
commit
9c82c86926
|
@ -0,0 +1,30 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
#
|
||||
# Copyright (C) 2023 - 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 UnassignOverridesInAsvQsv < ActiveRecord::Migration[7.0]
|
||||
tag :postdeploy
|
||||
def up
|
||||
connection.execute(MigrationHelpers::StudentVisibilities::StudentVisibilitiesV4.view(connection.quote_table_name("assignment_student_visibilities_v2"), Assignment.quoted_table_name, is_assignment: true))
|
||||
connection.execute(MigrationHelpers::StudentVisibilities::StudentVisibilitiesV4.view(connection.quote_table_name("quiz_student_visibilities_v2"), Quizzes::Quiz.quoted_table_name))
|
||||
end
|
||||
|
||||
def down
|
||||
connection.execute(MigrationHelpers::StudentVisibilities::StudentVisibilitiesV3.view(connection.quote_table_name("assignment_student_visibilities_v2"), Assignment.quoted_table_name, is_assignment: true))
|
||||
connection.execute(MigrationHelpers::StudentVisibilities::StudentVisibilitiesV3.view(connection.quote_table_name("quiz_student_visibilities_v2"), Quizzes::Quiz.quoted_table_name))
|
||||
end
|
||||
end
|
|
@ -0,0 +1,217 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
#
|
||||
# Copyright (C) 2023 - 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/>.
|
||||
|
||||
module MigrationHelpers::StudentVisibilities::StudentVisibilitiesV4
|
||||
def self.view(view_name, table_name, is_assignment: false)
|
||||
<<~SQL.squish
|
||||
/* if only_visible_to_overrides is false, or there's related
|
||||
modules with no overrides, then everyone can see it */
|
||||
CREATE OR REPLACE VIEW #{view_name} AS
|
||||
SELECT DISTINCT a.id as #{quiz_or_assignment(is_assignment)},
|
||||
e.user_id as user_id,
|
||||
e.course_id as course_id
|
||||
FROM #{table_name} a
|
||||
JOIN #{Enrollment.quoted_table_name} e
|
||||
ON e.course_id = a.context_id
|
||||
AND a.context_type = 'Course'
|
||||
AND e.type IN ('StudentEnrollment', 'StudentViewEnrollment')
|
||||
AND e.workflow_state NOT IN ('deleted', 'rejected', 'inactive')
|
||||
LEFT JOIN #{ContentTag.quoted_table_name} t
|
||||
ON t.content_id = a.id
|
||||
AND t.content_type = #{is_assignment ? "'Assignment'" : "'Quizzes::Quiz'"}
|
||||
AND t.tag_type='context_module'
|
||||
AND t.workflow_state<>'deleted'
|
||||
LEFT JOIN #{ContextModule.quoted_table_name} m
|
||||
ON m.id = t.context_module_id
|
||||
AND m.workflow_state<>'deleted'
|
||||
LEFT JOIN #{AssignmentOverride.quoted_table_name} ao
|
||||
ON m.id = ao.context_module_id
|
||||
AND ao.workflow_state = 'active'
|
||||
WHERE a.workflow_state NOT IN ('deleted','unpublished')
|
||||
AND COALESCE(a.only_visible_to_overrides, 'false') = 'false'
|
||||
AND (m.id IS NULL OR (ao.context_module_id IS NULL AND m.workflow_state = 'active'))
|
||||
|
||||
UNION
|
||||
|
||||
#{group_overrides(is_assignment)}
|
||||
|
||||
/* section overrides and related module section overrides */
|
||||
SELECT DISTINCT a.id as #{quiz_or_assignment(is_assignment)},
|
||||
e.user_id as user_id,
|
||||
e.course_id as course_id
|
||||
FROM #{table_name} a
|
||||
JOIN #{Enrollment.quoted_table_name} e
|
||||
ON e.course_id = a.context_id
|
||||
AND a.context_type = 'Course'
|
||||
AND e.type IN ('StudentEnrollment', 'StudentViewEnrollment')
|
||||
AND e.workflow_state NOT IN ('deleted', 'rejected', 'inactive')
|
||||
LEFT JOIN #{ContentTag.quoted_table_name} t
|
||||
ON t.content_id = a.id
|
||||
AND t.tag_type='context_module'
|
||||
AND t.workflow_state<>'deleted'
|
||||
AND t.content_type = #{is_assignment ? "'Assignment'" : "'Quizzes::Quiz'"}
|
||||
LEFT JOIN #{ContextModule.quoted_table_name} m
|
||||
ON m.id = t.context_module_id
|
||||
AND m.workflow_state = 'active'
|
||||
INNER JOIN #{AssignmentOverride.quoted_table_name} ao
|
||||
ON e.course_section_id = ao.set_id
|
||||
AND ao.set_type = 'CourseSection'
|
||||
AND (m.id = ao.context_module_id OR ao.#{quiz_or_assignment(is_assignment)} = a.id)
|
||||
AND ao.workflow_state = 'active'
|
||||
WHERE a.workflow_state NOT IN ('deleted','unpublished')
|
||||
AND (a.only_visible_to_overrides = 'true' OR m.id IS NOT NULL)
|
||||
AND ao.unassign_item = FALSE
|
||||
|
||||
EXCEPT
|
||||
|
||||
/* remove students with unassigned section overrides */
|
||||
SELECT DISTINCT a.id as #{quiz_or_assignment(is_assignment)},
|
||||
e.user_id as user_id,
|
||||
e.course_id as course_id
|
||||
FROM #{table_name} a
|
||||
JOIN #{Enrollment.quoted_table_name} e
|
||||
ON e.course_id = a.context_id
|
||||
AND a.context_type = 'Course'
|
||||
AND e.type IN ('StudentEnrollment', 'StudentViewEnrollment')
|
||||
AND e.workflow_state NOT IN ('deleted', 'rejected', 'inactive')
|
||||
INNER JOIN #{AssignmentOverride.quoted_table_name} ao
|
||||
ON e.course_section_id = ao.set_id
|
||||
AND ao.set_type = 'CourseSection'
|
||||
AND ao.#{quiz_or_assignment(is_assignment)} = a.id
|
||||
AND ao.workflow_state = 'active'
|
||||
WHERE a.workflow_state NOT IN ('deleted','unpublished')
|
||||
AND ao.unassign_item = TRUE
|
||||
|
||||
UNION
|
||||
|
||||
/* ADHOC overrides and related module ADHOC overrides */
|
||||
SELECT DISTINCT a.id as #{quiz_or_assignment(is_assignment)},
|
||||
e.user_id as user_id,
|
||||
e.course_id as course_id
|
||||
FROM #{table_name} a
|
||||
JOIN #{Enrollment.quoted_table_name} e
|
||||
ON e.course_id = a.context_id
|
||||
AND a.context_type = 'Course'
|
||||
AND e.type IN ('StudentEnrollment', 'StudentViewEnrollment')
|
||||
AND e.workflow_state NOT IN ('deleted', 'rejected', 'inactive')
|
||||
LEFT JOIN #{ContentTag.quoted_table_name} t
|
||||
ON t.content_id = a.id
|
||||
AND t.tag_type='context_module'
|
||||
AND t.workflow_state<>'deleted'
|
||||
AND t.content_type = #{is_assignment ? "'Assignment'" : "'Quizzes::Quiz'"}
|
||||
LEFT JOIN #{ContextModule.quoted_table_name} m
|
||||
ON m.id = t.context_module_id
|
||||
AND m.workflow_state = 'active'
|
||||
INNER JOIN #{AssignmentOverride.quoted_table_name} ao
|
||||
ON (m.id = ao.context_module_id OR a.id = ao.#{quiz_or_assignment(is_assignment)})
|
||||
AND ao.set_type = 'ADHOC'
|
||||
AND ao.workflow_state = 'active'
|
||||
INNER JOIN #{AssignmentOverrideStudent.quoted_table_name} aos
|
||||
ON ao.id = aos.assignment_override_id
|
||||
AND aos.user_id = e.user_id
|
||||
AND aos.workflow_state <> 'deleted'
|
||||
WHERE a.workflow_state NOT IN ('deleted','unpublished')
|
||||
AND (a.only_visible_to_overrides = 'true' OR m.id IS NOT NULL)
|
||||
AND ao.unassign_item = FALSE
|
||||
|
||||
EXCEPT
|
||||
|
||||
/* remove students with unassigned ADHOC overrides */
|
||||
SELECT DISTINCT a.id as #{quiz_or_assignment(is_assignment)},
|
||||
e.user_id as user_id,
|
||||
e.course_id as course_id
|
||||
FROM #{table_name} a
|
||||
JOIN #{Enrollment.quoted_table_name} e
|
||||
ON e.course_id = a.context_id
|
||||
AND a.context_type = 'Course'
|
||||
AND e.type IN ('StudentEnrollment', 'StudentViewEnrollment')
|
||||
AND e.workflow_state NOT IN ('deleted', 'rejected', 'inactive')
|
||||
INNER JOIN #{AssignmentOverride.quoted_table_name} ao
|
||||
ON a.id = ao.#{quiz_or_assignment(is_assignment)}
|
||||
AND ao.set_type = 'ADHOC'
|
||||
AND ao.workflow_state = 'active'
|
||||
INNER JOIN #{AssignmentOverrideStudent.quoted_table_name} aos
|
||||
ON ao.id = aos.assignment_override_id
|
||||
AND aos.user_id = e.user_id
|
||||
AND aos.workflow_state <> 'deleted'
|
||||
WHERE a.workflow_state NOT IN ('deleted','unpublished')
|
||||
AND ao.unassign_item = TRUE
|
||||
|
||||
UNION
|
||||
|
||||
/* course overrides */
|
||||
SELECT DISTINCT a.id as #{quiz_or_assignment(is_assignment)},
|
||||
e.user_id as user_id,
|
||||
e.course_id as course_id
|
||||
FROM #{table_name} a
|
||||
JOIN #{Enrollment.quoted_table_name} e
|
||||
ON e.course_id = a.context_id
|
||||
AND a.context_type = 'Course'
|
||||
AND e.type IN ('StudentEnrollment', 'StudentViewEnrollment')
|
||||
AND e.workflow_state NOT IN ('deleted', 'rejected', 'inactive')
|
||||
INNER JOIN #{AssignmentOverride.quoted_table_name} ao
|
||||
ON e.course_id = ao.set_id
|
||||
AND ao.set_type = 'Course'
|
||||
AND a.id = ao.#{quiz_or_assignment(is_assignment)}
|
||||
WHERE a.workflow_state NOT IN ('deleted','unpublished')
|
||||
AND ao.workflow_state = 'active'
|
||||
|
||||
SQL
|
||||
end
|
||||
|
||||
def self.group_overrides(is_assignment)
|
||||
if is_assignment
|
||||
"/* group overrides */
|
||||
SELECT DISTINCT a.id as assignment_id,
|
||||
e.user_id as user_id,
|
||||
e.course_id as course_id
|
||||
FROM #{Assignment.quoted_table_name} a
|
||||
JOIN #{Enrollment.quoted_table_name} e
|
||||
ON e.course_id = a.context_id
|
||||
AND a.context_type = 'Course'
|
||||
AND e.type IN ('StudentEnrollment', 'StudentViewEnrollment')
|
||||
AND e.workflow_state NOT IN ('deleted', 'rejected', 'inactive')
|
||||
INNER JOIN #{AssignmentOverride.quoted_table_name} ao
|
||||
ON a.id = ao.assignment_id
|
||||
AND ao.set_type = 'Group'
|
||||
INNER JOIN #{Group.quoted_table_name} g
|
||||
ON g.id = ao.set_id
|
||||
INNER JOIN #{GroupMembership.quoted_table_name} gm
|
||||
ON gm.group_id = g.id
|
||||
AND gm.user_id = e.user_id
|
||||
WHERE gm.workflow_state <> 'deleted'
|
||||
AND g.workflow_state <> 'deleted'
|
||||
AND ao.workflow_state = 'active'
|
||||
AND a.workflow_state NOT IN ('deleted','unpublished')
|
||||
AND a.only_visible_to_overrides = 'true'
|
||||
|
||||
UNION"
|
||||
else
|
||||
""
|
||||
end
|
||||
end
|
||||
|
||||
def self.quiz_or_assignment(is_assignment)
|
||||
if is_assignment
|
||||
"assignment_id"
|
||||
else
|
||||
"quiz_id"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -67,6 +67,7 @@ describe "differentiated_assignments" do
|
|||
ao.title = "ADHOC OVERRIDE"
|
||||
ao.workflow_state = "active"
|
||||
ao.set_type = "ADHOC"
|
||||
ao.unassign_item = opts[:unassign_item] || "false"
|
||||
ao.save!
|
||||
assignment.reload
|
||||
override_student = ao.assignment_override_students.build
|
||||
|
@ -118,10 +119,11 @@ describe "differentiated_assignments" do
|
|||
assignment.reload
|
||||
end
|
||||
|
||||
def give_section_due_date(assignment, section)
|
||||
def give_section_due_date(assignment, section, opts = {})
|
||||
create_override_for_assignment(assignment) do |ao|
|
||||
ao.set = section
|
||||
ao.due_at = 3.weeks.from_now
|
||||
ao.unassign_item = opts[:unassign_item] || "false"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -491,6 +493,75 @@ describe "differentiated_assignments" do
|
|||
end
|
||||
end
|
||||
|
||||
context "unassign item overrides" do
|
||||
before do
|
||||
Account.site_admin.enable_feature!(:differentiated_modules)
|
||||
Setting.set("differentiated_modules_setting", Account.site_admin.feature_enabled?(:differentiated_modules) ? "true" : "false")
|
||||
AssignmentStudentVisibility.reset_table_name
|
||||
assignment_with_true_only_visible_to_overrides
|
||||
end
|
||||
|
||||
it "is not visible with an unassigned adhoc override" do
|
||||
student_in_course_with_adhoc_override(@assignment, { unassign_item: "true" })
|
||||
ensure_user_does_not_see_assignment
|
||||
end
|
||||
|
||||
it "is not visible with an unassigned section override" do
|
||||
enroller_user_in_section(@section_foo)
|
||||
give_section_due_date(@assignment, @section_foo, { unassign_item: "true" })
|
||||
ensure_user_does_not_see_assignment
|
||||
end
|
||||
|
||||
it "is not visible with an unassigned adhoc override and assigned section override" do
|
||||
enroller_user_in_section(@section_foo)
|
||||
give_section_due_date(@assignment, @section_foo)
|
||||
student_in_course_with_adhoc_override(@assignment, { unassign_item: "true" })
|
||||
ensure_user_does_not_see_assignment
|
||||
end
|
||||
|
||||
it "is visible with an unassigned section override and assigned adhoc override" do
|
||||
enroller_user_in_section(@section_foo)
|
||||
give_section_due_date(@assignment, @section_foo, { unassign_item: "true" })
|
||||
student_in_course_with_adhoc_override(@assignment)
|
||||
ensure_user_sees_assignment
|
||||
end
|
||||
|
||||
it "does not apply context module section override with an unassigned section override" do
|
||||
enroller_user_in_section(@section_foo)
|
||||
module1 = @course.context_modules.create!(name: "Module 1")
|
||||
@assignment.context_module_tags.create! context_module: module1, context: @course, tag_type: "context_module"
|
||||
|
||||
module_override = module1.assignment_overrides.create!
|
||||
|
||||
module_override.set_type = "CourseSection"
|
||||
module_override.set_id = @section_foo
|
||||
module_override.save!
|
||||
|
||||
give_section_due_date(@assignment, @section_foo, { unassign_item: "true" })
|
||||
|
||||
ensure_user_does_not_see_assignment
|
||||
end
|
||||
|
||||
it "does not apply context module adhoc overrides with an unassigned adhoc override" do
|
||||
module1 = @course.context_modules.create!(name: "Module 1")
|
||||
@assignment.context_module_tags.create! context_module: module1, context: @course, tag_type: "context_module"
|
||||
|
||||
module_override = module1.assignment_overrides.create!
|
||||
module_override.assignment_override_students.create!(user: @user)
|
||||
|
||||
student_in_course_with_adhoc_override(@assignment, { unassign_item: "true" })
|
||||
ensure_user_does_not_see_assignment
|
||||
end
|
||||
|
||||
it "does not unassign if the flag is off" do
|
||||
Account.site_admin.disable_feature!(:differentiated_modules)
|
||||
Setting.set("differentiated_modules_setting", Account.site_admin.feature_enabled?(:differentiated_modules) ? "true" : "false")
|
||||
AssignmentStudentVisibility.reset_table_name
|
||||
student_in_course_with_adhoc_override(@assignment, { unassign: "true" })
|
||||
ensure_user_sees_assignment
|
||||
end
|
||||
end
|
||||
|
||||
context "course overrides" do
|
||||
before do
|
||||
Account.site_admin.enable_feature!(:differentiated_modules)
|
||||
|
|
|
@ -54,6 +54,7 @@ describe "differentiated_assignments" do
|
|||
ao.title = "ADHOC OVERRIDE"
|
||||
ao.workflow_state = "active"
|
||||
ao.set_type = "ADHOC"
|
||||
ao.unassign_item = opts[:unassign_item] || "false"
|
||||
ao.save!
|
||||
override_student = ao.assignment_override_students.build
|
||||
override_student.user = @user
|
||||
|
@ -89,10 +90,11 @@ describe "differentiated_assignments" do
|
|||
quiz.reload
|
||||
end
|
||||
|
||||
def give_section_foo_due_date(quiz)
|
||||
def give_section_foo_due_date(quiz, opts = {})
|
||||
create_override_for_quiz(quiz) do |ao|
|
||||
ao.set = @section_foo
|
||||
ao.due_at = 3.weeks.from_now
|
||||
ao.unassign_item = opts[:unassign_item] || "false"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -351,6 +353,75 @@ describe "differentiated_assignments" do
|
|||
end
|
||||
end
|
||||
|
||||
context "unassign item overrides" do
|
||||
before do
|
||||
Account.site_admin.enable_feature!(:differentiated_modules)
|
||||
Setting.set("differentiated_modules_setting", Account.site_admin.feature_enabled?(:differentiated_modules) ? "true" : "false")
|
||||
Quizzes::QuizStudentVisibility.reset_table_name
|
||||
quiz_with_true_only_visible_to_overrides
|
||||
end
|
||||
|
||||
it "is not visible with an unassigned adhoc override" do
|
||||
student_in_course_with_adhoc_override(@quiz, { unassign_item: "true" })
|
||||
ensure_user_does_not_see_quiz
|
||||
end
|
||||
|
||||
it "is not visible with an unassigned section override" do
|
||||
enroller_user_in_section(@section_foo)
|
||||
give_section_foo_due_date(@quiz, { unassign_item: "true" })
|
||||
ensure_user_does_not_see_quiz
|
||||
end
|
||||
|
||||
it "is not visible with an unassigned adhoc override and assigned section override" do
|
||||
enroller_user_in_section(@section_foo)
|
||||
give_section_foo_due_date(@quiz)
|
||||
student_in_course_with_adhoc_override(@quiz, { unassign_item: "true" })
|
||||
ensure_user_does_not_see_quiz
|
||||
end
|
||||
|
||||
it "is visible with an unassigned section override and assigned adhoc override" do
|
||||
enroller_user_in_section(@section_foo)
|
||||
give_section_foo_due_date(@quiz, { unassign_item: "true" })
|
||||
student_in_course_with_adhoc_override(@quiz)
|
||||
ensure_user_sees_quiz
|
||||
end
|
||||
|
||||
it "does not apply context module section override with an unassigned section override" do
|
||||
enroller_user_in_section(@section_foo)
|
||||
module1 = @course.context_modules.create!(name: "Module 1")
|
||||
@quiz.context_module_tags.create! context_module: module1, context: @course, tag_type: "context_module"
|
||||
|
||||
module_override = module1.assignment_overrides.create!
|
||||
|
||||
module_override.set_type = "CourseSection"
|
||||
module_override.set_id = @section_foo
|
||||
module_override.save!
|
||||
|
||||
give_section_foo_due_date(@quiz, { unassign_item: "true" })
|
||||
|
||||
ensure_user_does_not_see_quiz
|
||||
end
|
||||
|
||||
it "does not apply context module adhoc overrides with an unassigned adhoc override" do
|
||||
module1 = @course.context_modules.create!(name: "Module 1")
|
||||
@quiz.context_module_tags.create! context_module: module1, context: @course, tag_type: "context_module"
|
||||
|
||||
module_override = module1.assignment_overrides.create!
|
||||
module_override.assignment_override_students.create!(user: @user)
|
||||
|
||||
student_in_course_with_adhoc_override(@quiz, { unassign_item: "true" })
|
||||
ensure_user_does_not_see_quiz
|
||||
end
|
||||
|
||||
it "does not unassign if the flag is off" do
|
||||
Account.site_admin.disable_feature!(:differentiated_modules)
|
||||
Setting.set("differentiated_modules_setting", Account.site_admin.feature_enabled?(:differentiated_modules) ? "true" : "false")
|
||||
Quizzes::QuizStudentVisibility.reset_table_name
|
||||
student_in_course_with_adhoc_override(@quiz, { unassign: "true" })
|
||||
ensure_user_sees_quiz
|
||||
end
|
||||
end
|
||||
|
||||
context "course overrides" do
|
||||
before do
|
||||
Account.site_admin.enable_feature!(:differentiated_modules)
|
||||
|
|
Loading…
Reference in New Issue