canvas-lms/lib/outcomes/import.rb

301 lines
10 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
# Copyright (C) 2013 - 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/>.
#
module Outcomes
module Import
allow updating outcomes via csv closes OUT-1555 Test plan: Basic behavior: - follow instructions in g/140107 to do basic import of outcomes into a context - make changes to the csv file: - change titles/descriptions/ratings/etc. - change parents of groups and of outcomes - re-run the import command with the updated csv file - verify that changes can be seen in the console or in the canvas UI Subcontext behavior: - check LearningOutcome.count and LearningOutcomeGroup.count in the rails console - import the csv into a subaccount or course under the account used above - verify that the outcomes and groups are imported - verify that outcomes are re-used and groups are re-created by viewing LearningOutcome.count and LearningOutcomeGroup.count again; the former should be unchanged and the latter increased by the # of groups in the csv file Export/Import behavior: - generate a csv file using Account Settings/Reports/Outcome Export - make changes to the csv file, including updating vendor_guids for outcomes/groups in the file - import the csv and verify that changes are made using the UI and console (you can check vendor_guid changes by looking at LearningOutcome.find($canvas_id) Error behavior - Attempt to import the exported csv into the subcontext account or course from the second set of steps, verifying - groups cannot be imported or updated, with error that group was found in a different context - properties of outcomes cannot be updated, with error that fields for outcome from another context cannot be updated - non-existent canvas ids lead to errors Change-Id: Iceca02ec5157a4d187a2b9fd11b3415c84613ffa Reviewed-on: https://gerrit.instructure.com/141836 Tested-by: Jenkins Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Augusto Callejas <acallejas@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-02-25 11:26:55 +08:00
class InvalidDataError < RuntimeError; end
class DataFormatError < RuntimeError; end
OBJECT_ONLY_FIELDS = %i[calculation_method calculation_int ratings].freeze
VALID_WORKFLOWS = [nil, '', 'active', 'deleted'].freeze
def check_object(object)
allow updating outcomes via csv closes OUT-1555 Test plan: Basic behavior: - follow instructions in g/140107 to do basic import of outcomes into a context - make changes to the csv file: - change titles/descriptions/ratings/etc. - change parents of groups and of outcomes - re-run the import command with the updated csv file - verify that changes can be seen in the console or in the canvas UI Subcontext behavior: - check LearningOutcome.count and LearningOutcomeGroup.count in the rails console - import the csv into a subaccount or course under the account used above - verify that the outcomes and groups are imported - verify that outcomes are re-used and groups are re-created by viewing LearningOutcome.count and LearningOutcomeGroup.count again; the former should be unchanged and the latter increased by the # of groups in the csv file Export/Import behavior: - generate a csv file using Account Settings/Reports/Outcome Export - make changes to the csv file, including updating vendor_guids for outcomes/groups in the file - import the csv and verify that changes are made using the UI and console (you can check vendor_guid changes by looking at LearningOutcome.find($canvas_id) Error behavior - Attempt to import the exported csv into the subcontext account or course from the second set of steps, verifying - groups cannot be imported or updated, with error that group was found in a different context - properties of outcomes cannot be updated, with error that fields for outcome from another context cannot be updated - non-existent canvas ids lead to errors Change-Id: Iceca02ec5157a4d187a2b9fd11b3415c84613ffa Reviewed-on: https://gerrit.instructure.com/141836 Tested-by: Jenkins Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Augusto Callejas <acallejas@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-02-25 11:26:55 +08:00
%i[vendor_guid title].each do |field|
next if object[field].present?
allow updating outcomes via csv closes OUT-1555 Test plan: Basic behavior: - follow instructions in g/140107 to do basic import of outcomes into a context - make changes to the csv file: - change titles/descriptions/ratings/etc. - change parents of groups and of outcomes - re-run the import command with the updated csv file - verify that changes can be seen in the console or in the canvas UI Subcontext behavior: - check LearningOutcome.count and LearningOutcomeGroup.count in the rails console - import the csv into a subaccount or course under the account used above - verify that the outcomes and groups are imported - verify that outcomes are re-used and groups are re-created by viewing LearningOutcome.count and LearningOutcomeGroup.count again; the former should be unchanged and the latter increased by the # of groups in the csv file Export/Import behavior: - generate a csv file using Account Settings/Reports/Outcome Export - make changes to the csv file, including updating vendor_guids for outcomes/groups in the file - import the csv and verify that changes are made using the UI and console (you can check vendor_guid changes by looking at LearningOutcome.find($canvas_id) Error behavior - Attempt to import the exported csv into the subcontext account or course from the second set of steps, verifying - groups cannot be imported or updated, with error that group was found in a different context - properties of outcomes cannot be updated, with error that fields for outcome from another context cannot be updated - non-existent canvas ids lead to errors Change-Id: Iceca02ec5157a4d187a2b9fd11b3415c84613ffa Reviewed-on: https://gerrit.instructure.com/141836 Tested-by: Jenkins Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Augusto Callejas <acallejas@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-02-25 11:26:55 +08:00
raise InvalidDataError, I18n.t(
'The "%{field}" field is required', field: field
)
end
if object[:vendor_guid].match?(/\s/)
raise InvalidDataError, I18n.t(
'The "%{field}" field must have no spaces',
field: 'vendor_guid'
)
end
unless VALID_WORKFLOWS.include? object[:workflow_state]
raise InvalidDataError, I18n.t(
'"%{field}" must be either "%{active}" or "%{deleted}"',
field: 'workflow_state',
active: 'active',
deleted: 'deleted'
)
end
end
def import_object(object)
check_object(object)
type = object[:object_type]
if type == 'outcome'
import_outcome(object)
elsif type == 'group'
import_group(object)
else
allow updating outcomes via csv closes OUT-1555 Test plan: Basic behavior: - follow instructions in g/140107 to do basic import of outcomes into a context - make changes to the csv file: - change titles/descriptions/ratings/etc. - change parents of groups and of outcomes - re-run the import command with the updated csv file - verify that changes can be seen in the console or in the canvas UI Subcontext behavior: - check LearningOutcome.count and LearningOutcomeGroup.count in the rails console - import the csv into a subaccount or course under the account used above - verify that the outcomes and groups are imported - verify that outcomes are re-used and groups are re-created by viewing LearningOutcome.count and LearningOutcomeGroup.count again; the former should be unchanged and the latter increased by the # of groups in the csv file Export/Import behavior: - generate a csv file using Account Settings/Reports/Outcome Export - make changes to the csv file, including updating vendor_guids for outcomes/groups in the file - import the csv and verify that changes are made using the UI and console (you can check vendor_guid changes by looking at LearningOutcome.find($canvas_id) Error behavior - Attempt to import the exported csv into the subcontext account or course from the second set of steps, verifying - groups cannot be imported or updated, with error that group was found in a different context - properties of outcomes cannot be updated, with error that fields for outcome from another context cannot be updated - non-existent canvas ids lead to errors Change-Id: Iceca02ec5157a4d187a2b9fd11b3415c84613ffa Reviewed-on: https://gerrit.instructure.com/141836 Tested-by: Jenkins Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Augusto Callejas <acallejas@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-02-25 11:26:55 +08:00
raise InvalidDataError, I18n.t(
'Invalid %{field}: "%{type}"',
field: 'object_type',
type: type
)
end
end
def import_group(group)
invalid = group.keys.select do |k|
group[k].present? && OBJECT_ONLY_FIELDS.include?(k)
end
allow updating outcomes via csv closes OUT-1555 Test plan: Basic behavior: - follow instructions in g/140107 to do basic import of outcomes into a context - make changes to the csv file: - change titles/descriptions/ratings/etc. - change parents of groups and of outcomes - re-run the import command with the updated csv file - verify that changes can be seen in the console or in the canvas UI Subcontext behavior: - check LearningOutcome.count and LearningOutcomeGroup.count in the rails console - import the csv into a subaccount or course under the account used above - verify that the outcomes and groups are imported - verify that outcomes are re-used and groups are re-created by viewing LearningOutcome.count and LearningOutcomeGroup.count again; the former should be unchanged and the latter increased by the # of groups in the csv file Export/Import behavior: - generate a csv file using Account Settings/Reports/Outcome Export - make changes to the csv file, including updating vendor_guids for outcomes/groups in the file - import the csv and verify that changes are made using the UI and console (you can check vendor_guid changes by looking at LearningOutcome.find($canvas_id) Error behavior - Attempt to import the exported csv into the subcontext account or course from the second set of steps, verifying - groups cannot be imported or updated, with error that group was found in a different context - properties of outcomes cannot be updated, with error that fields for outcome from another context cannot be updated - non-existent canvas ids lead to errors Change-Id: Iceca02ec5157a4d187a2b9fd11b3415c84613ffa Reviewed-on: https://gerrit.instructure.com/141836 Tested-by: Jenkins Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Augusto Callejas <acallejas@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-02-25 11:26:55 +08:00
if invalid.present?
raise InvalidDataError, I18n.t(
'Invalid fields for a group: %{invalid}',
invalid: invalid.map(&:to_s).inspect
)
end
parents = find_parents(group)
allow updating outcomes via csv closes OUT-1555 Test plan: Basic behavior: - follow instructions in g/140107 to do basic import of outcomes into a context - make changes to the csv file: - change titles/descriptions/ratings/etc. - change parents of groups and of outcomes - re-run the import command with the updated csv file - verify that changes can be seen in the console or in the canvas UI Subcontext behavior: - check LearningOutcome.count and LearningOutcomeGroup.count in the rails console - import the csv into a subaccount or course under the account used above - verify that the outcomes and groups are imported - verify that outcomes are re-used and groups are re-created by viewing LearningOutcome.count and LearningOutcomeGroup.count again; the former should be unchanged and the latter increased by the # of groups in the csv file Export/Import behavior: - generate a csv file using Account Settings/Reports/Outcome Export - make changes to the csv file, including updating vendor_guids for outcomes/groups in the file - import the csv and verify that changes are made using the UI and console (you can check vendor_guid changes by looking at LearningOutcome.find($canvas_id) Error behavior - Attempt to import the exported csv into the subcontext account or course from the second set of steps, verifying - groups cannot be imported or updated, with error that group was found in a different context - properties of outcomes cannot be updated, with error that fields for outcome from another context cannot be updated - non-existent canvas ids lead to errors Change-Id: Iceca02ec5157a4d187a2b9fd11b3415c84613ffa Reviewed-on: https://gerrit.instructure.com/141836 Tested-by: Jenkins Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Augusto Callejas <acallejas@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-02-25 11:26:55 +08:00
raise InvalidDataError, I18n.t("An outcome group can only have one parent") if parents.length > 1
parent = parents.first
allow updating outcomes via csv closes OUT-1555 Test plan: Basic behavior: - follow instructions in g/140107 to do basic import of outcomes into a context - make changes to the csv file: - change titles/descriptions/ratings/etc. - change parents of groups and of outcomes - re-run the import command with the updated csv file - verify that changes can be seen in the console or in the canvas UI Subcontext behavior: - check LearningOutcome.count and LearningOutcomeGroup.count in the rails console - import the csv into a subaccount or course under the account used above - verify that the outcomes and groups are imported - verify that outcomes are re-used and groups are re-created by viewing LearningOutcome.count and LearningOutcomeGroup.count again; the former should be unchanged and the latter increased by the # of groups in the csv file Export/Import behavior: - generate a csv file using Account Settings/Reports/Outcome Export - make changes to the csv file, including updating vendor_guids for outcomes/groups in the file - import the csv and verify that changes are made using the UI and console (you can check vendor_guid changes by looking at LearningOutcome.find($canvas_id) Error behavior - Attempt to import the exported csv into the subcontext account or course from the second set of steps, verifying - groups cannot be imported or updated, with error that group was found in a different context - properties of outcomes cannot be updated, with error that fields for outcome from another context cannot be updated - non-existent canvas ids lead to errors Change-Id: Iceca02ec5157a4d187a2b9fd11b3415c84613ffa Reviewed-on: https://gerrit.instructure.com/141836 Tested-by: Jenkins Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Augusto Callejas <acallejas@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-02-25 11:26:55 +08:00
model = find_prior_group(group)
unless model.context == context
raise InvalidDataError, I18n.t(
'Group with ID %{guid} already exists in another unrelated course or account (%{name})',
guid: group[:vendor_guid],
name: model.context.name
allow updating outcomes via csv closes OUT-1555 Test plan: Basic behavior: - follow instructions in g/140107 to do basic import of outcomes into a context - make changes to the csv file: - change titles/descriptions/ratings/etc. - change parents of groups and of outcomes - re-run the import command with the updated csv file - verify that changes can be seen in the console or in the canvas UI Subcontext behavior: - check LearningOutcome.count and LearningOutcomeGroup.count in the rails console - import the csv into a subaccount or course under the account used above - verify that the outcomes and groups are imported - verify that outcomes are re-used and groups are re-created by viewing LearningOutcome.count and LearningOutcomeGroup.count again; the former should be unchanged and the latter increased by the # of groups in the csv file Export/Import behavior: - generate a csv file using Account Settings/Reports/Outcome Export - make changes to the csv file, including updating vendor_guids for outcomes/groups in the file - import the csv and verify that changes are made using the UI and console (you can check vendor_guid changes by looking at LearningOutcome.find($canvas_id) Error behavior - Attempt to import the exported csv into the subcontext account or course from the second set of steps, verifying - groups cannot be imported or updated, with error that group was found in a different context - properties of outcomes cannot be updated, with error that fields for outcome from another context cannot be updated - non-existent canvas ids lead to errors Change-Id: Iceca02ec5157a4d187a2b9fd11b3415c84613ffa Reviewed-on: https://gerrit.instructure.com/141836 Tested-by: Jenkins Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Augusto Callejas <acallejas@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-02-25 11:26:55 +08:00
)
end
if model.outcome_import_id == outcome_import_id
raise InvalidDataError, I18n.t(
'Group "%{guid}" has already appeared in this import',
guid: group[:vendor_guid]
)
end
allow updating outcomes via csv closes OUT-1555 Test plan: Basic behavior: - follow instructions in g/140107 to do basic import of outcomes into a context - make changes to the csv file: - change titles/descriptions/ratings/etc. - change parents of groups and of outcomes - re-run the import command with the updated csv file - verify that changes can be seen in the console or in the canvas UI Subcontext behavior: - check LearningOutcome.count and LearningOutcomeGroup.count in the rails console - import the csv into a subaccount or course under the account used above - verify that the outcomes and groups are imported - verify that outcomes are re-used and groups are re-created by viewing LearningOutcome.count and LearningOutcomeGroup.count again; the former should be unchanged and the latter increased by the # of groups in the csv file Export/Import behavior: - generate a csv file using Account Settings/Reports/Outcome Export - make changes to the csv file, including updating vendor_guids for outcomes/groups in the file - import the csv and verify that changes are made using the UI and console (you can check vendor_guid changes by looking at LearningOutcome.find($canvas_id) Error behavior - Attempt to import the exported csv into the subcontext account or course from the second set of steps, verifying - groups cannot be imported or updated, with error that group was found in a different context - properties of outcomes cannot be updated, with error that fields for outcome from another context cannot be updated - non-existent canvas ids lead to errors Change-Id: Iceca02ec5157a4d187a2b9fd11b3415c84613ffa Reviewed-on: https://gerrit.instructure.com/141836 Tested-by: Jenkins Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Augusto Callejas <acallejas@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-02-25 11:26:55 +08:00
model.vendor_guid = group[:vendor_guid]
model.title = group[:title]
model.description = group[:description] || ''
model.workflow_state = group[:workflow_state].presence || 'active'
allow updating outcomes via csv closes OUT-1555 Test plan: Basic behavior: - follow instructions in g/140107 to do basic import of outcomes into a context - make changes to the csv file: - change titles/descriptions/ratings/etc. - change parents of groups and of outcomes - re-run the import command with the updated csv file - verify that changes can be seen in the console or in the canvas UI Subcontext behavior: - check LearningOutcome.count and LearningOutcomeGroup.count in the rails console - import the csv into a subaccount or course under the account used above - verify that the outcomes and groups are imported - verify that outcomes are re-used and groups are re-created by viewing LearningOutcome.count and LearningOutcomeGroup.count again; the former should be unchanged and the latter increased by the # of groups in the csv file Export/Import behavior: - generate a csv file using Account Settings/Reports/Outcome Export - make changes to the csv file, including updating vendor_guids for outcomes/groups in the file - import the csv and verify that changes are made using the UI and console (you can check vendor_guid changes by looking at LearningOutcome.find($canvas_id) Error behavior - Attempt to import the exported csv into the subcontext account or course from the second set of steps, verifying - groups cannot be imported or updated, with error that group was found in a different context - properties of outcomes cannot be updated, with error that fields for outcome from another context cannot be updated - non-existent canvas ids lead to errors Change-Id: Iceca02ec5157a4d187a2b9fd11b3415c84613ffa Reviewed-on: https://gerrit.instructure.com/141836 Tested-by: Jenkins Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Augusto Callejas <acallejas@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-02-25 11:26:55 +08:00
model.learning_outcome_group = parent
model.outcome_import_id = outcome_import_id
model.save!
if model.workflow_state == 'deleted'
model.destroy!
end
model
end
def import_outcome(outcome)
parents = find_parents(outcome)
allow updating outcomes via csv closes OUT-1555 Test plan: Basic behavior: - follow instructions in g/140107 to do basic import of outcomes into a context - make changes to the csv file: - change titles/descriptions/ratings/etc. - change parents of groups and of outcomes - re-run the import command with the updated csv file - verify that changes can be seen in the console or in the canvas UI Subcontext behavior: - check LearningOutcome.count and LearningOutcomeGroup.count in the rails console - import the csv into a subaccount or course under the account used above - verify that the outcomes and groups are imported - verify that outcomes are re-used and groups are re-created by viewing LearningOutcome.count and LearningOutcomeGroup.count again; the former should be unchanged and the latter increased by the # of groups in the csv file Export/Import behavior: - generate a csv file using Account Settings/Reports/Outcome Export - make changes to the csv file, including updating vendor_guids for outcomes/groups in the file - import the csv and verify that changes are made using the UI and console (you can check vendor_guid changes by looking at LearningOutcome.find($canvas_id) Error behavior - Attempt to import the exported csv into the subcontext account or course from the second set of steps, verifying - groups cannot be imported or updated, with error that group was found in a different context - properties of outcomes cannot be updated, with error that fields for outcome from another context cannot be updated - non-existent canvas ids lead to errors Change-Id: Iceca02ec5157a4d187a2b9fd11b3415c84613ffa Reviewed-on: https://gerrit.instructure.com/141836 Tested-by: Jenkins Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Augusto Callejas <acallejas@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-02-25 11:26:55 +08:00
model = find_prior_outcome(outcome)
model.context = context if model.new_record?
allow updating outcomes via csv closes OUT-1555 Test plan: Basic behavior: - follow instructions in g/140107 to do basic import of outcomes into a context - make changes to the csv file: - change titles/descriptions/ratings/etc. - change parents of groups and of outcomes - re-run the import command with the updated csv file - verify that changes can be seen in the console or in the canvas UI Subcontext behavior: - check LearningOutcome.count and LearningOutcomeGroup.count in the rails console - import the csv into a subaccount or course under the account used above - verify that the outcomes and groups are imported - verify that outcomes are re-used and groups are re-created by viewing LearningOutcome.count and LearningOutcomeGroup.count again; the former should be unchanged and the latter increased by the # of groups in the csv file Export/Import behavior: - generate a csv file using Account Settings/Reports/Outcome Export - make changes to the csv file, including updating vendor_guids for outcomes/groups in the file - import the csv and verify that changes are made using the UI and console (you can check vendor_guid changes by looking at LearningOutcome.find($canvas_id) Error behavior - Attempt to import the exported csv into the subcontext account or course from the second set of steps, verifying - groups cannot be imported or updated, with error that group was found in a different context - properties of outcomes cannot be updated, with error that fields for outcome from another context cannot be updated - non-existent canvas ids lead to errors Change-Id: Iceca02ec5157a4d187a2b9fd11b3415c84613ffa Reviewed-on: https://gerrit.instructure.com/141836 Tested-by: Jenkins Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Augusto Callejas <acallejas@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-02-25 11:26:55 +08:00
unless context_visible?(model.context)
raise InvalidDataError, I18n.t(
'Outcome with ID %{guid} already exists in another unrelated course or account (%{name})',
guid: outcome[:vendor_guid],
name: model.context.name
allow updating outcomes via csv closes OUT-1555 Test plan: Basic behavior: - follow instructions in g/140107 to do basic import of outcomes into a context - make changes to the csv file: - change titles/descriptions/ratings/etc. - change parents of groups and of outcomes - re-run the import command with the updated csv file - verify that changes can be seen in the console or in the canvas UI Subcontext behavior: - check LearningOutcome.count and LearningOutcomeGroup.count in the rails console - import the csv into a subaccount or course under the account used above - verify that the outcomes and groups are imported - verify that outcomes are re-used and groups are re-created by viewing LearningOutcome.count and LearningOutcomeGroup.count again; the former should be unchanged and the latter increased by the # of groups in the csv file Export/Import behavior: - generate a csv file using Account Settings/Reports/Outcome Export - make changes to the csv file, including updating vendor_guids for outcomes/groups in the file - import the csv and verify that changes are made using the UI and console (you can check vendor_guid changes by looking at LearningOutcome.find($canvas_id) Error behavior - Attempt to import the exported csv into the subcontext account or course from the second set of steps, verifying - groups cannot be imported or updated, with error that group was found in a different context - properties of outcomes cannot be updated, with error that fields for outcome from another context cannot be updated - non-existent canvas ids lead to errors Change-Id: Iceca02ec5157a4d187a2b9fd11b3415c84613ffa Reviewed-on: https://gerrit.instructure.com/141836 Tested-by: Jenkins Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Augusto Callejas <acallejas@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-02-25 11:26:55 +08:00
)
end
if model.outcome_import_id == outcome_import_id
raise InvalidDataError, I18n.t(
'Outcome "%{guid}" has already appeared in this import',
guid: outcome[:vendor_guid]
)
end
allow updating outcomes via csv closes OUT-1555 Test plan: Basic behavior: - follow instructions in g/140107 to do basic import of outcomes into a context - make changes to the csv file: - change titles/descriptions/ratings/etc. - change parents of groups and of outcomes - re-run the import command with the updated csv file - verify that changes can be seen in the console or in the canvas UI Subcontext behavior: - check LearningOutcome.count and LearningOutcomeGroup.count in the rails console - import the csv into a subaccount or course under the account used above - verify that the outcomes and groups are imported - verify that outcomes are re-used and groups are re-created by viewing LearningOutcome.count and LearningOutcomeGroup.count again; the former should be unchanged and the latter increased by the # of groups in the csv file Export/Import behavior: - generate a csv file using Account Settings/Reports/Outcome Export - make changes to the csv file, including updating vendor_guids for outcomes/groups in the file - import the csv and verify that changes are made using the UI and console (you can check vendor_guid changes by looking at LearningOutcome.find($canvas_id) Error behavior - Attempt to import the exported csv into the subcontext account or course from the second set of steps, verifying - groups cannot be imported or updated, with error that group was found in a different context - properties of outcomes cannot be updated, with error that fields for outcome from another context cannot be updated - non-existent canvas ids lead to errors Change-Id: Iceca02ec5157a4d187a2b9fd11b3415c84613ffa Reviewed-on: https://gerrit.instructure.com/141836 Tested-by: Jenkins Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Augusto Callejas <acallejas@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-02-25 11:26:55 +08:00
model.vendor_guid = outcome[:vendor_guid]
model.title = outcome[:title]
model.description = infer_nil_value(model, :description, outcome)
model.display_name = infer_nil_value(model, :display_name, outcome)
model.calculation_method = outcome[:calculation_method].presence || model.default_calculation_method
model.calculation_int = outcome[:calculation_int].presence || model.default_calculation_int
# let removing the outcome_links content tags delete the underlying outcome
model.workflow_state = 'active' unless outcome[:workflow_state] == 'deleted'
allow updating outcomes via csv closes OUT-1555 Test plan: Basic behavior: - follow instructions in g/140107 to do basic import of outcomes into a context - make changes to the csv file: - change titles/descriptions/ratings/etc. - change parents of groups and of outcomes - re-run the import command with the updated csv file - verify that changes can be seen in the console or in the canvas UI Subcontext behavior: - check LearningOutcome.count and LearningOutcomeGroup.count in the rails console - import the csv into a subaccount or course under the account used above - verify that the outcomes and groups are imported - verify that outcomes are re-used and groups are re-created by viewing LearningOutcome.count and LearningOutcomeGroup.count again; the former should be unchanged and the latter increased by the # of groups in the csv file Export/Import behavior: - generate a csv file using Account Settings/Reports/Outcome Export - make changes to the csv file, including updating vendor_guids for outcomes/groups in the file - import the csv and verify that changes are made using the UI and console (you can check vendor_guid changes by looking at LearningOutcome.find($canvas_id) Error behavior - Attempt to import the exported csv into the subcontext account or course from the second set of steps, verifying - groups cannot be imported or updated, with error that group was found in a different context - properties of outcomes cannot be updated, with error that fields for outcome from another context cannot be updated - non-existent canvas ids lead to errors Change-Id: Iceca02ec5157a4d187a2b9fd11b3415c84613ffa Reviewed-on: https://gerrit.instructure.com/141836 Tested-by: Jenkins Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Augusto Callejas <acallejas@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-02-25 11:26:55 +08:00
prior_rubric = model.rubric_criterion || {}
i18n tweaks for outcome import Fixes OUT-2010 Test Plan - Save an .xlsx version of demo.csv: $ open spec/lib/outcomes/fixtures A finder window will open. Right click "demo.csv", and select "Open With..." > "Excel" Then "Save As" and specify the format as ".xslx". Remember where you saved this file. I recommend you save it to "Downloads" - Change your system language to Norwegian: - on OSX, go to "Language & Region" in System Preferences - click the '+' below "Preferred Languages" - Choose "Norsk bokmål" - Click "Add" - When it asks if you want to use it as a primary language, click "Use Norwegian Bokmål" - Keep the preferences window open so you can switch back. - Click the back button on the top left. - Don't restart your system when prompted. - Don't close the settings window, it should still remain in English so you can switch back at the end. - **Google Translate is now your best friend.** - Make sure that Excel is not running. - Open your previously saved file. - The excel window should have all menu options in Norwegian. - Choose Fil > Lagre Sum... to save as - Click the arrow next to "Arkiver som" to select a file path. - Choose the "Nedlastinger" (Downloads) directory, and set the name under "Arkiver som" to "norwegian" - Under "Filformat", select "Kommadelte verdier (.csv)" - Save by clicking "Arkiver" - Quit excel. You will see a dialog that says: "Vil du lagre endringene i dokumentet norwegian.csv?" Click: "Ikke lagre" - Change your system language back to English (optional, don't switch back for hard-mode test plan): - Go back to "Language & Region" in System Preferences - Click "Norsk bokmål" - Click the minus button. - Check that the file in "Downloads" is semicolon-separated. - Attempt to import "norwegian.csv" in "Downloads" via the canvas UI. - It should work! Change-Id: I0ed4b6d7547b605712278a08dadbd6f41b86376b Reviewed-on: https://gerrit.instructure.com/143007 Tested-by: Jenkins Reviewed-by: Augusto Callejas <acallejas@instructure.com> Reviewed-by: Neil Gupta <ngupta@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-03-09 03:42:32 +08:00
changed = ->(k) { outcome[k].present? && outcome[k] != prior_rubric[k] }
rubric_change = changed.call(:ratings) || changed.call(:mastery_points)
model.rubric_criterion = create_rubric(outcome[:ratings], outcome[:mastery_points]) if rubric_change
allow updating outcomes via csv closes OUT-1555 Test plan: Basic behavior: - follow instructions in g/140107 to do basic import of outcomes into a context - make changes to the csv file: - change titles/descriptions/ratings/etc. - change parents of groups and of outcomes - re-run the import command with the updated csv file - verify that changes can be seen in the console or in the canvas UI Subcontext behavior: - check LearningOutcome.count and LearningOutcomeGroup.count in the rails console - import the csv into a subaccount or course under the account used above - verify that the outcomes and groups are imported - verify that outcomes are re-used and groups are re-created by viewing LearningOutcome.count and LearningOutcomeGroup.count again; the former should be unchanged and the latter increased by the # of groups in the csv file Export/Import behavior: - generate a csv file using Account Settings/Reports/Outcome Export - make changes to the csv file, including updating vendor_guids for outcomes/groups in the file - import the csv and verify that changes are made using the UI and console (you can check vendor_guid changes by looking at LearningOutcome.find($canvas_id) Error behavior - Attempt to import the exported csv into the subcontext account or course from the second set of steps, verifying - groups cannot be imported or updated, with error that group was found in a different context - properties of outcomes cannot be updated, with error that fields for outcome from another context cannot be updated - non-existent canvas ids lead to errors Change-Id: Iceca02ec5157a4d187a2b9fd11b3415c84613ffa Reviewed-on: https://gerrit.instructure.com/141836 Tested-by: Jenkins Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Augusto Callejas <acallejas@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-02-25 11:26:55 +08:00
if model.context == context
model.outcome_import_id = outcome_import_id
model.save!
elsif non_vendor_guid_changes?(model)
allow updating outcomes via csv closes OUT-1555 Test plan: Basic behavior: - follow instructions in g/140107 to do basic import of outcomes into a context - make changes to the csv file: - change titles/descriptions/ratings/etc. - change parents of groups and of outcomes - re-run the import command with the updated csv file - verify that changes can be seen in the console or in the canvas UI Subcontext behavior: - check LearningOutcome.count and LearningOutcomeGroup.count in the rails console - import the csv into a subaccount or course under the account used above - verify that the outcomes and groups are imported - verify that outcomes are re-used and groups are re-created by viewing LearningOutcome.count and LearningOutcomeGroup.count again; the former should be unchanged and the latter increased by the # of groups in the csv file Export/Import behavior: - generate a csv file using Account Settings/Reports/Outcome Export - make changes to the csv file, including updating vendor_guids for outcomes/groups in the file - import the csv and verify that changes are made using the UI and console (you can check vendor_guid changes by looking at LearningOutcome.find($canvas_id) Error behavior - Attempt to import the exported csv into the subcontext account or course from the second set of steps, verifying - groups cannot be imported or updated, with error that group was found in a different context - properties of outcomes cannot be updated, with error that fields for outcome from another context cannot be updated - non-existent canvas ids lead to errors Change-Id: Iceca02ec5157a4d187a2b9fd11b3415c84613ffa Reviewed-on: https://gerrit.instructure.com/141836 Tested-by: Jenkins Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Augusto Callejas <acallejas@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-02-25 11:26:55 +08:00
raise InvalidDataError, I18n.t(
'Cannot modify outcome from another context: %{changes}; outcome must be modified in %{context}',
changes: model.changes.keys.inspect,
context: if model.context.present?
I18n.t('"%{name}"', name: model.context.name)
else
I18n.t('the global context')
end
allow updating outcomes via csv closes OUT-1555 Test plan: Basic behavior: - follow instructions in g/140107 to do basic import of outcomes into a context - make changes to the csv file: - change titles/descriptions/ratings/etc. - change parents of groups and of outcomes - re-run the import command with the updated csv file - verify that changes can be seen in the console or in the canvas UI Subcontext behavior: - check LearningOutcome.count and LearningOutcomeGroup.count in the rails console - import the csv into a subaccount or course under the account used above - verify that the outcomes and groups are imported - verify that outcomes are re-used and groups are re-created by viewing LearningOutcome.count and LearningOutcomeGroup.count again; the former should be unchanged and the latter increased by the # of groups in the csv file Export/Import behavior: - generate a csv file using Account Settings/Reports/Outcome Export - make changes to the csv file, including updating vendor_guids for outcomes/groups in the file - import the csv and verify that changes are made using the UI and console (you can check vendor_guid changes by looking at LearningOutcome.find($canvas_id) Error behavior - Attempt to import the exported csv into the subcontext account or course from the second set of steps, verifying - groups cannot be imported or updated, with error that group was found in a different context - properties of outcomes cannot be updated, with error that fields for outcome from another context cannot be updated - non-existent canvas ids lead to errors Change-Id: Iceca02ec5157a4d187a2b9fd11b3415c84613ffa Reviewed-on: https://gerrit.instructure.com/141836 Tested-by: Jenkins Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Augusto Callejas <acallejas@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-02-25 11:26:55 +08:00
)
end
parents = [] if outcome[:workflow_state] == 'deleted'
update_outcome_parents(model, parents)
model
end
private
# There is no representation for `nil` in the export format. All nil values
# are seen as "" when re-imported. We don't want to change those values when
# we re-import (and we want to be able to link to those values from other
# contexts), so we infer cases where `nil` was probably exported as ""
def infer_nil_value(model, key, outcome)
prior = model.send(key)
current = outcome[key]
if current.blank? && prior.blank?
prior
else
current
end
end
def non_vendor_guid_changes?(model)
model.has_changes_to_save? && !(model.changes_to_save.length == 1 &&
model.changes_to_save.key?('vendor_guid'))
end
allow updating outcomes via csv closes OUT-1555 Test plan: Basic behavior: - follow instructions in g/140107 to do basic import of outcomes into a context - make changes to the csv file: - change titles/descriptions/ratings/etc. - change parents of groups and of outcomes - re-run the import command with the updated csv file - verify that changes can be seen in the console or in the canvas UI Subcontext behavior: - check LearningOutcome.count and LearningOutcomeGroup.count in the rails console - import the csv into a subaccount or course under the account used above - verify that the outcomes and groups are imported - verify that outcomes are re-used and groups are re-created by viewing LearningOutcome.count and LearningOutcomeGroup.count again; the former should be unchanged and the latter increased by the # of groups in the csv file Export/Import behavior: - generate a csv file using Account Settings/Reports/Outcome Export - make changes to the csv file, including updating vendor_guids for outcomes/groups in the file - import the csv and verify that changes are made using the UI and console (you can check vendor_guid changes by looking at LearningOutcome.find($canvas_id) Error behavior - Attempt to import the exported csv into the subcontext account or course from the second set of steps, verifying - groups cannot be imported or updated, with error that group was found in a different context - properties of outcomes cannot be updated, with error that fields for outcome from another context cannot be updated - non-existent canvas ids lead to errors Change-Id: Iceca02ec5157a4d187a2b9fd11b3415c84613ffa Reviewed-on: https://gerrit.instructure.com/141836 Tested-by: Jenkins Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Augusto Callejas <acallejas@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-02-25 11:26:55 +08:00
def find_prior_outcome(outcome)
match = /canvas_outcome:(\d+)/.match(outcome[:vendor_guid])
if match
canvas_id = match[1]
allow updating outcomes via csv closes OUT-1555 Test plan: Basic behavior: - follow instructions in g/140107 to do basic import of outcomes into a context - make changes to the csv file: - change titles/descriptions/ratings/etc. - change parents of groups and of outcomes - re-run the import command with the updated csv file - verify that changes can be seen in the console or in the canvas UI Subcontext behavior: - check LearningOutcome.count and LearningOutcomeGroup.count in the rails console - import the csv into a subaccount or course under the account used above - verify that the outcomes and groups are imported - verify that outcomes are re-used and groups are re-created by viewing LearningOutcome.count and LearningOutcomeGroup.count again; the former should be unchanged and the latter increased by the # of groups in the csv file Export/Import behavior: - generate a csv file using Account Settings/Reports/Outcome Export - make changes to the csv file, including updating vendor_guids for outcomes/groups in the file - import the csv and verify that changes are made using the UI and console (you can check vendor_guid changes by looking at LearningOutcome.find($canvas_id) Error behavior - Attempt to import the exported csv into the subcontext account or course from the second set of steps, verifying - groups cannot be imported or updated, with error that group was found in a different context - properties of outcomes cannot be updated, with error that fields for outcome from another context cannot be updated - non-existent canvas ids lead to errors Change-Id: Iceca02ec5157a4d187a2b9fd11b3415c84613ffa Reviewed-on: https://gerrit.instructure.com/141836 Tested-by: Jenkins Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Augusto Callejas <acallejas@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-02-25 11:26:55 +08:00
begin
LearningOutcome.find(canvas_id)
allow updating outcomes via csv closes OUT-1555 Test plan: Basic behavior: - follow instructions in g/140107 to do basic import of outcomes into a context - make changes to the csv file: - change titles/descriptions/ratings/etc. - change parents of groups and of outcomes - re-run the import command with the updated csv file - verify that changes can be seen in the console or in the canvas UI Subcontext behavior: - check LearningOutcome.count and LearningOutcomeGroup.count in the rails console - import the csv into a subaccount or course under the account used above - verify that the outcomes and groups are imported - verify that outcomes are re-used and groups are re-created by viewing LearningOutcome.count and LearningOutcomeGroup.count again; the former should be unchanged and the latter increased by the # of groups in the csv file Export/Import behavior: - generate a csv file using Account Settings/Reports/Outcome Export - make changes to the csv file, including updating vendor_guids for outcomes/groups in the file - import the csv and verify that changes are made using the UI and console (you can check vendor_guid changes by looking at LearningOutcome.find($canvas_id) Error behavior - Attempt to import the exported csv into the subcontext account or course from the second set of steps, verifying - groups cannot be imported or updated, with error that group was found in a different context - properties of outcomes cannot be updated, with error that fields for outcome from another context cannot be updated - non-existent canvas ids lead to errors Change-Id: Iceca02ec5157a4d187a2b9fd11b3415c84613ffa Reviewed-on: https://gerrit.instructure.com/141836 Tested-by: Jenkins Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Augusto Callejas <acallejas@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-02-25 11:26:55 +08:00
rescue ActiveRecord::RecordNotFound
raise InvalidDataError, I18n.t(
'Outcome with canvas id "%{id}" not found',
id: outcome[:canvas_id]
)
end
else
vendor_guid = outcome[:vendor_guid]
prior = LearningOutcome.where(vendor_guid: vendor_guid).active_first.first
return prior if prior
LearningOutcome.new(vendor_guid: vendor_guid)
allow updating outcomes via csv closes OUT-1555 Test plan: Basic behavior: - follow instructions in g/140107 to do basic import of outcomes into a context - make changes to the csv file: - change titles/descriptions/ratings/etc. - change parents of groups and of outcomes - re-run the import command with the updated csv file - verify that changes can be seen in the console or in the canvas UI Subcontext behavior: - check LearningOutcome.count and LearningOutcomeGroup.count in the rails console - import the csv into a subaccount or course under the account used above - verify that the outcomes and groups are imported - verify that outcomes are re-used and groups are re-created by viewing LearningOutcome.count and LearningOutcomeGroup.count again; the former should be unchanged and the latter increased by the # of groups in the csv file Export/Import behavior: - generate a csv file using Account Settings/Reports/Outcome Export - make changes to the csv file, including updating vendor_guids for outcomes/groups in the file - import the csv and verify that changes are made using the UI and console (you can check vendor_guid changes by looking at LearningOutcome.find($canvas_id) Error behavior - Attempt to import the exported csv into the subcontext account or course from the second set of steps, verifying - groups cannot be imported or updated, with error that group was found in a different context - properties of outcomes cannot be updated, with error that fields for outcome from another context cannot be updated - non-existent canvas ids lead to errors Change-Id: Iceca02ec5157a4d187a2b9fd11b3415c84613ffa Reviewed-on: https://gerrit.instructure.com/141836 Tested-by: Jenkins Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Augusto Callejas <acallejas@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-02-25 11:26:55 +08:00
end
end
def find_prior_group(group)
vendor_guid = group[:vendor_guid]
prior = LearningOutcomeGroup.where(context: context).where(vendor_guid: vendor_guid).active_first.first
return prior if prior
match = /canvas_outcome_group:(\d+)/.match(vendor_guid)
if match
canvas_id = match[1]
allow updating outcomes via csv closes OUT-1555 Test plan: Basic behavior: - follow instructions in g/140107 to do basic import of outcomes into a context - make changes to the csv file: - change titles/descriptions/ratings/etc. - change parents of groups and of outcomes - re-run the import command with the updated csv file - verify that changes can be seen in the console or in the canvas UI Subcontext behavior: - check LearningOutcome.count and LearningOutcomeGroup.count in the rails console - import the csv into a subaccount or course under the account used above - verify that the outcomes and groups are imported - verify that outcomes are re-used and groups are re-created by viewing LearningOutcome.count and LearningOutcomeGroup.count again; the former should be unchanged and the latter increased by the # of groups in the csv file Export/Import behavior: - generate a csv file using Account Settings/Reports/Outcome Export - make changes to the csv file, including updating vendor_guids for outcomes/groups in the file - import the csv and verify that changes are made using the UI and console (you can check vendor_guid changes by looking at LearningOutcome.find($canvas_id) Error behavior - Attempt to import the exported csv into the subcontext account or course from the second set of steps, verifying - groups cannot be imported or updated, with error that group was found in a different context - properties of outcomes cannot be updated, with error that fields for outcome from another context cannot be updated - non-existent canvas ids lead to errors Change-Id: Iceca02ec5157a4d187a2b9fd11b3415c84613ffa Reviewed-on: https://gerrit.instructure.com/141836 Tested-by: Jenkins Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Augusto Callejas <acallejas@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-02-25 11:26:55 +08:00
begin
by_id = LearningOutcomeGroup.find(canvas_id)
return by_id if by_id.context == context
allow updating outcomes via csv closes OUT-1555 Test plan: Basic behavior: - follow instructions in g/140107 to do basic import of outcomes into a context - make changes to the csv file: - change titles/descriptions/ratings/etc. - change parents of groups and of outcomes - re-run the import command with the updated csv file - verify that changes can be seen in the console or in the canvas UI Subcontext behavior: - check LearningOutcome.count and LearningOutcomeGroup.count in the rails console - import the csv into a subaccount or course under the account used above - verify that the outcomes and groups are imported - verify that outcomes are re-used and groups are re-created by viewing LearningOutcome.count and LearningOutcomeGroup.count again; the former should be unchanged and the latter increased by the # of groups in the csv file Export/Import behavior: - generate a csv file using Account Settings/Reports/Outcome Export - make changes to the csv file, including updating vendor_guids for outcomes/groups in the file - import the csv and verify that changes are made using the UI and console (you can check vendor_guid changes by looking at LearningOutcome.find($canvas_id) Error behavior - Attempt to import the exported csv into the subcontext account or course from the second set of steps, verifying - groups cannot be imported or updated, with error that group was found in a different context - properties of outcomes cannot be updated, with error that fields for outcome from another context cannot be updated - non-existent canvas ids lead to errors Change-Id: Iceca02ec5157a4d187a2b9fd11b3415c84613ffa Reviewed-on: https://gerrit.instructure.com/141836 Tested-by: Jenkins Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Augusto Callejas <acallejas@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-02-25 11:26:55 +08:00
rescue ActiveRecord::RecordNotFound
raise InvalidDataError, I18n.t(
'Outcome group with canvas id %{id} not found',
id: group[:canvas_id]
)
end
end
LearningOutcomeGroup.new(vendor_guid: vendor_guid, context: context)
end
i18n tweaks for outcome import Fixes OUT-2010 Test Plan - Save an .xlsx version of demo.csv: $ open spec/lib/outcomes/fixtures A finder window will open. Right click "demo.csv", and select "Open With..." > "Excel" Then "Save As" and specify the format as ".xslx". Remember where you saved this file. I recommend you save it to "Downloads" - Change your system language to Norwegian: - on OSX, go to "Language & Region" in System Preferences - click the '+' below "Preferred Languages" - Choose "Norsk bokmål" - Click "Add" - When it asks if you want to use it as a primary language, click "Use Norwegian Bokmål" - Keep the preferences window open so you can switch back. - Click the back button on the top left. - Don't restart your system when prompted. - Don't close the settings window, it should still remain in English so you can switch back at the end. - **Google Translate is now your best friend.** - Make sure that Excel is not running. - Open your previously saved file. - The excel window should have all menu options in Norwegian. - Choose Fil > Lagre Sum... to save as - Click the arrow next to "Arkiver som" to select a file path. - Choose the "Nedlastinger" (Downloads) directory, and set the name under "Arkiver som" to "norwegian" - Under "Filformat", select "Kommadelte verdier (.csv)" - Save by clicking "Arkiver" - Quit excel. You will see a dialog that says: "Vil du lagre endringene i dokumentet norwegian.csv?" Click: "Ikke lagre" - Change your system language back to English (optional, don't switch back for hard-mode test plan): - Go back to "Language & Region" in System Preferences - Click "Norsk bokmål" - Click the minus button. - Check that the file in "Downloads" is semicolon-separated. - Attempt to import "norwegian.csv" in "Downloads" via the canvas UI. - It should work! Change-Id: I0ed4b6d7547b605712278a08dadbd6f41b86376b Reviewed-on: https://gerrit.instructure.com/143007 Tested-by: Jenkins Reviewed-by: Augusto Callejas <acallejas@instructure.com> Reviewed-by: Neil Gupta <ngupta@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-03-09 03:42:32 +08:00
def create_rubric(ratings, mastery_points)
rubric = {}
rubric[:enable] = true
i18n tweaks for outcome import Fixes OUT-2010 Test Plan - Save an .xlsx version of demo.csv: $ open spec/lib/outcomes/fixtures A finder window will open. Right click "demo.csv", and select "Open With..." > "Excel" Then "Save As" and specify the format as ".xslx". Remember where you saved this file. I recommend you save it to "Downloads" - Change your system language to Norwegian: - on OSX, go to "Language & Region" in System Preferences - click the '+' below "Preferred Languages" - Choose "Norsk bokmål" - Click "Add" - When it asks if you want to use it as a primary language, click "Use Norwegian Bokmål" - Keep the preferences window open so you can switch back. - Click the back button on the top left. - Don't restart your system when prompted. - Don't close the settings window, it should still remain in English so you can switch back at the end. - **Google Translate is now your best friend.** - Make sure that Excel is not running. - Open your previously saved file. - The excel window should have all menu options in Norwegian. - Choose Fil > Lagre Sum... to save as - Click the arrow next to "Arkiver som" to select a file path. - Choose the "Nedlastinger" (Downloads) directory, and set the name under "Arkiver som" to "norwegian" - Under "Filformat", select "Kommadelte verdier (.csv)" - Save by clicking "Arkiver" - Quit excel. You will see a dialog that says: "Vil du lagre endringene i dokumentet norwegian.csv?" Click: "Ikke lagre" - Change your system language back to English (optional, don't switch back for hard-mode test plan): - Go back to "Language & Region" in System Preferences - Click "Norsk bokmål" - Click the minus button. - Check that the file in "Downloads" is semicolon-separated. - Attempt to import "norwegian.csv" in "Downloads" via the canvas UI. - It should work! Change-Id: I0ed4b6d7547b605712278a08dadbd6f41b86376b Reviewed-on: https://gerrit.instructure.com/143007 Tested-by: Jenkins Reviewed-by: Augusto Callejas <acallejas@instructure.com> Reviewed-by: Neil Gupta <ngupta@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-03-09 03:42:32 +08:00
rubric[:mastery_points] = mastery_points
rubric[:ratings] = ratings.map.with_index { |v, i| [i, v] }.to_h
rubric
end
def root_parent
@root ||= LearningOutcomeGroup.find_or_create_root(context, true)
end
def find_parents(object)
if object[:parent_guids].nil? || object[:parent_guids].blank?
group = [LearningOutcomeGroup.find(object[:learning_outcome_group_id])] if object[:learning_outcome_group_id]
group ||= [root_parent]
return group
end
guids = object[:parent_guids].strip.split
LearningOutcomeGroup.where(context: context, outcome_import_id: outcome_import_id)
.where(vendor_guid: guids)
.tap do |parents|
if parents.length < guids.length
missing = guids - parents.map(&:vendor_guid)
raise InvalidDataError, I18n.t(
'Parent references not found prior to this row: %{missing}',
missing: missing.inspect,
)
allow updating outcomes via csv closes OUT-1555 Test plan: Basic behavior: - follow instructions in g/140107 to do basic import of outcomes into a context - make changes to the csv file: - change titles/descriptions/ratings/etc. - change parents of groups and of outcomes - re-run the import command with the updated csv file - verify that changes can be seen in the console or in the canvas UI Subcontext behavior: - check LearningOutcome.count and LearningOutcomeGroup.count in the rails console - import the csv into a subaccount or course under the account used above - verify that the outcomes and groups are imported - verify that outcomes are re-used and groups are re-created by viewing LearningOutcome.count and LearningOutcomeGroup.count again; the former should be unchanged and the latter increased by the # of groups in the csv file Export/Import behavior: - generate a csv file using Account Settings/Reports/Outcome Export - make changes to the csv file, including updating vendor_guids for outcomes/groups in the file - import the csv and verify that changes are made using the UI and console (you can check vendor_guid changes by looking at LearningOutcome.find($canvas_id) Error behavior - Attempt to import the exported csv into the subcontext account or course from the second set of steps, verifying - groups cannot be imported or updated, with error that group was found in a different context - properties of outcomes cannot be updated, with error that fields for outcome from another context cannot be updated - non-existent canvas ids lead to errors Change-Id: Iceca02ec5157a4d187a2b9fd11b3415c84613ffa Reviewed-on: https://gerrit.instructure.com/141836 Tested-by: Jenkins Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Augusto Callejas <acallejas@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-02-25 11:26:55 +08:00
end
end
end
allow updating outcomes via csv closes OUT-1555 Test plan: Basic behavior: - follow instructions in g/140107 to do basic import of outcomes into a context - make changes to the csv file: - change titles/descriptions/ratings/etc. - change parents of groups and of outcomes - re-run the import command with the updated csv file - verify that changes can be seen in the console or in the canvas UI Subcontext behavior: - check LearningOutcome.count and LearningOutcomeGroup.count in the rails console - import the csv into a subaccount or course under the account used above - verify that the outcomes and groups are imported - verify that outcomes are re-used and groups are re-created by viewing LearningOutcome.count and LearningOutcomeGroup.count again; the former should be unchanged and the latter increased by the # of groups in the csv file Export/Import behavior: - generate a csv file using Account Settings/Reports/Outcome Export - make changes to the csv file, including updating vendor_guids for outcomes/groups in the file - import the csv and verify that changes are made using the UI and console (you can check vendor_guid changes by looking at LearningOutcome.find($canvas_id) Error behavior - Attempt to import the exported csv into the subcontext account or course from the second set of steps, verifying - groups cannot be imported or updated, with error that group was found in a different context - properties of outcomes cannot be updated, with error that fields for outcome from another context cannot be updated - non-existent canvas ids lead to errors Change-Id: Iceca02ec5157a4d187a2b9fd11b3415c84613ffa Reviewed-on: https://gerrit.instructure.com/141836 Tested-by: Jenkins Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Augusto Callejas <acallejas@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-02-25 11:26:55 +08:00
def context_visible?(other_context)
return true if other_context.nil?
allow updating outcomes via csv closes OUT-1555 Test plan: Basic behavior: - follow instructions in g/140107 to do basic import of outcomes into a context - make changes to the csv file: - change titles/descriptions/ratings/etc. - change parents of groups and of outcomes - re-run the import command with the updated csv file - verify that changes can be seen in the console or in the canvas UI Subcontext behavior: - check LearningOutcome.count and LearningOutcomeGroup.count in the rails console - import the csv into a subaccount or course under the account used above - verify that the outcomes and groups are imported - verify that outcomes are re-used and groups are re-created by viewing LearningOutcome.count and LearningOutcomeGroup.count again; the former should be unchanged and the latter increased by the # of groups in the csv file Export/Import behavior: - generate a csv file using Account Settings/Reports/Outcome Export - make changes to the csv file, including updating vendor_guids for outcomes/groups in the file - import the csv and verify that changes are made using the UI and console (you can check vendor_guid changes by looking at LearningOutcome.find($canvas_id) Error behavior - Attempt to import the exported csv into the subcontext account or course from the second set of steps, verifying - groups cannot be imported or updated, with error that group was found in a different context - properties of outcomes cannot be updated, with error that fields for outcome from another context cannot be updated - non-existent canvas ids lead to errors Change-Id: Iceca02ec5157a4d187a2b9fd11b3415c84613ffa Reviewed-on: https://gerrit.instructure.com/141836 Tested-by: Jenkins Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Augusto Callejas <acallejas@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-02-25 11:26:55 +08:00
other_context == context || context.account_chain.include?(other_context)
end
allow updating outcomes via csv closes OUT-1555 Test plan: Basic behavior: - follow instructions in g/140107 to do basic import of outcomes into a context - make changes to the csv file: - change titles/descriptions/ratings/etc. - change parents of groups and of outcomes - re-run the import command with the updated csv file - verify that changes can be seen in the console or in the canvas UI Subcontext behavior: - check LearningOutcome.count and LearningOutcomeGroup.count in the rails console - import the csv into a subaccount or course under the account used above - verify that the outcomes and groups are imported - verify that outcomes are re-used and groups are re-created by viewing LearningOutcome.count and LearningOutcomeGroup.count again; the former should be unchanged and the latter increased by the # of groups in the csv file Export/Import behavior: - generate a csv file using Account Settings/Reports/Outcome Export - make changes to the csv file, including updating vendor_guids for outcomes/groups in the file - import the csv and verify that changes are made using the UI and console (you can check vendor_guid changes by looking at LearningOutcome.find($canvas_id) Error behavior - Attempt to import the exported csv into the subcontext account or course from the second set of steps, verifying - groups cannot be imported or updated, with error that group was found in a different context - properties of outcomes cannot be updated, with error that fields for outcome from another context cannot be updated - non-existent canvas ids lead to errors Change-Id: Iceca02ec5157a4d187a2b9fd11b3415c84613ffa Reviewed-on: https://gerrit.instructure.com/141836 Tested-by: Jenkins Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Augusto Callejas <acallejas@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-02-25 11:26:55 +08:00
def update_outcome_parents(outcome, parents)
existing_links = ContentTag.learning_outcome_links.where(context: context, content: outcome)
next_parent_ids = parents.map(&:id)
resurrect = existing_links
.where(associated_asset_id: next_parent_ids)
.where(associated_asset_type: 'LearningOutcomeGroup')
.where(workflow_state: 'deleted')
resurrect.update_all(workflow_state: 'active')
# add new parents before removing old to avoid deleting last link
# to an aligned outcome
existing_parent_ids = existing_links.pluck(:associated_asset_id)
new_parents = parents.reject { |p| existing_parent_ids.include?(p.id) }
new_parents.each { |p| p.add_outcome(outcome) }
kill = existing_links
.where.not(associated_asset_id: next_parent_ids)
.where(associated_asset_type: 'LearningOutcomeGroup')
.where(workflow_state: 'active')
kill.destroy_all
allow updating outcomes via csv closes OUT-1555 Test plan: Basic behavior: - follow instructions in g/140107 to do basic import of outcomes into a context - make changes to the csv file: - change titles/descriptions/ratings/etc. - change parents of groups and of outcomes - re-run the import command with the updated csv file - verify that changes can be seen in the console or in the canvas UI Subcontext behavior: - check LearningOutcome.count and LearningOutcomeGroup.count in the rails console - import the csv into a subaccount or course under the account used above - verify that the outcomes and groups are imported - verify that outcomes are re-used and groups are re-created by viewing LearningOutcome.count and LearningOutcomeGroup.count again; the former should be unchanged and the latter increased by the # of groups in the csv file Export/Import behavior: - generate a csv file using Account Settings/Reports/Outcome Export - make changes to the csv file, including updating vendor_guids for outcomes/groups in the file - import the csv and verify that changes are made using the UI and console (you can check vendor_guid changes by looking at LearningOutcome.find($canvas_id) Error behavior - Attempt to import the exported csv into the subcontext account or course from the second set of steps, verifying - groups cannot be imported or updated, with error that group was found in a different context - properties of outcomes cannot be updated, with error that fields for outcome from another context cannot be updated - non-existent canvas ids lead to errors Change-Id: Iceca02ec5157a4d187a2b9fd11b3415c84613ffa Reviewed-on: https://gerrit.instructure.com/141836 Tested-by: Jenkins Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Augusto Callejas <acallejas@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-02-25 11:26:55 +08:00
end
allow updating outcomes via csv closes OUT-1555 Test plan: Basic behavior: - follow instructions in g/140107 to do basic import of outcomes into a context - make changes to the csv file: - change titles/descriptions/ratings/etc. - change parents of groups and of outcomes - re-run the import command with the updated csv file - verify that changes can be seen in the console or in the canvas UI Subcontext behavior: - check LearningOutcome.count and LearningOutcomeGroup.count in the rails console - import the csv into a subaccount or course under the account used above - verify that the outcomes and groups are imported - verify that outcomes are re-used and groups are re-created by viewing LearningOutcome.count and LearningOutcomeGroup.count again; the former should be unchanged and the latter increased by the # of groups in the csv file Export/Import behavior: - generate a csv file using Account Settings/Reports/Outcome Export - make changes to the csv file, including updating vendor_guids for outcomes/groups in the file - import the csv and verify that changes are made using the UI and console (you can check vendor_guid changes by looking at LearningOutcome.find($canvas_id) Error behavior - Attempt to import the exported csv into the subcontext account or course from the second set of steps, verifying - groups cannot be imported or updated, with error that group was found in a different context - properties of outcomes cannot be updated, with error that fields for outcome from another context cannot be updated - non-existent canvas ids lead to errors Change-Id: Iceca02ec5157a4d187a2b9fd11b3415c84613ffa Reviewed-on: https://gerrit.instructure.com/141836 Tested-by: Jenkins Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Augusto Callejas <acallejas@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
2018-02-25 11:26:55 +08:00
def outcome_import_id
@outcome_import_id ||= @import&.id || SecureRandom.random_number(2**32)
end
end
end