canvas-lms/lib/outcomes/import.rb

236 lines
7.5 KiB
Ruby
Raw Normal View History

# 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
include OutcomeImporter
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
OBJECT_ONLY_FIELDS = %i[calculation_method calculation_int ratings].freeze
VALID_WORKFLOWS = ['', '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?
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 "%{guid}" exists in incorrect context',
guid: group[:vendor_guid]
)
end
model.vendor_guid = group[:vendor_guid]
model.title = group[:title]
model.description = group[:description] || ''
model.workflow_state = group[:workflow_state] || 'active'
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 "%{guid}" not in visible context',
guid: outcome[:vendor_guid]
)
end
model.vendor_guid = outcome[:vendor_guid]
model.title = outcome[:title]
model.description = outcome[:description] || ''
model.display_name = outcome[:display_name] || ''
model.calculation_method = outcome[:calculation_method]
model.calculation_int = outcome[:calculation_int]
model.workflow_state ||= 'active' # let removing the outcome_links content tags delete the underlying outcome
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 model.changed?
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
def find_prior_outcome(outcome)
if outcome[:canvas_id].present?
begin
LearningOutcome.find(outcome[:canvas_id])
rescue ActiveRecord::RecordNotFound
raise InvalidDataError, I18n.t(
'Outcome with canvas id "%{id}" not found',
id: outcome[:canvas_id]
)
end
else
LearningOutcome.find_or_initialize_by(
vendor_guid: outcome[:vendor_guid]
)
end
end
def find_prior_group(group)
if group[:canvas_id].present?
begin
LearningOutcomeGroup.find(group[:canvas_id])
rescue ActiveRecord::RecordNotFound
raise InvalidDataError, I18n.t(
'Outcome group with canvas id %{id} not found',
id: group[:canvas_id]
)
end
else
LearningOutcomeGroup.find_or_initialize_by(
vendor_guid: group[:vendor_guid],
context: context
)
end
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)
return [root_parent] if object[:parent_guids].nil? || object[:parent_guids].blank?
guids = object[:parent_guids].strip.split
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
LearningOutcomeGroup.where(context: context, outcome_import_id: outcome_import_id).
where(plural_vendor_clause(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,
)
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)
existing_parent_ids = existing_links.map(&:associated_asset_id)
updated_parent_ids = parents.map(&:id)
new_parents = parents.reject { |p| existing_parent_ids.include?(p.id) }
old_links = existing_links.reject { |l| updated_parent_ids.include?(l.associated_asset_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
new_parents.each { |p| p.add_outcome(outcome) }
old_links.each(&:destroy)
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