Check for section visibilities in date_details api
Because ungraded discussion topics were previously able to be differentiated by section, we need to ensure that those sections are present in the assign to tray. Note that the test plan uses the 'Post to' section of the discussion edit page, which will be eventually removed when the flag is on. This functionality is so far only for the tray outside of the discussions edit page. closes LF-1493 flag=differentiated_modules test plan: - create an ungraded discussion and use the 'Post to' drop down to assign it to a certain section. - save, and then open the assign to tray for that discussion - expect to see the section assigned in the tray. Do not save the tray yet - add the ungraded discussion to a module - assign that module to the same section that the you assigned to the discussion - open the tray again for the discussion, expect to still only see the section override (should not say inherited from module) - save the tray, try making edits to the overrides, expect the tray to behave as normal. Change-Id: I8d3967ffc18237b78821c541ee09cd3958830ab5 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/345626 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Jackson Howe <jackson.howe@instructure.com> QA-Review: Jason Gillett <jason.gillett@instructure.com> Product-Review: Sarah Gerard <sarah.gerard@instructure.com>
This commit is contained in:
parent
ae0554b895
commit
159cd82a95
|
@ -96,10 +96,21 @@ class LearningObjectDatesController < ApplicationController
|
|||
def show
|
||||
route = polymorphic_url([:api_v1, @context, asset, :date_details])
|
||||
overrides = Api.paginate(overridable.all_assignment_overrides.active, self, route)
|
||||
|
||||
# this is a temporary check for any discussion_topic_section_visibilities until we eventually backfill that table
|
||||
visibilities_to_override = if overridable.is_a?(DiscussionTopic) && overridable.is_section_specific
|
||||
section_overrides = overridable.assignment_overrides.active.where(set_type: "CourseSection").select(:set_id)
|
||||
section_visibilities = overridable.discussion_topic_section_visibilities.active.where.not(course_section_id: section_overrides)
|
||||
Api.paginate(section_visibilities, self, route)
|
||||
end
|
||||
|
||||
all_overrides = assignment_overrides_json(overrides, @current_user, include_names: true)
|
||||
all_overrides += section_visibility_to_override_json(section_visibilities, overridable) if visibilities_to_override
|
||||
|
||||
render json: {
|
||||
**learning_object_dates_json(asset, overridable),
|
||||
**blueprint_date_locks_json(asset),
|
||||
overrides: assignment_overrides_json(overrides, @current_user, include_names: true),
|
||||
overrides: all_overrides,
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -243,6 +254,11 @@ class LearningObjectDatesController < ApplicationController
|
|||
object.transaction do
|
||||
object.update!(params)
|
||||
perform_batch_update_assignment_overrides(object, batch) if overrides
|
||||
# this is temporary until we are able to remove the dicussion_topic_section_visibilities table
|
||||
if object.is_a?(DiscussionTopic) && object.is_section_specific
|
||||
object.discussion_topic_section_visibilities.destroy_all
|
||||
object.update!(is_section_specific: false)
|
||||
end
|
||||
end
|
||||
head :no_content
|
||||
end
|
||||
|
|
|
@ -54,6 +54,20 @@ module Api::V1::AssignmentOverride
|
|||
end
|
||||
end
|
||||
|
||||
# temporary function to convert discussion_topic_section_visibilities to section overrides
|
||||
# will be able to remove once we deprecate the old section visibilities table
|
||||
def section_visibility_to_override_json(section_visibilities, discussion)
|
||||
section_visibilities.map do |section_visibility|
|
||||
fields = %i[]
|
||||
api_json(section_visibility, @current_user, session, only: fields).tap do |json|
|
||||
json[:discussion_topic_id] = section_visibility.discussion_topic_id
|
||||
json[:course_section_id] = section_visibility.course_section_id
|
||||
json[:unlock_at] = discussion.unlock_at if discussion.unlock_at
|
||||
json[:lock_at] = discussion.lock_at if discussion.lock_at
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assignment_overrides_json(overrides, user = nil, include_names: false)
|
||||
visible_users_ids = ::AssignmentOverride.visible_enrollments_for(overrides.compact, user).select(:user_id)
|
||||
# we most likely already have the student_ids preloaded here because of overridden_for, but just in case
|
||||
|
|
|
@ -93,7 +93,13 @@ module DatesOverridable
|
|||
|
||||
def visible_to_everyone
|
||||
if Account.site_admin.feature_enabled? :differentiated_modules
|
||||
assignment_overrides.active.where(set_type: "Course").exists? || (!only_visible_to_overrides && (assignment_context_modules.empty? || (assignment_context_modules.any? && assignment_context_modules_without_overrides.any?)))
|
||||
if is_a?(DiscussionTopic)
|
||||
# need to check if is_section_specific for ungraded discussions
|
||||
# this column will eventually be deprecated and then this can be removed
|
||||
assignment_overrides.active.where(set_type: "Course").exists? || ((!only_visible_to_overrides && !is_section_specific) && (assignment_context_modules.empty? || (assignment_context_modules.any? && assignment_context_modules_without_overrides.any?)))
|
||||
else
|
||||
assignment_overrides.active.where(set_type: "Course").exists? || (!only_visible_to_overrides && (assignment_context_modules.empty? || (assignment_context_modules.any? && assignment_context_modules_without_overrides.any?)))
|
||||
end
|
||||
else
|
||||
!only_visible_to_overrides
|
||||
end
|
||||
|
|
|
@ -182,6 +182,89 @@ describe LearningObjectDatesController do
|
|||
})
|
||||
end
|
||||
|
||||
it "returns date details for an ungraded discussion with a section visibility" do
|
||||
discussion = @course.discussion_topics.create!(title: "ungraded topic",
|
||||
unlock_at: "2022-01-05T12:00:00Z",
|
||||
lock_at: "2022-03-05T12:00:00Z")
|
||||
discussion.discussion_topic_section_visibilities << DiscussionTopicSectionVisibility.new(
|
||||
discussion_topic: @topic,
|
||||
course_section: @course.default_section,
|
||||
workflow_state: "active"
|
||||
)
|
||||
discussion.is_section_specific = true
|
||||
discussion.save!
|
||||
|
||||
get :show, params: { course_id: @course.id, discussion_topic_id: discussion.id }
|
||||
expect(response).to be_successful
|
||||
expect(json_parse).to eq({
|
||||
"id" => discussion.id,
|
||||
"unlock_at" => "2022-01-05T12:00:00Z",
|
||||
"lock_at" => "2022-03-05T12:00:00Z",
|
||||
"only_visible_to_overrides" => false,
|
||||
"graded" => false,
|
||||
"visible_to_everyone" => false,
|
||||
"overrides" => [{
|
||||
"discussion_topic_id" => discussion.id,
|
||||
"course_section_id" => @course.default_section.id,
|
||||
"unlock_at" => "2022-01-05T12:00:00Z",
|
||||
"lock_at" => "2022-03-05T12:00:00Z"
|
||||
}]
|
||||
})
|
||||
end
|
||||
|
||||
it "returns date details for an ungraded discussion with a section visibility and section override" do
|
||||
section1 = @course.course_sections.create!
|
||||
section2 = @course.course_sections.create!
|
||||
discussion = @course.discussion_topics.create!(title: "ungraded topic",
|
||||
unlock_at: "2022-01-05T12:00:00Z",
|
||||
lock_at: "2022-03-05T12:00:00Z")
|
||||
discussion.discussion_topic_section_visibilities << DiscussionTopicSectionVisibility.new(
|
||||
discussion_topic: @topic,
|
||||
course_section: section1,
|
||||
workflow_state: "active"
|
||||
)
|
||||
|
||||
discussion.discussion_topic_section_visibilities << DiscussionTopicSectionVisibility.new(
|
||||
discussion_topic: @topic,
|
||||
course_section: section2,
|
||||
workflow_state: "active"
|
||||
)
|
||||
|
||||
discussion.is_section_specific = true
|
||||
discussion.save!
|
||||
|
||||
override = discussion.assignment_overrides.create!(set: section1,
|
||||
lock_at: "2022-01-04T12:00:00Z",
|
||||
lock_at_overridden: true)
|
||||
|
||||
get :show, params: { course_id: @course.id, discussion_topic_id: discussion.id }
|
||||
expect(response).to be_successful
|
||||
|
||||
expect(json_parse).to eq({
|
||||
"id" => discussion.id,
|
||||
"unlock_at" => "2022-01-05T12:00:00Z",
|
||||
"lock_at" => "2022-03-05T12:00:00Z",
|
||||
"only_visible_to_overrides" => false,
|
||||
"graded" => false,
|
||||
"visible_to_everyone" => false,
|
||||
"overrides" => [
|
||||
{
|
||||
"id" => override.id,
|
||||
"discussion_topic_id" => discussion.id,
|
||||
"title" => override.title,
|
||||
"course_section_id" => section1.id,
|
||||
"lock_at" => "2022-01-04T12:00:00Z"
|
||||
},
|
||||
{
|
||||
"discussion_topic_id" => discussion.id,
|
||||
"course_section_id" => section2.id,
|
||||
"unlock_at" => "2022-01-05T12:00:00Z",
|
||||
"lock_at" => "2022-03-05T12:00:00Z"
|
||||
}
|
||||
]
|
||||
})
|
||||
end
|
||||
|
||||
it "returns date details for a page" do
|
||||
wiki_page = @course.wiki_pages.create!(title: "My Page",
|
||||
unlock_at: "2022-01-05T00:00:00Z",
|
||||
|
@ -629,6 +712,24 @@ describe LearningObjectDatesController do
|
|||
|
||||
include_examples "learning object updates", false
|
||||
include_examples "learning objects without due dates"
|
||||
|
||||
it "removes section visibilities and changes 'is_section_specific' to false" do
|
||||
learning_object.discussion_topic_section_visibilities << DiscussionTopicSectionVisibility.new(
|
||||
discussion_topic: learning_object,
|
||||
course_section: @course.default_section,
|
||||
workflow_state: "active"
|
||||
)
|
||||
learning_object.is_section_specific = true
|
||||
learning_object.save!
|
||||
|
||||
expect(learning_object.discussion_topic_section_visibilities.count).to eq 1
|
||||
|
||||
put :update, params: { **default_params, unlock_at: "2019-01-02T05:00:00Z" }
|
||||
expect(response).to be_no_content
|
||||
learning_object.reload
|
||||
expect(learning_object.is_section_specific).to be false
|
||||
expect(learning_object.discussion_topic_section_visibilities.count).to eq 0
|
||||
end
|
||||
end
|
||||
|
||||
context "pages" do
|
||||
|
|
Loading…
Reference in New Issue