Wire up assingment overrides for DT create
refs VICE-3927 flag=create_discussion Test Plan: - go to new discussion create page - create a graded discussion with assignment overrides - should be able to view overrides on the discussion page - should be able to create overrides for students and sections NOTE: - group overrides are being created but workflow state is being set to deleted - mastery path overrides will not work as part of this patch set Change-Id: If12c686a4339a3b1cae85b9cf878c73164d45105 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/333836 Product-Review: Drake Harper <drake.harper@instructure.com> Reviewed-by: Chawn Neal <chawn.neal@instructure.com> Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> QA-Review: Jason Gillett <jason.gillett@instructure.com>
This commit is contained in:
parent
0842357f76
commit
c56c03d293
|
@ -24,7 +24,7 @@ class Mutations::AssignmentOverrideCreateOrUpdate < GraphQL::Schema::InputObject
|
|||
argument :lock_at, Types::DateTimeType, required: false
|
||||
argument :unlock_at, Types::DateTimeType, required: false
|
||||
|
||||
argument :section_id, ID, required: false
|
||||
argument :course_section_id, ID, required: false
|
||||
argument :group_id, ID, required: false
|
||||
argument :student_ids, [ID], required: false
|
||||
end
|
||||
|
@ -53,6 +53,7 @@ class Mutations::AssignmentInputBase < GraphQL::Schema::InputObject
|
|||
argument :due_at, Types::DateTimeType, required: false
|
||||
argument :grading_type, Types::AssignmentType::AssignmentGradingType, required: false
|
||||
argument :grading_standard_id, ID, required: false
|
||||
argument :group_category_id, ID, required: false
|
||||
argument :lock_at, Types::DateTimeType, required: false
|
||||
argument :peer_reviews, Mutations::AssignmentPeerReviewsUpdate, required: false
|
||||
argument :points_possible, Float, required: false
|
||||
|
@ -174,7 +175,7 @@ class Mutations::AssignmentBase < Mutations::BaseMutation
|
|||
end
|
||||
|
||||
def prepare_overrides!(input_hash, api_proxy)
|
||||
if input_hash.key? :assignment_overrides
|
||||
if input_hash.key?(:assignment_overrides) && input_hash[:assignment_overrides].present?
|
||||
api_proxy.load_root_account
|
||||
input_hash[:assignment_overrides].each do |override|
|
||||
if override[:id].blank?
|
||||
|
@ -182,9 +183,9 @@ class Mutations::AssignmentBase < Mutations::BaseMutation
|
|||
else
|
||||
override[:id] = GraphQLHelpers.parse_relay_or_legacy_id(override[:id], "AssignmentOverride")
|
||||
end
|
||||
override[:course_section_id] = GraphQLHelpers.parse_relay_or_legacy_id(override[:section_id], "Section") if override.key? :section_id
|
||||
override[:group_id] = GraphQLHelpers.parse_relay_or_legacy_id(override[:group_id], "Group") if override.key? :group_id
|
||||
override[:student_ids] = override[:student_ids].map { |id| GraphQLHelpers.parse_relay_or_legacy_id(id, "User") } if override.key? :student_ids
|
||||
override[:course_section_id] = GraphQLHelpers.parse_relay_or_legacy_id(override[:section_id], "Section") if override.key?(:section_id) && override[:section_id].present?
|
||||
override[:group_id] = GraphQLHelpers.parse_relay_or_legacy_id(override[:group_id], "Group") if override.key?(:group_id) && override[:group_id].present?
|
||||
override[:student_ids] = override[:student_ids].map { |id| GraphQLHelpers.parse_relay_or_legacy_id(id, "User") } if override.key?(:student_ids) && override[:student_ids].present?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -206,11 +207,11 @@ class Mutations::AssignmentBase < Mutations::BaseMutation
|
|||
def prepare_peer_reviews!(input_hash)
|
||||
if input_hash.key?(:peer_reviews) && input_hash[:peer_reviews].present?
|
||||
peer_reviews = input_hash.delete(:peer_reviews)
|
||||
input_hash[:peer_reviews] = peer_reviews[:enabled] if peer_reviews.key? :enabled
|
||||
input_hash[:peer_review_count] = peer_reviews[:count] if peer_reviews.key? :count
|
||||
input_hash[:intra_group_peer_reviews] = peer_reviews[:intra_reviews] if peer_reviews.key? :intra_reviews
|
||||
input_hash[:anonymous_peer_reviews] = peer_reviews[:anonymous_reviews] if peer_reviews.key? :anonymous_reviews
|
||||
input_hash[:automatic_peer_reviews] = peer_reviews[:automatic_reviews] if peer_reviews.key? :automatic_reviews
|
||||
input_hash[:peer_reviews] = peer_reviews[:enabled] if peer_reviews.key?(:enabled) && peer_reviews[:enabled].present?
|
||||
input_hash[:peer_review_count] = peer_reviews[:count] if peer_reviews.key?(:count) && peer_reviews[:count].present?
|
||||
input_hash[:intra_group_peer_reviews] = peer_reviews[:intra_reviews] if peer_reviews.key?(:intra_reviews) && peer_reviews[:intra_reviews].present?
|
||||
input_hash[:anonymous_peer_reviews] = peer_reviews[:anonymous_reviews] if peer_reviews.key?(:anonymous_reviews) && peer_reviews[:anonymous_reviews].present?
|
||||
input_hash[:automatic_peer_reviews] = peer_reviews[:automatic_reviews] if peer_reviews.key?(:automatic_reviews) && peer_reviews[:automatic_reviews].present?
|
||||
|
||||
# this should be peer_reviews_due_at, but its not permitted in the backend and peer_reviews_assign_at
|
||||
# is transformed into peer_reviews_due_at. that's probably a bug, but just to keep this update resilient
|
||||
|
|
|
@ -126,6 +126,8 @@ module Api::V1::AssignmentOverride
|
|||
end
|
||||
|
||||
def interpret_assignment_override_data(assignment, data, set_type = nil)
|
||||
@domain_root_account ||= LoadAccount.default_domain_root_account
|
||||
|
||||
data ||= {}
|
||||
return {}, ["invalid override data"] unless data.is_a?(Hash) || data.is_a?(ActionController::Parameters)
|
||||
|
||||
|
@ -168,7 +170,7 @@ module Api::V1::AssignmentOverride
|
|||
override_data[:students] = students
|
||||
end
|
||||
|
||||
if !set_type && data.key?(:group_id)
|
||||
if !set_type && data.key?(:group_id) && data[:group_id].present?
|
||||
group_category_id = assignment.group_category_id || assignment.discussion_topic.try(:group_category_id)
|
||||
if group_category_id
|
||||
set_type = "Group"
|
||||
|
@ -185,7 +187,7 @@ module Api::V1::AssignmentOverride
|
|||
end
|
||||
end
|
||||
|
||||
if !set_type && data.key?(:course_section_id)
|
||||
if !set_type && data.key?(:course_section_id) && data[:course_section_id].present?
|
||||
set_type = "CourseSection"
|
||||
|
||||
# look up the section
|
||||
|
@ -442,6 +444,7 @@ module Api::V1::AssignmentOverride
|
|||
|
||||
override_errors = []
|
||||
overrides_to_save = overrides_params.map do |override_params|
|
||||
# override_params.values.filter {|v| v.present?}.length > 0
|
||||
override = get_override_from_params(override_params, assignment, overrides_to_keep)
|
||||
update_override_with_invisible_data(override_params, override, invisible_override_ids, invisible_user_ids)
|
||||
|
||||
|
|
|
@ -282,7 +282,7 @@ describe Mutations::CreateAssignment do
|
|||
dueAt: "#{due2.iso8601}"
|
||||
},
|
||||
{
|
||||
sectionId: #{@course.default_section.to_param}
|
||||
courseSectionId: #{@course.default_section.to_param}
|
||||
dueAt: "#{due3.iso8601}"
|
||||
}
|
||||
]
|
||||
|
|
|
@ -104,6 +104,9 @@ describe Mutations::CreateDiscussionTopic do
|
|||
name
|
||||
pointsPossible
|
||||
gradingType
|
||||
groupSet {
|
||||
_id
|
||||
}
|
||||
peerReviews {
|
||||
anonymousReviews
|
||||
automaticReviews
|
||||
|
@ -860,6 +863,7 @@ describe Mutations::CreateDiscussionTopic do
|
|||
message = "Lorem ipsum..."
|
||||
published = true
|
||||
student = @course.enroll_student(User.create!, enrollment_state: "active").user
|
||||
group_category = @course.group_categories.create! name: "foo"
|
||||
|
||||
query = <<~GQL
|
||||
contextId: "#{@course.id}"
|
||||
|
@ -867,12 +871,14 @@ describe Mutations::CreateDiscussionTopic do
|
|||
title: "#{title}"
|
||||
message: "#{message}"
|
||||
published: #{published}
|
||||
groupCategoryId: "#{group_category.id}"
|
||||
assignment: {
|
||||
courseId: "#{@course.id}",
|
||||
name: "#{title}",
|
||||
pointsPossible: 15,
|
||||
gradingType: percent,
|
||||
postToSis: true,
|
||||
groupCategoryId: "#{group_category.id}"
|
||||
peerReviews: {
|
||||
anonymousReviews: true,
|
||||
automaticReviews: true,
|
||||
|
@ -900,6 +906,7 @@ describe Mutations::CreateDiscussionTopic do
|
|||
expect(discussion_topic["assignment"]["peerReviews"]["count"]).to eq 2
|
||||
expect(discussion_topic["assignment"]["assignmentOverrides"]["nodes"]).to match([{ "_id" => assignment.assignment_overrides.first.id.to_s, "title" => assignment.assignment_overrides.first.title }])
|
||||
expect(discussion_topic["assignment"]["_id"]).to eq assignment.id.to_s
|
||||
expect(discussion_topic["assignment"]["groupSet"]["_id"]).to eq group_category.id.to_s
|
||||
expect(discussion_topic["_id"]).to eq assignment.discussion_topic.id.to_s
|
||||
expect(DiscussionTopic.count).to eq 1
|
||||
expect(DiscussionTopic.last.assignment.post_to_sis).to be true
|
||||
|
|
|
@ -149,7 +149,7 @@ describe Mutations::UpdateAssignment do
|
|||
id: "#{@assignment_id}"
|
||||
assignmentOverrides: [
|
||||
{
|
||||
sectionId: "#{section.id}"
|
||||
courseSectionId: "#{section.id}"
|
||||
}
|
||||
]
|
||||
GQL
|
||||
|
@ -195,7 +195,7 @@ describe Mutations::UpdateAssignment do
|
|||
studentIds: ["#{@student.id}"]
|
||||
}
|
||||
{
|
||||
sectionId: "#{section.id}"
|
||||
courseSectionId: "#{section.id}"
|
||||
}
|
||||
{
|
||||
groupId: "#{@group.id}"
|
||||
|
@ -343,11 +343,11 @@ describe Mutations::UpdateAssignment do
|
|||
id: "#{@assignment_id}"
|
||||
assignmentOverrides: [
|
||||
{
|
||||
sectionId: "#{section.id}"
|
||||
courseSectionId: "#{section.id}"
|
||||
unlockAt: "2018-01-01T01:00:00Z"
|
||||
}
|
||||
{
|
||||
sectionId: "#{section.id}"
|
||||
courseSectionId: "#{section.id}"
|
||||
unlockAt: "2018-01-02T01:00:00Z"
|
||||
}
|
||||
]
|
||||
|
@ -363,11 +363,11 @@ describe Mutations::UpdateAssignment do
|
|||
id: "#{@assignment_id}"
|
||||
assignmentOverrides: [
|
||||
{
|
||||
sectionId: "#{section1.id}"
|
||||
courseSectionId: "#{section1.id}"
|
||||
dueAt: "2019-02-28T17:01:00Z-05:00"
|
||||
}
|
||||
{
|
||||
sectionId: "#{section2.id}"
|
||||
courseSectionId: "#{section2.id}"
|
||||
dueAt: "2018:02-28T17:02:00Z-05:00"
|
||||
}
|
||||
]
|
||||
|
|
|
@ -979,6 +979,282 @@ describe "discussions" do
|
|||
|
||||
expect(fj("body:contains('Groups can only be part of the actively selected group set.')")).to be_present
|
||||
end
|
||||
|
||||
context "assignment overrides" do
|
||||
before do
|
||||
@section_1 = course.course_sections.create!(name: "section 1")
|
||||
@section_2 = course.course_sections.create!(name: "section 2")
|
||||
@section_3 = course.course_sections.create!(name: "section 3")
|
||||
|
||||
@group_category = course.group_categories.create!(name: "group category 1")
|
||||
@group_1 = @group_category.groups.create!(name: "group 1", context_type: "Course", context_id: course.id)
|
||||
@group_2 = @group_category.groups.create!(name: "group 2", context_type: "Course", context_id: course.id)
|
||||
@group_3 = @group_category.groups.create!(name: "group 3", context_type: "Course", context_id: course.id)
|
||||
|
||||
@student_1 = User.create!(name: "student 1")
|
||||
@student_2 = User.create!(name: "student 2")
|
||||
@student_3 = User.create!(name: "student 3")
|
||||
|
||||
course.enroll_student(@student_1, enrollment_state: "active", section: @section_1)
|
||||
course.enroll_student(@student_2, enrollment_state: "active", section: @section_2)
|
||||
course.enroll_student(@student_3, enrollment_state: "active", section: @section_3)
|
||||
end
|
||||
|
||||
it "creates a discussion topic with an assignment with section overrides" do
|
||||
get "/courses/#{course.id}/discussion_topics/new"
|
||||
|
||||
title = "Graded Discussion Topic with section overrides"
|
||||
message = "replying to topic"
|
||||
|
||||
f("input[placeholder='Topic Title']").send_keys title
|
||||
type_in_tiny("textarea", message)
|
||||
|
||||
force_click('input[type=checkbox][value="graded"]')
|
||||
wait_for_ajaximations
|
||||
|
||||
f("input[data-testid='points-possible-input']").send_keys "12"
|
||||
|
||||
assign_to_element = f("input[data-testid='assign-to-select']")
|
||||
assign_to_element.click
|
||||
assign_to_element.send_keys :backspace
|
||||
assign_to_element.send_keys "section 1"
|
||||
assign_to_element.send_keys :enter
|
||||
assign_to_element.send_keys "section 2"
|
||||
assign_to_element.send_keys :enter
|
||||
assign_to_element.send_keys "section 3"
|
||||
assign_to_element.send_keys :enter
|
||||
|
||||
f("button[data-testid='save-and-publish-button']").click
|
||||
wait_for_ajaximations
|
||||
|
||||
dt = DiscussionTopic.last
|
||||
expect(dt.title).to eq title
|
||||
expect(dt.assignment.name).to eq title
|
||||
|
||||
overrides = dt.assignment.assignment_overrides
|
||||
expect(overrides.length).to be 3
|
||||
override_titles = overrides.map(&:title)
|
||||
expect(override_titles).to include @section_1.name
|
||||
expect(override_titles).to include @section_2.name
|
||||
expect(override_titles).to include @section_3.name
|
||||
end
|
||||
|
||||
it "creates a discussion topic with an assignment with group overrides" do
|
||||
skip # will fix as part of VICE-3927
|
||||
get "/courses/#{course.id}/discussion_topics/new"
|
||||
|
||||
title = "Graded Discussion Topic with group overrides"
|
||||
message = "replying to topic"
|
||||
|
||||
f("input[placeholder='Topic Title']").send_keys title
|
||||
type_in_tiny("textarea", message)
|
||||
|
||||
force_click('input[type=checkbox][value="graded"]')
|
||||
wait_for_ajaximations
|
||||
|
||||
f("input[data-testid='points-possible-input']").send_keys "12"
|
||||
|
||||
force_click("input[data-testid='group-discussion-checkbox']")
|
||||
group_category_input = f("input[placeholder='Select a group category']")
|
||||
group_category_input.click
|
||||
group_category_input.send_keys :arrow_down
|
||||
group_category_input.send_keys :enter
|
||||
|
||||
assign_to_element = f("input[data-testid='assign-to-select']")
|
||||
assign_to_element.click
|
||||
assign_to_element.send_keys :backspace
|
||||
assign_to_element.send_keys "group 1"
|
||||
assign_to_element.send_keys :enter
|
||||
assign_to_element.send_keys "group 2"
|
||||
assign_to_element.send_keys :enter
|
||||
assign_to_element.send_keys "group 3"
|
||||
assign_to_element.send_keys :enter
|
||||
|
||||
f("button[data-testid='save-and-publish-button']").click
|
||||
wait_for_ajaximations
|
||||
|
||||
dt = Assignment.last.discussion_topic
|
||||
expect(dt.title).to eq title
|
||||
expect(dt.assignment.name).to eq title
|
||||
|
||||
overrides = dt.assignment.assignment_overrides
|
||||
expect(overrides.length).to be 3
|
||||
override_titles = overrides.map(&:title)
|
||||
expect(override_titles).to include @group_1.name
|
||||
expect(override_titles).to include @group_2.name
|
||||
expect(override_titles).to include @group_3.name
|
||||
overrides.each do |override|
|
||||
expect(override.workflow_state).to eq "active"
|
||||
end
|
||||
end
|
||||
|
||||
it "creates a discussion topic with an assignment with student override" do
|
||||
get "/courses/#{course.id}/discussion_topics/new"
|
||||
|
||||
title = "Graded Discussion Topic with student overrides"
|
||||
message = "replying to topic"
|
||||
|
||||
f("input[placeholder='Topic Title']").send_keys title
|
||||
type_in_tiny("textarea", message)
|
||||
|
||||
force_click('input[type=checkbox][value="graded"]')
|
||||
wait_for_ajaximations
|
||||
|
||||
f("input[data-testid='points-possible-input']").send_keys "12"
|
||||
|
||||
assign_to_element = f("input[data-testid='assign-to-select']")
|
||||
assign_to_element.click
|
||||
assign_to_element.send_keys :backspace
|
||||
assign_to_element.send_keys "student 1"
|
||||
assign_to_element.send_keys :enter
|
||||
assign_to_element.send_keys "student 2"
|
||||
assign_to_element.send_keys :enter
|
||||
assign_to_element.send_keys "student 3"
|
||||
assign_to_element.send_keys :enter
|
||||
|
||||
f("button[data-testid='save-and-publish-button']").click
|
||||
wait_for_ajaximations
|
||||
|
||||
dt = DiscussionTopic.last
|
||||
expect(dt.title).to eq title
|
||||
expect(dt.assignment.name).to eq title
|
||||
|
||||
overrides = dt.assignment.assignment_overrides
|
||||
expect(overrides.length).to be 1
|
||||
expect(overrides[0].title).to eq "3 students"
|
||||
end
|
||||
|
||||
it "creates a discussion topic with an assignment with section, group, and student overries as part of one" do
|
||||
skip # will fix as part of VICE-3927
|
||||
get "/courses/#{course.id}/discussion_topics/new"
|
||||
|
||||
title = "Graded Discussion Topic with section, group, and student overries as part of one"
|
||||
message = "replying to topic"
|
||||
|
||||
f("input[placeholder='Topic Title']").send_keys title
|
||||
type_in_tiny("textarea", message)
|
||||
|
||||
force_click('input[type=checkbox][value="graded"]')
|
||||
wait_for_ajaximations
|
||||
|
||||
force_click("input[data-testid='group-discussion-checkbox']")
|
||||
group_category_input = f("input[placeholder='Select a group category']")
|
||||
group_category_input.click
|
||||
group_category_input.send_keys :arrow_down
|
||||
group_category_input.send_keys :enter
|
||||
|
||||
f("input[data-testid='points-possible-input']").send_keys "12"
|
||||
|
||||
assign_to_element = f("input[data-testid='assign-to-select']")
|
||||
assign_to_element.click
|
||||
assign_to_element.send_keys :backspace
|
||||
assign_to_element.send_keys "section 1"
|
||||
assign_to_element.send_keys :enter
|
||||
assign_to_element.send_keys "section 2"
|
||||
assign_to_element.send_keys :enter
|
||||
assign_to_element.send_keys "section 3"
|
||||
assign_to_element.send_keys :enter
|
||||
assign_to_element.send_keys "group 1"
|
||||
assign_to_element.send_keys :enter
|
||||
assign_to_element.send_keys "group 2"
|
||||
assign_to_element.send_keys :enter
|
||||
assign_to_element.send_keys "group 3"
|
||||
assign_to_element.send_keys :enter
|
||||
assign_to_element.send_keys "student 1"
|
||||
assign_to_element.send_keys :enter
|
||||
assign_to_element.send_keys "student 2"
|
||||
assign_to_element.send_keys :enter
|
||||
assign_to_element.send_keys "student 3"
|
||||
assign_to_element.send_keys :enter
|
||||
|
||||
f("button[data-testid='save-and-publish-button']").click
|
||||
wait_for_ajaximations
|
||||
|
||||
dt = Assignment.last.discussion_topic
|
||||
expect(dt.title).to eq title
|
||||
expect(dt.assignment.name).to eq title
|
||||
|
||||
overrides = dt.assignment.assignment_overrides
|
||||
override_titles = overrides.map(&:title)
|
||||
expect(overrides.length).to be 7
|
||||
expect(override_titles).to include "3 students"
|
||||
expect(override_titles).to include @section_1.name
|
||||
expect(override_titles).to include @section_2.name
|
||||
expect(override_titles).to include @section_3.name
|
||||
expect(override_titles).to include @group_1.name
|
||||
expect(override_titles).to include @group_2.name
|
||||
expect(override_titles).to include @group_3.name
|
||||
end
|
||||
|
||||
it "creates a discussion topic with an assignment with section, group, and student overries separately" do
|
||||
skip # will fix as part of VICE-3927
|
||||
get "/courses/#{course.id}/discussion_topics/new"
|
||||
|
||||
title = "Graded Discussion Topic with section, group, and student overries separately"
|
||||
message = "replying to topic"
|
||||
|
||||
f("input[placeholder='Topic Title']").send_keys title
|
||||
type_in_tiny("textarea", message)
|
||||
|
||||
force_click('input[type=checkbox][value="graded"]')
|
||||
wait_for_ajaximations
|
||||
|
||||
force_click("input[data-testid='group-discussion-checkbox']")
|
||||
group_category_input = f("input[placeholder='Select a group category']")
|
||||
group_category_input.click
|
||||
group_category_input.send_keys :arrow_down
|
||||
group_category_input.send_keys :enter
|
||||
|
||||
f("input[data-testid='points-possible-input']").send_keys "12"
|
||||
|
||||
f("button[data-testid='add-assignment-override-seciont-btn']").click
|
||||
f("button[data-testid='add-assignment-override-seciont-btn']").click
|
||||
|
||||
assign_to_elements = ff("input[data-testid='assign-to-select']")
|
||||
assign_to_elements[0].click
|
||||
assign_to_elements[0].send_keys :backspace
|
||||
assign_to_elements[0].send_keys "section 1"
|
||||
assign_to_elements[0].send_keys :enter
|
||||
assign_to_elements[0].send_keys "section 2"
|
||||
assign_to_elements[0].send_keys :enter
|
||||
assign_to_elements[0].send_keys "section 3"
|
||||
assign_to_elements[0].send_keys :enter
|
||||
|
||||
assign_to_elements[1].click
|
||||
assign_to_elements[1].send_keys "group 1"
|
||||
assign_to_elements[1].send_keys :enter
|
||||
assign_to_elements[1].send_keys "group 2"
|
||||
assign_to_elements[1].send_keys :enter
|
||||
assign_to_elements[1].send_keys "group 3"
|
||||
assign_to_elements[1].send_keys :enter
|
||||
|
||||
assign_to_elements[2].click
|
||||
assign_to_elements[2].send_keys "student 1"
|
||||
assign_to_elements[2].send_keys :enter
|
||||
assign_to_elements[2].send_keys "student 2"
|
||||
assign_to_elements[2].send_keys :enter
|
||||
assign_to_elements[2].send_keys "student 3"
|
||||
assign_to_elements[2].send_keys :enter
|
||||
|
||||
f("button[data-testid='save-and-publish-button']").click
|
||||
wait_for_ajaximations
|
||||
|
||||
dt = Assignment.last.discussion_topic
|
||||
expect(dt.title).to eq title
|
||||
expect(dt.assignment.name).to eq title
|
||||
|
||||
overrides = dt.assignment.assignment_overrides
|
||||
override_titles = overrides.map(&:title)
|
||||
expect(overrides.length).to be 7
|
||||
expect(override_titles).to include "3 students"
|
||||
expect(override_titles).to include @section_1.name
|
||||
expect(override_titles).to include @section_2.name
|
||||
expect(override_titles).to include @section_3.name
|
||||
expect(override_titles).to include @group_1.name
|
||||
expect(override_titles).to include @group_2.name
|
||||
expect(override_titles).to include @group_3.name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "editing" do
|
||||
|
|
|
@ -38,7 +38,11 @@ import CanvasMultiSelect from '@canvas/multi-select'
|
|||
import CanvasRce from '@canvas/rce/react/CanvasRce'
|
||||
import {Alert} from '@instructure/ui-alerts'
|
||||
import {GradedDiscussionOptions} from '../GradedDiscussionOptions/GradedDiscussionOptions'
|
||||
import {GradedDiscussionDueDatesContext} from '../../util/constants'
|
||||
import {
|
||||
GradedDiscussionDueDatesContext,
|
||||
defaultEveryoneOption,
|
||||
defaultEveryoneElseOption,
|
||||
} from '../../util/constants'
|
||||
import {nanoid} from 'nanoid'
|
||||
import {AttachmentDisplay} from '@canvas/discussions/react/components/AttachmentDisplay/AttachmentDisplay'
|
||||
import {responsiveQuerySizes} from '@canvas/discussions/react/utils'
|
||||
|
@ -141,7 +145,7 @@ export default function DiscussionTopicForm({
|
|||
const [assignedInfoList, setAssignedInfoList] = useState([
|
||||
{
|
||||
dueDateId: nanoid(),
|
||||
assignedList: ['everyone'],
|
||||
assignedList: [defaultEveryoneOption.assetCode],
|
||||
dueDate: '',
|
||||
availableFrom: '',
|
||||
availableUntil: '',
|
||||
|
@ -352,6 +356,88 @@ export default function DiscussionTopicForm({
|
|||
return true
|
||||
}
|
||||
|
||||
const prepareOverride = (
|
||||
overrideDueDate,
|
||||
overrideAvailableUntil,
|
||||
overrideAvailableFrom,
|
||||
overrideIds = {groupId: null, courseSectionId: null, studentIds: null}
|
||||
) => {
|
||||
return {
|
||||
dueAt: overrideDueDate || null,
|
||||
lockAt: overrideAvailableUntil || null,
|
||||
unlockAt: overrideAvailableFrom || null,
|
||||
groupId: overrideIds.groupIds || null,
|
||||
courseSectionId: overrideIds.courseSectionId || null,
|
||||
studentIds: overrideIds.studentIds || null,
|
||||
}
|
||||
}
|
||||
|
||||
const prepareAssignmentOverridesPayload = () => {
|
||||
const onlyVisibleToEveryone = assignedInfoList.every(
|
||||
info =>
|
||||
info.assignedList.length === 1 && info.assignedList[0] === defaultEveryoneOption.assetCode
|
||||
)
|
||||
|
||||
if (onlyVisibleToEveryone) return null
|
||||
|
||||
const preparedOverrides = []
|
||||
assignedInfoList.forEach(info => {
|
||||
const {assignedList} = info
|
||||
const studentIds = assignedList.filter(assetCode => assetCode.includes('user'))
|
||||
const sectionIds = assignedList.filter(assetCode => assetCode.includes('section'))
|
||||
const groupIds = assignedList.filter(assetCode => assetCode.includes('group'))
|
||||
|
||||
// override for student ids
|
||||
if (studentIds.length > 0) {
|
||||
preparedOverrides.push(
|
||||
prepareOverride(
|
||||
info.dueDate || null,
|
||||
info.availableUntil || null,
|
||||
info.availableFrom || null,
|
||||
{
|
||||
studentIds:
|
||||
studentIds.length > 0 ? studentIds.map(id => id.split('_').reverse()[0]) : null,
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// override for section ids
|
||||
if (sectionIds.length > 0) {
|
||||
sectionIds.forEach(sectionId => {
|
||||
preparedOverrides.push(
|
||||
prepareOverride(
|
||||
info.dueDate || null,
|
||||
info.availableUntil || null,
|
||||
info.availableFrom || null,
|
||||
{
|
||||
courseSectionId: sectionId.split('_').reverse()[0] || null,
|
||||
}
|
||||
)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
// override for group ids
|
||||
if (groupIds.length > 0) {
|
||||
groupIds.forEach(groupId => {
|
||||
preparedOverrides.push(
|
||||
prepareOverride(
|
||||
info.dueDate || null,
|
||||
info.availableUntil || null,
|
||||
info.availableFrom || null,
|
||||
{
|
||||
groupIds: groupId.split('_').reverse()[0] || null,
|
||||
}
|
||||
)
|
||||
)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
return preparedOverrides
|
||||
}
|
||||
|
||||
const preparePeerReviewPayload = () => {
|
||||
return peerReviewAssignment === 'off'
|
||||
? null
|
||||
|
@ -365,9 +451,15 @@ export default function DiscussionTopicForm({
|
|||
|
||||
const prepareAssignmentPayload = () => {
|
||||
// Return null immediately if the assignment is not graded
|
||||
if (!isGraded) {
|
||||
return null
|
||||
}
|
||||
if (!isGraded) return null
|
||||
|
||||
const everyoneOverride =
|
||||
assignedInfoList.find(
|
||||
info =>
|
||||
info.assignedList.includes(defaultEveryoneOption.assetCode) ||
|
||||
info.assignedList.includes(defaultEveryoneElseOption.assetCode)
|
||||
) || {}
|
||||
|
||||
// Common payload properties for graded assignments
|
||||
let payload = {
|
||||
pointsPossible,
|
||||
|
@ -375,6 +467,15 @@ export default function DiscussionTopicForm({
|
|||
gradingType: displayGradeAs,
|
||||
assignmentGroupId: assignmentGroup || null,
|
||||
peerReviews: preparePeerReviewPayload(),
|
||||
assignmentOverrides: prepareAssignmentOverridesPayload(),
|
||||
groupCategoryId: isGroupDiscussion ? groupCategoryId : null,
|
||||
dueAt: everyoneOverride.dueDate || null,
|
||||
lockAt: everyoneOverride.availableUntil || null,
|
||||
unlockAt: everyoneOverride.availableFrom || null,
|
||||
onlyVisibleToOverrides: assignedInfoList.every(
|
||||
info =>
|
||||
info.assignedList.length === 1 && info.assignedList[0] === defaultEveryoneOption.assetCode
|
||||
),
|
||||
}
|
||||
// Additional properties for creation of a graded assignment
|
||||
if (!isEditing) {
|
||||
|
|
|
@ -26,19 +26,14 @@ import {View} from '@instructure/ui-view'
|
|||
import {Flex} from '@instructure/ui-flex'
|
||||
import {IconAddLine} from '@instructure/ui-icons'
|
||||
import theme from '@instructure/canvas-theme'
|
||||
import {GradedDiscussionDueDatesContext} from '../../util/constants'
|
||||
import {
|
||||
GradedDiscussionDueDatesContext,
|
||||
defaultEveryoneOption,
|
||||
defaultEveryoneElseOption,
|
||||
} from '../../util/constants'
|
||||
|
||||
const I18n = useI18nScope('discussion_create')
|
||||
|
||||
const defaultEveryoneOption = {
|
||||
assetCode: 'everyone',
|
||||
label: 'Everyone',
|
||||
}
|
||||
const defaultEveryoneElseOption = {
|
||||
assetCode: 'everyone',
|
||||
label: 'Everyone else',
|
||||
}
|
||||
|
||||
const getDefaultBaseOptions = (includeMasteryPath, everyoneOption) => {
|
||||
return includeMasteryPath
|
||||
? [{...everyoneOption}, {assetCode: 'mastery_paths', label: 'Mastery Paths'}]
|
||||
|
@ -181,7 +176,11 @@ export const AssignmentDueDatesManager = () => {
|
|||
</div>
|
||||
</View>
|
||||
))}
|
||||
<Button renderIcon={IconAddLine} onClick={handleAddAssignment}>
|
||||
<Button
|
||||
renderIcon={IconAddLine}
|
||||
onClick={handleAddAssignment}
|
||||
data-testid="add-assignment-override-seciont-btn"
|
||||
>
|
||||
{I18n.t('Add Assignment')}
|
||||
</Button>
|
||||
</>
|
||||
|
|
|
@ -17,6 +17,15 @@
|
|||
*/
|
||||
import React from 'react'
|
||||
|
||||
export const defaultEveryoneOption = {
|
||||
assetCode: 'everyone',
|
||||
label: 'Everyone',
|
||||
}
|
||||
export const defaultEveryoneElseOption = {
|
||||
assetCode: 'everyone',
|
||||
label: 'Everyone else',
|
||||
}
|
||||
|
||||
const GradedDiscussionDueDateDefaultValues = {
|
||||
assignedInfoList: [],
|
||||
setAssignedInfoList: () => {},
|
||||
|
|
Loading…
Reference in New Issue