Skip to content

Commit

Permalink
allow for creating pseudonyms on consortium users
Browse files Browse the repository at this point in the history
refs CORE-3093

test plan
 - specs should pass

Change-Id: I1eb0345f9672e8eae842bfd0a3cf612d7b8552b7
Reviewed-on: https://gerrit.instructure.com/187495
Tested-by: Jenkins
Reviewed-by: James Williams <[email protected]>
QA-Review: James Williams <[email protected]>
Product-Review: James Williams <[email protected]>
  • Loading branch information
roor0 committed Jun 22, 2019
1 parent a3f09b9 commit 282f6ed
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions lib/sis/user_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,19 @@ def process_batch

pseudo = @root_account.pseudonyms.where(sis_user_id: user_row.user_id.to_s).take
pseudo_by_login = @root_account.pseudonyms.active.by_unique_id(user_row.login_id).take
pseudo_by_integration = nil
pseudo_by_integration = @root_account.pseudonyms.where(integration_id: user_row.integration_id.to_s).take if user_row.integration_id.present?
status_is_active = !(user_row.status =~ /\Adeleted/i)
pseudo ||= pseudo_by_login

status_is_active = !(user_row.status =~ /\Adeleted/i)
if pseudo_by_integration && status_is_active && pseudo_by_integration != pseudo
id_message = pseudo_by_integration.sis_user_id ? 'SIS ID' : 'Canvas ID'
user_id = pseudo_by_integration.sis_user_id || pseudo_by_integration.user_id
message = I18n.t("An existing Canvas user with the %{user_id} has already claimed %{other_user_id}'s requested integration_id, skipping", user_id: "#{id_message} #{user_id.to_s}", other_user_id: user_row.user_id)
@messages << SisBatch.build_error(user_row.csv, message, sis_batch: @batch, row: user_row.lineno, row_info: user_row.row_info)
next
end

if pseudo
if pseudo.sis_user_id && pseudo.sis_user_id != user_row.user_id
message = I18n.t("An existing Canvas user with the SIS ID %{user_id} has already claimed %{other_user_id}'s user_id requested login information, skipping", user_id: pseudo.sis_user_id, other_user_id: user_row.user_id)
Expand All @@ -147,10 +157,15 @@ def process_batch
user.short_name = user_row.short_name if user_row.short_name.present?
end
else
user = User.new
user.name = infer_user_name(user_row)
user.sortable_name = infer_sortable_name(user_row)
user.short_name = user_row.short_name if user_row.short_name.present?
user = nil
pseudo = Pseudonym.new
user = other_user(user_row, pseudo) if user_row.integration_id.present?
unless user
user = User.new
user.name = infer_user_name(user_row)
user.sortable_name = infer_sortable_name(user_row)
user.short_name = user_row.short_name if user_row.short_name.present?
end
end

# we just leave all users registered now
Expand All @@ -174,7 +189,6 @@ def process_batch
should_update_account_associations = remove_enrollments_if_last_login(user, user_row.user_id)
end

pseudo ||= Pseudonym.new
pseudo.unique_id = user_row.login_id unless pseudo.stuck_sis_fields.include?(:unique_id)
if user_row.authentication_provider_id.present?
unless @authentication_providers.key?(user_row.authentication_provider_id)
Expand All @@ -194,15 +208,6 @@ def process_batch
pseudo.authentication_provider = nil
end
pseudo.sis_user_id = user_row.user_id
pseudo_by_integration = nil
pseudo_by_integration = @root_account.pseudonyms.where(integration_id: user_row.integration_id.to_s).take if user_row.integration_id.present?
if pseudo_by_integration && status_is_active && pseudo_by_integration != pseudo
id_message = pseudo_by_integration.sis_user_id ? 'SIS ID' : 'Canvas ID'
user_id = pseudo_by_integration.sis_user_id || pseudo_by_integration.user_id
message = I18n.t("An existing Canvas user with the %{user_id} has already claimed %{other_user_id}'s requested integration_id, skipping", user_id: "#{id_message} #{user_id.to_s}", other_user_id: user_row.user_id)
@messages << SisBatch.build_error(user_row.csv, message, sis_batch: @batch, row: user_row.lineno, row_info: user_row.row_info)
next
end
pseudo.integration_id = user_row.integration_id if user_row.integration_id.present?
pseudo.account = @root_account
pseudo.workflow_state = status_is_active ? 'active' : 'deleted'
Expand Down Expand Up @@ -362,6 +367,8 @@ def process_batch
end
end

def other_user(_user_row, _pseudo); end

def maybe_write_roll_back_data
if @roll_back_data.count > 1000
SisBatchRollBackData.bulk_insert_roll_back_data(@roll_back_data)
Expand Down

0 comments on commit 282f6ed

Please sign in to comment.