From dffb146bd132984a3e274d12cb850c71659ba847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Gerardo=20Soto-Fortu=C3=B1o?= Date: Fri, 3 Jun 2022 11:44:36 -0400 Subject: [PATCH] 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 Reviewed-by: Drake Harper Product-Review: Drake Harper QA-Review: Chawn Neal --- app/graphql/types/discussion_type.rb | 14 +++++++++----- app/models/importers/discussion_topic_importer.rb | 4 ++-- lib/cc/importer/canvas/topic_converter.rb | 3 ++- lib/cc/topic_resources.rb | 2 ++ .../course_copy_discussions_spec.rb | 12 ++++++++++++ 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/app/graphql/types/discussion_type.rb b/app/graphql/types/discussion_type.rb index 804b86103cf..8a35db06eae 100644 --- a/app/graphql/types/discussion_type.rb +++ b/app/graphql/types/discussion_type.rb @@ -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 diff --git a/app/models/importers/discussion_topic_importer.rb b/app/models/importers/discussion_topic_importer.rb index 49e00058ff0..7e361fd40e4 100644 --- a/app/models/importers/discussion_topic_importer.rb +++ b/app/models/importers/discussion_topic_importer.rb @@ -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 diff --git a/lib/cc/importer/canvas/topic_converter.rb b/lib/cc/importer/canvas/topic_converter.rb index d6760105352..1ce1c285d30 100644 --- a/lib/cc/importer/canvas/topic_converter.rb +++ b/lib/cc/importer/canvas/topic_converter.rb @@ -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 diff --git a/lib/cc/topic_resources.rb b/lib/cc/topic_resources.rb index 9d5f69d5014..a1be4259476 100644 --- a/lib/cc/topic_resources.rb +++ b/lib/cc/topic_resources.rb @@ -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 diff --git a/spec/models/content_migration/course_copy_discussions_spec.rb b/spec/models/content_migration/course_copy_discussions_spec.rb index 0d1bf1fa10c..88761cc5a61 100644 --- a/spec/models/content_migration/course_copy_discussions_spec.rb +++ b/spec/models/content_migration/course_copy_discussions_spec.rb @@ -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: "

bloop

", + 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: "

bloop

", locked: true)