Remove assignments w/ sub assignments from undated items

closes VICE-4492
flag=discussion_checkpoints

Test plan:
- Go to SiteAdmin -> Feature Options and enable
the Discussion Checkpoints feature flag
- Create a course and enroll yourself as teacher
or student; take a note of the course id
- Create a graded discussion with checkpoints
and add due dates
- Create a graded discussion with checkpoints
but do not add due dates
- Get undated assignments from the Calendar API
http://<canvas url>/api/v1/calendar_events?
type=assignment&context_codes[]=course_<course id>&undated=1
- Verify that response is an empty array
- Repeat the API call for type=sub_assignment
- Verify that the two undated checkpoints are returned

Change-Id: I1630561f5817fb39acd8f7534b873b6d6825c56a
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/354994
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Chawn Neal <chawn.neal@instructure.com>
QA-Review: Omar Soto-Fortuño <omar.soto@instructure.com>
Product-Review: Omar Soto-Fortuño <omar.soto@instructure.com>
This commit is contained in:
Martin Yosifov 2024-08-13 12:50:27 -07:00
parent bd9433d259
commit 7f11bf61a0
2 changed files with 49 additions and 23 deletions

View File

@ -1670,6 +1670,13 @@ class CalendarEventsApiController < ApplicationController
# specific people, sections, etc. This applies the base assignment due_at for ordering
# as a more sane default then natural DB order. No, it isn't perfect but much better.
scope = assignment_context_scope(user, sub_assignment:)
# exclude undated assignments with sub assignments because the
# parent assignment does not have due date, only the sub assignments do
if @undated && !sub_assignment && discussion_checkpoints_enabled?
scope = scope.where(has_sub_assignments: false)
end
next unless scope
scope = scope.order(:due_at, :id)

View File

@ -27,6 +27,16 @@ describe CalendarEventsApiController, type: :request do
@me = @user
end
def create_checkpoint(topic:, type: "reply_to_topic", due_at: nil, points_possible: 5)
checkpoint_label = (type == "reply_to_topic") ? CheckpointLabels::REPLY_TO_TOPIC : CheckpointLabels::REPLY_TO_ENTRY
Checkpoints::DiscussionCheckpointCreatorService.call(
discussion_topic: topic,
checkpoint_label:,
dates: due_at.nil? ? [] : [{ type: "everyone", due_at: }],
points_possible:
)
end
context "events" do
expected_fields = %w[
all_context_codes
@ -2843,19 +2853,38 @@ describe CalendarEventsApiController, type: :request do
expect(json.size).to be 9 # first context has no events
end
it "returns undated assignments" do
@course.assignments.create(title: "undated")
@course.assignments.create(title: "dated", due_at: "2012-01-08 12:00:00")
json = api_call(:get, "/api/v1/calendar_events?type=assignment&undated=1&context_codes[]=course_#{@course.id}", {
controller: "calendar_events_api",
action: "index",
format: "json",
type: "assignment",
context_codes: ["course_#{@course.id}"],
undated: "1"
})
expect(json.size).to be 1
expect(json.first["due_at"]).to be_nil
context "undated assignments" do
it "returns undated assignments" do
@course.assignments.create(title: "undated")
@course.assignments.create(title: "dated", due_at: "2012-01-08 12:00:00")
json = api_call(:get, "/api/v1/calendar_events?type=assignment&undated=1&context_codes[]=course_#{@course.id}", {
controller: "calendar_events_api",
action: "index",
format: "json",
type: "assignment",
context_codes: ["course_#{@course.id}"],
undated: "1"
})
expect(json.size).to be 1
expect(json.first["due_at"]).to be_nil
end
it "does not return undated assignments associated with discussions with checkpoints" do
@course.root_account.enable_feature!(:discussion_checkpoints)
topic = DiscussionTopic.create_graded_topic!(course: @course, title: "#{@course.id} - graded topic with checkpoints")
create_checkpoint(topic:, due_at: "2024-08-01 12:00:00")
create_checkpoint(topic:, type: "reply_to_entry", due_at: "2024-08-02 12:00:00")
json = api_call(:get, "/api/v1/calendar_events", {
controller: "calendar_events_api",
action: "index",
format: "json",
type: "assignment",
context_codes: ["course_#{@course.id}"],
undated: "1"
})
expect(json.size).to be 0
end
end
context "mark_submitted_assignments" do
@ -4234,16 +4263,6 @@ describe CalendarEventsApiController, type: :request do
@checkpoint_2 = create_checkpoint(topic: @topic, type: "reply_to_entry", due_at: "2024-08-02 12:00:00")
end
def create_checkpoint(topic:, type: "reply_to_topic", due_at: nil, points_possible: 5)
checkpoint_label = (type == "reply_to_topic") ? CheckpointLabels::REPLY_TO_TOPIC : CheckpointLabels::REPLY_TO_ENTRY
Checkpoints::DiscussionCheckpointCreatorService.call(
discussion_topic: topic,
checkpoint_label:,
dates: due_at.nil? ? [] : [{ type: "everyone", due_at: }],
points_possible:
)
end
expected_sub_assignment_fields = %w[
all_day
all_day_date