case-insensitive lookups when adding users to course, fixes #4980
Change-Id: I676ce5c7e2735a3d240dcd53ec5021140edaf945 Reviewed-on: https://gerrit.instructure.com/5277 Reviewed-by: Cody Cutrer <cody@instructure.com> Tested-by: Hudson <hudson@instructure.com>
This commit is contained in:
parent
1247d10f30
commit
f9c88ae0da
|
@ -56,10 +56,10 @@ class EnrollmentsFromUserList
|
|||
|
||||
# really more of this should be SQL
|
||||
found_channels = {}
|
||||
CommunicationChannel.find(:all, :conditions => {:path => emails, :path_type => 'email', :workflow_state => ['active','unconfirmed']}, :include => {:user => :pseudonyms, :pseudonym => {}}).each do |cc|
|
||||
CommunicationChannel.find(:all, :conditions => "LOWER(path) IN (#{emails.map{|x|Pseudonym.sanitize(x.downcase)}.join(', ')}) AND path_type = 'email' AND communication_channels.workflow_state IN ('active', 'unconfirmed')", :include => {:user => :pseudonyms, :pseudonym => {}}).each do |cc|
|
||||
found_channels[cc.path.downcase] ||= []
|
||||
found_channels[cc.path.downcase] << cc
|
||||
end
|
||||
end if emails.size
|
||||
found_channels.keys.each do |path|
|
||||
found_channels[path] = found_channels[path].sort_by{|some_cc| [(some_cc.active? ? 0 : 1), (some_cc.pseudonym && some_cc.pseudonym.account_id == @course.root_account.id ? 0 : 1), (some_cc.created_at || Time.now)]}.first
|
||||
end
|
||||
|
|
|
@ -74,6 +74,15 @@ describe EnrollmentsFromUserList do
|
|||
enrollments.map(&:user).should be_include(u)
|
||||
end
|
||||
|
||||
it "should check communication channels in a case-insensitive manner" do
|
||||
u = user
|
||||
u.pseudonyms.create!(:account => Account.default, :unique_id => "david_richards", :path => "David_Richards_JR@example.com", :password => "dave4Instructure", :password_confirmation => "dave4Instructure")
|
||||
@el = UserList.new(list_to_parse_with_repeats)
|
||||
enrollments = EnrollmentsFromUserList.process(@el, @course)
|
||||
enrollments.length.should eql(3)
|
||||
enrollments.map(&:user).should be_include(u)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "EnrollmentsFromUserList.process" do
|
||||
|
@ -93,5 +102,5 @@ def list_to_parse
|
|||
end
|
||||
|
||||
def list_to_parse_with_repeats
|
||||
%{david@example.com, "Richards, David" <david_richards@example.com>, David Richards <david_richards_jr@example.com>, david_richards_jr@example.com}
|
||||
%{david@example.com, "Richards, David" <david_richards@example.com>, David Richards <david_richards_jr@example.com>, david_richards_jr@example.com, DAVID@example.com}
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue