add workflow_state to rubric_associations

Adds a workflow_state column to rubric_associations and backfills
all records to be 'active'. Support for soft-deletion (and the
'deleted' state) will be added later.

closes EVAL-1325
flag=none

Test Plan:
1. Before checking out this commit, on master, create a rubric and use
   it to grade a few students for an assignment. This will result in
   some rubric_associations records getting created.
2. Check out this commit and run migrations.
3. Check that the rubric_associations table now has a workflow_state
   column, with a default of "active" and a NOT NULL constraint.
4. Check that every rubric association record has workflow_state set
   to "active".
5. Create a new rubric association (you can do this by grading a new
   assignment with an existing rubric). Check that the newly-created
   rubric association has its workflow state set to "active".

Change-Id: Ib7a4874f3918b2f0d18a490c5b942a34804bf5ce
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/253663
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Cody Cutrer <cody@instructure.com>
Reviewed-by: Gary Mei <gmei@instructure.com>
Reviewed-by: Syed Hussain <shussain@instructure.com>
Product-Review: Syed Hussain <shussain@instructure.com>
QA-Review: Kai Bjorkman <kbjorkman@instructure.com>
This commit is contained in:
Spencer Olson 2020-11-24 12:46:25 -06:00
parent 2b4f579bce
commit 5885cbecd9
4 changed files with 87 additions and 0 deletions

View File

@ -23,6 +23,8 @@
# with this idea, such as assignment submissions.
# The other purpose of this class is just to make rubrics reusable.
class RubricAssociation < ActiveRecord::Base
include Workflow
attr_accessor :skip_updating_points_possible
attr_writer :updating_user
@ -38,6 +40,7 @@ class RubricAssociation < ActiveRecord::Base
has_a_broadcast_policy
validates_presence_of :purpose, :rubric_id, :association_id, :association_type, :context_id, :context_type
validates :workflow_state, inclusion: {in: ["active"]}, allow_nil: true
before_create :set_root_account_id
before_save :update_assignment_points
@ -60,6 +63,10 @@ class RubricAssociation < ActiveRecord::Base
before_destroy :record_deletion_audit_event
end
workflow do
state :active
end
ValidAssociationModels = {
'Course' => ::Course,
'Assignment' => ::Assignment,
@ -153,6 +160,7 @@ class RubricAssociation < ActiveRecord::Base
self.bookmarked = true if self.purpose == 'bookmark' || self.bookmarked.nil?
self.context_code ||= "#{self.context_type.underscore}_#{self.context_id}" rescue nil
self.title ||= (self.association_object.title rescue self.association_object.name) rescue nil
self.workflow_state ||= "active"
end
protected :update_values

View File

@ -0,0 +1,31 @@
# frozen_string_literal: true
#
# Copyright (C) 2020 - present 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/>.
#
class AddWorkflowStateToRubricAssociations < ActiveRecord::Migration[5.2]
tag :predeploy
def up
add_column :rubric_associations, :workflow_state, :string
change_column_default(:rubric_associations, :workflow_state, "active")
end
def down
remove_column :rubric_associations, :workflow_state
end
end

View File

@ -0,0 +1,33 @@
# frozen_string_literal: true
#
# Copyright (C) 2020 - present 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/>.
#
class BackfillWorkflowStateOnRubricAssociations < ActiveRecord::Migration[5.2]
tag :postdeploy
disable_ddl_transaction!
def up
DataFixup::BackfillNulls.run(RubricAssociation, :workflow_state, default_value: "active")
change_column_null(:rubric_associations, :workflow_state, false)
end
def down
change_column_null(:rubric_associations, :workflow_state, true)
end
end

View File

@ -440,4 +440,19 @@ describe RubricAssociation do
expect(@rubric_association.root_account_id).to eq sub_account.root_account_id
end
end
describe "workflow_state" do
it "is set to active by default" do
course = Course.create!
rubric = course.rubrics.create!
association = RubricAssociation.create!(
rubric: rubric,
association_object: course,
context: course,
purpose: "bookmark"
)
expect(association).to be_active
end
end
end