canvas-lms/app/models/grading_period_group.rb

43 lines
1.4 KiB
Ruby
Raw Normal View History

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
attr_accessible # None of this model's attributes are mass-assignable
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
belongs_to :course
belongs_to :account
has_many :grading_periods, dependent: :destroy
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
validate :belongs_to_course_or_account_exclusive
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
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
given { |user| multiple_grading_periods_enabled? && (course || account).grants_right?(user, :read) }
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
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
given { |user| account && multiple_grading_periods_enabled? && account.associated_user?(user) }
can :read
given { |user| multiple_grading_periods_enabled? && (course || account).grants_right?(user, :manage) }
can :manage
end
def multiple_grading_periods_enabled?
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
(course || 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
def belongs_to_course_or_account_exclusive
if course.blank? && account.blank?
errors.add(:course_id, t("cannot be nil when account_id is nil"))
errors.add(:account_id, t("cannot be nil when course_id is nil"))
end
if course.present? && account.present?
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 account_grading_period_allowed?
!!(account && account.feature_allowed?(:multiple_grading_periods))
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