Skip to content

Commit 9cf8aa2

Browse files
committed
allow adding course users by sis id
test plan: * create a user and login with a sis id * confirm that the user can be added to a course through the course 'People' page, by including their sis id in the list (just as with the login id) closes #CNVS-7086 Change-Id: Ia4369ba5e78083c233b3921aa1b9246f2db6824e Reviewed-on: https://gerrit.instructure.com/22647 Reviewed-by: Cody Cutrer <cody@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Jeremy Stanley <jeremy@instructure.com> Product-Review: Jeremy Stanley <jeremy@instructure.com> QA-Review: Clare Strong <clare@instructure.com>
1 parent 8dc7151 commit 9cf8aa2

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

lib/user_list.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,13 @@ def resolve
148148
# Search for matching pseudonyms
149149
Shard.partition_by_shard(all_account_ids) do |account_ids|
150150
Pseudonym.active.
151-
select('unique_id AS address, users.name AS name, user_id, account_id').
151+
select('unique_id AS address, users.name AS name, user_id, account_id, sis_user_id').
152152
joins(:user).
153-
where("pseudonyms.workflow_state='active' AND LOWER(unique_id) IN (?) AND account_id IN (?)", @addresses.map {|x| x[:address].downcase}, account_ids).
153+
where("pseudonyms.workflow_state='active' AND (LOWER(unique_id) IN (?) OR sis_user_id IN (?)) AND account_id IN (?)", @addresses.map {|x| x[:address].downcase}, @addresses.map {|x| x[:address]}, account_ids).
154154
map { |pseudonym| pseudonym.attributes.symbolize_keys }.each do |login|
155-
addresses = @addresses.select { |a| a[:address].downcase == login[:address].downcase }
155+
addresses = @addresses.select { |a| a[:address].downcase == login[:address].downcase ||
156+
a[:address] == login[:sis_user_id]}
157+
login.delete(:sis_user_id)
156158
addresses.each do |address|
157159
# already found a matching pseudonym
158160
if address[:user_id]

spec/lib/user_list_spec.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,25 @@
138138
ul.duplicate_addresses.length.should == 1
139139
end
140140

141-
it "should process login ids and email addresses" do
141+
it "should process login ids, SIS ids, and email addresses" do
142142
user = User.create!(:name => 'A 112351243')
143143
user.pseudonyms.create!(:unique_id => "A112351243", :account => @account)
144144
user = User.create!(:name => 'user 1')
145145
user.pseudonyms.create!(:unique_id => "user1", :account => @account)
146-
ul = UserList.new regular + "," + %{user1,test@example.com,A112351243,"thomas walsh" <test2@example.com>, "walsh, thomas" <test3@example.com>}, :root_account => @account
146+
user = User.create!(:name => 'sneaky hobbitses')
147+
p = user.pseudonyms.create!(:unique_id => "whatever", :account => @account)
148+
p.sis_user_id = '9001'
149+
p.save!
150+
151+
ul = UserList.new regular + "," + %{user1,test@example.com,A112351243,"thomas walsh" <test2@example.com>, 9001, "walsh, thomas" <test3@example.com>}, :root_account => @account
147152
ul.addresses.map{|x| [x[:name], x[:address], x[:type]]}.should eql([
148153
["Shaw, Ryan", "ryankshaw@gmail.com", :email],
149154
["Last, First", "lastfirst@gmail.com", :email],
150155
["user 1", "user1", :pseudonym],
151156
[nil, "test@example.com", :email],
152157
["A 112351243", "A112351243", :pseudonym],
153158
["thomas walsh", "test2@example.com", :email],
159+
["sneaky hobbitses", "whatever", :pseudonym],
154160
["walsh, thomas", "test3@example.com", :email]])
155161
ul.errors.should == []
156162
ul.duplicate_addresses.should == []

0 commit comments

Comments
 (0)