canvas-lms/lib/dates_overridable.rb

144 lines
4.2 KiB
Ruby
Raw Normal View History

module DatesOverridable
attr_accessor :applied_overrides, :overridden_for_user, :overridden,
:has_no_overrides
make observers viewing discussions vdd lock date aware fixes CNVS-518 also included: - observers now get visible students' section overrides in their AssignmentOverride.visible_to scope - fixed a bug where calling some DatesOverridable methods would use an overridden date where you wouldn't expect (see the specs) - added a method to get the original object from an overridden one - made DiscussionTopicPresenter handle due dates overridden to nil test plan notes - keep an eye out for regressions in displayed due dates - discussion locking behavior should be as follows -- viewing the discussion page before the earliest applicable unlock date should show a locked discussion page that lists the earliest unlock date -- viewing the discussion after the earliest unlock date should show the discussion -- the discussion page should show the due date when only one due date applies -- the discussion page should show a "multiple due dates" ui when more than one due date applies -- the "multiple due dates" ui should only display entries for sections that the observer's linked students are in -- the "multiple due dates" ui should display lock dates from the associated section override or from the original assignment if the section override does not override lock dates test plan - check an observer not observing student -- ensure that the discussion locking behavior behaves according to the observer's section's override - check an observer observing one student -- ensure that the discussion locking behaves according to the student's section's override - check an observer observing multiple student's in more than one section -- make overrides for each student's section that differ in due dates and lock dates -- ensure that the discussion locking behaves according to the students' sections' combined lock dates -- ensure that the discussion page shows a "multiple due dates" ui when the discussion is unlocked Change-Id: I8f2970f0962cdc60cf9a423f01a876bf0ae909d4 Reviewed-on: https://gerrit.instructure.com/17452 Reviewed-by: Simon Williams <simon@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Marc LeGendre <marc@instructure.com> Reviewed-by: Mark Ericksen <marke@instructure.com>
2013-02-05 08:51:39 +08:00
attr_writer :without_overrides
def self.included(base)
base.has_many :assignment_overrides, :dependent => :destroy
base.has_many :active_assignment_overrides, :class_name => 'AssignmentOverride', :conditions => {:workflow_state => 'active'}
base.has_many :assignment_override_students, :dependent => :destroy
base.validates_associated :assignment_overrides
base.extend(ClassMethods)
end
def without_overrides
@without_overrides || self
end
def overridden_for(user)
AssignmentOverrideApplicator.assignment_overridden_for(self, user)
end
# All overrides, not just dates
def overrides_for(user)
AssignmentOverrideApplicator.overrides_for_assignment_and_user(self, user)
end
def overridden_for?(user)
overridden && (overridden_for_user == user)
end
def has_overrides?
assignment_overrides.count > 0
end
make fancy midnight work for assignment overrides also fixes an issue where some dates display as "Friday at 11:59pm" instead of just "Friday" Also does a little bit of refactoring and spec backfilling for the override list presenter. The override list presenter now returns a much more friendly list of "due date" hashes to the outside world to make it easier to consume in views. Views don't have to format the dates by passing in a hash anymore. test plan: - specs should pass - as a teacher, create an assignment with overrides using the web form. In one of the overrides, enter a day like March 1 at 12am. - save the overrides - Make sure fancy midnight works for lock dates and due dates, but not unlock dates (12:00 am unlock date should show up as 12:00 am, not 11:59 pm) - on the assignment's show page, you should just see "Friday", meaning that the assignment is due at 11:59 pm on March 1. - The "fancy midnight" scheme should work correctly for assignments,quizzes,and discussion topics, including the default due dates. - Be sure to check that the dates show up correctly on the assignment,quiz, and discussion show pages. - Be sure to make an override that has a blank due_at, lock_at, and unlock_at, but has a default due date, lock date, and unlock date. The overrides should not inherit from the default due date (fixes CNVS-4216) fixes CNVS-4216, CNVS-4004, CNVS-3890 Change-Id: I8b5e10c074eb2a237a1298cb7def0cb32d3dcb7f Reviewed-on: https://gerrit.instructure.com/18142 QA-Review: Amber Taniuchi <amber@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Simon Williams <simon@instructure.com>
2013-03-06 00:04:59 +08:00
def has_active_overrides?
assignment_overrides.active.count > 0
end
def multiple_due_dates?
if overridden
!!multiple_due_dates_apply_to?(overridden_for_user)
else
raise "#{self.class.name} has not been overridden"
end
end
def multiple_due_dates_apply_to?(user)
return false if !context.multiple_sections?
return false if context.user_has_been_student?(user)
if context.user_has_been_observer?(user)
observed_student_due_dates(user).length > 1
elsif context.user_has_been_admin?(user)
dates = all_dates_visible_to(user)
dates && dates.map{ |hash| self.class.due_date_compare_value(hash[:due_at]) }.uniq.size > 1
elsif context.user_has_no_enrollments?(user)
all_due_dates.length > 1
end
end
def all_due_dates
all_dates = assignment_overrides.active.overriding_due_at.map(&:as_hash)
all_dates << base_due_date_hash
end
make fancy midnight work for assignment overrides also fixes an issue where some dates display as "Friday at 11:59pm" instead of just "Friday" Also does a little bit of refactoring and spec backfilling for the override list presenter. The override list presenter now returns a much more friendly list of "due date" hashes to the outside world to make it easier to consume in views. Views don't have to format the dates by passing in a hash anymore. test plan: - specs should pass - as a teacher, create an assignment with overrides using the web form. In one of the overrides, enter a day like March 1 at 12am. - save the overrides - Make sure fancy midnight works for lock dates and due dates, but not unlock dates (12:00 am unlock date should show up as 12:00 am, not 11:59 pm) - on the assignment's show page, you should just see "Friday", meaning that the assignment is due at 11:59 pm on March 1. - The "fancy midnight" scheme should work correctly for assignments,quizzes,and discussion topics, including the default due dates. - Be sure to check that the dates show up correctly on the assignment,quiz, and discussion show pages. - Be sure to make an override that has a blank due_at, lock_at, and unlock_at, but has a default due date, lock date, and unlock date. The overrides should not inherit from the default due date (fixes CNVS-4216) fixes CNVS-4216, CNVS-4004, CNVS-3890 Change-Id: I8b5e10c074eb2a237a1298cb7def0cb32d3dcb7f Reviewed-on: https://gerrit.instructure.com/18142 QA-Review: Amber Taniuchi <amber@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Simon Williams <simon@instructure.com>
2013-03-06 00:04:59 +08:00
def all_dates_visible_to(user)
if ObserverEnrollment.observed_students(context, user).any?
observed_student_due_dates(user)
elsif context.user_has_been_student?(user) || context.user_has_been_admin?(user) || context.user_has_been_observer?(user)
overrides = overrides_for(user)
overrides = overrides.map(&:as_hash)
overrides << base_due_date_hash if overrides.empty? || context.user_has_been_admin?(user)
overrides
elsif context.user_has_no_enrollments?(user)
all_due_dates
end
make fancy midnight work for assignment overrides also fixes an issue where some dates display as "Friday at 11:59pm" instead of just "Friday" Also does a little bit of refactoring and spec backfilling for the override list presenter. The override list presenter now returns a much more friendly list of "due date" hashes to the outside world to make it easier to consume in views. Views don't have to format the dates by passing in a hash anymore. test plan: - specs should pass - as a teacher, create an assignment with overrides using the web form. In one of the overrides, enter a day like March 1 at 12am. - save the overrides - Make sure fancy midnight works for lock dates and due dates, but not unlock dates (12:00 am unlock date should show up as 12:00 am, not 11:59 pm) - on the assignment's show page, you should just see "Friday", meaning that the assignment is due at 11:59 pm on March 1. - The "fancy midnight" scheme should work correctly for assignments,quizzes,and discussion topics, including the default due dates. - Be sure to check that the dates show up correctly on the assignment,quiz, and discussion show pages. - Be sure to make an override that has a blank due_at, lock_at, and unlock_at, but has a default due date, lock date, and unlock date. The overrides should not inherit from the default due date (fixes CNVS-4216) fixes CNVS-4216, CNVS-4004, CNVS-3890 Change-Id: I8b5e10c074eb2a237a1298cb7def0cb32d3dcb7f Reviewed-on: https://gerrit.instructure.com/18142 QA-Review: Amber Taniuchi <amber@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Simon Williams <simon@instructure.com>
2013-03-06 00:04:59 +08:00
end
def observed_student_due_dates(user)
dates = ObserverEnrollment.observed_students(context, user).map do |student, enrollments|
self.all_dates_visible_to(student)
end
dates.flatten.uniq
end
def dates_hash_visible_to(user)
all_dates = all_dates_visible_to(user)
# remove base if all sections are set
if all_dates
overrides = all_dates.select { |d| d[:set_type] == 'CourseSection' }
if overrides.count > 0 && overrides.count == context.active_course_sections.count
all_dates.delete_if {|d| d[:base] }
end
formatted_dates_hash(all_dates)
else
[due_date_hash]
end
Draft State Quizzes: show multiple due dates Closes CNVS-9880 This patch enables observers watching students across multiple sections to see each section's due date for a quiz in the quizzes index page, it also fixes the dates students get to see when they're in a section other than the base one. (BREAKING?) API CHANGES ----------- --- ------- - when a student queries a quiz, the `due_at`, `lock_at`, and `unlock_at` dates they receive are that of the section they're in as oppossed to the quiz's global dates - when an observer queries a quiz, they receive the dates for the sections they're bound to in the `all_dates` field like teachers do TEST PLAN ---- ---- Two ways to test this patch: a simple way that tests only the case described by the ticket, or the comprehensive way. > The simple way - turn DS on - create a course with multiple sections - create a quiz and assign a due date to each section - as an observer who's watching more than 1 student in different sections, go to the quizzes index: - verify that you see "Multiple Dates" for due dates (and availability if you set them) - hover over the link and verify that you see the proper dates in the tooltip > The comprehensive way Check this out: https://gist.github.com/amireh/375171767da8303e1b71 Change-Id: I934cb47f0229a43713dc6b4a6d280c047a2263b9 Reviewed-on: https://gerrit.instructure.com/30083 Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Myller de Araujo <myller@instructure.com> Reviewed-by: Derek DeVries <ddevries@instructure.com> Product-Review: Ahmad Amireh <ahmad@instructure.com>
2014-02-13 17:23:06 +08:00
end
def formatted_dates_hash(dates)
dates = dates.sort_by do |date|
due_at = date[:due_at]
[ due_at.present? ? CanvasSort::First : CanvasSort::Last, due_at.presence || CanvasSort::First ]
end
dates.map { |h| h.slice(:id, :due_at, :unlock_at, :lock_at, :title, :base) }
end
def due_date_hash
make fancy midnight work for assignment overrides also fixes an issue where some dates display as "Friday at 11:59pm" instead of just "Friday" Also does a little bit of refactoring and spec backfilling for the override list presenter. The override list presenter now returns a much more friendly list of "due date" hashes to the outside world to make it easier to consume in views. Views don't have to format the dates by passing in a hash anymore. test plan: - specs should pass - as a teacher, create an assignment with overrides using the web form. In one of the overrides, enter a day like March 1 at 12am. - save the overrides - Make sure fancy midnight works for lock dates and due dates, but not unlock dates (12:00 am unlock date should show up as 12:00 am, not 11:59 pm) - on the assignment's show page, you should just see "Friday", meaning that the assignment is due at 11:59 pm on March 1. - The "fancy midnight" scheme should work correctly for assignments,quizzes,and discussion topics, including the default due dates. - Be sure to check that the dates show up correctly on the assignment,quiz, and discussion show pages. - Be sure to make an override that has a blank due_at, lock_at, and unlock_at, but has a default due date, lock date, and unlock date. The overrides should not inherit from the default due date (fixes CNVS-4216) fixes CNVS-4216, CNVS-4004, CNVS-3890 Change-Id: I8b5e10c074eb2a237a1298cb7def0cb32d3dcb7f Reviewed-on: https://gerrit.instructure.com/18142 QA-Review: Amber Taniuchi <amber@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Simon Williams <simon@instructure.com>
2013-03-06 00:04:59 +08:00
hash = { :due_at => due_at, :unlock_at => unlock_at, :lock_at => lock_at }
if self.is_a?(Assignment)
hash.merge!({ :all_day => all_day, :all_day_date => all_day_date })
make fancy midnight work for assignment overrides also fixes an issue where some dates display as "Friday at 11:59pm" instead of just "Friday" Also does a little bit of refactoring and spec backfilling for the override list presenter. The override list presenter now returns a much more friendly list of "due date" hashes to the outside world to make it easier to consume in views. Views don't have to format the dates by passing in a hash anymore. test plan: - specs should pass - as a teacher, create an assignment with overrides using the web form. In one of the overrides, enter a day like March 1 at 12am. - save the overrides - Make sure fancy midnight works for lock dates and due dates, but not unlock dates (12:00 am unlock date should show up as 12:00 am, not 11:59 pm) - on the assignment's show page, you should just see "Friday", meaning that the assignment is due at 11:59 pm on March 1. - The "fancy midnight" scheme should work correctly for assignments,quizzes,and discussion topics, including the default due dates. - Be sure to check that the dates show up correctly on the assignment,quiz, and discussion show pages. - Be sure to make an override that has a blank due_at, lock_at, and unlock_at, but has a default due date, lock date, and unlock date. The overrides should not inherit from the default due date (fixes CNVS-4216) fixes CNVS-4216, CNVS-4004, CNVS-3890 Change-Id: I8b5e10c074eb2a237a1298cb7def0cb32d3dcb7f Reviewed-on: https://gerrit.instructure.com/18142 QA-Review: Amber Taniuchi <amber@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Simon Williams <simon@instructure.com>
2013-03-06 00:04:59 +08:00
elsif self.assignment
hash.merge!({ :all_day => assignment.all_day, :all_day_date => assignment.all_day_date})
end
if @applied_overrides && override = @applied_overrides.find { |o| o.due_at == due_at }
hash[:override] = override
hash[:title] = override.title
end
hash
end
def base_due_date_hash
without_overrides.due_date_hash.merge(:base => true)
end
module ClassMethods
def due_date_compare_value(date)
# due dates are considered equal if they're the same up to the minute
date.to_i / 60
end
def due_dates_equal?(date1, date2)
due_date_compare_value(date1) == due_date_compare_value(date2)
end
end
end