From 83610dd74d166a606092e4b689269c19e367c5f5 Mon Sep 17 00:00:00 2001 From: Angela Gomba Date: Mon, 21 Mar 2022 11:27:43 -0400 Subject: [PATCH] Display only outcomes with active workflow_state closes OUT-4964 flag=improved_outcomes_management test plan: - Navigate to Account > Outcomes - Create an outcome - In the rails console, find the outcome you just created and set the workflow_state to 'deleted' - Refresh Canvas - Observe that the outcome no longer shows in the UI and that the outcome count for that group is correct Change-Id: If5d528c544c64103b90f559f692c013f8689f928 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/287168 Tested-by: Service Cloud Jenkins Product-Review: Brian Watson Reviewed-by: Brian Watson Reviewed-by: Chrystal Langston QA-Review: Chrystal Langston --- lib/outcomes/learning_outcome_group_children.rb | 14 ++++++++------ .../learning_outcome_group_children_spec.rb | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/lib/outcomes/learning_outcome_group_children.rb b/lib/outcomes/learning_outcome_group_children.rb index e16c16b3c3b..9beb84a7cfe 100644 --- a/lib/outcomes/learning_outcome_group_children.rb +++ b/lib/outcomes/learning_outcome_group_children.rb @@ -79,11 +79,9 @@ module Outcomes end def suboutcomes_by_group_id(learning_outcome_group_id, args = {}) - learning_outcome_groups_ids = children_ids_with_self(learning_outcome_group_id) - relation = ContentTag.active.learning_outcome_links - .where(associated_asset_id: learning_outcome_groups_ids) - .joins(:learning_outcome_content) - .joins("INNER JOIN #{LearningOutcomeGroup.quoted_table_name} AS logs + relation = outcome_links(learning_outcome_group_id) + relation = relation.joins(:learning_outcome_content) + .joins("INNER JOIN #{LearningOutcomeGroup.quoted_table_name} AS logs ON logs.id = content_tags.associated_asset_id") if args[:search_query] @@ -112,7 +110,11 @@ module Outcomes def outcome_links(learning_outcome_group_id) group_ids = children_ids_with_self(learning_outcome_group_id) - ContentTag.active.learning_outcome_links.where(associated_asset_id: group_ids) + relation = ContentTag.active.learning_outcome_links + .where(associated_asset_id: group_ids) + # Check that the LearningOutcome the content tag is aligned to is not deleted + tag_ids = relation.reject { |tag| LearningOutcome.find(tag.content_id).workflow_state == "deleted" }.map(&:id) + ContentTag.where(id: tag_ids) end def total_outcomes_for(learning_outcome_group_id, args = {}) diff --git a/spec/lib/outcomes/learning_outcome_group_children_spec.rb b/spec/lib/outcomes/learning_outcome_group_children_spec.rb index e682a93be7a..77781cdec70 100644 --- a/spec/lib/outcomes/learning_outcome_group_children_spec.rb +++ b/spec/lib/outcomes/learning_outcome_group_children_spec.rb @@ -154,6 +154,23 @@ describe Outcomes::LearningOutcomeGroupChildren do end end + context "when outcome is marked as deleted, but content tag is still active" do + before do + o4.workflow_state = "deleted" + o4.save! + end + + it "returns the total outcomes for a learning outcome group without the deleted outcomes" do + expect(subject.total_outcomes(g0.id)).to eq 11 + expect(subject.total_outcomes(g1.id)).to eq 8 + expect(subject.total_outcomes(g2.id)).to eq 2 + expect(subject.total_outcomes(g3.id)).to eq 5 + expect(subject.total_outcomes(g4.id)).to eq 1 + expect(subject.total_outcomes(g5.id)).to eq 1 + expect(subject.total_outcomes(g6.id)).to eq 3 + end + end + context "when context is nil" do subject { described_class.new }