Permalink
Browse files

FEATURE: new API to search for a user by email

  • Loading branch information...
SamSaffron committed Nov 9, 2017
1 parent 2d5bf07 commit 06365023c4f215bb6867efe7e41bf740c919586b
Showing with 18 additions and 0 deletions.
  1. +4 −0 lib/admin_user_index_query.rb
  2. +14 −0 spec/components/admin_user_index_query_spec.rb
@@ -114,6 +114,10 @@ def filter_by_user_with_bypass(filter)
end
def filter_by_search
if params[:email].present?
return @query.where('user_emails.email = ?', params[:email].downcase)
end
filter = params[:filter]
if filter.present?
filter.strip!
@@ -188,6 +188,20 @@ def real_users_count(query)
expect(query.to_sql.downcase).not_to include("ilike")
end
it "can correctly bypass expensive ilike query" do
user = Fabricate(:user, email: 'sam2@Sam.com')
query = AdminUserIndexQuery.new(email: 'Sam@sam.com').find_users_query
expect(query.count).to eq(0)
expect(query.to_sql.downcase).not_to include("ilike")
query = AdminUserIndexQuery.new(email: 'Sam2@sam.com').find_users_query
expect(query.first.id).to eq(user.id)
expect(query.count).to eq(1)
expect(query.to_sql.downcase).not_to include("ilike")
end
end
context "by email fragment" do

3 comments on commit 0636502

@discoursebot

This comment has been minimized.

Show comment
Hide comment
@discoursebot

discoursebot Nov 9, 2017

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/discourse-api-searching-users-by-email/23097/16

discoursebot replied Nov 9, 2017

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/discourse-api-searching-users-by-email/23097/16

@discoursebot

This comment has been minimized.

Show comment
Hide comment
@discoursebot

discoursebot Nov 9, 2017

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/api-best-way-to-get-user-details-by-email/20806/10

discoursebot replied Nov 9, 2017

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/api-best-way-to-get-user-details-by-email/20806/10

@discoursebot

This comment has been minimized.

Show comment
Hide comment
@discoursebot

discoursebot Nov 9, 2017

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/use-the-api-to-find-a-username-based-on-an-email/45424/6

discoursebot replied Nov 9, 2017

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/use-the-api-to-find-a-username-based-on-an-email/45424/6

Please sign in to comment.