allow admins to search for names in other fields
closes #4450, #4762, refs #4497 course.name_like now searches name, sis_source_id, and course_code user.name_like now searches user.name, user.short_name, pseudonym.sis_user_id, pseudonym.unique_id Change-Id: If15255b3745139553a68fa2b6e768b4755394214 Reviewed-on: https://gerrit.instructure.com/4078 Reviewed-by: JT Olds <jt@instructure.com> Tested-by: Hudson <hudson@instructure.com>
This commit is contained in:
parent
3bca161dc5
commit
2bf5c22c5f
|
@ -314,7 +314,7 @@ class Course < ActiveRecord::Base
|
|||
{:limit => limit }
|
||||
}
|
||||
named_scope :name_like, lambda { |name|
|
||||
{ :conditions => wildcard('courses.name', name) }
|
||||
{ :conditions => wildcard('courses.name', 'courses.sis_source_id', 'courses.course_code', name) }
|
||||
}
|
||||
named_scope :needs_account, lambda{|account, limit|
|
||||
{:conditions => {:account_id => nil, :root_account_id => account.id}, :limit => limit }
|
||||
|
|
|
@ -130,7 +130,7 @@ class User < ActiveRecord::Base
|
|||
{:conditions => "enrollments.limit_priveleges_to_course_section IS NULL OR enrollments.limit_priveleges_to_course_section != #{ActiveRecord::Base.connection.quoted_true} OR enrollments.course_section_id IN (#{section_ids.join(",")})" }
|
||||
}
|
||||
named_scope :name_like, lambda { |name|
|
||||
{ :conditions => wildcard('users.name', name) }
|
||||
{ :conditions => ["(", wildcard('users.name', 'users.short_name', name), " OR exists (select 1 from pseudonyms where ", wildcard('pseudonyms.sis_user_id', 'pseudonyms.unique_id', name), " and pseudonyms.user_id = users.id and (", ActiveRecord::Base.send(:sanitize_sql_array, Pseudonym.active.proxy_options[:conditions]), ")))"].join }
|
||||
}
|
||||
named_scope :active, lambda {
|
||||
{ :conditions => ["users.workflow_state != ?", 'deleted'] }
|
||||
|
|
|
@ -653,3 +653,23 @@ describe Course, 'grade_publishing' do
|
|||
"test-jt-data"]
|
||||
end
|
||||
end
|
||||
|
||||
describe Course, 'scoping' do
|
||||
it 'should search by multiple fields' do
|
||||
c1 = Course.new
|
||||
c1.root_account = Account.create
|
||||
c1.name = "name1"
|
||||
c1.sis_source_id = "sisid1"
|
||||
c1.course_code = "code1"
|
||||
c1.save
|
||||
c2 = Course.new
|
||||
c2.root_account = Account.create
|
||||
c2.name = "name2"
|
||||
c2.course_code = "code2"
|
||||
c2.sis_source_id = "sisid2"
|
||||
c2.save
|
||||
Course.name_like("name1").map(&:id).should == [c1.id]
|
||||
Course.name_like("sisid2").map(&:id).should == [c2.id]
|
||||
Course.name_like("code1").map(&:id).should == [c1.id]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -177,6 +177,69 @@ describe User do
|
|||
user.associated_account_ids.include?(account1.id).should be_true
|
||||
user.associated_account_ids.include?(account2.id).should be_false
|
||||
end
|
||||
|
||||
it "should search by multiple fields" do
|
||||
@account = Account.create!
|
||||
user1 = User.create! :name => "longname1", :short_name => "shortname1"
|
||||
user1.register!
|
||||
user2 = User.create! :name => "longname2", :short_name => "shortname2"
|
||||
user2.register!
|
||||
|
||||
User.name_like("longname1").map(&:id).should == [user1.id]
|
||||
User.name_like("shortname2").map(&:id).should == [user2.id]
|
||||
User.name_like("sisid1").map(&:id).should == []
|
||||
User.name_like("uniqueid2").map(&:id).should == []
|
||||
|
||||
p1 = user1.pseudonyms.new :unique_id => "uniqueid1", :account => @account
|
||||
p1.sis_user_id = "sisid1"
|
||||
p1.save!
|
||||
p2 = user2.pseudonyms.new :unique_id => "uniqueid2", :account => @account
|
||||
p2.sis_user_id = "sisid2"
|
||||
p2.save!
|
||||
|
||||
User.name_like("longname1").map(&:id).should == [user1.id]
|
||||
User.name_like("shortname2").map(&:id).should == [user2.id]
|
||||
User.name_like("sisid1").map(&:id).should == [user1.id]
|
||||
User.name_like("uniqueid2").map(&:id).should == [user2.id]
|
||||
|
||||
p3 = user1.pseudonyms.new :unique_id => "uniqueid3", :account => @account
|
||||
p3.sis_user_id = "sisid3"
|
||||
p3.save!
|
||||
|
||||
User.name_like("longname1").map(&:id).should == [user1.id]
|
||||
User.name_like("shortname2").map(&:id).should == [user2.id]
|
||||
User.name_like("sisid1").map(&:id).should == [user1.id]
|
||||
User.name_like("uniqueid2").map(&:id).should == [user2.id]
|
||||
User.name_like("uniqueid3").map(&:id).should == [user1.id]
|
||||
|
||||
p4 = user1.pseudonyms.new :unique_id => "uniqueid4", :account => @account
|
||||
p4.sis_user_id = "sisid3 2"
|
||||
p4.save!
|
||||
|
||||
User.name_like("longname1").map(&:id).should == [user1.id]
|
||||
User.name_like("shortname2").map(&:id).should == [user2.id]
|
||||
User.name_like("sisid1").map(&:id).should == [user1.id]
|
||||
User.name_like("uniqueid2").map(&:id).should == [user2.id]
|
||||
User.name_like("uniqueid3").map(&:id).should == [user1.id]
|
||||
User.name_like("sisid3").map(&:id).should == [user1.id]
|
||||
|
||||
user3 = User.create! :name => "longname1", :short_name => "shortname3"
|
||||
user3.register!
|
||||
|
||||
User.name_like("longname1").map(&:id).should == [user1.id, user3.id]
|
||||
User.name_like("shortname2").map(&:id).should == [user2.id]
|
||||
User.name_like("sisid1").map(&:id).should == [user1.id]
|
||||
User.name_like("uniqueid2").map(&:id).should == [user2.id]
|
||||
User.name_like("uniqueid3").map(&:id).should == [user1.id]
|
||||
User.name_like("sisid3").map(&:id).should == [user1.id]
|
||||
|
||||
User.name_like("sisid3").map(&:id).should == [user1.id]
|
||||
User.name_like("uniqueid4").map(&:id).should == [user1.id]
|
||||
p4.destroy
|
||||
User.name_like("sisid3").map(&:id).should == [user1.id]
|
||||
User.name_like("uniqueid4").map(&:id).should == []
|
||||
|
||||
end
|
||||
|
||||
context "move_to_user" do
|
||||
it "should delete the old user" do
|
||||
|
|
Loading…
Reference in New Issue