canvas-lms/app/models/grading_period_group.rb

124 lines
3.6 KiB
Ruby
Raw Normal View History

remove account association from grading periods and their groups Accounts will no longer be directly associated with grading periods or grading period groups. A grading period group can: * have only one or more enrollment terms * belong only to a course (for legacy data) Testing Notes: * To create a GradingPeriodGroup for an EnrollmentTerm: * Create an EnrollmentTerm `enrollment_term` * `group = GradingPeriodGroup.new(title: "Example")` * `group.enrollment_terms << enrollment_term` * `group.save!` test plan: A. repeat tests with commit at SHA: 861015a B. grading standards for an account 1. find or create an Account 2. visit `/accounts/[account id]/grading_standards` 3. verify there is no grading periods UI 4. verify that grading schemes are still manageable C. grading standards for a course with grading periods 1. find or create: a. an Account b. an EnrollmentTerm for the Account c. a Course for that Account 2. associate the Course with the EnrollmentTerm 3. in the Rails console `bundle exec rails console` a. create a GradingPeriodGroup for the Course b. create at least one GradingPeriod in the course group c. create a GradingPeriodGroup for the EnrollmentTerm d. create at least one GradingPeriod in the term group 4. visit `/courses/[course id]/grading_standards` 5. verify the grading period(s) on the course are present 5. verify the grading period(s) on the term are not present 6. verify that grading schemes are still manageable D. grading standards for a course with no grading periods 1. find or create: a. an Account b. an EnrollmentTerm for the Account c. a Course for that Account 2. associate the Course with the EnrollmentTerm 3. in the Rails console `bundle exec rails console` a. create a GradingPeriodGroup for the EnrollmentTerm b. create at least one GradingPeriod in the group 4. visit `/courses/[course id]/grading_standards` 5. verify the grading periods on the term are present 6. verify that grading schemes are still manageable closes CNVS-26725 Change-Id: I7883cb421c87ebb91c818223c0483557fdd5e40a Reviewed-on: https://gerrit.instructure.com/78167 Reviewed-by: Derek Bender <djbender@instructure.com> Reviewed-by: Spencer Olson <solson@instructure.com> QA-Review: KC Naegle <knaegle@instructure.com> Tested-by: Jenkins Product-Review: Keith T. Garner <kgarner@instructure.com>
2016-04-22 06:09:15 +08:00
#
# Copyright (C) 2014-2016 Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
add grading period group model add GradingPeriodGroup, and change associations between GradingPeriods, GradingPeriodGroups, Courses, and Accounts. also adjust the grading periods controller to account for addition of grading period groups closes CNVS-16538 test plan: -run bundle exec rake db:migrate, and bundle exec rake db:migrate RAILS_ENV=test -verify the migrations successfully run -open the rails console in sandbox: bundle exec rails c -s -create a course, a few grading periods, and a grading period group. Add the grading periods to the group. Assign the grading period group to the course. $ course = Course.create $ grading_period1 = GradingPeriod.create(weight: 25.0, start_date: Time.zone.now, end_date: 2.days.from_now) $ grading_period2 = GradingPeriod.create(weight: 30.0, start_date: Time.zone.now, end_date: 2.days.from_now) $ grading_period_group = GradingPeriodGroup.create() $ grading_period_group.grading_periods << grading_period1 $ grading_period_group.grading_periods << grading_period2 $ grading_period_group.course = course -verify the associations are working as expected, i.e. a GradingPeriodGroup has GradingPeriods, a GradingPeriod belongs to a GradingPeriodGroup, and a GradingPeriodGroup belongs to a course or account. $ grading_period_group.grading_periods #should return an array containing grading_period1 and grading_period2 $ grading_period1.grading_period_group #should return grading_period_group $ grading_period2.grading_period_group #should return grading_period_group $ grading_period_group.course #should return course $ grading_period_group.account #should return nil (should not throw error) Change-Id: I9d7465431dabd2afa18e7a8a33706b9a78a94cd1 Reviewed-on: https://gerrit.instructure.com/43512 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Josh Simpson <jsimpson@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com> Reviewed-by: Jacob Fugal <jacob@instructure.com> Product-Review: Spencer Olson <solson@instructure.com>
2014-10-30 02:42:41 +08:00
class GradingPeriodGroup < ActiveRecord::Base
include Canvas::SoftDeletable
add workflow state to grading period groups and grading period grades add workflow state to grading period groups and grading period grades. also add a default value of 'active' and a not-null constraint for workflow state on grading periods, grading period groups, and grading period grades. also add a validate method for grading period group that ensures the group belongs to either a course or account. add a not-null constraint for grading period group id on grading periods. add an index for workflow_state on grading period groups, grading periods, and grading period grades. closes CNVS-18995 test plan: run migrations. in rails console: $ bundle exec rake db:migrate $ bundle exec rake db:migrate RAILS_ENV=test Grading Period Groups: - you should not be able to create a Grading Period Group without assigning it either a course or account. If you don't supply a workflow state when you create a grading period group, it should default to 'active'. $ g = GradingPeriodGroup.create $ g.valid? #should return false $ g = Account.default.grading_period_groups.create $ g.valid? #should return true $ g.workflow_state #should return 'active' $ new_course = Course.create $ g = new_course.grading_period_groups.create $ g.valid? #should return true $ g.workflow_state #should return 'active' - when you delete a grading period group, it should do a 'soft delete', which means it should set its workflow_state to 'deleted' instead of actually deleting it from the database $ g = Account.default.grading_period_groups.create $ g.destroy $ g.workflow_state #should return 'deleted' - when you delete a grading period group, it should also soft delete any grading periods that belong to it. $ gp_group = Account.default.grading_period_groups.create $ gp = gp_group.grading_periods.create( start_date: Time.now, end_date: 1.month.from_now) $ gp_group.destroy $ gp_group.workflow_state #should return 'deleted' $ gp.workflow_state #should return 'deleted' Grading Periods: - you should no longer be able to create a grading period without giving it a grading_period_group id. also, if you don't give it a workflow_state, it should default to 'active'. when you delete a grading period it should do a 'soft delete'. $ g = GradingPeriod.create(start_date: Time.now, end_date: 1.month.from_now) $ g.valid? #should return false $ gp_group = Account.default.grading_period_groups.create $ gp = gp_group.grading_periods.create( start_date: Time.now, end_date: 1.month.from_now) $ gp.valid? #should return true $ gp.workflow_state #should return 'active' $ gp.destroy $ gp.workflow_state #should return 'deleted' - when you delete a grading period, it should also do a 'soft delete' on any owned grading period grades. Enrollments are tricky to make via the rails console, so i'm just grabbing one here that was already made -- you should be able to do the same. if you don't have any enrollments created, create one via Canvas and then come back to the rails console. $ gp_group = Account.default.grading_period_groups.create $ gp = gp_group.grading_periods.create( start_date: Time.now, end_date: 1.month.from_now) $ enrollment = Enrollment.first $ gp_grade = gp.grading_period_grades.create( enrollment_id: enrollment) $ gp_grade.workflow_state #should return 'active' $ gp.destroy $ gp.workflow_state #should return 'deleted' $ gp_grade.workflow_state #should return 'deleted' Grading Period Grades: - these should now 'soft delete' as well. they require a grading period and an enrollment to be created (no change here, this has always been the case). $ enrollment = Enrollment.first $ gp_group = Account.default.grading_period_groups.create $ gp = gp_group.grading_periods.create( start_date: Time.now, end_date: 1.month.from_now) $ gp_grade = gp.grading_period_grades.create( enrollment_id: enrollment) $ gp_grade.workflow_state #should return 'active' $ gp_grade.destroy $ gp_grade.workflow_state #should return 'deleted' Change-Id: Ic397a03beca4782c0c80e486673c7cfef59d38e5 Reviewed-on: https://gerrit.instructure.com/49754 Reviewed-by: Josh Simpson <jsimpson@instructure.com> Reviewed-by: Jacob Fugal <jacob@instructure.com> QA-Review: Robert Lamb <rlamb@instructure.com> Tested-by: Jenkins Product-Review: Spencer Olson <solson@instructure.com>
2015-03-06 07:36:04 +08:00
remove account association from grading periods and their groups Accounts will no longer be directly associated with grading periods or grading period groups. A grading period group can: * have only one or more enrollment terms * belong only to a course (for legacy data) Testing Notes: * To create a GradingPeriodGroup for an EnrollmentTerm: * Create an EnrollmentTerm `enrollment_term` * `group = GradingPeriodGroup.new(title: "Example")` * `group.enrollment_terms << enrollment_term` * `group.save!` test plan: A. repeat tests with commit at SHA: 861015a B. grading standards for an account 1. find or create an Account 2. visit `/accounts/[account id]/grading_standards` 3. verify there is no grading periods UI 4. verify that grading schemes are still manageable C. grading standards for a course with grading periods 1. find or create: a. an Account b. an EnrollmentTerm for the Account c. a Course for that Account 2. associate the Course with the EnrollmentTerm 3. in the Rails console `bundle exec rails console` a. create a GradingPeriodGroup for the Course b. create at least one GradingPeriod in the course group c. create a GradingPeriodGroup for the EnrollmentTerm d. create at least one GradingPeriod in the term group 4. visit `/courses/[course id]/grading_standards` 5. verify the grading period(s) on the course are present 5. verify the grading period(s) on the term are not present 6. verify that grading schemes are still manageable D. grading standards for a course with no grading periods 1. find or create: a. an Account b. an EnrollmentTerm for the Account c. a Course for that Account 2. associate the Course with the EnrollmentTerm 3. in the Rails console `bundle exec rails console` a. create a GradingPeriodGroup for the EnrollmentTerm b. create at least one GradingPeriod in the group 4. visit `/courses/[course id]/grading_standards` 5. verify the grading periods on the term are present 6. verify that grading schemes are still manageable closes CNVS-26725 Change-Id: I7883cb421c87ebb91c818223c0483557fdd5e40a Reviewed-on: https://gerrit.instructure.com/78167 Reviewed-by: Derek Bender <djbender@instructure.com> Reviewed-by: Spencer Olson <solson@instructure.com> QA-Review: KC Naegle <knaegle@instructure.com> Tested-by: Jenkins Product-Review: Keith T. Garner <kgarner@instructure.com>
2016-04-22 06:09:15 +08:00
attr_readonly :account_id
attr_accessible :title
belongs_to :course
add grading period group model add GradingPeriodGroup, and change associations between GradingPeriods, GradingPeriodGroups, Courses, and Accounts. also adjust the grading periods controller to account for addition of grading period groups closes CNVS-16538 test plan: -run bundle exec rake db:migrate, and bundle exec rake db:migrate RAILS_ENV=test -verify the migrations successfully run -open the rails console in sandbox: bundle exec rails c -s -create a course, a few grading periods, and a grading period group. Add the grading periods to the group. Assign the grading period group to the course. $ course = Course.create $ grading_period1 = GradingPeriod.create(weight: 25.0, start_date: Time.zone.now, end_date: 2.days.from_now) $ grading_period2 = GradingPeriod.create(weight: 30.0, start_date: Time.zone.now, end_date: 2.days.from_now) $ grading_period_group = GradingPeriodGroup.create() $ grading_period_group.grading_periods << grading_period1 $ grading_period_group.grading_periods << grading_period2 $ grading_period_group.course = course -verify the associations are working as expected, i.e. a GradingPeriodGroup has GradingPeriods, a GradingPeriod belongs to a GradingPeriodGroup, and a GradingPeriodGroup belongs to a course or account. $ grading_period_group.grading_periods #should return an array containing grading_period1 and grading_period2 $ grading_period1.grading_period_group #should return grading_period_group $ grading_period2.grading_period_group #should return grading_period_group $ grading_period_group.course #should return course $ grading_period_group.account #should return nil (should not throw error) Change-Id: I9d7465431dabd2afa18e7a8a33706b9a78a94cd1 Reviewed-on: https://gerrit.instructure.com/43512 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Josh Simpson <jsimpson@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com> Reviewed-by: Jacob Fugal <jacob@instructure.com> Product-Review: Spencer Olson <solson@instructure.com>
2014-10-30 02:42:41 +08:00
has_many :grading_periods, dependent: :destroy
has_many :enrollment_terms, inverse_of: :grading_period_group
add grading period group model add GradingPeriodGroup, and change associations between GradingPeriods, GradingPeriodGroups, Courses, and Accounts. also adjust the grading periods controller to account for addition of grading period groups closes CNVS-16538 test plan: -run bundle exec rake db:migrate, and bundle exec rake db:migrate RAILS_ENV=test -verify the migrations successfully run -open the rails console in sandbox: bundle exec rails c -s -create a course, a few grading periods, and a grading period group. Add the grading periods to the group. Assign the grading period group to the course. $ course = Course.create $ grading_period1 = GradingPeriod.create(weight: 25.0, start_date: Time.zone.now, end_date: 2.days.from_now) $ grading_period2 = GradingPeriod.create(weight: 30.0, start_date: Time.zone.now, end_date: 2.days.from_now) $ grading_period_group = GradingPeriodGroup.create() $ grading_period_group.grading_periods << grading_period1 $ grading_period_group.grading_periods << grading_period2 $ grading_period_group.course = course -verify the associations are working as expected, i.e. a GradingPeriodGroup has GradingPeriods, a GradingPeriod belongs to a GradingPeriodGroup, and a GradingPeriodGroup belongs to a course or account. $ grading_period_group.grading_periods #should return an array containing grading_period1 and grading_period2 $ grading_period1.grading_period_group #should return grading_period_group $ grading_period2.grading_period_group #should return grading_period_group $ grading_period_group.course #should return course $ grading_period_group.account #should return nil (should not throw error) Change-Id: I9d7465431dabd2afa18e7a8a33706b9a78a94cd1 Reviewed-on: https://gerrit.instructure.com/43512 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Josh Simpson <jsimpson@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com> Reviewed-by: Jacob Fugal <jacob@instructure.com> Product-Review: Spencer Olson <solson@instructure.com>
2014-10-30 02:42:41 +08:00
validate :associated_with_course_or_account_or_enrollment_term?
add workflow state to grading period groups and grading period grades add workflow state to grading period groups and grading period grades. also add a default value of 'active' and a not-null constraint for workflow state on grading periods, grading period groups, and grading period grades. also add a validate method for grading period group that ensures the group belongs to either a course or account. add a not-null constraint for grading period group id on grading periods. add an index for workflow_state on grading period groups, grading periods, and grading period grades. closes CNVS-18995 test plan: run migrations. in rails console: $ bundle exec rake db:migrate $ bundle exec rake db:migrate RAILS_ENV=test Grading Period Groups: - you should not be able to create a Grading Period Group without assigning it either a course or account. If you don't supply a workflow state when you create a grading period group, it should default to 'active'. $ g = GradingPeriodGroup.create $ g.valid? #should return false $ g = Account.default.grading_period_groups.create $ g.valid? #should return true $ g.workflow_state #should return 'active' $ new_course = Course.create $ g = new_course.grading_period_groups.create $ g.valid? #should return true $ g.workflow_state #should return 'active' - when you delete a grading period group, it should do a 'soft delete', which means it should set its workflow_state to 'deleted' instead of actually deleting it from the database $ g = Account.default.grading_period_groups.create $ g.destroy $ g.workflow_state #should return 'deleted' - when you delete a grading period group, it should also soft delete any grading periods that belong to it. $ gp_group = Account.default.grading_period_groups.create $ gp = gp_group.grading_periods.create( start_date: Time.now, end_date: 1.month.from_now) $ gp_group.destroy $ gp_group.workflow_state #should return 'deleted' $ gp.workflow_state #should return 'deleted' Grading Periods: - you should no longer be able to create a grading period without giving it a grading_period_group id. also, if you don't give it a workflow_state, it should default to 'active'. when you delete a grading period it should do a 'soft delete'. $ g = GradingPeriod.create(start_date: Time.now, end_date: 1.month.from_now) $ g.valid? #should return false $ gp_group = Account.default.grading_period_groups.create $ gp = gp_group.grading_periods.create( start_date: Time.now, end_date: 1.month.from_now) $ gp.valid? #should return true $ gp.workflow_state #should return 'active' $ gp.destroy $ gp.workflow_state #should return 'deleted' - when you delete a grading period, it should also do a 'soft delete' on any owned grading period grades. Enrollments are tricky to make via the rails console, so i'm just grabbing one here that was already made -- you should be able to do the same. if you don't have any enrollments created, create one via Canvas and then come back to the rails console. $ gp_group = Account.default.grading_period_groups.create $ gp = gp_group.grading_periods.create( start_date: Time.now, end_date: 1.month.from_now) $ enrollment = Enrollment.first $ gp_grade = gp.grading_period_grades.create( enrollment_id: enrollment) $ gp_grade.workflow_state #should return 'active' $ gp.destroy $ gp.workflow_state #should return 'deleted' $ gp_grade.workflow_state #should return 'deleted' Grading Period Grades: - these should now 'soft delete' as well. they require a grading period and an enrollment to be created (no change here, this has always been the case). $ enrollment = Enrollment.first $ gp_group = Account.default.grading_period_groups.create $ gp = gp_group.grading_periods.create( start_date: Time.now, end_date: 1.month.from_now) $ gp_grade = gp.grading_period_grades.create( enrollment_id: enrollment) $ gp_grade.workflow_state #should return 'active' $ gp_grade.destroy $ gp_grade.workflow_state #should return 'deleted' Change-Id: Ic397a03beca4782c0c80e486673c7cfef59d38e5 Reviewed-on: https://gerrit.instructure.com/49754 Reviewed-by: Josh Simpson <jsimpson@instructure.com> Reviewed-by: Jacob Fugal <jacob@instructure.com> QA-Review: Robert Lamb <rlamb@instructure.com> Tested-by: Jenkins Product-Review: Spencer Olson <solson@instructure.com>
2015-03-06 07:36:04 +08:00
add grading period group model add GradingPeriodGroup, and change associations between GradingPeriods, GradingPeriodGroups, Courses, and Accounts. also adjust the grading periods controller to account for addition of grading period groups closes CNVS-16538 test plan: -run bundle exec rake db:migrate, and bundle exec rake db:migrate RAILS_ENV=test -verify the migrations successfully run -open the rails console in sandbox: bundle exec rails c -s -create a course, a few grading periods, and a grading period group. Add the grading periods to the group. Assign the grading period group to the course. $ course = Course.create $ grading_period1 = GradingPeriod.create(weight: 25.0, start_date: Time.zone.now, end_date: 2.days.from_now) $ grading_period2 = GradingPeriod.create(weight: 30.0, start_date: Time.zone.now, end_date: 2.days.from_now) $ grading_period_group = GradingPeriodGroup.create() $ grading_period_group.grading_periods << grading_period1 $ grading_period_group.grading_periods << grading_period2 $ grading_period_group.course = course -verify the associations are working as expected, i.e. a GradingPeriodGroup has GradingPeriods, a GradingPeriod belongs to a GradingPeriodGroup, and a GradingPeriodGroup belongs to a course or account. $ grading_period_group.grading_periods #should return an array containing grading_period1 and grading_period2 $ grading_period1.grading_period_group #should return grading_period_group $ grading_period2.grading_period_group #should return grading_period_group $ grading_period_group.course #should return course $ grading_period_group.account #should return nil (should not throw error) Change-Id: I9d7465431dabd2afa18e7a8a33706b9a78a94cd1 Reviewed-on: https://gerrit.instructure.com/43512 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Josh Simpson <jsimpson@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com> Reviewed-by: Jacob Fugal <jacob@instructure.com> Product-Review: Spencer Olson <solson@instructure.com>
2014-10-30 02:42:41 +08:00
set_policy do
given do |user|
multiple_grading_periods_enabled? &&
remove account association from grading periods and their groups Accounts will no longer be directly associated with grading periods or grading period groups. A grading period group can: * have only one or more enrollment terms * belong only to a course (for legacy data) Testing Notes: * To create a GradingPeriodGroup for an EnrollmentTerm: * Create an EnrollmentTerm `enrollment_term` * `group = GradingPeriodGroup.new(title: "Example")` * `group.enrollment_terms << enrollment_term` * `group.save!` test plan: A. repeat tests with commit at SHA: 861015a B. grading standards for an account 1. find or create an Account 2. visit `/accounts/[account id]/grading_standards` 3. verify there is no grading periods UI 4. verify that grading schemes are still manageable C. grading standards for a course with grading periods 1. find or create: a. an Account b. an EnrollmentTerm for the Account c. a Course for that Account 2. associate the Course with the EnrollmentTerm 3. in the Rails console `bundle exec rails console` a. create a GradingPeriodGroup for the Course b. create at least one GradingPeriod in the course group c. create a GradingPeriodGroup for the EnrollmentTerm d. create at least one GradingPeriod in the term group 4. visit `/courses/[course id]/grading_standards` 5. verify the grading period(s) on the course are present 5. verify the grading period(s) on the term are not present 6. verify that grading schemes are still manageable D. grading standards for a course with no grading periods 1. find or create: a. an Account b. an EnrollmentTerm for the Account c. a Course for that Account 2. associate the Course with the EnrollmentTerm 3. in the Rails console `bundle exec rails console` a. create a GradingPeriodGroup for the EnrollmentTerm b. create at least one GradingPeriod in the group 4. visit `/courses/[course id]/grading_standards` 5. verify the grading periods on the term are present 6. verify that grading schemes are still manageable closes CNVS-26725 Change-Id: I7883cb421c87ebb91c818223c0483557fdd5e40a Reviewed-on: https://gerrit.instructure.com/78167 Reviewed-by: Derek Bender <djbender@instructure.com> Reviewed-by: Spencer Olson <solson@instructure.com> QA-Review: KC Naegle <knaegle@instructure.com> Tested-by: Jenkins Product-Review: Keith T. Garner <kgarner@instructure.com>
2016-04-22 06:09:15 +08:00
(course || root_account).grants_right?(user, :read)
end
add grading period group model add GradingPeriodGroup, and change associations between GradingPeriods, GradingPeriodGroups, Courses, and Accounts. also adjust the grading periods controller to account for addition of grading period groups closes CNVS-16538 test plan: -run bundle exec rake db:migrate, and bundle exec rake db:migrate RAILS_ENV=test -verify the migrations successfully run -open the rails console in sandbox: bundle exec rails c -s -create a course, a few grading periods, and a grading period group. Add the grading periods to the group. Assign the grading period group to the course. $ course = Course.create $ grading_period1 = GradingPeriod.create(weight: 25.0, start_date: Time.zone.now, end_date: 2.days.from_now) $ grading_period2 = GradingPeriod.create(weight: 30.0, start_date: Time.zone.now, end_date: 2.days.from_now) $ grading_period_group = GradingPeriodGroup.create() $ grading_period_group.grading_periods << grading_period1 $ grading_period_group.grading_periods << grading_period2 $ grading_period_group.course = course -verify the associations are working as expected, i.e. a GradingPeriodGroup has GradingPeriods, a GradingPeriod belongs to a GradingPeriodGroup, and a GradingPeriodGroup belongs to a course or account. $ grading_period_group.grading_periods #should return an array containing grading_period1 and grading_period2 $ grading_period1.grading_period_group #should return grading_period_group $ grading_period2.grading_period_group #should return grading_period_group $ grading_period_group.course #should return course $ grading_period_group.account #should return nil (should not throw error) Change-Id: I9d7465431dabd2afa18e7a8a33706b9a78a94cd1 Reviewed-on: https://gerrit.instructure.com/43512 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Josh Simpson <jsimpson@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com> Reviewed-by: Jacob Fugal <jacob@instructure.com> Product-Review: Spencer Olson <solson@instructure.com>
2014-10-30 02:42:41 +08:00
can :read
given do |user|
remove account association from grading periods and their groups Accounts will no longer be directly associated with grading periods or grading period groups. A grading period group can: * have only one or more enrollment terms * belong only to a course (for legacy data) Testing Notes: * To create a GradingPeriodGroup for an EnrollmentTerm: * Create an EnrollmentTerm `enrollment_term` * `group = GradingPeriodGroup.new(title: "Example")` * `group.enrollment_terms << enrollment_term` * `group.save!` test plan: A. repeat tests with commit at SHA: 861015a B. grading standards for an account 1. find or create an Account 2. visit `/accounts/[account id]/grading_standards` 3. verify there is no grading periods UI 4. verify that grading schemes are still manageable C. grading standards for a course with grading periods 1. find or create: a. an Account b. an EnrollmentTerm for the Account c. a Course for that Account 2. associate the Course with the EnrollmentTerm 3. in the Rails console `bundle exec rails console` a. create a GradingPeriodGroup for the Course b. create at least one GradingPeriod in the course group c. create a GradingPeriodGroup for the EnrollmentTerm d. create at least one GradingPeriod in the term group 4. visit `/courses/[course id]/grading_standards` 5. verify the grading period(s) on the course are present 5. verify the grading period(s) on the term are not present 6. verify that grading schemes are still manageable D. grading standards for a course with no grading periods 1. find or create: a. an Account b. an EnrollmentTerm for the Account c. a Course for that Account 2. associate the Course with the EnrollmentTerm 3. in the Rails console `bundle exec rails console` a. create a GradingPeriodGroup for the EnrollmentTerm b. create at least one GradingPeriod in the group 4. visit `/courses/[course id]/grading_standards` 5. verify the grading periods on the term are present 6. verify that grading schemes are still manageable closes CNVS-26725 Change-Id: I7883cb421c87ebb91c818223c0483557fdd5e40a Reviewed-on: https://gerrit.instructure.com/78167 Reviewed-by: Derek Bender <djbender@instructure.com> Reviewed-by: Spencer Olson <solson@instructure.com> QA-Review: KC Naegle <knaegle@instructure.com> Tested-by: Jenkins Product-Review: Keith T. Garner <kgarner@instructure.com>
2016-04-22 06:09:15 +08:00
root_account &&
multiple_grading_periods_enabled? &&
root_account.associated_user?(user)
end
set up permissions for grading periods closes CNVS-18438 test plan: 1. create a root-account, a sub-account (belonging to the root-account), and a course belonging to the root-account (not belonging to the sub-account). Create an admin for your root-account and an admin for your sub-account, and a teacher and student for your course. 2. create grading periods for the root-account, sub-account, and course. For the example below i'm using the ids 1, 5, and 10 for the account, sub-account, and course, respectively. In rails console: $ root_gp_group = Account.find(1).grading_period_groups.create! $ sub_gp_group = Account.find(5).grading_period_groups.create! $ course_gp_group = Course.find(10).grading_period_groups.create! $ root_gp = root_gp_group.grading_periods.create!( start_date: Time.now, end_date: 2.days.from_now, weight: 0.50) $ sub_gp = sub_gp_group.grading_periods.create!( start_date: Time.now, end_date: 2.days.from_now, weight: 0.50) $ course_gp = root_gp_group.grading_periods.create!( start_date: Time.now, end_date: 2.days.from_now, weight: 0.50) 3. check the permissions for your root-admin, sub-admin, teacher, and student (while still in rails console). example below assumes root-admin, sub-admin, teacher, and student ids are 100, 200, 300, and 400 respectively. $ root_admin = User.find(100) $ sub_admin = User.find(200) $ teacher = User.find(300) $ student = User.find(400) $ root_gp.rights_status(root_admin, :read, :manage) -- should return {read: true, manage: true} $ root_gp.rights_status(sub_admin, :read, :manage) -- should return {read: true, manage: false} $ root_gp.rights_status(teacher, :read, :manage) -- should return {read: true, manage: false} $ root_gp.rights_status(student, :read, :manage) -- should return {read: true, manage: false} $ sub_gp.rights_status(root_admin, :read, :manage) -- should return {read: true, manage: true} $ sub_gp.rights_status(sub_admin, :read, :manage) -- should return {read: true, manage: true} $ sub_gp.rights_status(teacher, :read, :manage) -- should return {read: false, manage: false} $ sub_gp.rights_status(student, :read, :manage) -- should return {read: false, manage: false} $ course_gp.rights_status(root_admin, :read, :manage) -- should return {read: true, manage: true} $ course_gp.rights_status(sub_admin, :read, :manage) -- should return {read: false, manage: false} $ course_gp.rights_status(teacher, :read, :manage) -- should return {read: true, manage: true} $ course_gp.rights_status(student, :read, :manage) -- should return {read: true, manage: false} Change-Id: Ib5262ebcaa0554096ac9ddaacab017d45717bea6 Reviewed-on: https://gerrit.instructure.com/48524 Tested-by: Jenkins Reviewed-by: Cameron Sutter <csutter@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com> Product-Review: Spencer Olson <solson@instructure.com>
2015-02-10 02:23:23 +08:00
can :read
given do |user|
multiple_grading_periods_enabled? &&
remove account association from grading periods and their groups Accounts will no longer be directly associated with grading periods or grading period groups. A grading period group can: * have only one or more enrollment terms * belong only to a course (for legacy data) Testing Notes: * To create a GradingPeriodGroup for an EnrollmentTerm: * Create an EnrollmentTerm `enrollment_term` * `group = GradingPeriodGroup.new(title: "Example")` * `group.enrollment_terms << enrollment_term` * `group.save!` test plan: A. repeat tests with commit at SHA: 861015a B. grading standards for an account 1. find or create an Account 2. visit `/accounts/[account id]/grading_standards` 3. verify there is no grading periods UI 4. verify that grading schemes are still manageable C. grading standards for a course with grading periods 1. find or create: a. an Account b. an EnrollmentTerm for the Account c. a Course for that Account 2. associate the Course with the EnrollmentTerm 3. in the Rails console `bundle exec rails console` a. create a GradingPeriodGroup for the Course b. create at least one GradingPeriod in the course group c. create a GradingPeriodGroup for the EnrollmentTerm d. create at least one GradingPeriod in the term group 4. visit `/courses/[course id]/grading_standards` 5. verify the grading period(s) on the course are present 5. verify the grading period(s) on the term are not present 6. verify that grading schemes are still manageable D. grading standards for a course with no grading periods 1. find or create: a. an Account b. an EnrollmentTerm for the Account c. a Course for that Account 2. associate the Course with the EnrollmentTerm 3. in the Rails console `bundle exec rails console` a. create a GradingPeriodGroup for the EnrollmentTerm b. create at least one GradingPeriod in the group 4. visit `/courses/[course id]/grading_standards` 5. verify the grading periods on the term are present 6. verify that grading schemes are still manageable closes CNVS-26725 Change-Id: I7883cb421c87ebb91c818223c0483557fdd5e40a Reviewed-on: https://gerrit.instructure.com/78167 Reviewed-by: Derek Bender <djbender@instructure.com> Reviewed-by: Spencer Olson <solson@instructure.com> QA-Review: KC Naegle <knaegle@instructure.com> Tested-by: Jenkins Product-Review: Keith T. Garner <kgarner@instructure.com>
2016-04-22 06:09:15 +08:00
(course || root_account).grants_right?(user, :manage)
end
can :update and can :delete
given do |user|
remove account association from grading periods and their groups Accounts will no longer be directly associated with grading periods or grading period groups. A grading period group can: * have only one or more enrollment terms * belong only to a course (for legacy data) Testing Notes: * To create a GradingPeriodGroup for an EnrollmentTerm: * Create an EnrollmentTerm `enrollment_term` * `group = GradingPeriodGroup.new(title: "Example")` * `group.enrollment_terms << enrollment_term` * `group.save!` test plan: A. repeat tests with commit at SHA: 861015a B. grading standards for an account 1. find or create an Account 2. visit `/accounts/[account id]/grading_standards` 3. verify there is no grading periods UI 4. verify that grading schemes are still manageable C. grading standards for a course with grading periods 1. find or create: a. an Account b. an EnrollmentTerm for the Account c. a Course for that Account 2. associate the Course with the EnrollmentTerm 3. in the Rails console `bundle exec rails console` a. create a GradingPeriodGroup for the Course b. create at least one GradingPeriod in the course group c. create a GradingPeriodGroup for the EnrollmentTerm d. create at least one GradingPeriod in the term group 4. visit `/courses/[course id]/grading_standards` 5. verify the grading period(s) on the course are present 5. verify the grading period(s) on the term are not present 6. verify that grading schemes are still manageable D. grading standards for a course with no grading periods 1. find or create: a. an Account b. an EnrollmentTerm for the Account c. a Course for that Account 2. associate the Course with the EnrollmentTerm 3. in the Rails console `bundle exec rails console` a. create a GradingPeriodGroup for the EnrollmentTerm b. create at least one GradingPeriod in the group 4. visit `/courses/[course id]/grading_standards` 5. verify the grading periods on the term are present 6. verify that grading schemes are still manageable closes CNVS-26725 Change-Id: I7883cb421c87ebb91c818223c0483557fdd5e40a Reviewed-on: https://gerrit.instructure.com/78167 Reviewed-by: Derek Bender <djbender@instructure.com> Reviewed-by: Spencer Olson <solson@instructure.com> QA-Review: KC Naegle <knaegle@instructure.com> Tested-by: Jenkins Product-Review: Keith T. Garner <kgarner@instructure.com>
2016-04-22 06:09:15 +08:00
root_account &&
multiple_grading_periods_enabled? &&
remove account association from grading periods and their groups Accounts will no longer be directly associated with grading periods or grading period groups. A grading period group can: * have only one or more enrollment terms * belong only to a course (for legacy data) Testing Notes: * To create a GradingPeriodGroup for an EnrollmentTerm: * Create an EnrollmentTerm `enrollment_term` * `group = GradingPeriodGroup.new(title: "Example")` * `group.enrollment_terms << enrollment_term` * `group.save!` test plan: A. repeat tests with commit at SHA: 861015a B. grading standards for an account 1. find or create an Account 2. visit `/accounts/[account id]/grading_standards` 3. verify there is no grading periods UI 4. verify that grading schemes are still manageable C. grading standards for a course with grading periods 1. find or create: a. an Account b. an EnrollmentTerm for the Account c. a Course for that Account 2. associate the Course with the EnrollmentTerm 3. in the Rails console `bundle exec rails console` a. create a GradingPeriodGroup for the Course b. create at least one GradingPeriod in the course group c. create a GradingPeriodGroup for the EnrollmentTerm d. create at least one GradingPeriod in the term group 4. visit `/courses/[course id]/grading_standards` 5. verify the grading period(s) on the course are present 5. verify the grading period(s) on the term are not present 6. verify that grading schemes are still manageable D. grading standards for a course with no grading periods 1. find or create: a. an Account b. an EnrollmentTerm for the Account c. a Course for that Account 2. associate the Course with the EnrollmentTerm 3. in the Rails console `bundle exec rails console` a. create a GradingPeriodGroup for the EnrollmentTerm b. create at least one GradingPeriod in the group 4. visit `/courses/[course id]/grading_standards` 5. verify the grading periods on the term are present 6. verify that grading schemes are still manageable closes CNVS-26725 Change-Id: I7883cb421c87ebb91c818223c0483557fdd5e40a Reviewed-on: https://gerrit.instructure.com/78167 Reviewed-by: Derek Bender <djbender@instructure.com> Reviewed-by: Spencer Olson <solson@instructure.com> QA-Review: KC Naegle <knaegle@instructure.com> Tested-by: Jenkins Product-Review: Keith T. Garner <kgarner@instructure.com>
2016-04-22 06:09:15 +08:00
root_account.grants_right?(user, :manage)
end
can :create
set up permissions for grading periods closes CNVS-18438 test plan: 1. create a root-account, a sub-account (belonging to the root-account), and a course belonging to the root-account (not belonging to the sub-account). Create an admin for your root-account and an admin for your sub-account, and a teacher and student for your course. 2. create grading periods for the root-account, sub-account, and course. For the example below i'm using the ids 1, 5, and 10 for the account, sub-account, and course, respectively. In rails console: $ root_gp_group = Account.find(1).grading_period_groups.create! $ sub_gp_group = Account.find(5).grading_period_groups.create! $ course_gp_group = Course.find(10).grading_period_groups.create! $ root_gp = root_gp_group.grading_periods.create!( start_date: Time.now, end_date: 2.days.from_now, weight: 0.50) $ sub_gp = sub_gp_group.grading_periods.create!( start_date: Time.now, end_date: 2.days.from_now, weight: 0.50) $ course_gp = root_gp_group.grading_periods.create!( start_date: Time.now, end_date: 2.days.from_now, weight: 0.50) 3. check the permissions for your root-admin, sub-admin, teacher, and student (while still in rails console). example below assumes root-admin, sub-admin, teacher, and student ids are 100, 200, 300, and 400 respectively. $ root_admin = User.find(100) $ sub_admin = User.find(200) $ teacher = User.find(300) $ student = User.find(400) $ root_gp.rights_status(root_admin, :read, :manage) -- should return {read: true, manage: true} $ root_gp.rights_status(sub_admin, :read, :manage) -- should return {read: true, manage: false} $ root_gp.rights_status(teacher, :read, :manage) -- should return {read: true, manage: false} $ root_gp.rights_status(student, :read, :manage) -- should return {read: true, manage: false} $ sub_gp.rights_status(root_admin, :read, :manage) -- should return {read: true, manage: true} $ sub_gp.rights_status(sub_admin, :read, :manage) -- should return {read: true, manage: true} $ sub_gp.rights_status(teacher, :read, :manage) -- should return {read: false, manage: false} $ sub_gp.rights_status(student, :read, :manage) -- should return {read: false, manage: false} $ course_gp.rights_status(root_admin, :read, :manage) -- should return {read: true, manage: true} $ course_gp.rights_status(sub_admin, :read, :manage) -- should return {read: false, manage: false} $ course_gp.rights_status(teacher, :read, :manage) -- should return {read: true, manage: true} $ course_gp.rights_status(student, :read, :manage) -- should return {read: true, manage: false} Change-Id: Ib5262ebcaa0554096ac9ddaacab017d45717bea6 Reviewed-on: https://gerrit.instructure.com/48524 Tested-by: Jenkins Reviewed-by: Cameron Sutter <csutter@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com> Product-Review: Spencer Olson <solson@instructure.com>
2015-02-10 02:23:23 +08:00
end
def self.for(account)
root_account = account.root_account? ? account : account.root_account
grading_period_group_ids = root_account
.active_enrollment_terms.select(:grading_period_group_id)
active.where(id: grading_period_group_ids)
end
set up permissions for grading periods closes CNVS-18438 test plan: 1. create a root-account, a sub-account (belonging to the root-account), and a course belonging to the root-account (not belonging to the sub-account). Create an admin for your root-account and an admin for your sub-account, and a teacher and student for your course. 2. create grading periods for the root-account, sub-account, and course. For the example below i'm using the ids 1, 5, and 10 for the account, sub-account, and course, respectively. In rails console: $ root_gp_group = Account.find(1).grading_period_groups.create! $ sub_gp_group = Account.find(5).grading_period_groups.create! $ course_gp_group = Course.find(10).grading_period_groups.create! $ root_gp = root_gp_group.grading_periods.create!( start_date: Time.now, end_date: 2.days.from_now, weight: 0.50) $ sub_gp = sub_gp_group.grading_periods.create!( start_date: Time.now, end_date: 2.days.from_now, weight: 0.50) $ course_gp = root_gp_group.grading_periods.create!( start_date: Time.now, end_date: 2.days.from_now, weight: 0.50) 3. check the permissions for your root-admin, sub-admin, teacher, and student (while still in rails console). example below assumes root-admin, sub-admin, teacher, and student ids are 100, 200, 300, and 400 respectively. $ root_admin = User.find(100) $ sub_admin = User.find(200) $ teacher = User.find(300) $ student = User.find(400) $ root_gp.rights_status(root_admin, :read, :manage) -- should return {read: true, manage: true} $ root_gp.rights_status(sub_admin, :read, :manage) -- should return {read: true, manage: false} $ root_gp.rights_status(teacher, :read, :manage) -- should return {read: true, manage: false} $ root_gp.rights_status(student, :read, :manage) -- should return {read: true, manage: false} $ sub_gp.rights_status(root_admin, :read, :manage) -- should return {read: true, manage: true} $ sub_gp.rights_status(sub_admin, :read, :manage) -- should return {read: true, manage: true} $ sub_gp.rights_status(teacher, :read, :manage) -- should return {read: false, manage: false} $ sub_gp.rights_status(student, :read, :manage) -- should return {read: false, manage: false} $ course_gp.rights_status(root_admin, :read, :manage) -- should return {read: true, manage: true} $ course_gp.rights_status(sub_admin, :read, :manage) -- should return {read: false, manage: false} $ course_gp.rights_status(teacher, :read, :manage) -- should return {read: true, manage: true} $ course_gp.rights_status(student, :read, :manage) -- should return {read: true, manage: false} Change-Id: Ib5262ebcaa0554096ac9ddaacab017d45717bea6 Reviewed-on: https://gerrit.instructure.com/48524 Tested-by: Jenkins Reviewed-by: Cameron Sutter <csutter@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com> Product-Review: Spencer Olson <solson@instructure.com>
2015-02-10 02:23:23 +08:00
def multiple_grading_periods_enabled?
(course || root_account).feature_enabled?(:multiple_grading_periods) ||
account_grading_period_allowed?
add grading period group model add GradingPeriodGroup, and change associations between GradingPeriods, GradingPeriodGroups, Courses, and Accounts. also adjust the grading periods controller to account for addition of grading period groups closes CNVS-16538 test plan: -run bundle exec rake db:migrate, and bundle exec rake db:migrate RAILS_ENV=test -verify the migrations successfully run -open the rails console in sandbox: bundle exec rails c -s -create a course, a few grading periods, and a grading period group. Add the grading periods to the group. Assign the grading period group to the course. $ course = Course.create $ grading_period1 = GradingPeriod.create(weight: 25.0, start_date: Time.zone.now, end_date: 2.days.from_now) $ grading_period2 = GradingPeriod.create(weight: 30.0, start_date: Time.zone.now, end_date: 2.days.from_now) $ grading_period_group = GradingPeriodGroup.create() $ grading_period_group.grading_periods << grading_period1 $ grading_period_group.grading_periods << grading_period2 $ grading_period_group.course = course -verify the associations are working as expected, i.e. a GradingPeriodGroup has GradingPeriods, a GradingPeriod belongs to a GradingPeriodGroup, and a GradingPeriodGroup belongs to a course or account. $ grading_period_group.grading_periods #should return an array containing grading_period1 and grading_period2 $ grading_period1.grading_period_group #should return grading_period_group $ grading_period2.grading_period_group #should return grading_period_group $ grading_period_group.course #should return course $ grading_period_group.account #should return nil (should not throw error) Change-Id: I9d7465431dabd2afa18e7a8a33706b9a78a94cd1 Reviewed-on: https://gerrit.instructure.com/43512 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Josh Simpson <jsimpson@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com> Reviewed-by: Jacob Fugal <jacob@instructure.com> Product-Review: Spencer Olson <solson@instructure.com>
2014-10-30 02:42:41 +08:00
end
add workflow state to grading period groups and grading period grades add workflow state to grading period groups and grading period grades. also add a default value of 'active' and a not-null constraint for workflow state on grading periods, grading period groups, and grading period grades. also add a validate method for grading period group that ensures the group belongs to either a course or account. add a not-null constraint for grading period group id on grading periods. add an index for workflow_state on grading period groups, grading periods, and grading period grades. closes CNVS-18995 test plan: run migrations. in rails console: $ bundle exec rake db:migrate $ bundle exec rake db:migrate RAILS_ENV=test Grading Period Groups: - you should not be able to create a Grading Period Group without assigning it either a course or account. If you don't supply a workflow state when you create a grading period group, it should default to 'active'. $ g = GradingPeriodGroup.create $ g.valid? #should return false $ g = Account.default.grading_period_groups.create $ g.valid? #should return true $ g.workflow_state #should return 'active' $ new_course = Course.create $ g = new_course.grading_period_groups.create $ g.valid? #should return true $ g.workflow_state #should return 'active' - when you delete a grading period group, it should do a 'soft delete', which means it should set its workflow_state to 'deleted' instead of actually deleting it from the database $ g = Account.default.grading_period_groups.create $ g.destroy $ g.workflow_state #should return 'deleted' - when you delete a grading period group, it should also soft delete any grading periods that belong to it. $ gp_group = Account.default.grading_period_groups.create $ gp = gp_group.grading_periods.create( start_date: Time.now, end_date: 1.month.from_now) $ gp_group.destroy $ gp_group.workflow_state #should return 'deleted' $ gp.workflow_state #should return 'deleted' Grading Periods: - you should no longer be able to create a grading period without giving it a grading_period_group id. also, if you don't give it a workflow_state, it should default to 'active'. when you delete a grading period it should do a 'soft delete'. $ g = GradingPeriod.create(start_date: Time.now, end_date: 1.month.from_now) $ g.valid? #should return false $ gp_group = Account.default.grading_period_groups.create $ gp = gp_group.grading_periods.create( start_date: Time.now, end_date: 1.month.from_now) $ gp.valid? #should return true $ gp.workflow_state #should return 'active' $ gp.destroy $ gp.workflow_state #should return 'deleted' - when you delete a grading period, it should also do a 'soft delete' on any owned grading period grades. Enrollments are tricky to make via the rails console, so i'm just grabbing one here that was already made -- you should be able to do the same. if you don't have any enrollments created, create one via Canvas and then come back to the rails console. $ gp_group = Account.default.grading_period_groups.create $ gp = gp_group.grading_periods.create( start_date: Time.now, end_date: 1.month.from_now) $ enrollment = Enrollment.first $ gp_grade = gp.grading_period_grades.create( enrollment_id: enrollment) $ gp_grade.workflow_state #should return 'active' $ gp.destroy $ gp.workflow_state #should return 'deleted' $ gp_grade.workflow_state #should return 'deleted' Grading Period Grades: - these should now 'soft delete' as well. they require a grading period and an enrollment to be created (no change here, this has always been the case). $ enrollment = Enrollment.first $ gp_group = Account.default.grading_period_groups.create $ gp = gp_group.grading_periods.create( start_date: Time.now, end_date: 1.month.from_now) $ gp_grade = gp.grading_period_grades.create( enrollment_id: enrollment) $ gp_grade.workflow_state #should return 'active' $ gp_grade.destroy $ gp_grade.workflow_state #should return 'deleted' Change-Id: Ic397a03beca4782c0c80e486673c7cfef59d38e5 Reviewed-on: https://gerrit.instructure.com/49754 Reviewed-by: Josh Simpson <jsimpson@instructure.com> Reviewed-by: Jacob Fugal <jacob@instructure.com> QA-Review: Robert Lamb <rlamb@instructure.com> Tested-by: Jenkins Product-Review: Spencer Olson <solson@instructure.com>
2015-03-06 07:36:04 +08:00
private
remove account association from grading periods and their groups Accounts will no longer be directly associated with grading periods or grading period groups. A grading period group can: * have only one or more enrollment terms * belong only to a course (for legacy data) Testing Notes: * To create a GradingPeriodGroup for an EnrollmentTerm: * Create an EnrollmentTerm `enrollment_term` * `group = GradingPeriodGroup.new(title: "Example")` * `group.enrollment_terms << enrollment_term` * `group.save!` test plan: A. repeat tests with commit at SHA: 861015a B. grading standards for an account 1. find or create an Account 2. visit `/accounts/[account id]/grading_standards` 3. verify there is no grading periods UI 4. verify that grading schemes are still manageable C. grading standards for a course with grading periods 1. find or create: a. an Account b. an EnrollmentTerm for the Account c. a Course for that Account 2. associate the Course with the EnrollmentTerm 3. in the Rails console `bundle exec rails console` a. create a GradingPeriodGroup for the Course b. create at least one GradingPeriod in the course group c. create a GradingPeriodGroup for the EnrollmentTerm d. create at least one GradingPeriod in the term group 4. visit `/courses/[course id]/grading_standards` 5. verify the grading period(s) on the course are present 5. verify the grading period(s) on the term are not present 6. verify that grading schemes are still manageable D. grading standards for a course with no grading periods 1. find or create: a. an Account b. an EnrollmentTerm for the Account c. a Course for that Account 2. associate the Course with the EnrollmentTerm 3. in the Rails console `bundle exec rails console` a. create a GradingPeriodGroup for the EnrollmentTerm b. create at least one GradingPeriod in the group 4. visit `/courses/[course id]/grading_standards` 5. verify the grading periods on the term are present 6. verify that grading schemes are still manageable closes CNVS-26725 Change-Id: I7883cb421c87ebb91c818223c0483557fdd5e40a Reviewed-on: https://gerrit.instructure.com/78167 Reviewed-by: Derek Bender <djbender@instructure.com> Reviewed-by: Spencer Olson <solson@instructure.com> QA-Review: KC Naegle <knaegle@instructure.com> Tested-by: Jenkins Product-Review: Keith T. Garner <kgarner@instructure.com>
2016-04-22 06:09:15 +08:00
def root_account
@root_account ||= begin
return nil if enrollment_terms.count == 0
# TODO: take is broken here. it appears that loaded? is true
# but the @records is empty.
# enrollment_terms.take.root_account
enrollment_terms.limit(1).to_a.first.root_account
remove account association from grading periods and their groups Accounts will no longer be directly associated with grading periods or grading period groups. A grading period group can: * have only one or more enrollment terms * belong only to a course (for legacy data) Testing Notes: * To create a GradingPeriodGroup for an EnrollmentTerm: * Create an EnrollmentTerm `enrollment_term` * `group = GradingPeriodGroup.new(title: "Example")` * `group.enrollment_terms << enrollment_term` * `group.save!` test plan: A. repeat tests with commit at SHA: 861015a B. grading standards for an account 1. find or create an Account 2. visit `/accounts/[account id]/grading_standards` 3. verify there is no grading periods UI 4. verify that grading schemes are still manageable C. grading standards for a course with grading periods 1. find or create: a. an Account b. an EnrollmentTerm for the Account c. a Course for that Account 2. associate the Course with the EnrollmentTerm 3. in the Rails console `bundle exec rails console` a. create a GradingPeriodGroup for the Course b. create at least one GradingPeriod in the course group c. create a GradingPeriodGroup for the EnrollmentTerm d. create at least one GradingPeriod in the term group 4. visit `/courses/[course id]/grading_standards` 5. verify the grading period(s) on the course are present 5. verify the grading period(s) on the term are not present 6. verify that grading schemes are still manageable D. grading standards for a course with no grading periods 1. find or create: a. an Account b. an EnrollmentTerm for the Account c. a Course for that Account 2. associate the Course with the EnrollmentTerm 3. in the Rails console `bundle exec rails console` a. create a GradingPeriodGroup for the EnrollmentTerm b. create at least one GradingPeriod in the group 4. visit `/courses/[course id]/grading_standards` 5. verify the grading periods on the term are present 6. verify that grading schemes are still manageable closes CNVS-26725 Change-Id: I7883cb421c87ebb91c818223c0483557fdd5e40a Reviewed-on: https://gerrit.instructure.com/78167 Reviewed-by: Derek Bender <djbender@instructure.com> Reviewed-by: Spencer Olson <solson@instructure.com> QA-Review: KC Naegle <knaegle@instructure.com> Tested-by: Jenkins Product-Review: Keith T. Garner <kgarner@instructure.com>
2016-04-22 06:09:15 +08:00
end
end
def associated_with_course_or_account_or_enrollment_term?
if enrollment_terms?
validate_with_enrollment_terms
elsif active?
validate_without_enrollment_terms
end
end
def enrollment_terms?
if enrollment_terms.loaded?
enrollment_terms.any?(&:active?)
else
enrollment_terms.active.exists?
add workflow state to grading period groups and grading period grades add workflow state to grading period groups and grading period grades. also add a default value of 'active' and a not-null constraint for workflow state on grading periods, grading period groups, and grading period grades. also add a validate method for grading period group that ensures the group belongs to either a course or account. add a not-null constraint for grading period group id on grading periods. add an index for workflow_state on grading period groups, grading periods, and grading period grades. closes CNVS-18995 test plan: run migrations. in rails console: $ bundle exec rake db:migrate $ bundle exec rake db:migrate RAILS_ENV=test Grading Period Groups: - you should not be able to create a Grading Period Group without assigning it either a course or account. If you don't supply a workflow state when you create a grading period group, it should default to 'active'. $ g = GradingPeriodGroup.create $ g.valid? #should return false $ g = Account.default.grading_period_groups.create $ g.valid? #should return true $ g.workflow_state #should return 'active' $ new_course = Course.create $ g = new_course.grading_period_groups.create $ g.valid? #should return true $ g.workflow_state #should return 'active' - when you delete a grading period group, it should do a 'soft delete', which means it should set its workflow_state to 'deleted' instead of actually deleting it from the database $ g = Account.default.grading_period_groups.create $ g.destroy $ g.workflow_state #should return 'deleted' - when you delete a grading period group, it should also soft delete any grading periods that belong to it. $ gp_group = Account.default.grading_period_groups.create $ gp = gp_group.grading_periods.create( start_date: Time.now, end_date: 1.month.from_now) $ gp_group.destroy $ gp_group.workflow_state #should return 'deleted' $ gp.workflow_state #should return 'deleted' Grading Periods: - you should no longer be able to create a grading period without giving it a grading_period_group id. also, if you don't give it a workflow_state, it should default to 'active'. when you delete a grading period it should do a 'soft delete'. $ g = GradingPeriod.create(start_date: Time.now, end_date: 1.month.from_now) $ g.valid? #should return false $ gp_group = Account.default.grading_period_groups.create $ gp = gp_group.grading_periods.create( start_date: Time.now, end_date: 1.month.from_now) $ gp.valid? #should return true $ gp.workflow_state #should return 'active' $ gp.destroy $ gp.workflow_state #should return 'deleted' - when you delete a grading period, it should also do a 'soft delete' on any owned grading period grades. Enrollments are tricky to make via the rails console, so i'm just grabbing one here that was already made -- you should be able to do the same. if you don't have any enrollments created, create one via Canvas and then come back to the rails console. $ gp_group = Account.default.grading_period_groups.create $ gp = gp_group.grading_periods.create( start_date: Time.now, end_date: 1.month.from_now) $ enrollment = Enrollment.first $ gp_grade = gp.grading_period_grades.create( enrollment_id: enrollment) $ gp_grade.workflow_state #should return 'active' $ gp.destroy $ gp.workflow_state #should return 'deleted' $ gp_grade.workflow_state #should return 'deleted' Grading Period Grades: - these should now 'soft delete' as well. they require a grading period and an enrollment to be created (no change here, this has always been the case). $ enrollment = Enrollment.first $ gp_group = Account.default.grading_period_groups.create $ gp = gp_group.grading_periods.create( start_date: Time.now, end_date: 1.month.from_now) $ gp_grade = gp.grading_period_grades.create( enrollment_id: enrollment) $ gp_grade.workflow_state #should return 'active' $ gp_grade.destroy $ gp_grade.workflow_state #should return 'deleted' Change-Id: Ic397a03beca4782c0c80e486673c7cfef59d38e5 Reviewed-on: https://gerrit.instructure.com/49754 Reviewed-by: Josh Simpson <jsimpson@instructure.com> Reviewed-by: Jacob Fugal <jacob@instructure.com> QA-Review: Robert Lamb <rlamb@instructure.com> Tested-by: Jenkins Product-Review: Spencer Olson <solson@instructure.com>
2015-03-06 07:36:04 +08:00
end
end
add workflow state to grading period groups and grading period grades add workflow state to grading period groups and grading period grades. also add a default value of 'active' and a not-null constraint for workflow state on grading periods, grading period groups, and grading period grades. also add a validate method for grading period group that ensures the group belongs to either a course or account. add a not-null constraint for grading period group id on grading periods. add an index for workflow_state on grading period groups, grading periods, and grading period grades. closes CNVS-18995 test plan: run migrations. in rails console: $ bundle exec rake db:migrate $ bundle exec rake db:migrate RAILS_ENV=test Grading Period Groups: - you should not be able to create a Grading Period Group without assigning it either a course or account. If you don't supply a workflow state when you create a grading period group, it should default to 'active'. $ g = GradingPeriodGroup.create $ g.valid? #should return false $ g = Account.default.grading_period_groups.create $ g.valid? #should return true $ g.workflow_state #should return 'active' $ new_course = Course.create $ g = new_course.grading_period_groups.create $ g.valid? #should return true $ g.workflow_state #should return 'active' - when you delete a grading period group, it should do a 'soft delete', which means it should set its workflow_state to 'deleted' instead of actually deleting it from the database $ g = Account.default.grading_period_groups.create $ g.destroy $ g.workflow_state #should return 'deleted' - when you delete a grading period group, it should also soft delete any grading periods that belong to it. $ gp_group = Account.default.grading_period_groups.create $ gp = gp_group.grading_periods.create( start_date: Time.now, end_date: 1.month.from_now) $ gp_group.destroy $ gp_group.workflow_state #should return 'deleted' $ gp.workflow_state #should return 'deleted' Grading Periods: - you should no longer be able to create a grading period without giving it a grading_period_group id. also, if you don't give it a workflow_state, it should default to 'active'. when you delete a grading period it should do a 'soft delete'. $ g = GradingPeriod.create(start_date: Time.now, end_date: 1.month.from_now) $ g.valid? #should return false $ gp_group = Account.default.grading_period_groups.create $ gp = gp_group.grading_periods.create( start_date: Time.now, end_date: 1.month.from_now) $ gp.valid? #should return true $ gp.workflow_state #should return 'active' $ gp.destroy $ gp.workflow_state #should return 'deleted' - when you delete a grading period, it should also do a 'soft delete' on any owned grading period grades. Enrollments are tricky to make via the rails console, so i'm just grabbing one here that was already made -- you should be able to do the same. if you don't have any enrollments created, create one via Canvas and then come back to the rails console. $ gp_group = Account.default.grading_period_groups.create $ gp = gp_group.grading_periods.create( start_date: Time.now, end_date: 1.month.from_now) $ enrollment = Enrollment.first $ gp_grade = gp.grading_period_grades.create( enrollment_id: enrollment) $ gp_grade.workflow_state #should return 'active' $ gp.destroy $ gp.workflow_state #should return 'deleted' $ gp_grade.workflow_state #should return 'deleted' Grading Period Grades: - these should now 'soft delete' as well. they require a grading period and an enrollment to be created (no change here, this has always been the case). $ enrollment = Enrollment.first $ gp_group = Account.default.grading_period_groups.create $ gp = gp_group.grading_periods.create( start_date: Time.now, end_date: 1.month.from_now) $ gp_grade = gp.grading_period_grades.create( enrollment_id: enrollment) $ gp_grade.workflow_state #should return 'active' $ gp_grade.destroy $ gp_grade.workflow_state #should return 'deleted' Change-Id: Ic397a03beca4782c0c80e486673c7cfef59d38e5 Reviewed-on: https://gerrit.instructure.com/49754 Reviewed-by: Josh Simpson <jsimpson@instructure.com> Reviewed-by: Jacob Fugal <jacob@instructure.com> QA-Review: Robert Lamb <rlamb@instructure.com> Tested-by: Jenkins Product-Review: Spencer Olson <solson@instructure.com>
2015-03-06 07:36:04 +08:00
def validate_without_enrollment_terms
if course_id.blank? && account_id.blank?
errors.add(:enrollment_terms, t("cannot be empty when course_id is nil and account_id is nil"))
elsif course_id.present? && account_id.present?
add workflow state to grading period groups and grading period grades add workflow state to grading period groups and grading period grades. also add a default value of 'active' and a not-null constraint for workflow state on grading periods, grading period groups, and grading period grades. also add a validate method for grading period group that ensures the group belongs to either a course or account. add a not-null constraint for grading period group id on grading periods. add an index for workflow_state on grading period groups, grading periods, and grading period grades. closes CNVS-18995 test plan: run migrations. in rails console: $ bundle exec rake db:migrate $ bundle exec rake db:migrate RAILS_ENV=test Grading Period Groups: - you should not be able to create a Grading Period Group without assigning it either a course or account. If you don't supply a workflow state when you create a grading period group, it should default to 'active'. $ g = GradingPeriodGroup.create $ g.valid? #should return false $ g = Account.default.grading_period_groups.create $ g.valid? #should return true $ g.workflow_state #should return 'active' $ new_course = Course.create $ g = new_course.grading_period_groups.create $ g.valid? #should return true $ g.workflow_state #should return 'active' - when you delete a grading period group, it should do a 'soft delete', which means it should set its workflow_state to 'deleted' instead of actually deleting it from the database $ g = Account.default.grading_period_groups.create $ g.destroy $ g.workflow_state #should return 'deleted' - when you delete a grading period group, it should also soft delete any grading periods that belong to it. $ gp_group = Account.default.grading_period_groups.create $ gp = gp_group.grading_periods.create( start_date: Time.now, end_date: 1.month.from_now) $ gp_group.destroy $ gp_group.workflow_state #should return 'deleted' $ gp.workflow_state #should return 'deleted' Grading Periods: - you should no longer be able to create a grading period without giving it a grading_period_group id. also, if you don't give it a workflow_state, it should default to 'active'. when you delete a grading period it should do a 'soft delete'. $ g = GradingPeriod.create(start_date: Time.now, end_date: 1.month.from_now) $ g.valid? #should return false $ gp_group = Account.default.grading_period_groups.create $ gp = gp_group.grading_periods.create( start_date: Time.now, end_date: 1.month.from_now) $ gp.valid? #should return true $ gp.workflow_state #should return 'active' $ gp.destroy $ gp.workflow_state #should return 'deleted' - when you delete a grading period, it should also do a 'soft delete' on any owned grading period grades. Enrollments are tricky to make via the rails console, so i'm just grabbing one here that was already made -- you should be able to do the same. if you don't have any enrollments created, create one via Canvas and then come back to the rails console. $ gp_group = Account.default.grading_period_groups.create $ gp = gp_group.grading_periods.create( start_date: Time.now, end_date: 1.month.from_now) $ enrollment = Enrollment.first $ gp_grade = gp.grading_period_grades.create( enrollment_id: enrollment) $ gp_grade.workflow_state #should return 'active' $ gp.destroy $ gp.workflow_state #should return 'deleted' $ gp_grade.workflow_state #should return 'deleted' Grading Period Grades: - these should now 'soft delete' as well. they require a grading period and an enrollment to be created (no change here, this has always been the case). $ enrollment = Enrollment.first $ gp_group = Account.default.grading_period_groups.create $ gp = gp_group.grading_periods.create( start_date: Time.now, end_date: 1.month.from_now) $ gp_grade = gp.grading_period_grades.create( enrollment_id: enrollment) $ gp_grade.workflow_state #should return 'active' $ gp_grade.destroy $ gp_grade.workflow_state #should return 'deleted' Change-Id: Ic397a03beca4782c0c80e486673c7cfef59d38e5 Reviewed-on: https://gerrit.instructure.com/49754 Reviewed-by: Josh Simpson <jsimpson@instructure.com> Reviewed-by: Jacob Fugal <jacob@instructure.com> QA-Review: Robert Lamb <rlamb@instructure.com> Tested-by: Jenkins Product-Review: Spencer Olson <solson@instructure.com>
2015-03-06 07:36:04 +08:00
errors.add(:course_id, t("cannot be present when account_id is present"))
errors.add(:account_id, t("cannot be present when course_id is present"))
end
end
make grading periods feature flag a course level flag make the grading periods feature flag a course level flag, and also 'unlock' the account level grading periods. now, a teacher can edit account level periods, but when they click 'save' it will create a new course-level grading period instead of altering the original account-level period. also added a link to the feature flag settings page if there is only one grading period on the page. in addition, if only template periods are being shown on the page and you're logged in as a teacher, added a message that notifies the user that the periods were created by an administrator for them. closes CNVS-18741 closes CNVS-19692 test plan: this commit makes substantial changes to the way grading periods are being displayed, deleted, and saved on the 'accounts/:account_id/grading_standards' page and the 'courses/:course_id/grading_standards' page. users should still be able to create/update/delete grading periods without problems on those pages. in addition, this commit makes changes to the feature flag settings pages for admins and teachers. make sure the feature flags are working correctly (try setting the MGP flag to 'on', 'off', and 'allow' as an admin and see how it affects the feature flag options for sub-accounts and teachers). Change-Id: I0b442e708a8049180b55a86098e30a2c64673eda Reviewed-on: https://gerrit.instructure.com/51594 Tested-by: Jenkins Reviewed-by: Josh Simpson <jsimpson@instructure.com> QA-Review: Robert Lamb <rlamb@instructure.com> Product-Review: Spencer Olson <solson@instructure.com>
2015-04-01 02:04:09 +08:00
def validate_with_enrollment_terms
if enrollment_terms.loaded?
account_ids = enrollment_terms.map(&:root_account_id)
else
remove account association from grading periods and their groups Accounts will no longer be directly associated with grading periods or grading period groups. A grading period group can: * have only one or more enrollment terms * belong only to a course (for legacy data) Testing Notes: * To create a GradingPeriodGroup for an EnrollmentTerm: * Create an EnrollmentTerm `enrollment_term` * `group = GradingPeriodGroup.new(title: "Example")` * `group.enrollment_terms << enrollment_term` * `group.save!` test plan: A. repeat tests with commit at SHA: 861015a B. grading standards for an account 1. find or create an Account 2. visit `/accounts/[account id]/grading_standards` 3. verify there is no grading periods UI 4. verify that grading schemes are still manageable C. grading standards for a course with grading periods 1. find or create: a. an Account b. an EnrollmentTerm for the Account c. a Course for that Account 2. associate the Course with the EnrollmentTerm 3. in the Rails console `bundle exec rails console` a. create a GradingPeriodGroup for the Course b. create at least one GradingPeriod in the course group c. create a GradingPeriodGroup for the EnrollmentTerm d. create at least one GradingPeriod in the term group 4. visit `/courses/[course id]/grading_standards` 5. verify the grading period(s) on the course are present 5. verify the grading period(s) on the term are not present 6. verify that grading schemes are still manageable D. grading standards for a course with no grading periods 1. find or create: a. an Account b. an EnrollmentTerm for the Account c. a Course for that Account 2. associate the Course with the EnrollmentTerm 3. in the Rails console `bundle exec rails console` a. create a GradingPeriodGroup for the EnrollmentTerm b. create at least one GradingPeriod in the group 4. visit `/courses/[course id]/grading_standards` 5. verify the grading periods on the term are present 6. verify that grading schemes are still manageable closes CNVS-26725 Change-Id: I7883cb421c87ebb91c818223c0483557fdd5e40a Reviewed-on: https://gerrit.instructure.com/78167 Reviewed-by: Derek Bender <djbender@instructure.com> Reviewed-by: Spencer Olson <solson@instructure.com> QA-Review: KC Naegle <knaegle@instructure.com> Tested-by: Jenkins Product-Review: Keith T. Garner <kgarner@instructure.com>
2016-04-22 06:09:15 +08:00
account_ids = enrollment_terms.pluck(:root_account_id)
end
account_ids << self.account_id if self.account_id.present?
if account_ids.uniq.count > 1
errors.add(:enrollment_terms, t("cannot be associated with different accounts"))
end
end
make grading periods feature flag a course level flag make the grading periods feature flag a course level flag, and also 'unlock' the account level grading periods. now, a teacher can edit account level periods, but when they click 'save' it will create a new course-level grading period instead of altering the original account-level period. also added a link to the feature flag settings page if there is only one grading period on the page. in addition, if only template periods are being shown on the page and you're logged in as a teacher, added a message that notifies the user that the periods were created by an administrator for them. closes CNVS-18741 closes CNVS-19692 test plan: this commit makes substantial changes to the way grading periods are being displayed, deleted, and saved on the 'accounts/:account_id/grading_standards' page and the 'courses/:course_id/grading_standards' page. users should still be able to create/update/delete grading periods without problems on those pages. in addition, this commit makes changes to the feature flag settings pages for admins and teachers. make sure the feature flags are working correctly (try setting the MGP flag to 'on', 'off', and 'allow' as an admin and see how it affects the feature flag options for sub-accounts and teachers). Change-Id: I0b442e708a8049180b55a86098e30a2c64673eda Reviewed-on: https://gerrit.instructure.com/51594 Tested-by: Jenkins Reviewed-by: Josh Simpson <jsimpson@instructure.com> QA-Review: Robert Lamb <rlamb@instructure.com> Product-Review: Spencer Olson <solson@instructure.com>
2015-04-01 02:04:09 +08:00
def account_grading_period_allowed?
root_account.present? && root_account.feature_allowed?(:multiple_grading_periods)
make grading periods feature flag a course level flag make the grading periods feature flag a course level flag, and also 'unlock' the account level grading periods. now, a teacher can edit account level periods, but when they click 'save' it will create a new course-level grading period instead of altering the original account-level period. also added a link to the feature flag settings page if there is only one grading period on the page. in addition, if only template periods are being shown on the page and you're logged in as a teacher, added a message that notifies the user that the periods were created by an administrator for them. closes CNVS-18741 closes CNVS-19692 test plan: this commit makes substantial changes to the way grading periods are being displayed, deleted, and saved on the 'accounts/:account_id/grading_standards' page and the 'courses/:course_id/grading_standards' page. users should still be able to create/update/delete grading periods without problems on those pages. in addition, this commit makes changes to the feature flag settings pages for admins and teachers. make sure the feature flags are working correctly (try setting the MGP flag to 'on', 'off', and 'allow' as an admin and see how it affects the feature flag options for sub-accounts and teachers). Change-Id: I0b442e708a8049180b55a86098e30a2c64673eda Reviewed-on: https://gerrit.instructure.com/51594 Tested-by: Jenkins Reviewed-by: Josh Simpson <jsimpson@instructure.com> QA-Review: Robert Lamb <rlamb@instructure.com> Product-Review: Spencer Olson <solson@instructure.com>
2015-04-01 02:04:09 +08:00
end
add grading period group model add GradingPeriodGroup, and change associations between GradingPeriods, GradingPeriodGroups, Courses, and Accounts. also adjust the grading periods controller to account for addition of grading period groups closes CNVS-16538 test plan: -run bundle exec rake db:migrate, and bundle exec rake db:migrate RAILS_ENV=test -verify the migrations successfully run -open the rails console in sandbox: bundle exec rails c -s -create a course, a few grading periods, and a grading period group. Add the grading periods to the group. Assign the grading period group to the course. $ course = Course.create $ grading_period1 = GradingPeriod.create(weight: 25.0, start_date: Time.zone.now, end_date: 2.days.from_now) $ grading_period2 = GradingPeriod.create(weight: 30.0, start_date: Time.zone.now, end_date: 2.days.from_now) $ grading_period_group = GradingPeriodGroup.create() $ grading_period_group.grading_periods << grading_period1 $ grading_period_group.grading_periods << grading_period2 $ grading_period_group.course = course -verify the associations are working as expected, i.e. a GradingPeriodGroup has GradingPeriods, a GradingPeriod belongs to a GradingPeriodGroup, and a GradingPeriodGroup belongs to a course or account. $ grading_period_group.grading_periods #should return an array containing grading_period1 and grading_period2 $ grading_period1.grading_period_group #should return grading_period_group $ grading_period2.grading_period_group #should return grading_period_group $ grading_period_group.course #should return course $ grading_period_group.account #should return nil (should not throw error) Change-Id: I9d7465431dabd2afa18e7a8a33706b9a78a94cd1 Reviewed-on: https://gerrit.instructure.com/43512 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Josh Simpson <jsimpson@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com> Reviewed-by: Jacob Fugal <jacob@instructure.com> Product-Review: Spencer Olson <solson@instructure.com>
2014-10-30 02:42:41 +08:00
end