Add Discussion anonymous state to Course Importer

flag=none
closes VICE-2774

Test Plan:
 - Tests pass
 - Go to course A
 - Create an Anonymous Discussion Topic
 - Go to course B
 - Go to Settings
 - On the right side, click on Import Course Content
 - On Content Type select Copy a Canvas Course
 - Search for the course A (whatever name it has)
 - On Content choose: "Select specific content"
 - Click on Import
 - Then on the Current Jobs table click on Select Content
 - Expand Discussion Topics (clicking on the arrow)
 - Select the discussion topic to import
 - Click on Select Content.
 - Once the job is completed, verify that the
     Discussion Topic was added to the course
     as anonymous.

Change-Id: Ib9c4e2ba3e112805e5d68b7feabd94ab34bae20b
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/293232
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Drake Harper <drake.harper@instructure.com>
Product-Review: Drake Harper <drake.harper@instructure.com>
QA-Review: Chawn Neal <chawn.neal@instructure.com>
This commit is contained in:
Omar Gerardo Soto-Fortuño 2022-06-03 11:44:36 -04:00 committed by Omar Soto-Fortuño
parent 0cf67f7f5c
commit dffb146bd1
5 changed files with 27 additions and 8 deletions

View File

@ -181,11 +181,15 @@ module Types
def anonymous_author
if object.anonymous_state == "full_anonymity" || (object.anonymous_state == "partial_anonymity" && object.is_anonymous_author)
Loaders::DiscussionTopicParticipantLoader.for(object.id).load(object.user_id).then do |participant|
{
id: participant.id.to_s(36),
short_name: object.user_id == current_user.id ? "current_user" : participant.id.to_s(36),
avatar_url: nil
}
if participant.nil?
nil
else
{
id: participant.id.to_s(36),
short_name: object.user_id == current_user.id ? "current_user" : participant.id.to_s(36),
avatar_url: nil
}
end
end
else
nil

View File

@ -101,7 +101,7 @@ module Importers
%i[migration_id title discussion_type position pinned
require_initial_post allow_rating only_graders_can_rate
sort_by_rating].each do |attr|
sort_by_rating anonymous_state is_anonymous_author].each do |attr|
next if options[attr].nil? && item.class.columns_hash[attr.to_s].type == :boolean
item.send("#{attr}=", options[attr])
@ -197,7 +197,7 @@ module Importers
class DiscussionTopicOptions
attr_reader :options
BOOLEAN_KEYS = %i[pinned require_initial_post locked].freeze
BOOLEAN_KEYS = %i[pinned require_initial_post locked is_anonymous_author].freeze
def initialize(options = {})
@options = options.with_indifferent_access

View File

@ -70,12 +70,13 @@ module CC::Importer::Canvas
topic["workflow_state"] = wf_state if wf_state.present?
topic["group_category"] = get_node_val(meta_doc, "group_category")
topic["todo_date"] = get_time_val(meta_doc, "todo_date")
%w[has_group_category allow_rating only_graders_can_rate sort_by_rating locked].each do |setting|
%w[has_group_category allow_rating only_graders_can_rate sort_by_rating locked is_anonymous_author].each do |setting|
get_bool_val(meta_doc, setting).tap { |val| topic[setting] = val unless val.nil? }
end
if (asmnt_node = meta_doc.at_css("assignment"))
topic["assignment"] = parse_canvas_assignment_data(asmnt_node)
end
topic["anonymous_state"] = get_node_val(meta_doc, "anonymous_state")
end
topic

View File

@ -138,6 +138,8 @@ module CC
AssignmentResources.create_canvas_assignment(a, topic.assignment, @manifest)
end
end
doc.anonymous_state topic.anonymous_state
doc.is_anonymous_author "true" if topic.is_anonymous_author
end
end
end

View File

@ -48,6 +48,18 @@ describe ContentMigration do
expect(new_topic.todo_date.to_i).to eq todo_date.to_i
end
it "copies discussion topic full_anonymity anonymous_state" do
topic = @copy_from.discussion_topics.create!(title: "full_anonymity topic", message: "<p>bloop</p>",
anonymous_state: "full_anonymity")
run_course_copy
new_topic = @copy_to.discussion_topics.where(migration_id: mig_id(topic)).first
expect(topic.anonymous_state).to eq new_topic.anonymous_state
expect(topic.is_anonymous_author).to eq new_topic.is_anonymous_author
end
it "copies locked state for announcements" do
@copy_from.announcements.create!(title: "topic", message: "<p>bloop</p>", locked: true)