Revert "Fix Canvas.assignment.dueAt.iso8601 LTI variable logic"
This reverts commit 3a25dc44cf
.
Reason for revert: on some clusters, this query does not perform well
Change-Id: I0579a51ec1718d235ba312234c08cea7b7375279
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/360558
Reviewed-by: Evan Battaglia <ebattaglia@instructure.com>
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
QA-Review: Evan Battaglia <ebattaglia@instructure.com>
Product-Review: Evan Battaglia <ebattaglia@instructure.com>
This commit is contained in:
parent
da025f1d33
commit
b32c0f4bff
|
@ -1386,16 +1386,17 @@ Only available when launched as an assignment with a `lock_at` set.
|
|||
2018-02-20:00:00Z
|
||||
```
|
||||
## Canvas.assignment.dueAt.iso8601
|
||||
Returns the `due_at` date of the assignment that was launched.
|
||||
If the tool is launched as a student, this will be the date that assignment
|
||||
is due for that student (or unexpanded -- "$Canvas.assignment.dueAt.iso8601" --
|
||||
if there is no due date for the student).
|
||||
If the tool is launched as an instructor and there are multiple
|
||||
possible due dates (i.e., there are multiple sections and at
|
||||
least one has a due date override), this will be the LATEST effective
|
||||
due date of any section or student.
|
||||
Returns the `due_at` date of the assignment that was launched. Only
|
||||
available when launched as an assignment with a `due_at` set. If the tool
|
||||
is launched as a student, this will be the date that assignment is due
|
||||
for that student (or unexpanded -- "$Canvas.assignment.dueAt.iso8601" --
|
||||
if there is no due date for the student). If the tool is launched as an
|
||||
instructor and there are multiple possible due dates (i.e., there are
|
||||
multiple sections and at least one has a due date override), this will be
|
||||
the LATEST effective due date of any section or student (or unexpanded if
|
||||
there is at least one section or student with no effective due date).
|
||||
|
||||
**Availability**: *when launched as an assignment*
|
||||
**Availability**: *always*
|
||||
|
||||
|
||||
```
|
||||
|
|
|
@ -1762,14 +1762,15 @@ module Lti
|
|||
-> { @assignment.lock_at.utc.iso8601 },
|
||||
-> { @assignment && @assignment.lock_at.present? }
|
||||
|
||||
# Returns the `due_at` date of the assignment that was launched.
|
||||
# If the tool is launched as a student, this will be the date that assignment
|
||||
# is due for that student (or unexpanded -- "$Canvas.assignment.dueAt.iso8601" --
|
||||
# if there is no due date for the student).
|
||||
# If the tool is launched as an instructor and there are multiple
|
||||
# possible due dates (i.e., there are multiple sections and at
|
||||
# least one has a due date override), this will be the LATEST effective
|
||||
# due date of any section or student.
|
||||
# Returns the `due_at` date of the assignment that was launched. Only
|
||||
# available when launched as an assignment with a `due_at` set. If the tool
|
||||
# is launched as a student, this will be the date that assignment is due
|
||||
# for that student (or unexpanded -- "$Canvas.assignment.dueAt.iso8601" --
|
||||
# if there is no due date for the student). If the tool is launched as an
|
||||
# instructor and there are multiple possible due dates (i.e., there are
|
||||
# multiple sections and at least one has a due date override), this will be
|
||||
# the LATEST effective due date of any section or student (or unexpanded if
|
||||
# there is at least one section or student with no effective due date).
|
||||
#
|
||||
# @example
|
||||
# ```
|
||||
|
@ -1777,8 +1778,8 @@ module Lti
|
|||
# ```
|
||||
register_expansion "Canvas.assignment.dueAt.iso8601",
|
||||
[],
|
||||
-> { latest_due_at&.utc&.iso8601 },
|
||||
ASSIGNMENT_GUARD
|
||||
-> { @assignment.due_at.utc.iso8601 },
|
||||
-> { @assignment && @assignment.due_at.present? }
|
||||
|
||||
# Returns the `due_at` date of the assignment that was launched.
|
||||
# If the tool is launched as a student, this will be the date that
|
||||
|
@ -2101,31 +2102,17 @@ module Lti
|
|||
|
||||
def earliest_due_at
|
||||
context = @assignment.context
|
||||
# Mirrors logic in AssignmentOverrideApplicator to determine if user is a student or teacher.
|
||||
# If a user is a student, we return their due date. Otherwise, in our case here, we return
|
||||
# the earliest of all due dates for the assignment.
|
||||
if course_admin?(context)
|
||||
if context.user_has_been_admin?(current_user) || (context.user_has_no_enrollments?(current_user) &&
|
||||
context.grants_any_right?(current_user, *RoleOverride::GRANULAR_MANAGE_ASSIGNMENT_PERMISSIONS))
|
||||
@assignment.submissions.minimum(:cached_due_date)
|
||||
else
|
||||
@assignment.due_at
|
||||
end
|
||||
end
|
||||
|
||||
def latest_due_at
|
||||
context = @assignment.context
|
||||
# We return the latest of all due dates for the assignment if the user is a course admin.
|
||||
if course_admin?(context)
|
||||
@assignment.submissions.maximum(:cached_due_date)
|
||||
else
|
||||
@assignment.due_at
|
||||
end
|
||||
end
|
||||
|
||||
def course_admin?(context)
|
||||
# Mirrors logic in AssignmentOverrideApplicator to determine if user is a student or teacher.
|
||||
context.user_has_been_admin?(current_user) ||
|
||||
(context.user_has_no_enrollments?(current_user) && context.grants_any_right?(current_user, *RoleOverride::GRANULAR_MANAGE_ASSIGNMENT_PERMISSIONS))
|
||||
end
|
||||
|
||||
def sis_pseudonym
|
||||
context = @enrollment || @context
|
||||
@sis_pseudonym ||= SisPseudonym.for(@current_user, context, type: :trusted, require_sis: false, root_account: @root_account) if @current_user
|
||||
|
|
|
@ -29,7 +29,7 @@ module Lti
|
|||
let(:group_category) { course.group_categories.new(name: "Category") }
|
||||
let(:group) { course.groups.new(name: "Group", group_category:) }
|
||||
let(:user) { User.new }
|
||||
let(:assignment) { Assignment.new(context: course) }
|
||||
let(:assignment) { Assignment.new }
|
||||
let(:collaboration) do
|
||||
ExternalToolCollaboration.new(
|
||||
title: "my collab",
|
||||
|
@ -38,7 +38,7 @@ module Lti
|
|||
)
|
||||
end
|
||||
let(:substitution_helper) { double.as_null_object }
|
||||
let(:right_now) { Time.current }
|
||||
let(:right_now) { DateTime.now }
|
||||
let(:tool) do
|
||||
shard_mock = double("shard")
|
||||
allow(shard_mock).to receive(:settings).and_return({ encription_key: "abc" })
|
||||
|
@ -1967,49 +1967,9 @@ module Lti
|
|||
expect(expand!("$Canvas.assignment.lockAt.iso8601")).to eq right_now.utc.iso8601
|
||||
end
|
||||
|
||||
describe "$Canvas.assignment.dueAt.iso8601" do
|
||||
before do
|
||||
course.save!
|
||||
user.save!
|
||||
assignment.update!(course:)
|
||||
end
|
||||
|
||||
context "for student" do
|
||||
before do
|
||||
course.enroll_user(user, "StudentEnrollment")
|
||||
end
|
||||
|
||||
it "is expanded" do
|
||||
assignment.update!(due_at: right_now)
|
||||
expect(expand!("$Canvas.assignment.dueAt.iso8601")).to eq right_now.utc.iso8601
|
||||
end
|
||||
|
||||
it "handles a nil due_at" do
|
||||
assignment.update!(due_at: nil)
|
||||
expect_unexpanded! "$Canvas.assignment.dueAt.iso8601"
|
||||
end
|
||||
end
|
||||
|
||||
context "for teacher" do
|
||||
before do
|
||||
course.enroll_user(user, "TeacherEnrollment")
|
||||
course.enroll_user(User.create!, "StudentEnrollment")
|
||||
course.enroll_user(User.create!, "StudentEnrollment")
|
||||
end
|
||||
|
||||
it "is expanded" do
|
||||
subm1, subm2 = assignment.submissions.to_a
|
||||
subm1.update! cached_due_date: right_now
|
||||
subm2.update! cached_due_date: right_now - 1.day
|
||||
expect(assignment.due_at).to be_nil
|
||||
expect(expand!("$Canvas.assignment.dueAt.iso8601")).to eq right_now.utc.iso8601
|
||||
end
|
||||
|
||||
it "handles a nil due_at" do
|
||||
assignment.update!(due_at: nil)
|
||||
expect_unexpanded! "$Canvas.assignment.dueAt.iso8601"
|
||||
end
|
||||
end
|
||||
it "has substitution for $Canvas.assignment.dueAt.iso8601" do
|
||||
allow(assignment).to receive(:due_at).and_return(right_now)
|
||||
expect(expand!("$Canvas.assignment.dueAt.iso8601")).to eq right_now.utc.iso8601
|
||||
end
|
||||
|
||||
it "has substitution for $Canvas.assignment.allDueAts.iso8601" do
|
||||
|
@ -2026,6 +1986,11 @@ module Lti
|
|||
allow(assignment).to receive(:lock_at).and_return(nil)
|
||||
expect_unexpanded! "$Canvas.assignment.lockAt.iso8601"
|
||||
end
|
||||
|
||||
it "handles a nil due_at" do
|
||||
allow(assignment).to receive(:lock_at).and_return(nil)
|
||||
expect_unexpanded! "$Canvas.assignment.dueAt.iso8601"
|
||||
end
|
||||
end
|
||||
|
||||
describe "$Canvas.assignment.earliestEnrollmentDueAt.iso8601" do
|
||||
|
|
Loading…
Reference in New Issue