Commit Graph

7 Commits

Author SHA1 Message Date
Strand McCutchen 05f4b9190e Extract Soft Deletion
fixes CNVS-20361

This is the first step in extracting soft deletion and
only touches grading period models. I audited other models
to see if this extraction would work for them, but no other
models met my criteria which are as follows

- [ ] defines workflow state of _only_ active and deleted
- [ ] active scope where state is active
      (not `workflow_state<>'deleted'`)
In `def destroy`:
  - [ ] state set to deleted
  - [ ] then save
  - [ ] runs callbacks

Many variants of soft deletion exist, including scoping
active to `workflow_state<>'deleted'`, not running
callbacks after save, and wrapping the state change in a
transaction block.

This is the first step in making soft deletion behave
consistently. There are approximately 30 models that have
an implementation of soft deletion.

Change-Id: I6cb48571377a4bb403285f95c058020b46ca3a30
Reviewed-on: https://gerrit.instructure.com/53821
Reviewed-by: Derek Bender <dbender@instructure.com>
Product-Review: Strand McCutchen <smccutchen@instructure.com>
QA-Review: Strand McCutchen <smccutchen@instructure.com>
Tested-by: Jenkins
2015-05-18 18:45:01 +00:00
Spencer Olson d7162d0e12 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-16 15:19:49 +00:00
Spencer Olson 0f53b9f7a7 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-04-01 00:07:44 +00:00
Spencer Olson 690aeb7c17 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-21 00:25:21 +00:00
Cameron Sutter f2e2e76d5b Grading Period Grade join table - MGP
fixes CNVS-16454

test plan:
 * test in the console
 - `GradingPeriodGrade.all` should return `[]` (no error)
 - `Enrollment.find(1).grading_period_grades` should return `[]` (no error)
 - make a GradingPeriod:
   `g = GradingPeriod.create(weight: 100, start_date: Time.now, end_date: 1.month.from_now)`
   `g.save!`
 - `g.grading_period_grades` should return `[]` (no error)

Change-Id: I7183d715dbfac3fcd89ab7e453237ad4ce6c650d
Reviewed-on: https://gerrit.instructure.com/45312
Product-Review: Cameron Sutter <csutter@instructure.com>
Reviewed-by: Nick Cloward <ncloward@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Amber Taniuchi <amber@instructure.com>
2014-12-11 17:28:33 +00:00
Cameron Sutter c71c36ee06 MGP - no permissions for grading period without feature flag on
fixes CNVS-15968

test plan:
 * using the API
 * with the Multiple Grading Periods flag off
 - try to create/read/update/delete a grading period
 > it should return a 'not found' error

Change-Id: I92ed920fde7f03c4ac9a051d4a7212bf43a53fa3
Reviewed-on: https://gerrit.instructure.com/44552
Reviewed-by: Josh Simpson <jsimpson@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Amber Taniuchi <amber@instructure.com>
Product-Review: Cameron Sutter <csutter@instructure.com>
2014-12-04 22:06:03 +00:00
Spencer Olson 9cde815d68 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-11-14 22:07:00 +00:00