feat: add root account reference to collaborations table

closes VICE-4374
flag=none

Test plan:
- Create some collaborations (in rails c its easy)
- Run the migration, see root account id is backfilled
- Create new collaboration through API, see the root_account_id properly filled

Change-Id: I8d467133c3db4b51d7e5eb5ad5c49704bd420f4b
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/350425
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Migration-Review: Jake Oeding <jake.oeding@instructure.com>
QA-Review: Omar Soto-Fortuño <omar.soto@instructure.com>
Product-Review: Daniel Matyas Vincze <daniel.vincze@instructure.com>
Reviewed-by: Jason Gillett <jason.gillett@instructure.com>
Reviewed-by: Mysti Lilla <mysti@instructure.com>
This commit is contained in:
Daniel Vincze 2024-06-18 12:07:22 +02:00 committed by Daniel Matyas Vincze
parent 95c5576003
commit 36987ed388
7 changed files with 73 additions and 0 deletions

View File

@ -35,6 +35,7 @@ class Collaboration < ActiveRecord::Base
before_save :assign_uuid
before_save :set_context_code
before_save :set_root_account_id
after_save :include_author_as_collaborator
after_save :touch_context
@ -328,6 +329,10 @@ class Collaboration < ActiveRecord::Base
end
protected :set_context_code
def set_root_account_id
self.root_account_id = context.root_account_id
end
# Internal: Delete existing collaborating users and add new ones.
#
# users - The array of users to add. Any duplicates with current users

View File

@ -0,0 +1,32 @@
# frozen_string_literal: true
#
# Copyright (C) 2024 - 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 AddRootAccountIdForCollaborations < ActiveRecord::Migration[7.0]
tag :predeploy
disable_ddl_transaction!
def change
add_reference :collaborations,
:root_account,
foreign_key: { to_table: :accounts },
index: { algorithm: :concurrently, if_not_exists: true },
if_not_exists: true
end
end

View File

@ -0,0 +1,30 @@
# frozen_string_literal: true
#
# Copyright (C) 2024 - 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 PopulateRootAccountIdForCollaborations < ActiveRecord::Migration[7.0]
tag :postdeploy
def up
DataFixup::PopulateRootAccountIdOnModels.delay_if_production(
priority: Delayed::LOWER_PRIORITY,
n_strand: ["root_account_ids_backfill_collab_strand", Shard.current.database_server.id]
).run
end
end

View File

@ -68,6 +68,7 @@ module DataFixup::PopulateRootAccountIdOnModels
Attachment => [],
AttachmentAssociation => %i[course group submission attachment], # attachment is last, only used if context is a ConversationMessage
CalendarEvent => %i[context_course context_group context_course_section],
Collaboration => :context,
CommunicationChannel => [], # has override
ContentMigration => %i[account course group],
ContentParticipation => :content,

View File

@ -350,6 +350,7 @@ describe CollaborationsController do
post "create", params: { course_id: @course.id, collaboration: { collaboration_type: "EtherPad", title: "My Collab" } }
expect(response).to be_redirect
expect(assigns[:collaboration]).not_to be_nil
expect(assigns[:collaboration].root_account_id).to eq(@course.root_account_id)
expect(assigns[:collaboration].class).to eql(EtherpadCollaboration)
expect(assigns[:collaboration].collaboration_type).to eql("EtherPad")
expect(Collaboration.find(assigns[:collaboration].id)).to be_is_a(EtherpadCollaboration)

View File

@ -3689,6 +3689,7 @@ describe ContextExternalTool do
external_tool_collaboration_model(
context: course,
title: "Indirect Collaboration",
root_account_id: course.root_account_id,
url:
)
end

View File

@ -59,6 +59,7 @@ describe ExternalToolCollaboration do
external_tool_collaboration_model(
context: course,
title: "Indirect Collaboration",
root_account_id: course.root_account_id,
url:
)
end
@ -73,6 +74,7 @@ describe ExternalToolCollaboration do
external_tool_collaboration_model(
context: course,
title: "Indirect Collaboration",
root_account_id: course.root_account_id,
url: "http://tool2.other.com"
)
end
@ -81,6 +83,7 @@ describe ExternalToolCollaboration do
external_tool_collaboration_model(
context: other_course,
title: "Other Course - Indirect Collaboration",
root_account_id: other_course.root_account_id,
url:
)
end