Fix error in assignment_scope when checkpoints enabled

closes EGG-270
flag=discussion_checkpoints

Test plan:
- Enable discussion checkpoints feature flag
- Go to Calendar and open devtools->network
- Select only your own calendar and reload the page
- Verify that the requests for calendar_events with
type assignment and sub_assignment return 200 OK
- Alternatively, paste in browser the URLs below and
verify that they succeed without errors
{local canvas}/api/v1/calendar_events?type=assignment
{local canvas}/api/v1/calendar_events?type=sub_assignment

Change-Id: I998c02ed40228ed5f414ff34d25bc74eff091422
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/360905
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Caleb Guanzon <cguanzon@instructure.com>
QA-Review: Jason Gillett <jason.gillett@instructure.com>
Product-Review: Sam Garza <sam.garza@instructure.com>
This commit is contained in:
Martin Yosifov 2024-10-23 14:57:24 -07:00
parent 8b622f26bf
commit 18118a2a32
2 changed files with 83 additions and 27 deletions

View File

@ -1683,12 +1683,12 @@ class CalendarEventsApiController < ApplicationController
# as a more sane default then natural DB order. No, it isn't perfect but much better.
scope = assignment_context_scope(user, sub_assignment:)
next unless scope
# exclude parent assignment when the discussion checkpoints FF is enabled
# because due dates and other relevant info is stored in the sub_assignments/checkpoints
scope = scope.where(has_sub_assignments: false) if discussion_checkpoints_enabled?
next unless scope
scope = scope.order(:due_at, :id)
scope = scope.active
if exclude_submission_types.any?

View File

@ -3356,19 +3356,47 @@ describe CalendarEventsApiController, type: :request do
expect(json.size).to be 2
end
it "does not return assignments associated with discussions with checkpoints when the checkpoints FF is enabled" do
@course.root_account.enable_feature!(:discussion_checkpoints)
graded_discussion_topic_with_checkpoints(context: @course, title: "Discussion with Checkpoints")
context "discussion_checkpoints feature flag enabled" do
before do
@course.root_account.enable_feature!(:discussion_checkpoints)
end
json = api_call(:get, "/api/v1/calendar_events", {
controller: "calendar_events_api",
action: "index",
format: "json",
type: "assignment",
context_codes: ["course_#{@course.id}"],
all_events: "1"
})
expect(json.size).to be 2
it "does not return assignments associated with discussions with checkpoints" do
graded_discussion_topic_with_checkpoints(context: @course, title: "Discussion with Checkpoints")
json = api_call(:get, "/api/v1/calendar_events", {
controller: "calendar_events_api",
action: "index",
format: "json",
type: "assignment",
context_codes: ["course_#{@course.id}"],
all_events: "1"
})
expect(json.size).to be 2
end
it "does not throw error if context is not a course" do
api_call(:get, "/api/v1/calendar_events", {
controller: "calendar_events_api",
action: "index",
format: "json",
type: "assignment",
context_codes: ["user_#{@teacher.id}"],
all_events: "1"
})
expect(response).to have_http_status :ok
end
it "does not throw error if context is not provided" do
api_call(:get, "/api/v1/calendar_events", {
controller: "calendar_events_api",
action: "index",
format: "json",
type: "assignment",
all_events: "1"
})
expect(response).to have_http_status :ok
end
end
end
@ -4411,19 +4439,47 @@ describe CalendarEventsApiController, type: :request do
submission_types
]
context "dicussion_checkpoints feature flag" do
it "returns sub_assignments when feature flag is enabled" do
@course.root_account.enable_feature!(:discussion_checkpoints)
json = api_call(:get, "/api/v1/calendar_events", {
controller: "calendar_events_api",
action: "index",
format: "json",
type: "sub_assignment",
context_codes: ["course_#{@course.id}"],
start_date: "2024-08-01",
end_date: "2024-08-02"
})
expect(json.size).to be 2
context "discussion_checkpoints feature flag" do
context "when feature flag is enabled" do
before do
@course.root_account.enable_feature!(:discussion_checkpoints)
end
it "returns sub_assignments" do
json = api_call(:get, "/api/v1/calendar_events", {
controller: "calendar_events_api",
action: "index",
format: "json",
type: "sub_assignment",
context_codes: ["course_#{@course.id}"],
start_date: "2024-08-01",
end_date: "2024-08-02"
})
expect(json.size).to be 2
end
it "does not throw error when context is not a course" do
api_call(:get, "/api/v1/calendar_events", {
controller: "calendar_events_api",
action: "index",
format: "json",
type: "sub_assignment",
context_codes: ["user_#{@teacher.id}"],
all_events: "1"
})
expect(response).to have_http_status :ok
end
it "does not throw error when context is not provided" do
api_call(:get, "/api/v1/calendar_events", {
controller: "calendar_events_api",
action: "index",
format: "json",
type: "sub_assignment",
all_events: "1"
})
expect(response).to have_http_status :ok
end
end
it "does not return sub_assignments when feature flag is disabled" do