canvas-lms/lib/submittables_grading_period...

141 lines
6.5 KiB
Ruby
Raw Normal View History

protect due dates in closed grading periods This ensures that due dates cannot be set or changed in a way which puts them into, takes them out of, or adjusts them within a closed grading period. closes CNVS-32489 closes CNVS-33037 test plan: * Test the following endpoints: * POST /courses/:course_id/quizzes (quizzes/quizzes#create) * PUT /courses/:course_id/quizzes/:id (quizzes/quizzes#update) * POST /api/v1/courses/:course_id/quizzes (quizzes/quizzes_api#create) * PUT /api/v1/courses/:course_id/quizzes/:id (quizzes/quizzes_api#update) * POST /api/v1/courses/:course_id/assignments (assignments_api#create) * PUT /api/v1/courses/:course_id/assignments/:id (assignments_api#update) * A teacher cannot: * create a quiz/assignment * with a due date in a closed grading period * with an override due date in a closed grading period * with a nil due date when the last grading period is closed * with a nil override due date when the last grading period is closed * change the due date on a quiz or assignment * due in a closed grading period * with an override due in a closed grading period * to a date within a closed grading period * change the due date of an override * due in a closed grading period * to a date within a closed grading period * unset (nullify) the due date when the last grading period is closed * unset (nullify) the due date of an override when the last grading period is closed * delete (by omission from parameters) an override due in a closed grading period * A teacher can: * create a quiz/assignment with a due date in an open grading period * change the quiz/assignment due date when the assignment is only visible to overrides * change the quiz/assignment due date when not within a closed grading period * change the quiz/assignment due date when set to the same value * An ADMIN does not have these restrictions. Change-Id: I0da260e831784e7b6d0f6e5a35c43d6ecff9e977 Reviewed-on: https://gerrit.instructure.com/93806 Tested-by: Jenkins Reviewed-by: Spencer Olson <solson@instructure.com> Reviewed-by: Shahbaz Javeed <sjaveed@instructure.com> QA-Review: KC Naegle <knaegle@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2016-10-20 00:22:55 +08:00
module SubmittablesGradingPeriodProtection
def grading_periods_allow_submittable_create?(submittable, submittable_params, flash_message: false)
apply_grading_params(submittable, submittable_params)
return true unless submittable.graded?
Get rid of multiple_grading_periods feature flag Fixes CNVS-27109 Test plan: Regression test everything related to multiple grading periods. In particular, make sure: * there is no mention of the multiple grading periods feature flag on the account or course features pages * make sure grading periods UI always shows up on the account grading standards page * make sure the grading periods UI only shows on the course grading standards page if legacy course grading periods exist for that course (see below) * grading period dropdowns only show up everywhere else if there are grading periods to show. Otherwise, it should behave as if MGP is "disabled" * Grade calculation should work as expected with and without grading periods To create legacy course grading periods, you have to use rails console: 1. Find your course: course = Course.find(<id>) 2. Create a grading period group: group = course.grading_period_groups.create!(title: "2017") 2. Create a grading period: group.grading_periods.create!( weight: 1, title: 'Fall', start_date: 5.days.ago, end_date: 10.days.from_now ) Here's the list of known places grading periods can be seen in the UI: Instructor Assignments page (https://community.canvaslms.com/docs/DOC-2615) Student Assignments page (https://community.canvaslms.com/docs/DOC-3123) Gradebook (https://community.canvaslms.com/docs/DOC-2785) Gradebook Individual View (https://community.canvaslms.com/docs/DOC-2788) Course Settings grading schemes page (https://community.canvaslms.com/docs/DOC-4042) Student Grades page (https://community.canvaslms.com/docs/DOC-1291) Dashboard global Grades page (https://community.canvaslms.com/docs/DOC-5464) Change-Id: Iefac4b08120bd1699d4ed98bcb418089eec9b3b8 Reviewed-on: https://gerrit.instructure.com/99744 Reviewed-by: Spencer Olson <solson@instructure.com> Tested-by: Jenkins QA-Review: KC Naegle <knaegle@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2017-01-17 09:18:24 +08:00
return true unless grading_periods? && !current_user_is_context_admin?
protect due dates in closed grading periods This ensures that due dates cannot be set or changed in a way which puts them into, takes them out of, or adjusts them within a closed grading period. closes CNVS-32489 closes CNVS-33037 test plan: * Test the following endpoints: * POST /courses/:course_id/quizzes (quizzes/quizzes#create) * PUT /courses/:course_id/quizzes/:id (quizzes/quizzes#update) * POST /api/v1/courses/:course_id/quizzes (quizzes/quizzes_api#create) * PUT /api/v1/courses/:course_id/quizzes/:id (quizzes/quizzes_api#update) * POST /api/v1/courses/:course_id/assignments (assignments_api#create) * PUT /api/v1/courses/:course_id/assignments/:id (assignments_api#update) * A teacher cannot: * create a quiz/assignment * with a due date in a closed grading period * with an override due date in a closed grading period * with a nil due date when the last grading period is closed * with a nil override due date when the last grading period is closed * change the due date on a quiz or assignment * due in a closed grading period * with an override due in a closed grading period * to a date within a closed grading period * change the due date of an override * due in a closed grading period * to a date within a closed grading period * unset (nullify) the due date when the last grading period is closed * unset (nullify) the due date of an override when the last grading period is closed * delete (by omission from parameters) an override due in a closed grading period * A teacher can: * create a quiz/assignment with a due date in an open grading period * change the quiz/assignment due date when the assignment is only visible to overrides * change the quiz/assignment due date when not within a closed grading period * change the quiz/assignment due date when set to the same value * An ADMIN does not have these restrictions. Change-Id: I0da260e831784e7b6d0f6e5a35c43d6ecff9e977 Reviewed-on: https://gerrit.instructure.com/93806 Tested-by: Jenkins Reviewed-by: Spencer Olson <solson@instructure.com> Reviewed-by: Shahbaz Javeed <sjaveed@instructure.com> QA-Review: KC Naegle <knaegle@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2016-10-20 00:22:55 +08:00
return true if submittable_params[:only_visible_to_overrides]
submittable.due_at = submittable_params[:due_at]
return true unless GradingPeriodHelper.date_in_closed_grading_period?(submittable.due_at, context_grading_periods)
apply_error(submittable, :due_at, ERROR_MESSAGES[:set_due_at_in_closed], flash_message)
false
end
def grading_periods_allow_submittable_update?(submittable, submittable_params, flash_message: false)
return true unless submittable.graded?
submittable.only_visible_to_overrides =
submittable_params[:only_visible_to_overrides] if submittable_params.key?(:only_visible_to_overrides)
submittable.due_at = submittable_params[:due_at] if submittable_params.key?(:due_at)
return true unless submittable.only_visible_to_overrides_changed? || due_at_changed?(submittable)
Get rid of multiple_grading_periods feature flag Fixes CNVS-27109 Test plan: Regression test everything related to multiple grading periods. In particular, make sure: * there is no mention of the multiple grading periods feature flag on the account or course features pages * make sure grading periods UI always shows up on the account grading standards page * make sure the grading periods UI only shows on the course grading standards page if legacy course grading periods exist for that course (see below) * grading period dropdowns only show up everywhere else if there are grading periods to show. Otherwise, it should behave as if MGP is "disabled" * Grade calculation should work as expected with and without grading periods To create legacy course grading periods, you have to use rails console: 1. Find your course: course = Course.find(<id>) 2. Create a grading period group: group = course.grading_period_groups.create!(title: "2017") 2. Create a grading period: group.grading_periods.create!( weight: 1, title: 'Fall', start_date: 5.days.ago, end_date: 10.days.from_now ) Here's the list of known places grading periods can be seen in the UI: Instructor Assignments page (https://community.canvaslms.com/docs/DOC-2615) Student Assignments page (https://community.canvaslms.com/docs/DOC-3123) Gradebook (https://community.canvaslms.com/docs/DOC-2785) Gradebook Individual View (https://community.canvaslms.com/docs/DOC-2788) Course Settings grading schemes page (https://community.canvaslms.com/docs/DOC-4042) Student Grades page (https://community.canvaslms.com/docs/DOC-1291) Dashboard global Grades page (https://community.canvaslms.com/docs/DOC-5464) Change-Id: Iefac4b08120bd1699d4ed98bcb418089eec9b3b8 Reviewed-on: https://gerrit.instructure.com/99744 Reviewed-by: Spencer Olson <solson@instructure.com> Tested-by: Jenkins QA-Review: KC Naegle <knaegle@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2017-01-17 09:18:24 +08:00
return true unless grading_periods? && !current_user_is_context_admin?
protect due dates in closed grading periods This ensures that due dates cannot be set or changed in a way which puts them into, takes them out of, or adjusts them within a closed grading period. closes CNVS-32489 closes CNVS-33037 test plan: * Test the following endpoints: * POST /courses/:course_id/quizzes (quizzes/quizzes#create) * PUT /courses/:course_id/quizzes/:id (quizzes/quizzes#update) * POST /api/v1/courses/:course_id/quizzes (quizzes/quizzes_api#create) * PUT /api/v1/courses/:course_id/quizzes/:id (quizzes/quizzes_api#update) * POST /api/v1/courses/:course_id/assignments (assignments_api#create) * PUT /api/v1/courses/:course_id/assignments/:id (assignments_api#update) * A teacher cannot: * create a quiz/assignment * with a due date in a closed grading period * with an override due date in a closed grading period * with a nil due date when the last grading period is closed * with a nil override due date when the last grading period is closed * change the due date on a quiz or assignment * due in a closed grading period * with an override due in a closed grading period * to a date within a closed grading period * change the due date of an override * due in a closed grading period * to a date within a closed grading period * unset (nullify) the due date when the last grading period is closed * unset (nullify) the due date of an override when the last grading period is closed * delete (by omission from parameters) an override due in a closed grading period * A teacher can: * create a quiz/assignment with a due date in an open grading period * change the quiz/assignment due date when the assignment is only visible to overrides * change the quiz/assignment due date when not within a closed grading period * change the quiz/assignment due date when set to the same value * An ADMIN does not have these restrictions. Change-Id: I0da260e831784e7b6d0f6e5a35c43d6ecff9e977 Reviewed-on: https://gerrit.instructure.com/93806 Tested-by: Jenkins Reviewed-by: Spencer Olson <solson@instructure.com> Reviewed-by: Shahbaz Javeed <sjaveed@instructure.com> QA-Review: KC Naegle <knaegle@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2016-10-20 00:22:55 +08:00
in_closed_grading_period = date_in_closed_grading_period?(submittable.due_at_was)
if in_closed_grading_period && !submittable.only_visible_to_overrides_was
if due_at_changed?(submittable)
protect due dates in closed grading periods This ensures that due dates cannot be set or changed in a way which puts them into, takes them out of, or adjusts them within a closed grading period. closes CNVS-32489 closes CNVS-33037 test plan: * Test the following endpoints: * POST /courses/:course_id/quizzes (quizzes/quizzes#create) * PUT /courses/:course_id/quizzes/:id (quizzes/quizzes#update) * POST /api/v1/courses/:course_id/quizzes (quizzes/quizzes_api#create) * PUT /api/v1/courses/:course_id/quizzes/:id (quizzes/quizzes_api#update) * POST /api/v1/courses/:course_id/assignments (assignments_api#create) * PUT /api/v1/courses/:course_id/assignments/:id (assignments_api#update) * A teacher cannot: * create a quiz/assignment * with a due date in a closed grading period * with an override due date in a closed grading period * with a nil due date when the last grading period is closed * with a nil override due date when the last grading period is closed * change the due date on a quiz or assignment * due in a closed grading period * with an override due in a closed grading period * to a date within a closed grading period * change the due date of an override * due in a closed grading period * to a date within a closed grading period * unset (nullify) the due date when the last grading period is closed * unset (nullify) the due date of an override when the last grading period is closed * delete (by omission from parameters) an override due in a closed grading period * A teacher can: * create a quiz/assignment with a due date in an open grading period * change the quiz/assignment due date when the assignment is only visible to overrides * change the quiz/assignment due date when not within a closed grading period * change the quiz/assignment due date when set to the same value * An ADMIN does not have these restrictions. Change-Id: I0da260e831784e7b6d0f6e5a35c43d6ecff9e977 Reviewed-on: https://gerrit.instructure.com/93806 Tested-by: Jenkins Reviewed-by: Spencer Olson <solson@instructure.com> Reviewed-by: Shahbaz Javeed <sjaveed@instructure.com> QA-Review: KC Naegle <knaegle@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2016-10-20 00:22:55 +08:00
apply_error(submittable, :due_at, ERROR_MESSAGES[:change_due_at_in_closed], flash_message)
else
message = ERROR_MESSAGES[:change_only_visible_to_overrides]
apply_error(submittable, :only_visible_to_overrides, message, flash_message)
end
return false
end
return true if submittable.only_visible_to_overrides && submittable.only_visible_to_overrides_was
return true unless date_in_closed_grading_period?(submittable.due_at)
protect due dates in closed grading periods This ensures that due dates cannot be set or changed in a way which puts them into, takes them out of, or adjusts them within a closed grading period. closes CNVS-32489 closes CNVS-33037 test plan: * Test the following endpoints: * POST /courses/:course_id/quizzes (quizzes/quizzes#create) * PUT /courses/:course_id/quizzes/:id (quizzes/quizzes#update) * POST /api/v1/courses/:course_id/quizzes (quizzes/quizzes_api#create) * PUT /api/v1/courses/:course_id/quizzes/:id (quizzes/quizzes_api#update) * POST /api/v1/courses/:course_id/assignments (assignments_api#create) * PUT /api/v1/courses/:course_id/assignments/:id (assignments_api#update) * A teacher cannot: * create a quiz/assignment * with a due date in a closed grading period * with an override due date in a closed grading period * with a nil due date when the last grading period is closed * with a nil override due date when the last grading period is closed * change the due date on a quiz or assignment * due in a closed grading period * with an override due in a closed grading period * to a date within a closed grading period * change the due date of an override * due in a closed grading period * to a date within a closed grading period * unset (nullify) the due date when the last grading period is closed * unset (nullify) the due date of an override when the last grading period is closed * delete (by omission from parameters) an override due in a closed grading period * A teacher can: * create a quiz/assignment with a due date in an open grading period * change the quiz/assignment due date when the assignment is only visible to overrides * change the quiz/assignment due date when not within a closed grading period * change the quiz/assignment due date when set to the same value * An ADMIN does not have these restrictions. Change-Id: I0da260e831784e7b6d0f6e5a35c43d6ecff9e977 Reviewed-on: https://gerrit.instructure.com/93806 Tested-by: Jenkins Reviewed-by: Spencer Olson <solson@instructure.com> Reviewed-by: Shahbaz Javeed <sjaveed@instructure.com> QA-Review: KC Naegle <knaegle@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2016-10-20 00:22:55 +08:00
apply_error(submittable, :due_at, ERROR_MESSAGES[:change_due_at_to_closed], flash_message)
false
end
def grading_periods_allow_assignment_overrides_batch_create?(submittable, overrides, flash_message: false)
Get rid of multiple_grading_periods feature flag Fixes CNVS-27109 Test plan: Regression test everything related to multiple grading periods. In particular, make sure: * there is no mention of the multiple grading periods feature flag on the account or course features pages * make sure grading periods UI always shows up on the account grading standards page * make sure the grading periods UI only shows on the course grading standards page if legacy course grading periods exist for that course (see below) * grading period dropdowns only show up everywhere else if there are grading periods to show. Otherwise, it should behave as if MGP is "disabled" * Grade calculation should work as expected with and without grading periods To create legacy course grading periods, you have to use rails console: 1. Find your course: course = Course.find(<id>) 2. Create a grading period group: group = course.grading_period_groups.create!(title: "2017") 2. Create a grading period: group.grading_periods.create!( weight: 1, title: 'Fall', start_date: 5.days.ago, end_date: 10.days.from_now ) Here's the list of known places grading periods can be seen in the UI: Instructor Assignments page (https://community.canvaslms.com/docs/DOC-2615) Student Assignments page (https://community.canvaslms.com/docs/DOC-3123) Gradebook (https://community.canvaslms.com/docs/DOC-2785) Gradebook Individual View (https://community.canvaslms.com/docs/DOC-2788) Course Settings grading schemes page (https://community.canvaslms.com/docs/DOC-4042) Student Grades page (https://community.canvaslms.com/docs/DOC-1291) Dashboard global Grades page (https://community.canvaslms.com/docs/DOC-5464) Change-Id: Iefac4b08120bd1699d4ed98bcb418089eec9b3b8 Reviewed-on: https://gerrit.instructure.com/99744 Reviewed-by: Spencer Olson <solson@instructure.com> Tested-by: Jenkins QA-Review: KC Naegle <knaegle@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2017-01-17 09:18:24 +08:00
return true unless grading_periods? && !current_user_is_context_admin?
protect due dates in closed grading periods This ensures that due dates cannot be set or changed in a way which puts them into, takes them out of, or adjusts them within a closed grading period. closes CNVS-32489 closes CNVS-33037 test plan: * Test the following endpoints: * POST /courses/:course_id/quizzes (quizzes/quizzes#create) * PUT /courses/:course_id/quizzes/:id (quizzes/quizzes#update) * POST /api/v1/courses/:course_id/quizzes (quizzes/quizzes_api#create) * PUT /api/v1/courses/:course_id/quizzes/:id (quizzes/quizzes_api#update) * POST /api/v1/courses/:course_id/assignments (assignments_api#create) * PUT /api/v1/courses/:course_id/assignments/:id (assignments_api#update) * A teacher cannot: * create a quiz/assignment * with a due date in a closed grading period * with an override due date in a closed grading period * with a nil due date when the last grading period is closed * with a nil override due date when the last grading period is closed * change the due date on a quiz or assignment * due in a closed grading period * with an override due in a closed grading period * to a date within a closed grading period * change the due date of an override * due in a closed grading period * to a date within a closed grading period * unset (nullify) the due date when the last grading period is closed * unset (nullify) the due date of an override when the last grading period is closed * delete (by omission from parameters) an override due in a closed grading period * A teacher can: * create a quiz/assignment with a due date in an open grading period * change the quiz/assignment due date when the assignment is only visible to overrides * change the quiz/assignment due date when not within a closed grading period * change the quiz/assignment due date when set to the same value * An ADMIN does not have these restrictions. Change-Id: I0da260e831784e7b6d0f6e5a35c43d6ecff9e977 Reviewed-on: https://gerrit.instructure.com/93806 Tested-by: Jenkins Reviewed-by: Spencer Olson <solson@instructure.com> Reviewed-by: Shahbaz Javeed <sjaveed@instructure.com> QA-Review: KC Naegle <knaegle@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2016-10-20 00:22:55 +08:00
return true unless overrides.any? {|override| date_in_closed_grading_period?(override[:due_at])}
apply_error(submittable, :due_at, ERROR_MESSAGES[:set_override_due_at_in_closed], flash_message)
false
end
def grading_periods_allow_assignment_overrides_batch_update?(submittable, prepared_batch, flash_message: false)
Get rid of multiple_grading_periods feature flag Fixes CNVS-27109 Test plan: Regression test everything related to multiple grading periods. In particular, make sure: * there is no mention of the multiple grading periods feature flag on the account or course features pages * make sure grading periods UI always shows up on the account grading standards page * make sure the grading periods UI only shows on the course grading standards page if legacy course grading periods exist for that course (see below) * grading period dropdowns only show up everywhere else if there are grading periods to show. Otherwise, it should behave as if MGP is "disabled" * Grade calculation should work as expected with and without grading periods To create legacy course grading periods, you have to use rails console: 1. Find your course: course = Course.find(<id>) 2. Create a grading period group: group = course.grading_period_groups.create!(title: "2017") 2. Create a grading period: group.grading_periods.create!( weight: 1, title: 'Fall', start_date: 5.days.ago, end_date: 10.days.from_now ) Here's the list of known places grading periods can be seen in the UI: Instructor Assignments page (https://community.canvaslms.com/docs/DOC-2615) Student Assignments page (https://community.canvaslms.com/docs/DOC-3123) Gradebook (https://community.canvaslms.com/docs/DOC-2785) Gradebook Individual View (https://community.canvaslms.com/docs/DOC-2788) Course Settings grading schemes page (https://community.canvaslms.com/docs/DOC-4042) Student Grades page (https://community.canvaslms.com/docs/DOC-1291) Dashboard global Grades page (https://community.canvaslms.com/docs/DOC-5464) Change-Id: Iefac4b08120bd1699d4ed98bcb418089eec9b3b8 Reviewed-on: https://gerrit.instructure.com/99744 Reviewed-by: Spencer Olson <solson@instructure.com> Tested-by: Jenkins QA-Review: KC Naegle <knaegle@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2017-01-17 09:18:24 +08:00
return true unless grading_periods? && !current_user_is_context_admin?
protect due dates in closed grading periods This ensures that due dates cannot be set or changed in a way which puts them into, takes them out of, or adjusts them within a closed grading period. closes CNVS-32489 closes CNVS-33037 test plan: * Test the following endpoints: * POST /courses/:course_id/quizzes (quizzes/quizzes#create) * PUT /courses/:course_id/quizzes/:id (quizzes/quizzes#update) * POST /api/v1/courses/:course_id/quizzes (quizzes/quizzes_api#create) * PUT /api/v1/courses/:course_id/quizzes/:id (quizzes/quizzes_api#update) * POST /api/v1/courses/:course_id/assignments (assignments_api#create) * PUT /api/v1/courses/:course_id/assignments/:id (assignments_api#update) * A teacher cannot: * create a quiz/assignment * with a due date in a closed grading period * with an override due date in a closed grading period * with a nil due date when the last grading period is closed * with a nil override due date when the last grading period is closed * change the due date on a quiz or assignment * due in a closed grading period * with an override due in a closed grading period * to a date within a closed grading period * change the due date of an override * due in a closed grading period * to a date within a closed grading period * unset (nullify) the due date when the last grading period is closed * unset (nullify) the due date of an override when the last grading period is closed * delete (by omission from parameters) an override due in a closed grading period * A teacher can: * create a quiz/assignment with a due date in an open grading period * change the quiz/assignment due date when the assignment is only visible to overrides * change the quiz/assignment due date when not within a closed grading period * change the quiz/assignment due date when set to the same value * An ADMIN does not have these restrictions. Change-Id: I0da260e831784e7b6d0f6e5a35c43d6ecff9e977 Reviewed-on: https://gerrit.instructure.com/93806 Tested-by: Jenkins Reviewed-by: Spencer Olson <solson@instructure.com> Reviewed-by: Shahbaz Javeed <sjaveed@instructure.com> QA-Review: KC Naegle <knaegle@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2016-10-20 00:22:55 +08:00
can_create_overrides?(submittable, prepared_batch[:overrides_to_create], flash_message: flash_message) &&
can_update_overrides?(submittable, prepared_batch[:overrides_to_update], flash_message: flash_message) &&
can_delete_overrides?(submittable, prepared_batch[:overrides_to_delete], flash_message: flash_message)
end
private
def due_at_changed?(submittable)
submittable.due_at_was.to_i != submittable.due_at.to_i
end
protect due dates in closed grading periods This ensures that due dates cannot be set or changed in a way which puts them into, takes them out of, or adjusts them within a closed grading period. closes CNVS-32489 closes CNVS-33037 test plan: * Test the following endpoints: * POST /courses/:course_id/quizzes (quizzes/quizzes#create) * PUT /courses/:course_id/quizzes/:id (quizzes/quizzes#update) * POST /api/v1/courses/:course_id/quizzes (quizzes/quizzes_api#create) * PUT /api/v1/courses/:course_id/quizzes/:id (quizzes/quizzes_api#update) * POST /api/v1/courses/:course_id/assignments (assignments_api#create) * PUT /api/v1/courses/:course_id/assignments/:id (assignments_api#update) * A teacher cannot: * create a quiz/assignment * with a due date in a closed grading period * with an override due date in a closed grading period * with a nil due date when the last grading period is closed * with a nil override due date when the last grading period is closed * change the due date on a quiz or assignment * due in a closed grading period * with an override due in a closed grading period * to a date within a closed grading period * change the due date of an override * due in a closed grading period * to a date within a closed grading period * unset (nullify) the due date when the last grading period is closed * unset (nullify) the due date of an override when the last grading period is closed * delete (by omission from parameters) an override due in a closed grading period * A teacher can: * create a quiz/assignment with a due date in an open grading period * change the quiz/assignment due date when the assignment is only visible to overrides * change the quiz/assignment due date when not within a closed grading period * change the quiz/assignment due date when set to the same value * An ADMIN does not have these restrictions. Change-Id: I0da260e831784e7b6d0f6e5a35c43d6ecff9e977 Reviewed-on: https://gerrit.instructure.com/93806 Tested-by: Jenkins Reviewed-by: Spencer Olson <solson@instructure.com> Reviewed-by: Shahbaz Javeed <sjaveed@instructure.com> QA-Review: KC Naegle <knaegle@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
2016-10-20 00:22:55 +08:00
def apply_grading_params(submittable, submittable_params)
case submittable
when Quizzes::Quiz
submittable.quiz_type = submittable_params[:quiz_type]
when Assignment
submittable.submission_types = submittable_params[:submission_types]
end
end
def can_create_overrides?(submittable, overrides, flash_message: false)
# Known Issue: This method explicitly does not handle the case where
# creating an override would cause a student to assume a due date in an
# open grading period when previously in a closed grading period.
return true unless overrides.any? {|override| date_in_closed_grading_period?(override.due_at)}
apply_error(submittable, :due_at, ERROR_MESSAGES[:set_override_due_at_in_closed], flash_message)
false
end
def can_update_overrides?(submittable, overrides, flash_message: false)
changed_overrides = overrides.select {|override| override.due_at_was.to_i != override.due_at.to_i}
return true if changed_overrides.empty?
if changed_overrides.any? {|override| date_in_closed_grading_period?(override.due_at_was)}
apply_error(submittable, :due_at, ERROR_MESSAGES[:change_override_due_at_in_closed], flash_message)
return false
end
return true unless changed_overrides.any? {|override| date_in_closed_grading_period?(override.due_at)}
apply_error(submittable, :due_at, ERROR_MESSAGES[:change_override_due_at_to_closed], flash_message)
false
end
def can_delete_overrides?(submittable, overrides, flash_message: false)
# Known Issue: This method explicitly does not handle the case where
# deleting an override would cause a student to assume a due date in a
# closed grading period when previously in an open grading period.
return true unless overrides.any? {|override| date_in_closed_grading_period?(override.due_at)}
apply_error(submittable, :due_at, ERROR_MESSAGES[:delete_override_in_closed], flash_message)
false
end
def current_user_is_context_admin?
if @current_user_is_context_admin.nil?
@current_user_is_context_admin = @context.account_membership_allows(@current_user)
end
@current_user_is_context_admin
end
def context_grading_periods
@context_grading_periods ||= GradingPeriod.for(@context)
end
def date_in_closed_grading_period?(date)
GradingPeriodHelper.date_in_closed_grading_period?(date, context_grading_periods)
end
def apply_error(submittable, attribute, message, flash_message)
submittable.errors.add(attribute, message)
flash[:error] = message if flash_message
end
ERROR_MESSAGES = {
set_due_at_in_closed: I18n.t("Cannot set the due date to a date within a closed grading period"),
change_due_at_in_closed: I18n.t("Cannot change the due date when due in a closed grading period"),
change_due_at_to_closed: I18n.t("Cannot change the due date to a date within a closed grading period"),
set_override_due_at_in_closed: I18n.t("Cannot set override due date to a date within a closed grading period"),
change_override_due_at_in_closed: I18n.t("Cannot change the due date of an override in a closed grading period"),
change_override_due_at_to_closed: I18n.t("Cannot change an override due date \
to a date within a closed grading period"),
delete_override_in_closed: I18n.t("Cannot delete an override with a due date within a closed grading period"),
change_only_visible_to_overrides: I18n.t("Cannot set only visible to overrides when due in a closed grading period")
}.freeze
end