add caching to heavy queries for selective release
This adds caching to queries that are commonly used to determine visibilty, somtimes multiple times in the same call. For now, we'll cache up to a minute to give the database some breathing room. This also removes unused functions from the visibility services and replaces a function with one provided by rails. flag=none test plan: - specs pass - determine if the queries are being cached by looking at the logs Change-Id: I30cc97ea614a6fc9578582dc3d97be45e8427365 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/360794 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Sarah Gerard <sarah.gerard@instructure.com> QA-Review: Sarah Gerard <sarah.gerard@instructure.com> Product-Review: Keith Garner <kgarner@instructure.com>
This commit is contained in:
parent
6a13dd4601
commit
97c62b2563
|
@ -64,26 +64,11 @@ class AssignmentStudentVisibility < ActiveRecord::Base
|
|||
end
|
||||
|
||||
if visible_to_everyone.any?
|
||||
assignment_visibilities.merge!(
|
||||
assignments_visible_to_all_students(visible_to_everyone)
|
||||
)
|
||||
assignment_visibilities.merge!(visible_to_everyone.map(&:id).index_with { [] })
|
||||
end
|
||||
assignment_visibilities
|
||||
end
|
||||
|
||||
def self.assignments_visible_to_all_students(assignments_visible_to_everyone)
|
||||
if Account.site_admin.feature_enabled?(:selective_release_backend)
|
||||
raise StandardError, "AssignmentStudentVisibility view should not be used when selective_release_backend site admin flag is on. Use AssignmentVisibilityService instead"
|
||||
end
|
||||
|
||||
assignments_visible_to_everyone.each_with_object({}) do |assignment, assignment_visibilities|
|
||||
# if an assignment is visible to everyone, we do not care about the contents
|
||||
# of its assignment_visibilities. instead of setting this to an array of every
|
||||
# student's ID, we set it to an empty array to save time when calling to_json
|
||||
assignment_visibilities[assignment.id] = []
|
||||
end
|
||||
end
|
||||
|
||||
def self.users_with_visibility_by_assignment(opts)
|
||||
if Account.site_admin.feature_enabled?(:selective_release_backend)
|
||||
raise StandardError, "AssignmentStudentVisibility view should not be used when selective_release_backend site admin flag is on. Use AssignmentVisibilityService instead"
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
module AssignmentVisibility
|
||||
class AssignmentVisibilityService
|
||||
extend VisibilityHelpers::Common
|
||||
class << self
|
||||
def visible_assignment_ids_in_course_by_user(user_ids:, course_ids:, use_global_id: false)
|
||||
raise ArgumentError, "course_ids cannot be nil" if course_ids.nil?
|
||||
|
@ -34,16 +35,7 @@ module AssignmentVisibility
|
|||
vis_hash[user_id] << assignment_visible_to_student.assignment_id
|
||||
end
|
||||
# if users have no visibilities add their keys to the hash with an empty array
|
||||
vis_hash.reverse_merge!(empty_id_hash(user_ids))
|
||||
end
|
||||
|
||||
def visible_assignment_ids_in_course_for_user(user_id:, course_id:, use_global_id: false)
|
||||
raise ArgumentError, "course_id cannot be nil" if course_id.nil?
|
||||
raise ArgumentError, "course_id must not be an array" if course_id.is_a?(Array)
|
||||
raise ArgumentError, "user_id cannot be nil" if user_id.nil?
|
||||
raise ArgumentError, "user_id must not be an array" if user_id.is_a?(Array)
|
||||
|
||||
visible_assignment_ids_in_course_by_user(user_ids: [user_id], course_ids: [course_id], use_global_id:)
|
||||
vis_hash.reverse_merge!(user_ids.index_with { [] })
|
||||
end
|
||||
|
||||
def users_with_visibility_by_assignment(course_id:, assignment_ids:)
|
||||
|
@ -60,10 +52,9 @@ module AssignmentVisibility
|
|||
end
|
||||
|
||||
# if assignment/quiz has no users with visibility, add their keys to the hash with an empty array
|
||||
vis_hash.reverse_merge!(empty_id_hash(assignment_ids))
|
||||
vis_hash.reverse_merge!(assignment_ids.index_with { [] })
|
||||
end
|
||||
|
||||
# users_with_visibility_by_assignment(course_id, assignment_id [], user_id [])
|
||||
def users_with_visibility_by_assignment_for_users(course_id:, assignment_ids:, user_ids:)
|
||||
raise ArgumentError, "course_id cannot be nil" if course_id.nil?
|
||||
raise ArgumentError, "course_id must not be an array" if course_id.is_a?(Array)
|
||||
|
@ -80,7 +71,7 @@ module AssignmentVisibility
|
|||
end
|
||||
|
||||
# if assignment/quiz has no users with visibility, add their keys to the hash with an empty array
|
||||
vis_hash.reverse_merge!(empty_id_hash(assignment_ids))
|
||||
vis_hash.reverse_merge!(assignment_ids.index_with { [] })
|
||||
end
|
||||
|
||||
def assignments_visible_to_student(course_id:, user_id:)
|
||||
|
@ -163,117 +154,110 @@ module AssignmentVisibility
|
|||
assignment_visibilities = {}
|
||||
|
||||
if only_visible_to_overrides.any?
|
||||
assignment_visibilities.merge!(users_with_visibility_by_assignment(course_id: course.id, assignment_ids: only_visible_to_overrides.map(&:id)))
|
||||
assignment_visibilities.merge!(users_with_visibility_by_assignment(
|
||||
course_id: course.id,
|
||||
assignment_ids: only_visible_to_overrides.map(&:id)
|
||||
))
|
||||
end
|
||||
|
||||
if visible_to_everyone.any?
|
||||
assignment_visibilities.merge!(
|
||||
assignments_visible_to_all_students(visible_to_everyone)
|
||||
)
|
||||
end
|
||||
assignment_visibilities
|
||||
end
|
||||
|
||||
# TODO: better name for this method, or a better location?
|
||||
# it has to do with JSON serialization of assignments' visibility,
|
||||
# and hiding the list of students when all students can see an assignment
|
||||
def assignments_visible_to_all_students(assignments)
|
||||
assignments.each_with_object({}) do |assignment, assignment_visibilities|
|
||||
# if an assignment is visible to everyone, we do not care about the contents
|
||||
# of its assignment_visibilities. instead of setting this to an array of every
|
||||
# student's ID, we set it to an empty array to save time when calling to_json
|
||||
assignment_visibilities[assignment.id] = []
|
||||
assignment_visibilities.merge!(visible_to_everyone.map(&:id).index_with { [] })
|
||||
end
|
||||
|
||||
assignment_visibilities
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def assignments_visible_to_students(course_id_params: nil, user_id_params: nil, assignment_id_params: nil)
|
||||
# Must have a course_id or assignment_id for performance of the all_tags section of the query
|
||||
# General query performance requires at least one non-nil course_id, assignment_id, or user_id
|
||||
if course_id_params.nil? && assignment_id_params.nil?
|
||||
raise ArgumentError, "at least one non nil course_id or assignment_id is required (for query performance reasons)"
|
||||
end
|
||||
|
||||
if Account.site_admin.feature_enabled?(:selective_release_optimized_services_v3)
|
||||
AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository.full_assignment_visibility_query(course_id_params:, user_id_params:, assignment_id_params:)
|
||||
elsif Account.site_admin.feature_enabled?(:selective_release_optimized_services_v2)
|
||||
visible_assignments = []
|
||||
|
||||
# add assignments visible to everyone
|
||||
assignments_visible_to_all = AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository
|
||||
.find_assignments_visible_to_everyone(course_id_params:, user_id_params:, assignment_id_params:)
|
||||
visible_assignments |= assignments_visible_to_all
|
||||
|
||||
# add assignments visible to groups (only assignments can have group overrides)
|
||||
assignments_visible_to_groups = AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository
|
||||
.find_assignments_visible_to_groups(course_id_params:, user_id_params:, assignment_id_params:)
|
||||
visible_assignments |= assignments_visible_to_groups
|
||||
|
||||
# add assignments assigned to sections, students, or the course
|
||||
assignments_assigned_to_others = AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository
|
||||
.find_assignments_assigned_to_others(course_id_params:, user_id_params:, assignment_id_params:)
|
||||
|
||||
visible_assignments | assignments_assigned_to_others
|
||||
else
|
||||
visible_assignments = []
|
||||
|
||||
# add assignments visible to everyone
|
||||
assignments_visible_to_all = AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository
|
||||
.find_assignments_visible_to_everyone(course_id_params:, user_id_params:, assignment_id_params:)
|
||||
visible_assignments |= assignments_visible_to_all
|
||||
|
||||
# add assignments visible to groups (only assignments can have group overrides)
|
||||
assignments_visible_to_groups = AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository
|
||||
.find_assignments_visible_to_groups(course_id_params:, user_id_params:, assignment_id_params:)
|
||||
visible_assignments |= assignments_visible_to_groups
|
||||
|
||||
if Account.site_admin.feature_enabled?(:selective_release_optimized_services)
|
||||
# add assignments visible to sections (and related module section overrides) without unassign overrides
|
||||
assignments_assigned_to_sections = AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository
|
||||
.find_assignments_assigned_to_sections(course_id_params:, user_id_params:, assignment_id_params:)
|
||||
visible_assignments |= assignments_assigned_to_sections
|
||||
else
|
||||
# add assignments visible to sections (and related module section overrides)
|
||||
assignments_visible_to_sections = AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository
|
||||
.find_assignments_visible_to_sections(course_id_params:, user_id_params:, assignment_id_params:)
|
||||
visible_assignments |= assignments_visible_to_sections
|
||||
|
||||
# remove assignments for students with unassigned section overrides
|
||||
assignments_with_unassigned_section_overrides = AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository
|
||||
.find_assignments_with_unassigned_section_overrides(course_id_params:, user_id_params:, assignment_id_params:)
|
||||
visible_assignments -= assignments_with_unassigned_section_overrides
|
||||
service_cache_fetch(service: name,
|
||||
course_id_params:,
|
||||
user_id_params:,
|
||||
additional_id_params: assignment_id_params) do
|
||||
# Must have a course_id or assignment_id for performance of the all_tags section of the query
|
||||
# General query performance requires at least one non-nil course_id, assignment_id, or user_id
|
||||
if course_id_params.nil? && assignment_id_params.nil?
|
||||
raise ArgumentError, "at least one non nil course_id or assignment_id is required (for query performance reasons)"
|
||||
end
|
||||
|
||||
if Account.site_admin.feature_enabled?(:selective_release_optimized_services)
|
||||
# add assignments visible due to ADHOC overrides (and related module ADHOC overrides) without unassign overrides
|
||||
assignments_assigned_to_adhoc_overrides = AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository
|
||||
.find_assignments_assigned_to_adhoc_overrides(course_id_params:, user_id_params:, assignment_id_params:)
|
||||
visible_assignments |= assignments_assigned_to_adhoc_overrides
|
||||
if Account.site_admin.feature_enabled?(:selective_release_optimized_services_v3)
|
||||
AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository.full_assignment_visibility_query(course_id_params:, user_id_params:, assignment_id_params:)
|
||||
elsif Account.site_admin.feature_enabled?(:selective_release_optimized_services_v2)
|
||||
visible_assignments = []
|
||||
|
||||
# add assignments visible to everyone
|
||||
assignments_visible_to_all = AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository
|
||||
.find_assignments_visible_to_everyone(course_id_params:, user_id_params:, assignment_id_params:)
|
||||
visible_assignments |= assignments_visible_to_all
|
||||
|
||||
# add assignments visible to groups (only assignments can have group overrides)
|
||||
assignments_visible_to_groups = AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository
|
||||
.find_assignments_visible_to_groups(course_id_params:, user_id_params:, assignment_id_params:)
|
||||
visible_assignments |= assignments_visible_to_groups
|
||||
|
||||
# add assignments assigned to sections, students, or the course
|
||||
assignments_assigned_to_others = AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository
|
||||
.find_assignments_assigned_to_others(course_id_params:, user_id_params:, assignment_id_params:)
|
||||
|
||||
visible_assignments | assignments_assigned_to_others
|
||||
else
|
||||
# add assignments visible due to ADHOC overrides (and related module ADHOC overrides)
|
||||
assignments_visible_to_adhoc_overrides = AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository
|
||||
.find_assignments_visible_to_adhoc_overrides(course_id_params:, user_id_params:, assignment_id_params:)
|
||||
visible_assignments |= assignments_visible_to_adhoc_overrides
|
||||
visible_assignments = []
|
||||
|
||||
# remove assignments for students with unassigned ADHOC overrides
|
||||
assignments_with_unassigned_adhoc_overrides = AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository
|
||||
.find_assignments_with_unassigned_adhoc_overrides(course_id_params:, user_id_params:, assignment_id_params:)
|
||||
visible_assignments -= assignments_with_unassigned_adhoc_overrides
|
||||
# add assignments visible to everyone
|
||||
assignments_visible_to_all = AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository
|
||||
.find_assignments_visible_to_everyone(course_id_params:, user_id_params:, assignment_id_params:)
|
||||
visible_assignments |= assignments_visible_to_all
|
||||
|
||||
# add assignments visible to groups (only assignments can have group overrides)
|
||||
assignments_visible_to_groups = AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository
|
||||
.find_assignments_visible_to_groups(course_id_params:, user_id_params:, assignment_id_params:)
|
||||
visible_assignments |= assignments_visible_to_groups
|
||||
|
||||
if Account.site_admin.feature_enabled?(:selective_release_optimized_services)
|
||||
# add assignments visible to sections (and related module section overrides) without unassign overrides
|
||||
assignments_assigned_to_sections = AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository
|
||||
.find_assignments_assigned_to_sections(course_id_params:, user_id_params:, assignment_id_params:)
|
||||
visible_assignments |= assignments_assigned_to_sections
|
||||
else
|
||||
# add assignments visible to sections (and related module section overrides)
|
||||
assignments_visible_to_sections = AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository
|
||||
.find_assignments_visible_to_sections(course_id_params:, user_id_params:, assignment_id_params:)
|
||||
visible_assignments |= assignments_visible_to_sections
|
||||
|
||||
# remove assignments for students with unassigned section overrides
|
||||
assignments_with_unassigned_section_overrides = AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository
|
||||
.find_assignments_with_unassigned_section_overrides(course_id_params:, user_id_params:, assignment_id_params:)
|
||||
visible_assignments -= assignments_with_unassigned_section_overrides
|
||||
end
|
||||
|
||||
if Account.site_admin.feature_enabled?(:selective_release_optimized_services)
|
||||
# add assignments visible due to ADHOC overrides (and related module ADHOC overrides) without unassign overrides
|
||||
assignments_assigned_to_adhoc_overrides = AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository
|
||||
.find_assignments_assigned_to_adhoc_overrides(course_id_params:, user_id_params:, assignment_id_params:)
|
||||
visible_assignments |= assignments_assigned_to_adhoc_overrides
|
||||
else
|
||||
# add assignments visible due to ADHOC overrides (and related module ADHOC overrides)
|
||||
assignments_visible_to_adhoc_overrides = AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository
|
||||
.find_assignments_visible_to_adhoc_overrides(course_id_params:, user_id_params:, assignment_id_params:)
|
||||
visible_assignments |= assignments_visible_to_adhoc_overrides
|
||||
|
||||
# remove assignments for students with unassigned ADHOC overrides
|
||||
assignments_with_unassigned_adhoc_overrides = AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository
|
||||
.find_assignments_with_unassigned_adhoc_overrides(course_id_params:, user_id_params:, assignment_id_params:)
|
||||
visible_assignments -= assignments_with_unassigned_adhoc_overrides
|
||||
end
|
||||
|
||||
# add assignments visible due to course overrides
|
||||
assignments_visible_to_course_overrides = AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository
|
||||
.find_assignments_visible_to_course_overrides(course_id_params:, user_id_params:, assignment_id_params:)
|
||||
|
||||
visible_assignments | assignments_visible_to_course_overrides
|
||||
end
|
||||
|
||||
# add assignments visible due to course overrides
|
||||
assignments_visible_to_course_overrides = AssignmentVisibility::Repositories::AssignmentVisibleToStudentRepository
|
||||
.find_assignments_visible_to_course_overrides(course_id_params:, user_id_params:, assignment_id_params:)
|
||||
|
||||
visible_assignments | assignments_visible_to_course_overrides
|
||||
end
|
||||
end
|
||||
|
||||
def empty_id_hash(ids)
|
||||
# [1,2,3] => {1:[],2:[],3:[]}
|
||||
ids.zip(ids.map { [] }).to_h
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,7 +19,9 @@
|
|||
|
||||
module ModuleVisibility
|
||||
class ModuleVisibilityService
|
||||
extend VisibilityHelpers::Common
|
||||
class << self
|
||||
# this is seemingly only called in specs
|
||||
def modules_visible_to_student(course_id:, user_id:)
|
||||
raise ArgumentError, "course_id cannot be nil" if course_id.nil?
|
||||
raise ArgumentError, "course_id must not be an array" if course_id.is_a?(Array)
|
||||
|
@ -38,6 +40,7 @@ module ModuleVisibility
|
|||
modules_visible_to_students(course_id_params: course_ids, user_id_params: user_ids)
|
||||
end
|
||||
|
||||
# this is seemingly only called in specs.
|
||||
def module_visible_to_student(context_module_id:, user_id:)
|
||||
raise ArgumentError, "context_module_id cannot be nil" if context_module_id.nil?
|
||||
raise ArgumentError, "context_module_id must not be an array" if context_module_id.is_a?(Array)
|
||||
|
@ -56,26 +59,6 @@ module ModuleVisibility
|
|||
modules_visible_to_students(context_module_id_params: context_module_id, user_id_params: user_ids)
|
||||
end
|
||||
|
||||
def module_visible_to_students_in_course(context_module_id:, user_ids:, course_id:)
|
||||
raise ArgumentError, "course_id cannot be nil" if course_id.nil?
|
||||
raise ArgumentError, "course_id must not be an array" if course_id.is_a?(Array)
|
||||
raise ArgumentError, "context_module_id cannot be nil" if context_module_id.nil?
|
||||
raise ArgumentError, "context_module_id must not be an array" if context_module_id.is_a?(Array)
|
||||
raise ArgumentError, "user_ids cannot be nil" if user_ids.nil?
|
||||
raise ArgumentError, "user_ids must be an array" unless user_ids.is_a?(Array)
|
||||
|
||||
modules_visible_to_students(course_id_params: course_id, context_module_id_params: context_module_id, user_id_params: user_ids)
|
||||
end
|
||||
|
||||
def module_visible_in_course(context_module_id:, course_id:)
|
||||
raise ArgumentError, "course_id cannot be nil" if course_id.nil?
|
||||
raise ArgumentError, "course_id must not be an array" if course_id.is_a?(Array)
|
||||
raise ArgumentError, "context_module_id cannot be nil" if context_module_id.nil?
|
||||
raise ArgumentError, "context_module_id must not be an array" if context_module_id.is_a?(Array)
|
||||
|
||||
modules_visible_to_students(course_id_params: course_id, context_module_id_params: context_module_id)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def modules_visible_to_students(course_id_params: nil, user_id_params: nil, context_module_id_params: nil)
|
||||
|
@ -83,27 +66,27 @@ module ModuleVisibility
|
|||
raise ArgumentError, "at least one non nil course_id, user_id, or context_module_id_params is required (for query performance reasons)"
|
||||
end
|
||||
|
||||
visible_modules = []
|
||||
service_cache_fetch(service: name,
|
||||
course_id_params:,
|
||||
user_id_params:,
|
||||
additional_id_params: context_module_id_params) do
|
||||
visible_modules = []
|
||||
|
||||
# add modules visible to everyone
|
||||
modules_visible_to_all = ModuleVisibility::Repositories::ModuleVisibleToStudentRepository
|
||||
.find_modules_visible_to_everyone(course_id_params:, user_id_params:, context_module_id_params:)
|
||||
visible_modules |= modules_visible_to_all
|
||||
# add modules visible to everyone
|
||||
modules_visible_to_all = ModuleVisibility::Repositories::ModuleVisibleToStudentRepository
|
||||
.find_modules_visible_to_everyone(course_id_params:, user_id_params:, context_module_id_params:)
|
||||
visible_modules |= modules_visible_to_all
|
||||
|
||||
# add modules visible to sections (and related module section overrides)
|
||||
modules_visible_to_sections = ModuleVisibility::Repositories::ModuleVisibleToStudentRepository
|
||||
.find_modules_visible_to_sections(course_id_params:, user_id_params:, context_module_id_params:)
|
||||
visible_modules |= modules_visible_to_sections
|
||||
# add modules visible to sections (and related module section overrides)
|
||||
modules_visible_to_sections = ModuleVisibility::Repositories::ModuleVisibleToStudentRepository
|
||||
.find_modules_visible_to_sections(course_id_params:, user_id_params:, context_module_id_params:)
|
||||
visible_modules |= modules_visible_to_sections
|
||||
|
||||
# add modules visible due to ADHOC overrides (and related module ADHOC overrides)
|
||||
modules_visible_to_adhoc_overrides = ModuleVisibility::Repositories::ModuleVisibleToStudentRepository
|
||||
.find_modules_visible_to_adhoc_overrides(course_id_params:, user_id_params:, context_module_id_params:)
|
||||
visible_modules | modules_visible_to_adhoc_overrides
|
||||
end
|
||||
|
||||
def empty_id_hash(ids)
|
||||
# [1,2,3] => {1:[],2:[],3:[]}
|
||||
ids.zip(ids.map { [] }).to_h
|
||||
# add modules visible due to ADHOC overrides (and related module ADHOC overrides)
|
||||
modules_visible_to_adhoc_overrides = ModuleVisibility::Repositories::ModuleVisibleToStudentRepository
|
||||
.find_modules_visible_to_adhoc_overrides(course_id_params:, user_id_params:, context_module_id_params:)
|
||||
visible_modules | modules_visible_to_adhoc_overrides
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
module QuizVisibility
|
||||
class QuizVisibilityService
|
||||
extend VisibilityHelpers::Common
|
||||
class << self
|
||||
def visible_quiz_ids_in_course_by_user(user_ids:, course_ids:, use_global_id: false)
|
||||
raise ArgumentError, "course_ids cannot be nil" if course_ids.nil?
|
||||
|
@ -34,7 +35,7 @@ module QuizVisibility
|
|||
vis_hash[user_id] << quiz_visible_to_student.quiz_id
|
||||
end
|
||||
# if users have no visibilities add their keys to the hash with an empty array
|
||||
vis_hash.reverse_merge!(empty_id_hash(user_ids))
|
||||
vis_hash.reverse_merge!(user_ids.index_with { [] })
|
||||
end
|
||||
|
||||
def quizzes_visible_to_student(course_id:, user_id:)
|
||||
|
@ -73,17 +74,6 @@ module QuizVisibility
|
|||
quizzes_visible_to_students(quiz_id_params: quiz_id, user_id_params: user_ids)
|
||||
end
|
||||
|
||||
def quiz_visible_to_students_in_course(quiz_id:, user_ids:, course_id:)
|
||||
raise ArgumentError, "course_id cannot be nil" if course_id.nil?
|
||||
raise ArgumentError, "course_id must not be an array" if course_id.is_a?(Array)
|
||||
raise ArgumentError, "quiz_id cannot be nil" if quiz_id.nil?
|
||||
raise ArgumentError, "quiz_id must not be an array" if quiz_id.is_a?(Array)
|
||||
raise ArgumentError, "user_ids cannot be nil" if user_ids.nil?
|
||||
raise ArgumentError, "user_ids must be an array" unless user_ids.is_a?(Array)
|
||||
|
||||
quizzes_visible_to_students(course_id_params: course_id, quiz_id_params: quiz_id, user_id_params: user_ids)
|
||||
end
|
||||
|
||||
def quiz_visible_in_course(quiz_id:, course_id:)
|
||||
raise ArgumentError, "course_id cannot be nil" if course_id.nil?
|
||||
raise ArgumentError, "course_id must not be an array" if course_id.is_a?(Array)
|
||||
|
@ -100,75 +90,72 @@ module QuizVisibility
|
|||
raise ArgumentError, "at least one non nil course_id, user_id, or quiz_id_params is required (for query performance reasons)"
|
||||
end
|
||||
|
||||
if Account.site_admin.feature_enabled?(:selective_release_optimized_services_v3)
|
||||
QuizVisibility::Repositories::QuizVisibleToStudentRepository.full_quiz_visibility_query(course_id_params:, user_id_params:, quiz_id_params:)
|
||||
elsif Account.site_admin.feature_enabled?(:selective_release_optimized_services_v2)
|
||||
visible_quizzes = []
|
||||
service_cache_fetch(service: name, course_id_params:, user_id_params:, additional_id_params: quiz_id_params) do
|
||||
if Account.site_admin.feature_enabled?(:selective_release_optimized_services_v3)
|
||||
QuizVisibility::Repositories::QuizVisibleToStudentRepository.full_quiz_visibility_query(course_id_params:, user_id_params:, quiz_id_params:)
|
||||
elsif Account.site_admin.feature_enabled?(:selective_release_optimized_services_v2)
|
||||
visible_quizzes = []
|
||||
|
||||
# add quizzes visible to everyone
|
||||
quizzes_visible_to_all = QuizVisibility::Repositories::QuizVisibleToStudentRepository
|
||||
.find_quizzes_visible_to_everyone(course_id_params:, user_id_params:, quiz_id_params:)
|
||||
visible_quizzes |= quizzes_visible_to_all
|
||||
# add quizzes visible to everyone
|
||||
quizzes_visible_to_all = QuizVisibility::Repositories::QuizVisibleToStudentRepository
|
||||
.find_quizzes_visible_to_everyone(course_id_params:, user_id_params:, quiz_id_params:)
|
||||
visible_quizzes |= quizzes_visible_to_all
|
||||
|
||||
# add quizzes assigned to sections, students, or the course
|
||||
quizzes_assigned_to_others = QuizVisibility::Repositories::QuizVisibleToStudentRepository
|
||||
.find_quizzes_assigned_to_others(course_id_params:, user_id_params:, quiz_id_params:)
|
||||
# add quizzes assigned to sections, students, or the course
|
||||
quizzes_assigned_to_others = QuizVisibility::Repositories::QuizVisibleToStudentRepository
|
||||
.find_quizzes_assigned_to_others(course_id_params:, user_id_params:, quiz_id_params:)
|
||||
|
||||
visible_quizzes | quizzes_assigned_to_others
|
||||
else
|
||||
visible_quizzes = []
|
||||
|
||||
# add quizzes visible to everyone
|
||||
quizzes_visible_to_all = QuizVisibility::Repositories::QuizVisibleToStudentRepository
|
||||
.find_quizzes_visible_to_everyone(course_id_params:, user_id_params:, quiz_id_params:)
|
||||
visible_quizzes |= quizzes_visible_to_all
|
||||
|
||||
if Account.site_admin.feature_enabled?(:selective_release_optimized_services)
|
||||
# add quizzes visible to sections (and related module section overrides) without unassign overrides
|
||||
quizzes_assigned_to_sections = QuizVisibility::Repositories::QuizVisibleToStudentRepository
|
||||
.find_quizzes_assigned_to_sections(course_id_params:, user_id_params:, quiz_id_params:)
|
||||
visible_quizzes |= quizzes_assigned_to_sections
|
||||
visible_quizzes | quizzes_assigned_to_others
|
||||
else
|
||||
# add quizzes visible to sections (and related module section overrides)
|
||||
quizzes_visible_to_sections = QuizVisibility::Repositories::QuizVisibleToStudentRepository
|
||||
.find_quizzes_visible_to_sections(course_id_params:, user_id_params:, quiz_id_params:)
|
||||
visible_quizzes |= quizzes_visible_to_sections
|
||||
visible_quizzes = []
|
||||
|
||||
# remove quizzes for students with unassigned section overrides
|
||||
quizzes_with_unassigned_section_overrides = QuizVisibility::Repositories::QuizVisibleToStudentRepository
|
||||
.find_quizzes_with_unassigned_section_overrides(course_id_params:, user_id_params:, quiz_id_params:)
|
||||
visible_quizzes -= quizzes_with_unassigned_section_overrides
|
||||
# add quizzes visible to everyone
|
||||
quizzes_visible_to_all = QuizVisibility::Repositories::QuizVisibleToStudentRepository
|
||||
.find_quizzes_visible_to_everyone(course_id_params:, user_id_params:, quiz_id_params:)
|
||||
visible_quizzes |= quizzes_visible_to_all
|
||||
|
||||
if Account.site_admin.feature_enabled?(:selective_release_optimized_services)
|
||||
# add quizzes visible to sections (and related module section overrides) without unassign overrides
|
||||
quizzes_assigned_to_sections = QuizVisibility::Repositories::QuizVisibleToStudentRepository
|
||||
.find_quizzes_assigned_to_sections(course_id_params:, user_id_params:, quiz_id_params:)
|
||||
visible_quizzes |= quizzes_assigned_to_sections
|
||||
else
|
||||
# add quizzes visible to sections (and related module section overrides)
|
||||
quizzes_visible_to_sections = QuizVisibility::Repositories::QuizVisibleToStudentRepository
|
||||
.find_quizzes_visible_to_sections(course_id_params:, user_id_params:, quiz_id_params:)
|
||||
visible_quizzes |= quizzes_visible_to_sections
|
||||
|
||||
# remove quizzes for students with unassigned section overrides
|
||||
quizzes_with_unassigned_section_overrides = QuizVisibility::Repositories::QuizVisibleToStudentRepository
|
||||
.find_quizzes_with_unassigned_section_overrides(course_id_params:, user_id_params:, quiz_id_params:)
|
||||
visible_quizzes -= quizzes_with_unassigned_section_overrides
|
||||
end
|
||||
|
||||
if Account.site_admin.feature_enabled?(:selective_release_optimized_services)
|
||||
# add quizzes visible due to ADHOC overrides (and related module ADHOC overrides) without unassign overrides
|
||||
quizzes_assigned_to_adhoc_overrides = QuizVisibility::Repositories::QuizVisibleToStudentRepository
|
||||
.find_quizzes_assigned_to_adhoc_overrides(course_id_params:, user_id_params:, quiz_id_params:)
|
||||
visible_quizzes |= quizzes_assigned_to_adhoc_overrides
|
||||
else
|
||||
# add quizzes visible due to ADHOC overrides (and related module ADHOC overrides)
|
||||
quizzes_visible_to_adhoc_overrides = QuizVisibility::Repositories::QuizVisibleToStudentRepository
|
||||
.find_quizzes_visible_to_adhoc_overrides(course_id_params:, user_id_params:, quiz_id_params:)
|
||||
visible_quizzes |= quizzes_visible_to_adhoc_overrides
|
||||
|
||||
# remove quizzes for students with unassigned ADHOC overrides
|
||||
quizzes_with_unassigned_adhoc_overrides = QuizVisibility::Repositories::QuizVisibleToStudentRepository
|
||||
.find_quizzes_with_unassigned_adhoc_overrides(course_id_params:, user_id_params:, quiz_id_params:)
|
||||
visible_quizzes -= quizzes_with_unassigned_adhoc_overrides
|
||||
end
|
||||
|
||||
# add quizzes visible due to course overrides
|
||||
quizzes_visible_to_course_overrides = QuizVisibility::Repositories::QuizVisibleToStudentRepository
|
||||
.find_quizzes_visible_to_course_overrides(course_id_params:, user_id_params:, quiz_id_params:)
|
||||
|
||||
visible_quizzes | quizzes_visible_to_course_overrides
|
||||
end
|
||||
|
||||
if Account.site_admin.feature_enabled?(:selective_release_optimized_services)
|
||||
# add quizzes visible due to ADHOC overrides (and related module ADHOC overrides) without unassign overrides
|
||||
quizzes_assigned_to_adhoc_overrides = QuizVisibility::Repositories::QuizVisibleToStudentRepository
|
||||
.find_quizzes_assigned_to_adhoc_overrides(course_id_params:, user_id_params:, quiz_id_params:)
|
||||
visible_quizzes |= quizzes_assigned_to_adhoc_overrides
|
||||
else
|
||||
# add quizzes visible due to ADHOC overrides (and related module ADHOC overrides)
|
||||
quizzes_visible_to_adhoc_overrides = QuizVisibility::Repositories::QuizVisibleToStudentRepository
|
||||
.find_quizzes_visible_to_adhoc_overrides(course_id_params:, user_id_params:, quiz_id_params:)
|
||||
visible_quizzes |= quizzes_visible_to_adhoc_overrides
|
||||
|
||||
# remove quizzes for students with unassigned ADHOC overrides
|
||||
quizzes_with_unassigned_adhoc_overrides = QuizVisibility::Repositories::QuizVisibleToStudentRepository
|
||||
.find_quizzes_with_unassigned_adhoc_overrides(course_id_params:, user_id_params:, quiz_id_params:)
|
||||
visible_quizzes -= quizzes_with_unassigned_adhoc_overrides
|
||||
end
|
||||
|
||||
# add quizzes visible due to course overrides
|
||||
quizzes_visible_to_course_overrides = QuizVisibility::Repositories::QuizVisibleToStudentRepository
|
||||
.find_quizzes_visible_to_course_overrides(course_id_params:, user_id_params:, quiz_id_params:)
|
||||
|
||||
visible_quizzes | quizzes_visible_to_course_overrides
|
||||
end
|
||||
end
|
||||
|
||||
def empty_id_hash(ids)
|
||||
# [1,2,3] => {1:[],2:[],3:[]}
|
||||
ids.zip(ids.map { [] }).to_h
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
module UngradedDiscussionVisibility
|
||||
class UngradedDiscussionVisibilityService
|
||||
extend VisibilityHelpers::Common
|
||||
class << self
|
||||
def discussion_topics_visible_to_student_in_course(course_id:, user_id:)
|
||||
raise ArgumentError, "course_id cannot be nil" if course_id.nil?
|
||||
|
@ -72,35 +73,6 @@ module UngradedDiscussionVisibility
|
|||
discussion_topics_visible(discussion_topic_id_params: discussion_topic_id, user_id_params: user_ids)
|
||||
end
|
||||
|
||||
def discussion_topics_visible_to_students_by_topics(discussion_topic_ids:, user_ids:)
|
||||
raise ArgumentError, "discussion_topic_ids cannot be nil" if discussion_topic_ids.nil?
|
||||
raise ArgumentError, "discussion_topic_ids must be an array" unless discussion_topic_ids.is_a?(Array)
|
||||
raise ArgumentError, "user_ids cannot be nil" if user_ids.nil?
|
||||
raise ArgumentError, "user_ids must be an array" unless user_ids.is_a?(Array)
|
||||
|
||||
discussion_topics_visible(discussion_topic_id_params: discussion_topic_ids, user_id_params: user_ids)
|
||||
end
|
||||
|
||||
def discussion_topic_visible_to_students_in_course(discussion_topic_id:, user_ids:, course_id:)
|
||||
raise ArgumentError, "course_id cannot be nil" if course_id.nil?
|
||||
raise ArgumentError, "course_id must not be an array" if course_id.is_a?(Array)
|
||||
raise ArgumentError, "discussion_topic_id cannot be nil" if discussion_topic_id.nil?
|
||||
raise ArgumentError, "discussion_topic_id must not be an array" if discussion_topic_id.is_a?(Array)
|
||||
raise ArgumentError, "user_ids cannot be nil" if user_ids.nil?
|
||||
raise ArgumentError, "user_ids must be an array" unless user_ids.is_a?(Array)
|
||||
|
||||
discussion_topics_visible(course_id_params: course_id, discussion_topic_id_params: discussion_topic_id, user_id_params: user_ids)
|
||||
end
|
||||
|
||||
def discussion_topic_visible_in_course(discussion_topic_id:, course_id:)
|
||||
raise ArgumentError, "course_id cannot be nil" if course_id.nil?
|
||||
raise ArgumentError, "course_id must not be an array" if course_id.is_a?(Array)
|
||||
raise ArgumentError, "discussion_topic_id cannot be nil" if discussion_topic_id.nil?
|
||||
raise ArgumentError, "discussion_topic_id must not be an array" if discussion_topic_id.is_a?(Array)
|
||||
|
||||
discussion_topics_visible(course_id_params: course_id, discussion_topic_id_params: discussion_topic_id)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def discussion_topics_visible(course_id_params: nil, user_id_params: nil, discussion_topic_id_params: nil)
|
||||
|
@ -108,75 +80,75 @@ module UngradedDiscussionVisibility
|
|||
raise ArgumentError, "at least one non nil course_id, user_id, or discussion_topic_id_params is required (for query performance reasons)"
|
||||
end
|
||||
|
||||
if Account.site_admin.feature_enabled?(:selective_release_optimized_services_v3)
|
||||
UngradedDiscussionVisibility::Repositories::UngradedDiscussionVisibleToStudentRepository.full_discussion_topic_visibility_query(course_id_params:, user_id_params:, discussion_topic_id_params:)
|
||||
elsif Account.site_admin.feature_enabled?(:selective_release_optimized_services_v2)
|
||||
visible_discussion_topics = []
|
||||
service_cache_fetch(service: name,
|
||||
course_id_params:,
|
||||
user_id_params:,
|
||||
additional_id_params: discussion_topic_id_params) do
|
||||
if Account.site_admin.feature_enabled?(:selective_release_optimized_services_v3)
|
||||
UngradedDiscussionVisibility::Repositories::UngradedDiscussionVisibleToStudentRepository.full_discussion_topic_visibility_query(course_id_params:, user_id_params:, discussion_topic_id_params:)
|
||||
elsif Account.site_admin.feature_enabled?(:selective_release_optimized_services_v2)
|
||||
visible_discussion_topics = []
|
||||
|
||||
# add discussion topics visible to everyone
|
||||
discussion_topics_visible_to_all = UngradedDiscussionVisibility::Repositories::UngradedDiscussionVisibleToStudentRepository
|
||||
.find_discussion_topics_visible_to_everyone(course_id_params:, user_id_params:, discussion_topic_id_params:)
|
||||
visible_discussion_topics |= discussion_topics_visible_to_all
|
||||
# add discussion topics visible to everyone
|
||||
discussion_topics_visible_to_all = UngradedDiscussionVisibility::Repositories::UngradedDiscussionVisibleToStudentRepository
|
||||
.find_discussion_topics_visible_to_everyone(course_id_params:, user_id_params:, discussion_topic_id_params:)
|
||||
visible_discussion_topics |= discussion_topics_visible_to_all
|
||||
|
||||
# add discussion topics assigned to sections, students, or the course
|
||||
discussion_topics_assigned_to_others = UngradedDiscussionVisibility::Repositories::UngradedDiscussionVisibleToStudentRepository
|
||||
.find_discussion_topics_assigned_to_others(course_id_params:, user_id_params:, discussion_topic_id_params:)
|
||||
# add discussion topics assigned to sections, students, or the course
|
||||
discussion_topics_assigned_to_others = UngradedDiscussionVisibility::Repositories::UngradedDiscussionVisibleToStudentRepository
|
||||
.find_discussion_topics_assigned_to_others(course_id_params:, user_id_params:, discussion_topic_id_params:)
|
||||
|
||||
visible_discussion_topics | discussion_topics_assigned_to_others
|
||||
else
|
||||
visible_discussion_topics = []
|
||||
|
||||
# add discussion topics visible to everyone
|
||||
discussion_topics_visible_to_all = UngradedDiscussionVisibility::Repositories::UngradedDiscussionVisibleToStudentRepository
|
||||
.find_discussion_topics_visible_to_everyone(course_id_params:, user_id_params:, discussion_topic_id_params:)
|
||||
visible_discussion_topics |= discussion_topics_visible_to_all
|
||||
|
||||
if Account.site_admin.feature_enabled?(:selective_release_optimized_services)
|
||||
# add discussion topics visible to sections (and related module section overrides) without unassign overrides
|
||||
discussion_topics_assigned_to_sections = UngradedDiscussionVisibility::Repositories::UngradedDiscussionVisibleToStudentRepository
|
||||
.find_discussion_topics_assigned_to_sections(course_id_params:, user_id_params:, discussion_topic_id_params:)
|
||||
visible_discussion_topics |= discussion_topics_assigned_to_sections
|
||||
visible_discussion_topics | discussion_topics_assigned_to_others
|
||||
else
|
||||
# add discussion topics visible to sections (and related module section overrides)
|
||||
discussion_topics_visible_to_sections = UngradedDiscussionVisibility::Repositories::UngradedDiscussionVisibleToStudentRepository
|
||||
.find_discussion_topics_visible_to_sections(course_id_params:, user_id_params:, discussion_topic_id_params:)
|
||||
visible_discussion_topics |= discussion_topics_visible_to_sections
|
||||
visible_discussion_topics = []
|
||||
|
||||
# remove discussion topics for students with unassigned section overrides
|
||||
discussion_topics_with_unassigned_section_overrides = UngradedDiscussionVisibility::Repositories::UngradedDiscussionVisibleToStudentRepository
|
||||
.find_discussion_topics_with_unassigned_section_overrides(course_id_params:, user_id_params:, discussion_topic_id_params:)
|
||||
visible_discussion_topics -= discussion_topics_with_unassigned_section_overrides
|
||||
# add discussion topics visible to everyone
|
||||
discussion_topics_visible_to_all = UngradedDiscussionVisibility::Repositories::UngradedDiscussionVisibleToStudentRepository
|
||||
.find_discussion_topics_visible_to_everyone(course_id_params:, user_id_params:, discussion_topic_id_params:)
|
||||
visible_discussion_topics |= discussion_topics_visible_to_all
|
||||
|
||||
if Account.site_admin.feature_enabled?(:selective_release_optimized_services)
|
||||
# add discussion topics visible to sections (and related module section overrides) without unassign overrides
|
||||
discussion_topics_assigned_to_sections = UngradedDiscussionVisibility::Repositories::UngradedDiscussionVisibleToStudentRepository
|
||||
.find_discussion_topics_assigned_to_sections(course_id_params:, user_id_params:, discussion_topic_id_params:)
|
||||
visible_discussion_topics |= discussion_topics_assigned_to_sections
|
||||
else
|
||||
# add discussion topics visible to sections (and related module section overrides)
|
||||
discussion_topics_visible_to_sections = UngradedDiscussionVisibility::Repositories::UngradedDiscussionVisibleToStudentRepository
|
||||
.find_discussion_topics_visible_to_sections(course_id_params:, user_id_params:, discussion_topic_id_params:)
|
||||
visible_discussion_topics |= discussion_topics_visible_to_sections
|
||||
|
||||
# remove discussion topics for students with unassigned section overrides
|
||||
discussion_topics_with_unassigned_section_overrides = UngradedDiscussionVisibility::Repositories::UngradedDiscussionVisibleToStudentRepository
|
||||
.find_discussion_topics_with_unassigned_section_overrides(course_id_params:, user_id_params:, discussion_topic_id_params:)
|
||||
visible_discussion_topics -= discussion_topics_with_unassigned_section_overrides
|
||||
end
|
||||
|
||||
if Account.site_admin.feature_enabled?(:selective_release_optimized_services)
|
||||
# add discussion topics visible due to ADHOC overrides (and related module ADHOC overrides) without unassign overrides
|
||||
discussion_topics_assigned_to_adhoc_overrides = UngradedDiscussionVisibility::Repositories::UngradedDiscussionVisibleToStudentRepository
|
||||
.find_discussion_topics_assigned_to_adhoc_overrides(course_id_params:, user_id_params:, discussion_topic_id_params:)
|
||||
visible_discussion_topics |= discussion_topics_assigned_to_adhoc_overrides
|
||||
else
|
||||
# add discussion topics visible due to ADHOC overrides (and related module ADHOC overrides)
|
||||
discussion_topics_visible_to_adhoc_overrides = UngradedDiscussionVisibility::Repositories::UngradedDiscussionVisibleToStudentRepository
|
||||
.find_discussion_topics_visible_to_adhoc_overrides(course_id_params:, user_id_params:, discussion_topic_id_params:)
|
||||
visible_discussion_topics |= discussion_topics_visible_to_adhoc_overrides
|
||||
|
||||
# remove discussion topics for students with unassigned ADHOC overrides
|
||||
discussion_topics_with_unassigned_adhoc_overrides = UngradedDiscussionVisibility::Repositories::UngradedDiscussionVisibleToStudentRepository
|
||||
.find_discussion_topics_with_unassigned_adhoc_overrides(course_id_params:, user_id_params:, discussion_topic_id_params:)
|
||||
visible_discussion_topics -= discussion_topics_with_unassigned_adhoc_overrides
|
||||
end
|
||||
|
||||
# add discussion topics visible due to course overrides
|
||||
discussion_topics_visible_to_course_overrides = UngradedDiscussionVisibility::Repositories::UngradedDiscussionVisibleToStudentRepository
|
||||
.find_discussion_topics_visible_to_course_overrides(course_id_params:, user_id_params:, discussion_topic_id_params:)
|
||||
|
||||
visible_discussion_topics | discussion_topics_visible_to_course_overrides
|
||||
end
|
||||
|
||||
if Account.site_admin.feature_enabled?(:selective_release_optimized_services)
|
||||
# add discussion topics visible due to ADHOC overrides (and related module ADHOC overrides) without unassign overrides
|
||||
discussion_topics_assigned_to_adhoc_overrides = UngradedDiscussionVisibility::Repositories::UngradedDiscussionVisibleToStudentRepository
|
||||
.find_discussion_topics_assigned_to_adhoc_overrides(course_id_params:, user_id_params:, discussion_topic_id_params:)
|
||||
visible_discussion_topics |= discussion_topics_assigned_to_adhoc_overrides
|
||||
else
|
||||
# add discussion topics visible due to ADHOC overrides (and related module ADHOC overrides)
|
||||
discussion_topics_visible_to_adhoc_overrides = UngradedDiscussionVisibility::Repositories::UngradedDiscussionVisibleToStudentRepository
|
||||
.find_discussion_topics_visible_to_adhoc_overrides(course_id_params:, user_id_params:, discussion_topic_id_params:)
|
||||
visible_discussion_topics |= discussion_topics_visible_to_adhoc_overrides
|
||||
|
||||
# remove discussion topics for students with unassigned ADHOC overrides
|
||||
discussion_topics_with_unassigned_adhoc_overrides = UngradedDiscussionVisibility::Repositories::UngradedDiscussionVisibleToStudentRepository
|
||||
.find_discussion_topics_with_unassigned_adhoc_overrides(course_id_params:, user_id_params:, discussion_topic_id_params:)
|
||||
visible_discussion_topics -= discussion_topics_with_unassigned_adhoc_overrides
|
||||
end
|
||||
|
||||
# add discussion topics visible due to course overrides
|
||||
discussion_topics_visible_to_course_overrides = UngradedDiscussionVisibility::Repositories::UngradedDiscussionVisibleToStudentRepository
|
||||
.find_discussion_topics_visible_to_course_overrides(course_id_params:, user_id_params:, discussion_topic_id_params:)
|
||||
|
||||
visible_discussion_topics | discussion_topics_visible_to_course_overrides
|
||||
end
|
||||
end
|
||||
|
||||
def empty_id_hash(ids)
|
||||
# [1,2,3] => {1:[],2:[],3:[]}
|
||||
ids.zip(ids.map { [] }).to_h
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
#
|
||||
# Copyright (C) 2024 - 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 VisibilityHelpers
|
||||
module Common
|
||||
def service_cache_fetch(service:, course_id_params: nil, user_id_params: nil, additional_id_params: nil, &)
|
||||
key = service_cache_key(service:, course_id_params:, user_id_params:, additional_id_params:)
|
||||
Rails.cache.fetch(key, expires_in: 1.minute, &)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def sanitize_and_stringify_ids(ids)
|
||||
Array(ids).map { |id| id.respond_to?(:id) ? id.id : id }.sort.join(",")
|
||||
end
|
||||
|
||||
def service_cache_key(service:, course_id_params: nil, user_id_params: nil, additional_id_params: nil)
|
||||
# Sometimes we get ids, sometimes we get full AR objects, let's sanitize
|
||||
c = sanitize_and_stringify_ids(course_id_params)
|
||||
u = sanitize_and_stringify_ids(user_id_params)
|
||||
a = sanitize_and_stringify_ids(additional_id_params)
|
||||
Digest::SHA256.hexdigest("#{service}:c#{c}:u#{u}:a#{a}")
|
||||
end
|
||||
end
|
||||
end
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
module WikiPageVisibility
|
||||
class WikiPageVisibilityService
|
||||
extend VisibilityHelpers::Common
|
||||
class << self
|
||||
def wiki_pages_visible_to_student(course_id:, user_id:)
|
||||
raise ArgumentError, "course_id cannot be nil" if course_id.nil?
|
||||
|
@ -56,15 +57,6 @@ module WikiPageVisibility
|
|||
wiki_pages_visible_to_students(wiki_page_id_params: wiki_page_id, user_id_params: user_id)
|
||||
end
|
||||
|
||||
def wiki_pages_visible_to_student_by_pages(wiki_page_ids:, user_id:)
|
||||
raise ArgumentError, "wiki_page_ids cannot be nil" if wiki_page_ids.nil?
|
||||
raise ArgumentError, "wiki_page_ids must be an array" unless wiki_page_ids.is_a?(Array)
|
||||
raise ArgumentError, "user_id cannot be nil" if user_id.nil?
|
||||
raise ArgumentError, "user_id must not be an array" if user_id.is_a?(Array)
|
||||
|
||||
wiki_pages_visible_to_students(wiki_page_id_params: wiki_page_ids, user_id_params: user_id)
|
||||
end
|
||||
|
||||
def wiki_page_visible_to_students(wiki_page_id:, user_ids:)
|
||||
raise ArgumentError, "wiki_page_id cannot be nil" if wiki_page_id.nil?
|
||||
raise ArgumentError, "wiki_page_id must not be an array" if wiki_page_id.is_a?(Array)
|
||||
|
@ -85,15 +77,6 @@ module WikiPageVisibility
|
|||
wiki_pages_visible_to_students(course_id_params: course_id, wiki_page_id_params: wiki_page_id, user_id_params: user_ids)
|
||||
end
|
||||
|
||||
def wiki_page_visible_in_course(wiki_page_id:, course_id:)
|
||||
raise ArgumentError, "course_id cannot be nil" if course_id.nil?
|
||||
raise ArgumentError, "course_id must not be an array" if course_id.is_a?(Array)
|
||||
raise ArgumentError, "wiki_page_id cannot be nil" if wiki_page_id.nil?
|
||||
raise ArgumentError, "wiki_page_id must not be an array" if wiki_page_id.is_a?(Array)
|
||||
|
||||
wiki_pages_visible_to_students(course_id_params: course_id, wiki_page_id_params: wiki_page_id)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def wiki_pages_visible_to_students(course_id_params: nil, user_id_params: nil, wiki_page_id_params: nil)
|
||||
|
@ -101,76 +84,76 @@ module WikiPageVisibility
|
|||
raise ArgumentError, "at least one non nil course_id, user_id, or wiki_page_id_params is required (for query performance reasons)"
|
||||
end
|
||||
|
||||
if Account.site_admin.feature_enabled?(:selective_release_optimized_services_v3)
|
||||
WikiPageVisibility::Repositories::WikiPageVisibleToStudentRepository.full_wiki_page_visibility_query(course_id_params:, user_id_params:, wiki_page_id_params:)
|
||||
elsif Account.site_admin.feature_enabled?(:selective_release_optimized_services_v2)
|
||||
visible_wiki_pages = []
|
||||
service_cache_fetch(service: name,
|
||||
course_id_params:,
|
||||
user_id_params:,
|
||||
additional_id_params: wiki_page_id_params) do
|
||||
if Account.site_admin.feature_enabled?(:selective_release_optimized_services_v3)
|
||||
WikiPageVisibility::Repositories::WikiPageVisibleToStudentRepository.full_wiki_page_visibility_query(course_id_params:, user_id_params:, wiki_page_id_params:)
|
||||
elsif Account.site_admin.feature_enabled?(:selective_release_optimized_services_v2)
|
||||
visible_wiki_pages = []
|
||||
|
||||
# add wiki pages visible to everyone
|
||||
wiki_pages_visible_to_all = WikiPageVisibility::Repositories::WikiPageVisibleToStudentRepository
|
||||
.find_wiki_pages_visible_to_everyone(course_id_params:, user_id_params:, wiki_page_id_params:)
|
||||
visible_wiki_pages |= wiki_pages_visible_to_all
|
||||
# add wiki pages visible to everyone
|
||||
wiki_pages_visible_to_all = WikiPageVisibility::Repositories::WikiPageVisibleToStudentRepository
|
||||
.find_wiki_pages_visible_to_everyone(course_id_params:, user_id_params:, wiki_page_id_params:)
|
||||
visible_wiki_pages |= wiki_pages_visible_to_all
|
||||
|
||||
# add wiki pages assigned to sections, students, or the course
|
||||
wiki_pages_assigned_to_others = WikiPageVisibility::Repositories::WikiPageVisibleToStudentRepository
|
||||
.find_wiki_pages_assigned_to_others(course_id_params:, user_id_params:, wiki_page_id_params:)
|
||||
# add wiki pages assigned to sections, students, or the course
|
||||
wiki_pages_assigned_to_others = WikiPageVisibility::Repositories::WikiPageVisibleToStudentRepository
|
||||
.find_wiki_pages_assigned_to_others(course_id_params:, user_id_params:, wiki_page_id_params:)
|
||||
|
||||
visible_wiki_pages | wiki_pages_assigned_to_others
|
||||
else
|
||||
visible_wiki_pages = []
|
||||
|
||||
# add wiki pages visible to everyone
|
||||
wiki_pages_visible_to_all = WikiPageVisibility::Repositories::WikiPageVisibleToStudentRepository
|
||||
.find_wiki_pages_visible_to_everyone(course_id_params:, user_id_params:, wiki_page_id_params:)
|
||||
visible_wiki_pages |= wiki_pages_visible_to_all
|
||||
|
||||
if Account.site_admin.feature_enabled?(:selective_release_optimized_services)
|
||||
# add wiki pages visible to sections (and related module section overrides) without unassign overrides
|
||||
wiki_pages_assigned_to_sections = WikiPageVisibility::Repositories::WikiPageVisibleToStudentRepository
|
||||
.find_wiki_pages_assigned_to_sections(course_id_params:, user_id_params:, wiki_page_id_params:)
|
||||
visible_wiki_pages |= wiki_pages_assigned_to_sections
|
||||
visible_wiki_pages | wiki_pages_assigned_to_others
|
||||
else
|
||||
# add wiki pages visible to sections (and related module section overrides)
|
||||
wiki_pages_visible_to_sections = WikiPageVisibility::Repositories::WikiPageVisibleToStudentRepository
|
||||
.find_wiki_pages_visible_to_sections(course_id_params:, user_id_params:, wiki_page_id_params:)
|
||||
visible_wiki_pages |= wiki_pages_visible_to_sections
|
||||
visible_wiki_pages = []
|
||||
|
||||
# remove wiki pages for students with unassigned section overrides
|
||||
wiki_pages_with_unassigned_section_overrides = WikiPageVisibility::Repositories::WikiPageVisibleToStudentRepository
|
||||
.find_wiki_pages_with_unassigned_section_overrides(course_id_params:, user_id_params:, wiki_page_id_params:)
|
||||
visible_wiki_pages -= wiki_pages_with_unassigned_section_overrides
|
||||
# add wiki pages visible to everyone
|
||||
wiki_pages_visible_to_all = WikiPageVisibility::Repositories::WikiPageVisibleToStudentRepository
|
||||
.find_wiki_pages_visible_to_everyone(course_id_params:, user_id_params:, wiki_page_id_params:)
|
||||
visible_wiki_pages |= wiki_pages_visible_to_all
|
||||
|
||||
if Account.site_admin.feature_enabled?(:selective_release_optimized_services)
|
||||
# add wiki pages visible to sections (and related module section overrides) without unassign overrides
|
||||
wiki_pages_assigned_to_sections = WikiPageVisibility::Repositories::WikiPageVisibleToStudentRepository
|
||||
.find_wiki_pages_assigned_to_sections(course_id_params:, user_id_params:, wiki_page_id_params:)
|
||||
visible_wiki_pages |= wiki_pages_assigned_to_sections
|
||||
else
|
||||
# add wiki pages visible to sections (and related module section overrides)
|
||||
wiki_pages_visible_to_sections = WikiPageVisibility::Repositories::WikiPageVisibleToStudentRepository
|
||||
.find_wiki_pages_visible_to_sections(course_id_params:, user_id_params:, wiki_page_id_params:)
|
||||
visible_wiki_pages |= wiki_pages_visible_to_sections
|
||||
|
||||
# remove wiki pages for students with unassigned section overrides
|
||||
wiki_pages_with_unassigned_section_overrides = WikiPageVisibility::Repositories::WikiPageVisibleToStudentRepository
|
||||
.find_wiki_pages_with_unassigned_section_overrides(course_id_params:, user_id_params:, wiki_page_id_params:)
|
||||
visible_wiki_pages -= wiki_pages_with_unassigned_section_overrides
|
||||
end
|
||||
|
||||
if Account.site_admin.feature_enabled?(:selective_release_optimized_services)
|
||||
# add wiki pages visible due to ADHOC overrides (and related module ADHOC overrides) without unassign overrides
|
||||
wiki_pages_assigned_to_adhoc_overrides = WikiPageVisibility::Repositories::WikiPageVisibleToStudentRepository
|
||||
.find_wiki_pages_assigned_to_adhoc_overrides(course_id_params:, user_id_params:, wiki_page_id_params:)
|
||||
visible_wiki_pages |= wiki_pages_assigned_to_adhoc_overrides
|
||||
else
|
||||
|
||||
# add wiki pages visible due to ADHOC overrides (and related module ADHOC overrides)
|
||||
wiki_pages_visible_to_adhoc_overrides = WikiPageVisibility::Repositories::WikiPageVisibleToStudentRepository
|
||||
.find_wiki_pages_visible_to_adhoc_overrides(course_id_params:, user_id_params:, wiki_page_id_params:)
|
||||
visible_wiki_pages |= wiki_pages_visible_to_adhoc_overrides
|
||||
|
||||
# remove wiki pages for students with unassigned ADHOC overrides
|
||||
wiki_pages_with_unassigned_adhoc_overrides = WikiPageVisibility::Repositories::WikiPageVisibleToStudentRepository
|
||||
.find_wiki_pages_with_unassigned_adhoc_overrides(course_id_params:, user_id_params:, wiki_page_id_params:)
|
||||
visible_wiki_pages -= wiki_pages_with_unassigned_adhoc_overrides
|
||||
end
|
||||
|
||||
# add wiki pages visible due to course overrides
|
||||
wiki_pages_visible_to_course_overrides = WikiPageVisibility::Repositories::WikiPageVisibleToStudentRepository
|
||||
.find_wiki_pages_visible_to_course_overrides(course_id_params:, user_id_params:, wiki_page_id_params:)
|
||||
|
||||
visible_wiki_pages | wiki_pages_visible_to_course_overrides
|
||||
end
|
||||
|
||||
if Account.site_admin.feature_enabled?(:selective_release_optimized_services)
|
||||
# add wiki pages visible due to ADHOC overrides (and related module ADHOC overrides) without unassign overrides
|
||||
wiki_pages_assigned_to_adhoc_overrides = WikiPageVisibility::Repositories::WikiPageVisibleToStudentRepository
|
||||
.find_wiki_pages_assigned_to_adhoc_overrides(course_id_params:, user_id_params:, wiki_page_id_params:)
|
||||
visible_wiki_pages |= wiki_pages_assigned_to_adhoc_overrides
|
||||
else
|
||||
|
||||
# add wiki pages visible due to ADHOC overrides (and related module ADHOC overrides)
|
||||
wiki_pages_visible_to_adhoc_overrides = WikiPageVisibility::Repositories::WikiPageVisibleToStudentRepository
|
||||
.find_wiki_pages_visible_to_adhoc_overrides(course_id_params:, user_id_params:, wiki_page_id_params:)
|
||||
visible_wiki_pages |= wiki_pages_visible_to_adhoc_overrides
|
||||
|
||||
# remove wiki pages for students with unassigned ADHOC overrides
|
||||
wiki_pages_with_unassigned_adhoc_overrides = WikiPageVisibility::Repositories::WikiPageVisibleToStudentRepository
|
||||
.find_wiki_pages_with_unassigned_adhoc_overrides(course_id_params:, user_id_params:, wiki_page_id_params:)
|
||||
visible_wiki_pages -= wiki_pages_with_unassigned_adhoc_overrides
|
||||
end
|
||||
|
||||
# add wiki pages visible due to course overrides
|
||||
wiki_pages_visible_to_course_overrides = WikiPageVisibility::Repositories::WikiPageVisibleToStudentRepository
|
||||
.find_wiki_pages_visible_to_course_overrides(course_id_params:, user_id_params:, wiki_page_id_params:)
|
||||
|
||||
visible_wiki_pages | wiki_pages_visible_to_course_overrides
|
||||
end
|
||||
end
|
||||
|
||||
def empty_id_hash(ids)
|
||||
# [1,2,3] => {1:[],2:[],3:[]}
|
||||
ids.zip(ids.map { [] }).to_h
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1058,7 +1058,11 @@ describe PlannerController do
|
|||
end
|
||||
|
||||
it "shows new activity when a new discussion topic has been created" do
|
||||
get :index, params: { start_date: @start_date, end_date: @end_date }
|
||||
# the queries behind this be expensive, there is a 1.minute cache on some of them, we'll do our first get
|
||||
# in a time longer ago than the cache length
|
||||
Timecop.freeze(2.minutes.ago) do
|
||||
get :index, params: { start_date: @start_date, end_date: @end_date }
|
||||
end
|
||||
discussion_topic_model(context: @course, todo_date: 1.day.from_now)
|
||||
get :index, params: { start_date: @start_date, end_date: @end_date }
|
||||
topic_json = json_parse(response.body).find { |j| j["plannable_id"] == @topic.id && j["plannable_type"] == "discussion_topic" }
|
||||
|
|
|
@ -470,16 +470,6 @@ describe "differentiated_assignments" do
|
|||
Account.site_admin.disable_feature!(:selective_release_backend)
|
||||
end
|
||||
|
||||
describe ".assignments_visible_to_all_students" do
|
||||
let(:assignments_visible_to_all_students) do
|
||||
AssignmentStudentVisibility.assignments_visible_to_all_students([assignment])
|
||||
end
|
||||
|
||||
it "returns a hash with an empty visibility array for each assignment" do
|
||||
expect(assignments_visible_to_all_students).to eq({ assignment.id => [] })
|
||||
end
|
||||
end
|
||||
|
||||
describe ".assignments_with_user_visibilities" do
|
||||
let(:assignment_only_visible_to_overrides) do
|
||||
assignment = course.assignments.create!({
|
||||
|
|
|
@ -148,14 +148,11 @@ describe AssignmentVisibility::AssignmentVisibilityService do
|
|||
def ensure_user_does_not_see_assignment
|
||||
visible_assignment_ids = AssignmentVisibility::AssignmentVisibilityService.assignments_visible_to_student(user_id: @user.id, course_id: @course.id).map(&:assignment_id)
|
||||
expect(visible_assignment_ids.map(&:to_i).include?(@assignment.id)).to be_falsey
|
||||
expect(AssignmentVisibility::AssignmentVisibilityService.visible_assignment_ids_in_course_for_user(user_id: @user.id, course_id: @course.id)[@user.id]).not_to include(@assignment.id)
|
||||
end
|
||||
|
||||
def ensure_user_sees_assignment
|
||||
visible_assignment_ids = AssignmentVisibility::AssignmentVisibilityService.assignments_visible_to_student(user_id: @user.id, course_id: @course.id).map(&:assignment_id)
|
||||
expect(visible_assignment_ids.map(&:to_i).include?(@assignment.id)).to be_truthy
|
||||
expect(AssignmentVisibility::AssignmentVisibilityService.visible_assignment_ids_in_course_for_user(user_id: @user.id, course_id: @course.id)[@user.id]).to include(@assignment.id)
|
||||
expect(AssignmentVisibility::AssignmentVisibilityService.visible_assignment_ids_in_course_for_user(user_id: @user.id, course_id: @course.id, use_global_id: true)[Shard.global_id_for(@user.id)]).to include(@assignment.id)
|
||||
end
|
||||
|
||||
context "course_with_differentiated_assignments_enabled" do
|
||||
|
@ -679,16 +676,6 @@ describe AssignmentVisibility::AssignmentVisibilityService do
|
|||
let(:second_student) { User.create! }
|
||||
let(:fake_student) { User.create! }
|
||||
|
||||
describe ".assignments_visible_to_all_students" do
|
||||
let(:assignments_visible_to_all_students) do
|
||||
AssignmentVisibility::AssignmentVisibilityService.assignments_visible_to_all_students([assignment])
|
||||
end
|
||||
|
||||
it "returns a hash with an empty visibility array for each assignment" do
|
||||
expect(assignments_visible_to_all_students).to eq({ assignment.id => [] })
|
||||
end
|
||||
end
|
||||
|
||||
describe ".assignments_with_user_visibilities" do
|
||||
let(:assignment_only_visible_to_overrides) do
|
||||
assignment = course.assignments.create!({
|
||||
|
|
|
@ -142,14 +142,6 @@ describe "differentiated_assignments" do
|
|||
ensure_user_sees_quiz
|
||||
end
|
||||
|
||||
it "works with course section and return a single visibility" do
|
||||
student_in_course_with_adhoc_override(@quiz)
|
||||
give_section_foo_due_date(@quiz)
|
||||
enroller_user_in_section(@section_foo)
|
||||
ensure_user_sees_quiz
|
||||
expect(QuizVisibility::QuizVisibilityService.quiz_visible_to_students_in_course(user_ids: [@user.id], course_id: @course.id, quiz_id: @quiz.id).count).to eq 1
|
||||
end
|
||||
|
||||
it "does not return a visibility for a student without an ADHOC override" do
|
||||
@user = user_model
|
||||
ensure_user_does_not_see_quiz
|
||||
|
|
Loading…
Reference in New Issue