2012-12-13 03:14:17 +08:00
|
|
|
module DatesOverridable
|
2013-07-24 09:46:05 +08:00
|
|
|
attr_accessor :applied_overrides, :overridden_for_user, :overridden,
|
|
|
|
:has_no_overrides
|
2013-02-05 08:51:39 +08:00
|
|
|
attr_writer :without_overrides
|
2012-12-20 04:38:12 +08:00
|
|
|
|
2012-12-13 03:14:17 +08:00
|
|
|
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
|
2012-12-29 05:02:21 +08:00
|
|
|
|
|
|
|
base.extend(ClassMethods)
|
2012-12-13 03:14:17 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def overridden_for(user)
|
|
|
|
AssignmentOverrideApplicator.assignment_overridden_for(self, user)
|
|
|
|
end
|
|
|
|
|
|
|
|
def overrides_visible_to(user, overrides=active_assignment_overrides)
|
|
|
|
# the visible_to scope is potentially expensive. skip its conditions if the
|
|
|
|
# initial scope is already empty
|
|
|
|
if overrides.first.present?
|
|
|
|
overrides.visible_to(user, context)
|
|
|
|
else
|
|
|
|
overrides
|
|
|
|
end
|
|
|
|
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
|
|
|
|
|
2013-02-05 08:51:39 +08:00
|
|
|
def without_overrides
|
|
|
|
@without_overrides || self
|
|
|
|
end
|
|
|
|
|
2012-12-13 03:14:17 +08:00
|
|
|
# returns two values indicating which due dates for this assignment apply
|
|
|
|
# and/or are visible to the user.
|
|
|
|
#
|
|
|
|
# the first is the due date as it applies to the user as a student, if any
|
|
|
|
# (nil if the user has no student enrollment(s) in the assignment's course)
|
|
|
|
#
|
|
|
|
# the second is a list of due dates a they apply to users, sections, or
|
|
|
|
# groups visible to the user as an admin (nil if the user has no
|
|
|
|
# admin/observer enrollment(s) in the assignment's course)
|
|
|
|
#
|
|
|
|
# in both cases, "due dates" is a hash with due_at (full timestamp), all_day
|
|
|
|
# flag, and all_day_date. for the "as an admin" list, each due date from
|
|
|
|
# an override will also have a 'title' key to identify which subset of the
|
|
|
|
# course is affected by that due date, and an 'override' key referencing the
|
|
|
|
# override itself. for the original due date, it will instead have a 'base'
|
|
|
|
# flag (value true).
|
2014-01-11 03:38:38 +08:00
|
|
|
#
|
|
|
|
# TODO: only used externally by app/controllers/calendar_events_api_controller.rb,
|
2014-02-13 17:23:06 +08:00
|
|
|
# app/serializers/quiz_serializer.rb, and internally by
|
|
|
|
# multiple_due_dates_apply_to?. This would be a good candidate to refactor away.
|
2013-01-24 03:20:36 +08:00
|
|
|
def due_dates_for(user)
|
2012-12-13 03:14:17 +08:00
|
|
|
as_student, as_admin = nil, nil
|
|
|
|
return nil, nil if context.nil?
|
|
|
|
|
2013-01-16 00:36:11 +08:00
|
|
|
if user.nil?
|
2013-02-05 08:51:39 +08:00
|
|
|
return self.without_overrides.due_date_hash, nil
|
2013-01-16 00:36:11 +08:00
|
|
|
end
|
|
|
|
|
2012-12-13 03:14:17 +08:00
|
|
|
if context.user_has_been_student?(user)
|
|
|
|
as_student = self.overridden_for(user).due_date_hash
|
|
|
|
end
|
|
|
|
|
|
|
|
if context.user_has_been_admin?(user)
|
|
|
|
as_admin = due_dates_visible_to(user)
|
|
|
|
|
|
|
|
elsif context.user_has_been_observer?(user)
|
|
|
|
as_admin = observed_student_due_dates(user).uniq
|
|
|
|
|
|
|
|
if as_admin.empty?
|
|
|
|
as_admin = [self.overridden_for(user).due_date_hash]
|
|
|
|
end
|
|
|
|
|
|
|
|
elsif context.user_has_no_enrollments?(user)
|
|
|
|
as_admin = all_due_dates
|
|
|
|
end
|
|
|
|
|
|
|
|
return as_student, as_admin
|
|
|
|
end
|
|
|
|
|
|
|
|
def all_due_dates
|
|
|
|
all_dates = assignment_overrides.overriding_due_at.map(&:as_hash)
|
2013-02-05 08:51:39 +08:00
|
|
|
all_dates << without_overrides.due_date_hash.merge(:base => true)
|
2012-12-13 03:14:17 +08:00
|
|
|
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)
|
2013-12-05 06:09:17 +08:00
|
|
|
if context.user_has_been_observer?(user)
|
|
|
|
observed_student_due_dates(user).uniq
|
|
|
|
else
|
|
|
|
all_dates = overrides_visible_to(user).active
|
|
|
|
all_dates = all_dates.map(&:as_hash)
|
|
|
|
all_dates << without_overrides.due_date_hash.merge(:base => true)
|
|
|
|
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
|
|
|
|
|
2012-12-13 03:14:17 +08:00
|
|
|
def due_dates_visible_to(user)
|
|
|
|
# Overrides
|
|
|
|
overrides = overrides_visible_to(user).overriding_due_at
|
|
|
|
list = overrides.map(&:as_hash)
|
|
|
|
|
|
|
|
# Base
|
2013-02-05 08:51:39 +08:00
|
|
|
list << without_overrides.due_date_hash.merge(:base => true)
|
2012-12-13 03:14:17 +08:00
|
|
|
end
|
|
|
|
|
2013-08-21 03:33:02 +08:00
|
|
|
def dates_hash_visible_to(user)
|
|
|
|
all_dates = all_dates_visible_to(user)
|
|
|
|
|
|
|
|
# remove base if all sections are set
|
|
|
|
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
|
|
|
|
|
2014-02-13 17:23:06 +08:00
|
|
|
formatted_dates_hash(all_dates)
|
|
|
|
end
|
|
|
|
|
|
|
|
def formatted_dates_hash(dates)
|
|
|
|
dates = dates.sort_by do |date|
|
2013-08-21 03:33:02 +08:00
|
|
|
due_at = date[:due_at]
|
2014-03-18 04:54:26 +08:00
|
|
|
[ due_at.present? ? CanvasSort::First : CanvasSort::Last, due_at.presence || CanvasSort::First ]
|
2013-08-21 03:33:02 +08:00
|
|
|
end
|
|
|
|
|
2014-03-05 00:02:02 +08:00
|
|
|
dates.map { |h| h.slice(:id, :due_at, :unlock_at, :lock_at, :title, :base) }
|
2013-08-21 03:33:02 +08:00
|
|
|
end
|
|
|
|
|
2012-12-13 03:14:17 +08:00
|
|
|
def observed_student_due_dates(user)
|
|
|
|
ObserverEnrollment.observed_students(context, user).map do |student, enrollments|
|
|
|
|
self.overridden_for(student).due_date_hash
|
|
|
|
end
|
|
|
|
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 }
|
2012-12-13 03:14:17 +08:00
|
|
|
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})
|
2012-12-13 03:14:17 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
if @applied_overrides && override = @applied_overrides.find { |o| o.due_at == due_at }
|
|
|
|
hash[:override] = override
|
|
|
|
hash[:title] = override.title
|
|
|
|
end
|
|
|
|
|
|
|
|
hash
|
|
|
|
end
|
|
|
|
|
2012-12-29 05:02:21 +08:00
|
|
|
def multiple_due_dates_apply_to?(user)
|
2013-11-20 02:22:22 +08:00
|
|
|
if !context.multiple_sections?
|
|
|
|
return false
|
|
|
|
else
|
|
|
|
as_instructor = self.due_dates_for(user).second
|
|
|
|
as_instructor && as_instructor.map{ |hash|
|
|
|
|
self.class.due_date_compare_value(hash[:due_at]) }.uniq.size > 1
|
|
|
|
end
|
2012-12-13 03:14:17 +08:00
|
|
|
end
|
|
|
|
|
2012-12-29 05:02:21 +08:00
|
|
|
def multiple_due_dates?
|
2013-01-16 00:36:11 +08:00
|
|
|
if overridden
|
2012-12-29 05:02:21 +08:00
|
|
|
!!multiple_due_dates_apply_to?(overridden_for_user)
|
|
|
|
else
|
|
|
|
raise "#{self.class.name} has not been overridden"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def overridden_for?(user)
|
2013-01-16 00:36:11 +08:00
|
|
|
overridden && (overridden_for_user == user)
|
2012-12-29 05:02:21 +08:00
|
|
|
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
|
2012-12-20 04:38:12 +08:00
|
|
|
end
|