set root_account_id on custom gradebook column datum model
closes TALLY-696 flag=none Test Plan: 1. Create some custom gradebook column datum that do not have root_account_id set (either create them before checking out this patchset, or create them and then force the root_account_id column to nil using `update_column`). 2. Verify that the CustomGradebookColumnDataApiController#bulk_update API endpoint fills in the root_account_id for the custom column data when it is called. Change-Id: Ia35e2cde1c56be9f07eb97f365f51ec482982db0 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/239035 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> QA-Review: Adrian Packel <apackel@instructure.com> Product-Review: Syed Hussain <shussain@instructure.com> Reviewed-by: Gary Mei <gmei@instructure.com> Reviewed-by: Adrian Packel <apackel@instructure.com>
This commit is contained in:
parent
247db4d6c2
commit
6641b07d04
|
@ -30,6 +30,8 @@ class CustomGradebookColumnDatum < ActiveRecord::Base
|
|||
can :update
|
||||
end
|
||||
|
||||
before_save :set_root_account_id
|
||||
|
||||
def self.queue_bulk_update_custom_columns(context, column_data)
|
||||
progress = Progress.create!(context: context, tag: "custom_columns_submissions_update")
|
||||
progress.process_job(self, :process_bulk_update_custom_columns, {}, context, column_data)
|
||||
|
@ -37,7 +39,8 @@ class CustomGradebookColumnDatum < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.process_bulk_update_custom_columns(_, context, column_data)
|
||||
Delayed::Batch.serial_batch(priority: Delayed::LOW_PRIORITY, n_strand: ["bulk_update_submissions", context.root_account.global_id]) do
|
||||
root_account = context.root_account
|
||||
Delayed::Batch.serial_batch(priority: Delayed::LOW_PRIORITY, n_strand: ["bulk_update_submissions", root_account.global_id]) do
|
||||
custom_gradebook_columns = context.custom_gradebook_columns.preload(:custom_gradebook_column_data)
|
||||
column_data.each do |data_point|
|
||||
column_id = data_point.fetch(:column_id)
|
||||
|
@ -49,6 +52,7 @@ class CustomGradebookColumnDatum < ActiveRecord::Base
|
|||
CustomGradebookColumnDatum.unique_constraint_retry do
|
||||
datum = custom_column.custom_gradebook_column_data.find_or_initialize_by(user_id: user_id)
|
||||
datum.content = content
|
||||
datum.root_account_id ||= root_account.id
|
||||
datum.save!
|
||||
end
|
||||
else
|
||||
|
@ -57,4 +61,10 @@ class CustomGradebookColumnDatum < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_root_account_id
|
||||
self.root_account_id ||= custom_gradebook_column&.course&.root_account_id
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,9 +18,12 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
describe CustomGradebookColumnDatum do
|
||||
before(:once) do
|
||||
course_with_teacher(active_all: true)
|
||||
end
|
||||
|
||||
describe "process_bulk_update_custom_columns" do
|
||||
before :once do
|
||||
course_with_teacher(active_all: true)
|
||||
before(:once) do
|
||||
@first_student = student_in_course(active_all: true, course: @course).user
|
||||
@second_student = student_in_course(active_all: true, course: @course).user
|
||||
@first_col = @course.custom_gradebook_columns.create!(title: "cc1", position: 1)
|
||||
|
@ -50,6 +53,17 @@ describe CustomGradebookColumnDatum do
|
|||
])
|
||||
end
|
||||
|
||||
let(:first_student_data) do
|
||||
@course.custom_gradebook_columns.
|
||||
find_by!(id: @first_col.id).
|
||||
custom_gradebook_column_data.
|
||||
find_by(user_id: @first_student.id)
|
||||
end
|
||||
|
||||
it "sets the root account id on the column datum" do
|
||||
expect(first_student_data.root_account_id).to eq @course.root_account.id
|
||||
end
|
||||
|
||||
it "adds a datum for a matching student and column" do
|
||||
data = @course.custom_gradebook_columns.
|
||||
find_by!(id: @first_col.id).
|
||||
|
@ -59,12 +73,7 @@ describe CustomGradebookColumnDatum do
|
|||
end
|
||||
|
||||
it "checks content exists for the first student in the first column" do
|
||||
data = @course.custom_gradebook_columns.
|
||||
find_by!(id: @first_col.id).
|
||||
custom_gradebook_column_data.
|
||||
find_by!(user_id: @first_student.id).
|
||||
content
|
||||
expect(data).to eql "first column, first student"
|
||||
expect(first_student_data.content).to eql "first column, first student"
|
||||
end
|
||||
|
||||
it "adds data for multiple students for a column" do
|
||||
|
@ -146,9 +155,51 @@ describe CustomGradebookColumnDatum do
|
|||
},
|
||||
])
|
||||
|
||||
data = @course.custom_gradebook_columns.find_by!(id: @first_col.id).
|
||||
custom_gradebook_column_data.find_by(user_id: @first_student.id)
|
||||
expect(data).to be_nil
|
||||
expect(first_student_data).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "root_account_id" do
|
||||
before(:once) do
|
||||
@column = @course.custom_gradebook_columns.create!(title: "cc1", position: 1)
|
||||
@student = student_in_course(active_all: true, course: @course).user
|
||||
end
|
||||
|
||||
context "on create" do
|
||||
it "sets root_account_id to the course's root_account_id if root_account_id is nil" do
|
||||
datum = @column.custom_gradebook_column_data.create!(content: "some content", user_id: @student.id)
|
||||
expect(datum.root_account_id).to eq @course.root_account_id
|
||||
end
|
||||
|
||||
it "does not modify root_account_id if it is already set" do
|
||||
second_account = account_model
|
||||
datum = @column.custom_gradebook_column_data.create!(
|
||||
content: "some content",
|
||||
user_id: @student.id,
|
||||
root_account_id: second_account.id
|
||||
)
|
||||
expect(datum.root_account_id).to eq second_account.id
|
||||
end
|
||||
end
|
||||
|
||||
context "on update" do
|
||||
it "sets root_account_id to the course's root_account_id if root_account_id is nil" do
|
||||
datum = @column.custom_gradebook_column_data.create!(content: "some content", user_id: @student.id)
|
||||
datum.update_column(:root_account_id, nil)
|
||||
datum.update!(content: "some new content")
|
||||
expect(datum.root_account_id).to eq @course.root_account_id
|
||||
end
|
||||
|
||||
it "does not modify root_account_id if it is already set" do
|
||||
second_account = account_model
|
||||
datum = @column.custom_gradebook_column_data.create!(
|
||||
content: "some content",
|
||||
user_id: @student.id,
|
||||
root_account_id: second_account.id
|
||||
)
|
||||
datum.update!(content: "some new content")
|
||||
expect(datum.root_account_id).to eq second_account.id
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue