Fix multiple due dates that appear on to do list

closes LX-2049

flag=selective_release_backend
flag=selective_release_ui_api

test plan:
- Create an assignment, assign it to a specific student and add a due date
- Add the assignment to a new module
- Add a module override and assign it to the same student
- Check that "Multiple due dates" is working as expected

Change-Id: Ie29c3b76321c2ba25848dbf8d58e85f0ada384d3
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/360277
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Sarah Gerard <sarah.gerard@instructure.com>
QA-Review: Sarah Gerard <sarah.gerard@instructure.com>
Product-Review: Alvaro Talavera <alvaro.talavera@instructure.com>
This commit is contained in:
alvaro.talavera 2024-10-16 22:02:50 -03:00 committed by Alvaro Talavera
parent 27e2d64ce2
commit dc57eb1972
6 changed files with 47 additions and 33 deletions

View File

@ -66,14 +66,24 @@ module AssignmentsHelper
def due_at(assignment, user)
if assignment.multiple_due_dates_apply_to?(user)
multiple_due_dates
overrides = assignment.formatted_dates_hash_visible_to(user, assignment.context)
overrides = assignment.merge_overrides_by_date(overrides)
if overrides.length > 1
multiple_due_dates
else
single_due_at(assignment, user)
end
else
assignment = assignment.overridden_for(user)
due_date = assignment.due_at || assignment.applied_overrides.filter_map(&:due_at).first
due_date ? datetime_string(due_date) : I18n.t("No Due Date")
single_due_at(assignment, user)
end
end
def single_due_at(assignment, user)
assignment = assignment.overridden_for(user)
due_date = assignment.due_at || assignment.applied_overrides.filter_map(&:due_at).first
due_date ? datetime_string(due_date) : I18n.t("No Due Date")
end
def assignment_publishing_enabled?(assignment, user)
assignment.grants_right?(user, :update)
end

View File

@ -51,27 +51,6 @@ class OverrideListPresenter
multiple_due_dates? ? I18n.t("overrides.everyone_else", "Everyone else") : I18n.t("overrides.everyone", "Everyone")
end
def merge_overrides_by_date(overrides)
result = {}
overrides.each do |override|
key = [override[:due_at], override[:unlock_at], override[:lock_at]]
unless result[key]
result[key] = {
due_at: override[:due_at],
unlock_at: override[:unlock_at],
lock_at: override[:lock_at],
options: []
}
end
result[key][:options].concat(override[:options])
end
result.values
end
def formatted_due_for(formatted_override, other_due_dates_exist: false)
everyone = false
section_count = 0
@ -163,7 +142,7 @@ class OverrideListPresenter
type_is_allowed = assignment.is_a?(Assignment) ? assignment.submission_types != "discussion_topic" : assignment.is_a?(Quizzes::Quiz)
if Account.site_admin.feature_enabled?(:selective_release_ui_api) && type_is_allowed
overrides = assignment.formatted_dates_hash_visible_to(user, assignment.context)
overrides = merge_overrides_by_date(overrides)
overrides = assignment.merge_overrides_by_date(overrides)
other_due_dates_exist = overrides.length > 1
overrides.sort_by! { |card| [card[:due_at].nil? ? 1 : 0, card[:due_at]] }

View File

@ -50,7 +50,7 @@ class OverrideTooltipPresenter < OverrideListPresenter
end
def total_dates
visible_due_dates.length
grouped_and_sorted_by_visible_due_dates.length
end
def dates_visible
@ -66,7 +66,7 @@ class OverrideTooltipPresenter < OverrideListPresenter
end
def due_date_summary
visible_due_dates[0...dates_visible].map do |date|
grouped_and_sorted_by_visible_due_dates[0...dates_visible].map do |date|
{ due_for: date[:due_for], due_at: date[:due_at] }
end
end

View File

@ -580,6 +580,27 @@ module DatesOverridable
result
end
def merge_overrides_by_date(overrides)
result = {}
overrides.each do |override|
key = [override[:due_at], override[:unlock_at], override[:lock_at]]
unless result[key]
result[key] = {
due_at: override[:due_at],
unlock_at: override[:unlock_at],
lock_at: override[:lock_at],
options: []
}
end
result[key][:options].concat(override[:options])
end
result.values
end
def base_due_date_hash
without_overrides.due_date_hash.merge(base: true)
end

View File

@ -520,7 +520,7 @@ describe "context modules" do
wait_for_ajaximations
tooltip = fj(".vdd_tooltip_content:visible")
expect(tooltip).to include_text "New Section"
expect(tooltip).to include_text "1 Section"
expect(tooltip).to include_text "Everyone else"
end

View File

@ -312,10 +312,14 @@ window.modules = (function () {
} else if (info.has_many_overrides != null) {
data.due_date_display = I18n.t('Multiple Due Dates')
} else if (info.vdd_tooltip != null) {
info.vdd_tooltip.link_href = $context_module_item.find('a.title').attr('href')
$context_module_item
.find('.due_date_display')
.html(vddTooltipView(info.vdd_tooltip))
if (info.vdd_tooltip.due_dates.length === 1) {
data.due_date_display = dateString(info.vdd_tooltip.due_dates[0].due_at)
} else {
info.vdd_tooltip.link_href = $context_module_item.find('a.title').attr('href')
$context_module_item
.find('.due_date_display')
.html(vddTooltipView(info.vdd_tooltip))
}
} else {
$context_module_item.find('.due_date_display').remove()
}