Add UUID to asset_id_mapping in content migration

fixes rcx-1974
flag=file_verifiers_for_quiz_links

Test plan
- Do a course copy and export/import (might need
  a New Quiz in the course to ensure the
  asset mapping gets created)
- Check to make sure the asset_id_url attachment
  has the UUID for the files if the FF is on
- Check to make sure it doesn't if the FF is off

Change-Id: I08e393745ae50c92e1a69bec3dce846671331e19
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/349586
Reviewed-by: Jacob DeWar <jacob.dewar@instructure.com>
QA-Review: Jacob DeWar <jacob.dewar@instructure.com>
Product-Review: Mysti Lilla <mysti@instructure.com>
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
This commit is contained in:
Mysti Lilla 2024-06-07 18:34:18 -06:00
parent 6e3146246a
commit ae4fce34e3
4 changed files with 44 additions and 4 deletions

View File

@ -1186,7 +1186,7 @@ class ContentMigration < ActiveRecord::Base
MIGRATION_DATA_FIELDS = {
"WikiPage" => %i[url current_lookup_id],
"Attachment" => %i[media_entry_id]
"Attachment" => %i[media_entry_id uuid]
}.freeze
def migration_data_fields_for(asset_type)
@ -1250,6 +1250,14 @@ class ContentMigration < ActiveRecord::Base
end
end
if key == "files" && context.root_account.feature_enabled?(:file_verifiers_for_quiz_links)
dest_id_to_dest_uuid = {}
scope.each do |file|
dest_id_to_dest_uuid[file.id] = file.uuid
end
mapping["verifiers"] = dest_id_to_dest_uuid unless dest_id_to_dest_uuid.empty?
end
next if mig_id_to_dest_id.empty?
mapping[key] ||= {}

View File

@ -189,7 +189,7 @@ class Course < ActiveRecord::Base
belongs_to :wiki
has_many :wiki_pages, as: :context, inverse_of: :context
has_many :wiki_page_lookups, as: :context, inverse_of: :context
has_many :quizzes, -> { order("lock_at, title, id") }, class_name: "Quizzes::Quiz", as: :context, inverse_of: :context, dependent: :destroy
has_many :quizzes, -> { order(:lock_at, :title, :id) }, class_name: "Quizzes::Quiz", as: :context, inverse_of: :context, dependent: :destroy
has_many :quiz_questions, class_name: "Quizzes::QuizQuestion", through: :quizzes
has_many :active_quizzes, -> { preload(:assignment).where("quizzes.workflow_state<>'deleted'").order(:created_at) }, class_name: "Quizzes::Quiz", as: :context, inverse_of: :context
has_many :assessment_question_banks, -> { preload(:assessment_questions, :assessment_question_bank_users) }, as: :context, inverse_of: :context

View File

@ -73,6 +73,8 @@ module Importers
# it to the URL as a verifier, which we don't want to do with links inside
# of Canvas, so we're excluding it
att = @context.attachments.find_by(migration_id:)
return nil unless att
att.media_entry_id ||= att.media_object&.media_id
att.attributes.except("uuid")
end

View File

@ -923,7 +923,7 @@ describe ContentMigrationsController, type: :request do
@user = @dst.teachers.first
end
def test_asset_id_mapping(json)
def test_asset_id_mapping(json, verifiers: true)
expect(@dst.announcements.find(json["announcements"][@ann.id.to_s]).title).to eq "ann"
expect(@dst.assignments.find(json["assignments"][@assign.id.to_s]).name).to eq "assign"
expect(@dst.assignments.find(json["assignments"][@shell_assign.id.to_s]).description).to eq "assigned"
@ -933,7 +933,11 @@ describe ContentMigrationsController, type: :request do
expect(@dst.discussion_topics.find(json["discussion_topics"][@topic.id.to_s]).message).to eq "some topic"
expect(@dst.discussion_topics.find(json["discussion_topics"][@assign_topic.id.to_s]).message).to eq "assigned"
expect(@dst.quizzes.find(json["quizzes"][@quiz.id.to_s]).title).to eq "a quiz"
expect(@dst.attachments.find(json["files"][@file.id.to_s]).filename).to eq "teh_file.txt"
dst_attachment = @dst.attachments.find(json["files"][@file.id.to_s])
expect(dst_attachment.filename).to eq "teh_file.txt"
if verifiers
expect(json["verifiers"][dst_attachment.id.to_s]).to eq dst_attachment.uuid
end
end
# accepts block which should return the migration id
@ -1010,6 +1014,19 @@ describe ContentMigrationsController, type: :request do
test_asset_id_mapping(json)
end
it "doesn't add verifiers to the asset map if the file_verifiers_for_quiz_links flag is off" do
@dst.root_account.disable_feature!(:file_verifiers_for_quiz_links)
json = api_call(:get,
"/api/v1/courses/#{@dst.to_param}/content_migrations/#{@migration.to_param}/asset_id_mapping",
{ controller: "content_migrations",
action: "asset_id_mapping",
format: "json",
course_id: @dst.to_param,
id: @migration.to_param })
test_asset_id_mapping(json, verifiers: false)
@dst.root_account.enable_feature!(:file_verifiers_for_quiz_links)
end
context "with the :content_migration_asset_map_v2 flag on" do
it "maps migration_ids to a hash containing the destination id" do
Account.site_admin.enable_feature!(:content_migration_asset_map_v2)
@ -1088,6 +1105,19 @@ describe ContentMigrationsController, type: :request do
test_asset_id_mapping(json)
end
it "doesn't add verifiers to the asset map if the file_verifiers_for_quiz_links flag is off" do
@dst.root_account.disable_feature!(:file_verifiers_for_quiz_links)
json = api_call(:get,
"/api/v1/courses/#{@dst.to_param}/content_migrations/#{@migration.to_param}/asset_id_mapping",
{ controller: "content_migrations",
action: "asset_id_mapping",
format: "json",
course_id: @dst.to_param,
id: @migration.to_param })
test_asset_id_mapping(json, verifiers: false)
@dst.root_account.enable_feature!(:file_verifiers_for_quiz_links)
end
context "with the :content_migration_asset_map_v2 on" do
it "maps migration_ids to a hash containing the destination id" do
Account.site_admin.enable_feature!(:content_migration_asset_map_v2)